Technology Lab / Information Technology

Developers create open-source OS kernels using .NET tools

Two open-source software projects aim to create operating systems with modular …

Developers are working to create experimental open-source operating systems with modular microkernels using the C# programming language. The SharpOS and Cosmos projects both announced their first major milestone releases last month, demonstrating the technical viability of the concept.

Although some previous research has been conducted in the area of VM-based operating systems, the Cosmos and SharpOS projects break a lot of new ground. One particularly notable prior effort in this field is Microsoft's Singularity experiment, a research project that began in 2003 with the intent of creating a managed code operating system that uses the Barktok compiler and leverages static analysis and programmatic verifiability to ensure high dependability.

Unlike Singularity, which includes a hardware abstraction layer coded in C++ and some other components written in assembly, the Cosmos and SharpOS projects seek to use standard C# pervasively throughout as much of the system as possible and also eschew the kind of specialized C# language extensions (like the DbC syntax of Spec#) that are used broadly in Singularity. Although the developers plan to use C#, it is worth noting that practically any language that conforms to the Common Language Infrastructure specification could theoretically be used for kernel development in both Cosmos and SharpOS.

The Cosmos compiler, which is called IL2CPU and is written in C#, converts Intermediate Language code into assembly, which is then processed by NASM to generate native x86 code. The developers say that IL2CPU will eventually be able to generate native code code directly without needing NASM and will also support native code generation for multiple architectures.

In an interview published on the Obsethryl's Lab blog, Cosmos developer Scott Balmos explains how the operating system works. "As with all VM-based operating systems, the first step after being handed boot control by the boot loader is a precompiled image—a native blob, if you will. Its purpose is to initialize the platform-specific hardware with sane defaults (e.g. load temporary ISRs, set up memory and other defaults), prepare the JIT compiler for the runtime, and do other native housekeeping tasks," Balmos said. "Afterwards, the rest of the kernel is loaded from its bytecode file, and the JIT compiler starts its job. At this point, the rest of the kernel, through normal bytecode and unsafe pointer memory access, performs the rest of the system initialization, loads device drivers, and gets things going from a userspace standpoint. It's a gross simplification, but the main idea is that, like all other VM OSs, we have a very small native code nanokernel, if you will, which initializes just enough of the system in order to load the kernel proper, which is in platform-independent VM bytecode form."

Cosmos running a shell demo in QEMU

Cosmos comes with a UserKit, which enables developers to create their own custom Cosmos distributions with specialized behavior. The UserKit can generate QEMU images or bootable ISOs, and there are also instructions that explain how to make a USB boot image. The UserKit will eventually supply what the developers describe as an "operating system Lego set" that will allow programmers to combine various components in order to create custom operating systems. Several demos are available, including a basic shell with Ext2 filesystem support.

Although the Cosmos developers say that they have undertaken the project primarily for their own pleasure, they note that there are numerous contexts in which their operating system could have practical value. One might someday be able to use Cosmos to rapidly develop specialized operating systems for embedded devices. Cosmos also provides a rich canvas for operating system design experimentation. For instance, Balmos notes that using a TCP/IP-based remoting protocol between the AppDomains would bring transparent distributed capabilities to Cosmos similar to those of Bell Labs' Plan9 operating system.

A Snake game running on SharpOS in QEMU

Another prominent C#-based operating system project is SharpOS, which announced its first milestone release early last month. Unlike Cosmos, the SharpOS project doesn't depend on any proprietary tools. The kernel can be compiled using either open-source Mono or Microsoft's .NET. There are several demos on the project's web site, including a playable Snake game implemented under SharpOS.

Both projects are distributed under open-source licenses. SharpOS uses the General Public License with the Classpath linking exception, and Cosmos uses the BSD license.

Those of you who are interested in the concept of VM-based operating systems might also want to have a look at the JNode project, which seeks to create an open-source operating system written primarily in Java.

Although SharpOS and Cosmos are still largely experimental and aren't really intended for use on regular desktop systems, they provide some insight into the kind of innovations that would be made possible if next-generation operating system kernels were designed to use managed code. The theoretical implications of these projects are very intriguing and will likely spur a lot of discussion in the operating system design community.

Further reading

Expand full story

You must to comment.


You May Also Like