Click here to Skip to main content
11,432,168 members (60,241 online)
Click here to Skip to main content

Develop Your Own Operating System in C# or VB.NET

, 12 Aug 2010 BSD
Rate this:
Please Sign up or sign in to vote.
Develop your own operating system using C# (or VB.NET, etc.) and Visual Studio!

Introducing Cosmos

Cosmos (C# Open Source Managed Operating System) is an operating system development kit which uses Visual Studio as its development environment. Despite C# in the name, any .NET based language can be used including VB.NET, Fortran, Delphi Prism, IronPython, F# and more. Cosmos itself and the kernel routines are primarily written in C#, and thus the Cosmos name. Besides that, NOSMOS (.NET Open Source Managed Operating System) 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". Cosmos lets you create operating systems just as Visual Studio and C# normally let you create applications. Most users can write and boot their own operating system in just a few minutes, all using Visual Studio. Milestone 5 includes new features such as an integrated project type in Visual Studio, and an integrated debugger. You can debug your operating system directly from Visual Studio using breakpoints.

Cosmos is available in two distributions, the developer kit (dev kit), and the user kit. The dev kit is designed for users who want to work on Cosmos itself. The user kit is designed for those who are interested in building their own operating system and doing some Cosmos work. The dev kit might be thought of as the Cosmos SDK. Most users should start off with the user kit as it is not so overwhelming like the dev kit. This article focuses on the user kit.

Writing Your First Operating System

Create a new project as you would any C# project, but select Cosmos as the project type.

A starter project will be created. It looks very much like a standard C# console application.

Program.cs contains the boot and execution code. Instead of seeing a Windows console window, you will see the following:

This is your operating system running in VMWare Player! Cosmos can of course also be booted in VMWare Workstation, Hyper-V, Virtual PC, or on real hardware. But by default, Cosmos uses VMWare Player because it is both free, and reliable. Cosmos can even debug in Visual Studio, even when running on another machine.

Integrated Debugging

Debugging is a major issue with operating system development. The Cosmos team was not content enough to simply conquer building and deployment, we want to make developing operating system as easy as developing Windows applications. Debugging a Cosmos based operating system should feel very familiar to you. Let's modify our project a little bit to show the effect, and set a breakpoint.

Now run the project again.

Note that the execution stopped at "One"? That is because in Visual Studio, our project has stopped on a breakpoint. Simply press F5 to continue just as you would in a normal application!

In addition to breakpoints, Cosmos also supports step into (F11) as well. Trace over (F10) is not supported yet.

Debugger Communication

The debugger uses the serial port to communicate. Because of this, debugging only works with virtualization environments that support serial ports such as VMWare. QEMU supports serial ports as well, but its serial port implementation is seriously broken on Windows and makes debugging impossible using QEMU. To debug on real hardware, you must use a physical serial cable. In the future, Cosmos will also support debugging over Ethernet.

Extra Debugging

Cosmos supports some explicit methods that can be used to communicate with the debugger and use additional functionality. It is accessed using the Debugger class in the Cosmos.Debug namespace in the Cosmos.Kernel assembly. This assembly is used by all Cosmos projects.

Code Based Breakpoints

Debugger.Break();

Break can be used to issue a code based break. Visual Studio will break on the line after this statement.

Since Cosmos does not support conditional breaks in the IDE yet, code base breaks are very useful for implementing such. For example:

if (x == 5) {
    Debugger.Break();
}

Alternatively, you can call the .NET class library break:

System.Diagnostics.Debugger.Break();

Both functions will produce the same result.

Debug Output

Debug strings can be output to the debug window of the host. Because Cosmos does not support watches yet, this functionality can be very useful for watching variable values and for performing tracing without breakpoints.

Debugger.Send("Hello from Cosmos!");

When this line is executed, it will send a message over the debugging channel and it will appear in the Visual Studio output window.

What's the Catch?

There really is no catch. Everything I've shown here is functioning as seen. No mockups were used. However we still have a lot of work to go. Items of interest that are on our current task list include interfaces (necessary for foreach), file systems (partial support exists), threads, networking, and graphics. We have prototypes and experimentation for each, but none have been rolled into the mainline Cosmos development as of yet.

What Was That Syslinux Thing I Saw on Boot?

Cosmos does not run on Linux. A boot loader called Syslinux is used to boot Cosmos. After booting, Syslinux is not used. Syslinux is a bootloader and is not a Linux distro.

Obtaining Cosmos

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

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

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.

Comments and Discussions

 
GeneralRe: [My vote of 1] is this joke ?? Pin
Member 963207718-Jul-13 6:08
memberMember 963207718-Jul-13 6:08 
GeneralRe: [My vote of 1] is this joke ?? Pin
Matthijs ter Woord18-Jul-13 6:24
memberMatthijs ter Woord18-Jul-13 6:24 
GeneralRe: [My vote of 1] is this joke ?? Pin
Connor Harries7-Oct-13 12:51
memberConnor Harries7-Oct-13 12:51 
AnswerRe: [My vote of 1] is this joke ?? Pin
Dan Suthar19-Jul-13 9:00
memberDan Suthar19-Jul-13 9:00 
QuestionCan i install it as application for checking bootable cd and asking for pass on startup Pin
RAHUL7775830-Jul-12 4:50
memberRAHUL7775830-Jul-12 4:50 
AnswerRe: Can i install it as application for checking bootable cd and asking for pass on startup Pin
Matthijs ter Woord30-Jul-12 5:19
memberMatthijs ter Woord30-Jul-12 5:19 
GeneralRe: Can i install it as application for checking bootable cd and asking for pass on startup Pin
RAHUL7775830-Jul-12 5:27
memberRAHUL7775830-Jul-12 5:27 
GeneralMy vote of 5 Pin
Md. Rashidul Hasan Masum27-Jul-12 4:52
memberMd. Rashidul Hasan Masum27-Jul-12 4:52 
GeneralMy vote of 5 Pin
Kim Togo27-Jun-12 0:11
memberKim Togo27-Jun-12 0:11 
GeneralMy vote of 5 Pin
Nithin Rudraswamy21-Jun-12 3:23
memberNithin Rudraswamy21-Jun-12 3:23 
GeneralMy vote of 5 Pin
Chintanhiremath10-Jun-12 20:40
memberChintanhiremath10-Jun-12 20:40 
QuestionThis is very, very, very cool! Pin
Zac Greve10-Apr-12 20:25
memberZac Greve10-Apr-12 20:25 
QuestionSo it needs windows to run ? Pin
Xmen W.K.3-Mar-12 6:49
memberXmen W.K.3-Mar-12 6:49 
AnswerRe: So it needs windows to run ? Pin
HuntrCkr3-Mar-12 19:47
memberHuntrCkr3-Mar-12 19:47 
GeneralRe: So it needs windows to run ? Pin
Xmen W.K.3-Mar-12 22:31
memberXmen W.K.3-Mar-12 22:31 
GeneralRe: So it needs windows to run ? Pin
Matthijs ter Woord3-Mar-12 23:09
memberMatthijs ter Woord3-Mar-12 23:09 
GeneralRe: So it needs windows to run ? Pin
Xmen W.K.4-Mar-12 6:22
memberXmen W.K.4-Mar-12 6:22 
GeneralMy vote of 5 Pin
manoj kumar choubey1-Feb-12 20:13
membermanoj kumar choubey1-Feb-12 20:13 
GeneralMy vote of 5 Pin
CS140118-Oct-11 21:44
memberCS140118-Oct-11 21:44 
Questionhow can i write or read from disk Pin
juanico1714-Oct-11 15:38
memberjuanico1714-Oct-11 15:38 
AnswerRe: how can i write or read from disk Pin
Chad Z. Hower aka Kudzu17-Oct-11 14:18
memberChad Z. Hower aka Kudzu17-Oct-11 14:18 
QuestionCOSMOS will not do anything [modified] Pin
Kodemaster12318-Aug-11 19:12
memberKodemaster12318-Aug-11 19:12 
AnswerRe: COSMOS will not do anything... Yes it will Pin
Kodemaster12318-Aug-11 19:42
memberKodemaster12318-Aug-11 19:42 
AnswerRe: COSMOS will not do anything Pin
Chad Z. Hower aka Kudzu19-Aug-11 4:27
memberChad Z. Hower aka Kudzu19-Aug-11 4:27 
QuestionMy vote 5/5 Pin
Gerallt G. Franke20-Jul-11 4:23
memberGerallt G. Franke20-Jul-11 4:23 
GeneralMy vote of 5 Pin
Gerallt G. Franke20-Jul-11 4:21
memberGerallt G. Franke20-Jul-11 4:21 
GeneralMy vote of 5 Pin
Rudi Kruger11-Jul-11 23:39
memberRudi Kruger11-Jul-11 23:39 
GeneralMy vote of 5 Pin
xExTxCx29-Jun-11 10:22
memberxExTxCx29-Jun-11 10:22 
GeneralMy vote of 4 Pin
Sushil Kumar Purohit27-Apr-11 20:34
memberSushil Kumar Purohit27-Apr-11 20:34 
GeneralMy vote of 5 Pin
leonguan17-Apr-11 5:10
memberleonguan17-Apr-11 5:10 
GeneralMy vote of 5 Pin
vishwavijay7-Mar-11 1:36
membervishwavijay7-Mar-11 1:36 
GeneralMy project Pin
xlar5414-Feb-11 19:29
memberxlar5414-Feb-11 19:29 
GeneralMy vote of 5 Pin
Anirudha_baba5-Feb-11 5:33
memberAnirudha_baba5-Feb-11 5:33 
QuestionVirtualBox support? Pin
xlar543-Feb-11 20:21
memberxlar543-Feb-11 20:21 
AnswerRe: VirtualBox support? Pin
Chad Z. Hower aka Kudzu4-Feb-11 6:15
memberChad Z. Hower aka Kudzu4-Feb-11 6:15 
QuestionSome Errors and Questions Pin
WildN00b12-Jan-11 9:47
memberWildN00b12-Jan-11 9:47 
AnswerRe: Some Errors and Questions Pin
Chad Z. Hower aka Kudzu23-Jan-11 14:14
memberChad Z. Hower aka Kudzu23-Jan-11 14:14 
AnswerRe: Some Errors and Questions Pin
steveoneill28-Apr-11 3:05
membersteveoneill28-Apr-11 3:05 
GeneralMy vote of 5 Pin
prasad025-Jan-11 19:15
memberprasad025-Jan-11 19:15 
GeneralMy vote of 5 Pin
ingenvzla17-Dec-10 5:57
memberingenvzla17-Dec-10 5:57 
GeneralMy vote of 5 Pin
Andy_L_J24-Oct-10 21:53
memberAndy_L_J24-Oct-10 21:53 
GeneralGreat work! Pin
Ant210013-Oct-10 10:17
memberAnt210013-Oct-10 10:17 
GeneralSystem.Exception: Plug needed. System.Boolean Microsoft.Win32.Win32Native.ReadConsoleInput(System.IntPtr, &Microsoft.Win32.Win32Native+InputRecord, System.Int32, &System.Int32) Pin
WildN00b12-Oct-10 9:31
memberWildN00b12-Oct-10 9:31 
GeneralRe: System.Exception: Plug needed. System.Boolean Microsoft.Win32.Win32Native.ReadConsoleInput(System.IntPtr, &Microsoft.Win32.Win32Native+InputRecord, System.Int32, &System.Int32) Pin
Chad Z. Hower aka Kudzu13-Oct-10 1:55
memberChad Z. Hower aka Kudzu13-Oct-10 1:55 
AnswerRe: System.Exception: Plug needed. System.Boolean Microsoft.Win32.Win32Native.ReadConsoleInput(System.IntPtr, &Microsoft.Win32.Win32Native+InputRecord, System.Int32, &System.Int32) [modified] Pin
Kodemaster12319-Aug-11 11:07
memberKodemaster12319-Aug-11 11:07 
GeneralRe: System.Exception: Plug needed. System.Boolean Microsoft.Win32.Win32Native.ReadConsoleInput(System.IntPtr, &Microsoft.Win32.Win32Native+InputRecord, System.Int32, &System.Int32) Pin
Chad Z. Hower aka Kudzu19-Aug-11 12:49
memberChad Z. Hower aka Kudzu19-Aug-11 12:49 
GeneralGood article Pin
CIDev11-Oct-10 2:53
memberCIDev11-Oct-10 2:53 
GeneralAwesome article Pin
The Manoj Kumar1-Oct-10 13:22
memberThe Manoj Kumar1-Oct-10 13:22 
GeneralMy vote of 5 Pin
Runa Jack20-Sep-10 22:07
memberRuna Jack20-Sep-10 22:07 
GeneralMy vote of 5 Pin
iDesmet20-Sep-10 21:50
memberiDesmet20-Sep-10 21:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web02 | 2.8.150428.2 | Last Updated 12 Aug 2010
Article Copyright 2010 by Chad Z. Hower aka Kudzu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid