Click here to Skip to main content
Email Password   helpLost your password?

Cosmos?

Cosmos is short 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 VBOSMOS just does not sound as nice.

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.

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 www.GoCosmos.org..

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

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.

Conclusion

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!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalvery nice!!
ikookal
14:02 2 Jan '10  
very nice project,

I´ll be watching it.

since the last post somewhere in september 2008 any more news about the grafics?
QuestionFile Systems
aaronlego2
12:27 19 Dec '09  
Are the file systems ready for reading and writing yet?
I've made a GUI with COSMOS, (can be seen in link in sig.) and someone was asking about an old DOS command "tree". From the one second of Googling I've done [I'm not old enough to know DOS], I think it displays files and folders. Is this possible as of yet in COSMOS?


AnswerRe: File Systems
Matthijs ter Woord
21:34 19 Dec '09  
Reading definitely works, writing not sure. Some work has been done on that, but dont know the real status of that.

If you're interested, please join our chat room or mailinglist (see www.gocosmos.org for more info)

Regards,

Matthijs ter Woord
GeneralRe: File Systems
aaronlego2
9:13 20 Dec '09  
cool! thank you!


QuestionCosmos.Hardware.PC.Bus.PCIBus.Devices Missing Namespace
Nathan Campos
9:14 4 Nov '09  
Hello,
When I try to implement a PCI device scan function I got an error saying that the namespace Hardware is missing and in the Documentation you said about this, but don't say about where it is located now.

Thanks,
Nathan Paulino Campos
QuestionCan I use it to develop my own OS
Nathan Campos
11:04 3 Nov '09  
Hello,
I'm thinking in create my own OS, but if I use your library I can distribute it?

Thanks,
Nathan Paulino Campos
AnswerRe: Can I use it to develop my own OS
Chad Z. Hower aka Kudzu
11:10 3 Nov '09  
Yes, thats what its designed for.

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

GeneralRe: Can I use it to develop my own OS
Nathan Campos
13:02 3 Nov '09  
Thanks very much, this project is so big and very useful! Wink
QuestionGreat work so far... But...
bj7lewis@live.com
4:58 12 Oct '09  
Hello,

Great work so far with Cosmos development... But what about for the OS projects of your readers? Seems like you got one project in the Cosmos User kit(couldn't find access to the dev kit) where you could split it up into subprojects (i.e.. il2CPU, General HW/BOOT/Debugger library, & Cosmos Barebones)...

These subprojects will then give your readers access to different parts of the project based on there needs. Like I am only mainly interested in the il2CPU C# -> native code part and it was only a Google search for "C# OS dev JIT" keywords that lead me to your article. I like to work on my own boot/loader/kernel codes like I would if it were C++ OS DEV project - just instead of C++ now C#...

I used to be more into OS DEV in C++ then I had to abandoned(because lack of free time) it for a while and now coming back to OS DEV I decided to check out C# OS DEV so myself and other reader could benefit from the second subproject General HW/BOOT/Debugger library until we can adapt our own boot/loader/kernel codes for C# OS DEV...

Like I say I am more interested in the mainly il2CPU part so I am not really in interested in the third subproject Cosmos Barebones which would be setting up the system (i.e. PMODE/GDT/IDT/... specific run Cosmos). Some reader could use this subproject as a barebones to join your team and further Cosmos as an OS. Other reader(like me) can use this subproject as test to see a demo of C# OS DEV working before they/I start adapt our own boot/loader/kernel codes for C# OS DEV...

OH well... Great work so far... Looking forwar to seeing more... Again I ask - What about for the OS projects of your readers?

Good luck...
AnswerRe: Great work so far... But...
ben.Kloosterman
21:19 12 Oct '09  
Dev kit is normally just the source repository download. This is split into many projects but for the userkit has it merged for people who use the free version of Visual Studio.

Cosmos will evolve to be a more modular system though this is a bit hard due to compiler customizations/dependencies at the moment.

The OS project itself is bare bones as we only have a few people working on the il2cpu part this is holding back creating better projects eg il2cpu has no float support which is being worked on.


Check out yahoo group if you would like to know more
Cosmos-Dev@yahoogroups.com


Ben

Ben

GeneralRe: Great work so far... But...
bj7lewis@live.com
17:25 14 Oct '09  
Thanks for your reply...

Thanks for the pointing the way to the dev kit - I missed the final link (on the right source snapshot select page) somehow when I view the source online...

Well - I took a look and there is a lot to sort through - it is a bit much for me to make heads or tails of to even find a place to start understanding what is what at this time - with my time still a bit limited...

Well for now I think I will look into Ngen since it is just a cmd to run - and not 70 projects to sort through...

I understand where you are in devlopment and do think it is a great work so far - and still look forward to more...

Good luck...
QuestionMethod Not Found
bjuraga
8:33 17 Sep '09  
Hi i just downloaded the User Kit and installed it correctly
It shows in VS2008 and it creates the project perfectly

But when i run it (F5) it shows error ... Method Not Found...

What can be cosing this and has someone else seen this and solved it?

[Edit]
System.MissingMethodException was unhandled
Message="Method not found: 'System.Object System.Windows.Threading.Dispatcher.Invoke(System.Delegate, System.Object[])'."
Source="Cosmos.Compiler.Builder"
StackTrace:
at Cosmos.Compiler.Builder.BuildUC.aBuilder_LogMessage(LogSeverityEnum aSeverity, String aMessage)
at Cosmos.Compiler.Builder.Builder.OnLogMessage(LogSeverityEnum aSeverity, String aMessage)
at Cosmos.Compiler.Builder.Builder.ThreadExecute(Object aParam)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
InnerException:

[/Edit]

If You need more info feel free to ask
AnswerRe: Method Not Found
Chad Z. Hower aka Kudzu
9:15 17 Sep '09  
Do you have VS 2008 SP1 installed?

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

GeneralRe: Method Not Found [modified]
bjuraga
10:01 17 Sep '09  
No,

i have tested the Milestone1 and it works,
but the Milestone 3 not, so...?

OK i missed the SP1 being "Recommended" or "Obligatory" but no problem
Can i just use .NET 3.5 SP1 or i have to upgrade VS?

modified on Thursday, September 17, 2009 3:32 PM

GeneralRe: Method Not Found
Chad Z. Hower aka Kudzu
10:58 17 Sep '09  
Try applying SP1, later builds we built against SP1 and it also updates the .NET framework and some new methods were added that we rely on.

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

GeneralRe: Method Not Found
bjuraga
11:00 17 Sep '09  
Ok, thanks issue resolved than

KEEP THE AWESOME WORK ! ! !
QuestionGraphic card drivers?
vasil_ek
23:33 13 Aug '09  
Hi,

First of all this is a wonderful project!
Congratulations for everyone involved.

I was wondering when you come to the graphics will you be able to write drivers for graphic cards of ATI and NVIDIA? What I mean is will there be a fully accelerated 3d or you will supply only VGA/SuperVGA support?
AnswerRe: Graphic card drivers?
Chad Z. Hower aka Kudzu
4:47 14 Aug '09  
Writing full graphics drivers is some ways off yet. We are currently speeding up the compiler and working on other areas. We feel its very important to have an absolutely solid foundation before moving to such areas.

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

QuestionIL2CPU = Manual NGen?
Philip Laureano
21:57 5 Aug '09  
Is there anyway to use IL2CPU to precompile IL into native x86 instructions? For example, could I use it to statically link an entire assembly that runs off .NET 2.x so that it runs completely independent of the CLR? It would be amazing to be able to see this run off a native EXE without an underlying CLR, but I'm not sure if we're talking about the same thing here. Is this even possible with IL2CPU?

Do you know...LinFu?

AnswerRe: IL2CPU = Manual NGen?
Chad Z. Hower aka Kudzu
7:52 6 Aug '09  
Our first prototypes compiled exe files for Windows and did what you ask. However they had a lot of limitations and was only a way point for us, so we removed support for this once we got Cosmos booting.

There are several commercial products that do what you want.

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

GeneralRe: IL2CPU = Manual NGen?
Philip Laureano
14:31 6 Aug '09  
Chad Z. Hower aka Kudzu wrote:
Our first prototypes compiled exe files for Windows and did what you ask. However they had a lot of limitations and was only a way point for us, so we removed support for this once we got Cosmos booting.


But didn't you say that you were eventually going to rewrite IL2CPU so that it generates native instructions instead of NASM assembly files?


Chad Z. Hower aka Kudzu wrote:
There are several commercial products that do what you want.


There might be some commercial alternatives out there, but the problem is that they're not open source and they certainly won't let you look at their code base (much less allow you to modify it).

The reason why I'm so curious about this is that a few years ago, there was a DNR podcast about .NET obfuscation from a guy named Huihong Luo who claimed that he could take any .NET executable and compile it down to the native x86 instructions so that it could run on both Linux and Windows without an underlying CLR. Suffice to say, application virtualization is some pretty crazy stuff, and I wonder if it would be possible to use part of Cosmos to pull it off...

Do you know...LinFu?

GeneralRe: IL2CPU = Manual NGen?
Chad Z. Hower aka Kudzu
15:24 6 Aug '09  
Philip Laureano wrote:
But didn't you say that you were eventually going to rewrite IL2CPU so that it generates native instructions instead of NASM assembly files?


It can already do that. We are rewriting the scanner and compiler currently though to be faster.

Philip Laureano wrote:
.NET executable and compile it down to the native x86 instructions so that it could run on both Linux and Windows without an underlying CLR


You could modify the Cosmos compiler to do so, but we are targetting it to run on bare metal as an OS. Currently x86 and later ARM and others. You could easily use our plug system to supply OS API calls instead of our OS code.

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

My Technical Stuff:
http://www.KudzuWorld.com

My Blogs:
http://www.KudzuWorld.com/blogs/

Generalgraphic user interface
oexc0
11:51 21 Jun '09  
i think that it is important that i can draw to the screen and handle mouse/keyboard events,but i don't think that you should support WPF or anything that uses xaml because i am using .net 2.0 and i am not planning to install vs2008 or .NET framework > 2.0.
GeneralRe: graphic user interface
ben.Kloosterman
16:15 5 Jul '09  
As explained going to VS2005 is not really possible. Any maintained software on the net is going to be VS2008 ( as it upgrades the solution and project files) , to make it worse we add VS addons so you can debug and build the OS which are not backward compatible.

At this time we have VGA ( as in 640 * 480) and mouse working but not much more. We do eventually plan to support Silverlight via Mono Moonlight.

Ben

GeneralI don't have vs2008
oexc0
10:06 21 Jun '09  
the project should be converted to vs2005 format.


Last Updated 21 Sep 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010