Click here to Skip to main content
11,927,324 members (51,338 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


309 bookmarked

Cosmos - C# Open Source Managed Operating System

, 23 Jul 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Build your own OS in Visual Studio and C#.


Cosmos is an acronym for C# Open Source Managed Operating System. Despite C# being in the name, VB.NET, Fortran, and any .NET language can be used. We chose the C# title because our work is done in C#, and because VBOSMOS sounds stupid.

Cosmos is not an Operating System in the traditional sense, but instead, it is an "Operating System Kit", or as I like to say "Operating System Legos", that allows you to create your own Operating System. However, having been down this path before, we wanted to make it easy to use and build. Most users can write and boot their own Operating System in just a few minutes, and using Visual Studio.

Cosmos lets Visual Studio compile your code to IL and then Cosmos compiles the IL into machine code.


This article was originally written in 2008. Cosmos has come a long way since then and many of the screens, especially the build process, look significantly different now. If you like what you see here, I strongly suggest you check out the more recent builds as we have made a lot of progress since then.

Dev Kit or User Kit?

Cosmos comes in two flavors, a user kit and a dev kit. The user kit hides the kernel source away from the user, and presents a new project type in File, New. Building a new Operating System is as simple as File, New, writing a few lines of code, and pressing F5 to build and run it. The user kit is a bit old though, and is really only designed to interest people in obtaining the dev kit.

The dev kit is available as a project on CodePlex, and the Cosmos website is

Dev Kit

To get the dev kit, simply sync the sources from the CodePlex project. It might appear daunting at first, 43 projects? A lot of these projects are demos, tests, and playgrounds.

Note that Visual Studio Express cannot handle the solution folders. Because of this, Express users should use the Flat solution file, but first, you must update the Flat solution file from the main solution using the Flat file updater utility.

In the Boot folder, and then the Demo folder, you will see a CosmosBoot project. This is the empty shell used in the user kit for the new project template. This is the minimal Operating System that Cosmos can build. You can copy this file and change it to your needs. Let's take a quick look.

Properties and References are standard parts of any .NET project. Let's look in Program.cs.

Note on images: CodeProject limits images to 600 pixels in width. I've chosen to crop the width to retain readability.

Init is the entry point that will be called after the system is booted. This is where you put your code. Some sample code has been generated already, and you can change it. Be sure to leave the first two lines alone, they initialize memory, hardware, etc.

Let's take a look at something a little more complex though. Here is a demo called Guess. It is a simple application which asks the user to guess a number. As you can see, it is all standard C# code, and aside from the first two lines for booting, the code can function unchanged on Windows.

Now, let's run it. Are you expecting some complicated process involving batch files and CD-R's? If so, you will be disappointed. Simply press F5 in Visual Studio to run it. Instead of the project running immediately, you will see a Cosmos Builder Options window.

The builder supports many environments including physical hardware. Virtual Machines are easier to develop against, and are certainly easier to take screenshots of, so I will use VMWare for this article.

With these options set, I clicked the Build button (the Enter key also proceeds). Next, a build progress window will appear. Cosmos is now compiling the IL to machine code, linking and preparing the boot image.

When this is done, the window will disappear, and VMWare will automatically be launched with an ISO mounted.

Select "Power on this virtual machine", and the Guess demo will boot.

This is the demo, booted directly to hardware. There is no need for Windows, Linux, or any other Operating System to run this code. During the boot process, you may notice SysLinux. The SysLinux however is not a Linux distribution, but instead, just a boot loader used to read files from the disk. We use SysLinux instead of Grub because it has support for PXE and other options. SysLinux is only used for the initial loading of the Cosmos binaries, and as soon as Cosmos is loaded, SysLinux is unloaded, and is not used to run Cosmos code.

Graphics, Network, File Systems

Ease of use, or what I like to call "Nail the basics", is a priority for us. However, graphics and other things will follow in the future. Currently, we are working on a wide range of file systems including FAT and ext2. We are also working on Ethernet support, and can already send basic UDP packets, and are working on TCP support as well.


Debugging Operating Systems is typically inconvenient and hinders progress. Because of this, just as we did with making the build and boot process, we strived to make the debugging process easy. The debugger is still a work in progress, but is already quite advanced for an Operating System debugger.

Adding the Cosmos.Debug namespace gives the code access to communicate directly with the debugger.

In the Guess demo, I am adding a Debugger.Send, which will write a debug string to the debugger. This can be used to track code execution, but can also be used for watching variables. In this case, I will use it to write out the magic number.

Notice I have also added a Debugger.Break. This will force the program to execute a breakpoint at that location.

Now, let's run the Guess again. Which demo is booted is selected in Visual Studio simply by selecting it as the startup project for the solution.

This time in debugger options, Source and User Only is selected. Source tells the debugger to debug C# code, rather than the lower level IL. And, User Only tells the debugger not to trace into the Cosmos Kernel or the .NET libraries. This speeds up execution, but also lets me focus on tracing just the demo code.

Note that this time it did prompt us for the number? This is because it hit the breakpoint. Another window will appear as well, this is the Cosmos Debugger.

The message and breakpoint are displayed in the trace log, and the code is selected for the breakpoint. Breakpoints occur on the next statement after the requested break.

Now, we can use the Step button (F11, just like Visual Studio) to step through the code. Each step is recorded in the trace log, and previous items can be selected to walk backwards through the code. The trace log functions similar to the call stack window in Visual Studio.

Press continue (F5), and the code will run again until a breakpoint is encountered in the code, or requested from the debugger. After Continue, a new button will appear that allows a forced instant break. After Continue, the code will continue, and we will be prompted for the number.

We can also turn tracing on and off for specific sections of code, using the Cosmos.Debug namespace.

This will cause the trace log to be populated with all the statement executions between the TraceOn and TraceOff, without needing to step through each statement manually.

This time Cosmos & User is selected to show more details in the trace log. Normally, this option is only needed by developers working on the Cosmos kernel source.


Cosmos is an open source project, as included as part of its name. I hope this article gives an easy to understand introduction. If you are interested in Operating System development, I hope you will try Cosmos!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chad Z. Hower, a.k.a. Kudzu
"Programming is an art form that fights back"

Formerly the Regional Developer Adviser (DPE) for Microsoft Middle East and Africa, he was responsible for 85 countries spanning 4 continents and 10 time zones. Now Chad is a Microsoft MVP.

Chad is the chair of several popular open source projects including Indy and Cosmos (C# Open Source Managed Operating System).

Chad is the author of the book Indy in Depth and has contributed to several other books on network communications and general programming.

Chad has lived in Canada, Cyprus, Switzerland, France, Jordan, Russia, Turkey, and the United States. Chad has visited more than 60 countries, visiting most of them several times.

You may also be interested in...

Comments and Discussions

QuestionCosmos on a bare metal device? Pin
Austin Mullins24-Jul-14 9:42
memberAustin Mullins24-Jul-14 9:42 
AnswerRe: Cosmos on a bare metal device? Pin
Chad Z. Hower aka Kudzu25-Jul-14 8:00
memberChad Z. Hower aka Kudzu25-Jul-14 8:00 
GeneralMy vote of 5 Pin
Member 1022385427-Feb-14 6:24
memberMember 1022385427-Feb-14 6:24 
GeneralMy vote of 4 Pin
Mic8-Aug-13 13:27
memberMic8-Aug-13 13:27 
Very Good
GeneralMy vote of 5 Pin
Gun Gun Febrianza7-Jun-13 19:43
member Gun Gun Febrianza7-Jun-13 19:43 
GeneralMy vote of 5 Pin
CS140118-Oct-11 21:57
memberCS140118-Oct-11 21:57 
GeneralMy vote 5/5 Pin
Gerallt G. Franke20-Jul-11 4:20
memberGerallt G. Franke20-Jul-11 4:20 
GeneralMy vote of 5 Pin
Gerallt G. Franke20-Jul-11 4:18
memberGerallt G. Franke20-Jul-11 4:18 
GeneralMy vote of 5 Pin
Filip D'haene31-May-11 5:46
memberFilip D'haene31-May-11 5:46 
GeneralMy vote of 5 Pin
xComaWhitex15-Jan-11 0:17
memberxComaWhitex15-Jan-11 0:17 
GeneralNew updated release and article! Pin
Chad Z. Hower aka Kudzu6-Aug-10 16:53
memberChad Z. Hower aka Kudzu6-Aug-10 16:53 
QuestionError Pin
WildN00b22-Jul-10 2:32
memberWildN00b22-Jul-10 2:32 
AnswerRe: Error Pin
Matthijs ter Woord22-Jul-10 2:53
memberMatthijs ter Woord22-Jul-10 2:53 
GeneralCosmos.Compiler.Builder Pin
joe10429-May-10 23:43
memberjoe10429-May-10 23:43 
GeneralRe: Cosmos.Compiler.Builder Pin
Chad Z. Hower aka Kudzu31-May-10 10:20
memberChad Z. Hower aka Kudzu31-May-10 10:20 
GeneralReading / Writing to disk Pin
xlar5414-Apr-10 21:01
memberxlar5414-Apr-10 21:01 
GeneralRe: Reading / Writing to disk Pin
Chad Z. Hower aka Kudzu18-Apr-10 15:05
memberChad Z. Hower aka Kudzu18-Apr-10 15:05 
GeneralError Pin
Thomas de Roo7-Mar-10 10:24
memberThomas de Roo7-Mar-10 10:24 
GeneralRe: Error Pin
Chad Z. Hower aka Kudzu14-Mar-10 9:25
memberChad Z. Hower aka Kudzu14-Mar-10 9:25 
QuestionShow Image Pin
Rex 12411-Mar-10 8:42
memberRex 12411-Mar-10 8:42 
AnswerRe: Show Image Pin
ben.Kloosterman1-Mar-10 13:48
memberben.Kloosterman1-Mar-10 13:48 
AnswerRe: Show Image Pin
bader115-Mar-10 13:30
memberbader115-Mar-10 13:30 
GeneralFiles Pin
MatheusMK313-Feb-10 12:59
memberMatheusMK313-Feb-10 12:59 
GeneralRe: Files Pin
Thomas de Roo7-Mar-10 9:48
memberThomas de Roo7-Mar-10 9:48 
Generalvery nice!! Pin
ikookal2-Jan-10 14:02
memberikookal2-Jan-10 14:02 
QuestionFile Systems Pin
aaronlego219-Dec-09 12:27
memberaaronlego219-Dec-09 12:27 
AnswerRe: File Systems Pin
Matthijs ter Woord19-Dec-09 21:34
memberMatthijs ter Woord19-Dec-09 21:34 
GeneralRe: File Systems Pin
aaronlego220-Dec-09 9:13
memberaaronlego220-Dec-09 9:13 
QuestionCosmos.Hardware.PC.Bus.PCIBus.Devices Missing Namespace Pin
Nathan Campos4-Nov-09 9:14
memberNathan Campos4-Nov-09 9:14 
QuestionCan I use it to develop my own OS Pin
Nathan Campos3-Nov-09 11:04
memberNathan Campos3-Nov-09 11:04 
AnswerRe: Can I use it to develop my own OS Pin
Chad Z. Hower aka Kudzu3-Nov-09 11:10
memberChad Z. Hower aka Kudzu3-Nov-09 11:10 
GeneralRe: Can I use it to develop my own OS Pin
Nathan Campos3-Nov-09 13:02
memberNathan Campos3-Nov-09 13:02 
QuestionGreat work so far... But... Pin
bj7lewis@live.com12-Oct-09 4:58
memberbj7lewis@live.com12-Oct-09 4:58 
AnswerRe: Great work so far... But... Pin
ben.Kloosterman12-Oct-09 21:19
memberben.Kloosterman12-Oct-09 21:19 
GeneralRe: Great work so far... But... Pin
bj7lewis@live.com14-Oct-09 17:25
memberbj7lewis@live.com14-Oct-09 17:25 
QuestionMethod Not Found Pin
bjuraga17-Sep-09 8:33
memberbjuraga17-Sep-09 8:33 
AnswerRe: Method Not Found Pin
Chad Z. Hower aka Kudzu17-Sep-09 9:15
memberChad Z. Hower aka Kudzu17-Sep-09 9:15 
GeneralRe: Method Not Found [modified] Pin
bjuraga17-Sep-09 10:01
memberbjuraga17-Sep-09 10:01 
GeneralRe: Method Not Found Pin
Chad Z. Hower aka Kudzu17-Sep-09 10:58
memberChad Z. Hower aka Kudzu17-Sep-09 10:58 
GeneralRe: Method Not Found Pin
bjuraga17-Sep-09 11:00
memberbjuraga17-Sep-09 11:00 
QuestionGraphic card drivers? Pin
vasil_ek13-Aug-09 23:33
membervasil_ek13-Aug-09 23:33 
AnswerRe: Graphic card drivers? Pin
Chad Z. Hower aka Kudzu14-Aug-09 4:47
memberChad Z. Hower aka Kudzu14-Aug-09 4:47 
QuestionIL2CPU = Manual NGen? Pin
Philip Laureano5-Aug-09 21:57
memberPhilip Laureano5-Aug-09 21:57 
AnswerRe: IL2CPU = Manual NGen? Pin
Chad Z. Hower aka Kudzu6-Aug-09 7:52
memberChad Z. Hower aka Kudzu6-Aug-09 7:52 
GeneralRe: IL2CPU = Manual NGen? Pin
Philip Laureano6-Aug-09 14:31
memberPhilip Laureano6-Aug-09 14:31 
GeneralRe: IL2CPU = Manual NGen? Pin
Chad Z. Hower aka Kudzu6-Aug-09 15:24
memberChad Z. Hower aka Kudzu6-Aug-09 15:24 
Generalgraphic user interface Pin
oexc021-Jun-09 11:51
memberoexc021-Jun-09 11:51 
GeneralRe: graphic user interface Pin
ben.Kloosterman5-Jul-09 16:15
memberben.Kloosterman5-Jul-09 16:15 
GeneralI don't have vs2008 Pin
oexc021-Jun-09 10:06
memberoexc021-Jun-09 10:06 
GeneralRe: I don't have vs2008 Pin
ben.Kloosterman5-Jul-09 16:08
memberben.Kloosterman5-Jul-09 16:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 23 Jul 2014
Article Copyright 2008 by Chad Z. Hower aka Kudzu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid