Thursday, December 20, 2007

Getting the Juices Flowing

Well folks, if you've made it here, you can see that SharpOS now has a development blog. On the other side of things, if you have no idea what SharpOS is, then I should point you at our website – http://sharpos.sourceforge.net/ However, the website is under construction as part of a move (back) to http://www.sharpos.org/ . So, I'll introduce you to the project.

The SharpOS project aims to create an operating system using 100% C# code. A lot of programmers will respond to that thinking, "How is that even possible?" C# is a managed, JITed language. It compiles to CIL, which creates a safety net by being completely compiled into native code, on the spot by the .NET (or Mono) runtime, only when the program gets executed. Unlike C/++ or Assembler, it has no constructs that make it immediately useful on a low level. But, it does have pointers. And that's all we really need.

The founding members of SharpOS decided to tackle the conundrum at hand by writing an Ahead-Of-Time compiler, (in 100% C#), that takes our kernel .NET assembly, and generate a bootable kernel image from it. That is, it compiles the CIL of the kernel DLL into native code. To get around not being able to do low-level machine language stuff, the AOT contains a class with static method stubs on it, (which in and of themselves do nothing). There is a stub for every x86 assembler instruction. And when the AOT compiles the kernel, and encounters calls to those method stubs, it converts them into the correct native instructions. This, along with using method stubs to declaratively label static memory allocations, allows us to leverage C# against the entire CPU without leaving the comfort of our C# IDE.

The project is definitely still in an infantile state. We need to write an entire runtime support layer so that we can embed a JIT. Remember: think assembler – unless we write memory management, there is no: object foo = new object(); And unless we write type information handling, there is no: if(foo is Int32) {…}

So, in order to stick to our C#-only motif, we have to use a restrained form of C# (that is, no heap types, no type information, etc.), to write a runtime, that the rest of our kernel can be AOTed against. This means we also have to emulate parts of the Mono/.NET corlib. Eventually, our goal is to use our AOT as the JIT that will get embedded in the kernel.

People tend to notice that SharpOS developers are not scared of chicken-and-the-egg problems. If you understood the last couple of paragraphs, you'll understand why.

Currently, the three most active SharpOS members are all doing very different things. xfury is working on porting/emulating common Unix utilities in C# - because we will definitely need them when the time comes. DarxKies, being the lead on the AOT part of the project, is working on writing runtime support so that we can start embedding fully managed code into the kernel (but at that point, still AOTed). And yours truly, has been working on a demo command-line shell to grab the attention of passer-bys, like you.

Here is a screen-shot of the beginnings of fruits of my labors (see the yellow text at the bottom):

You'll notice I had to type the "version" command in twice. Frankly, it's very much full of bugs. But considering our memory management code was just a temporary satisfaction of a complex need, and I had to write a ton of dynamic string handling code from scratch, it's pretty impressive, right?

Within the next few weeks, I'll hopefully iron out the rest of the bugs and code a handful of commands so that we can put out a first release.

Each of the commands is stored as a structure consisting basically of a string pointer for the command's alias, and a function pointer that points to the function that does the work for the command. I know, who thinks of string pointers and function pointers when they think of C#? But when you don't have class instances, and you don't have Runtime Type Information, what is an OO programmer to do?

Like I said, we are in baby stages. (And in need of lots of help!) But hopefully, the screenshot will help get those juices flowing…

No comments: