- Cosmos (operating system)
-
Cosmos
Screenshot of a Cosmos test shell booted in QEMUCompany / developer Cosmos Project Working state Publicly released/under development Source model Open source Kernel type Microkernel License BSD Official website cosmos.codeplex.com Cosmos is an open source operating system written in C#. It also encompasses a compiler (IL2CPU) for converting Common Intermediate Language (.NET) bytecode into native instructions. The operating system is compiled together with a user program and associated libraries using IL2CPU to create a bootable standalone native binary. The binary can be booted from a floppy disk, USB flash drive, CD-ROM, over the network using PXE booting, or inside a virtual machine. The currently supported architecture is x86, with more planned, and although the system is aimed at C#, it can be used with most .NET compliant languages (requirements are that the language must compile to pure CIL without using P/Invokes). Cosmos is primarily intended for use with Microsoft's .NET Framework, but Mono support is also in the works.
According to the Cosmos website, Cosmos is a backronym for C# Open Source Managed Operating System, in that the name was chosen before the meaning. Cosmos does not currently aim to become a full operating system, but rather a toolkit to allow other developers to simply and easily build their own operating systems, or as one of the project leaders put it, to act as "operating system Legos". It also functions as an abstraction layer, hiding much of the inner workings of the hardware from the eventual developer.
Milestone 5 was released in August 2010 and work on future releases is well underway. Most work on Cosmos is currently aimed at the debugger and Visual Studio integration. Kernel work is focused on file systems and developing a network interface for the system, with the system already supporting some network cards and some of the features of TCP/IP. Two versions of Cosmos are currently available, the (more up-to-date) source code version and the release version (known as the User Kit). The source version is intended for anyone who wants to help develop the kernel while the user kit is designed for anyone who just wants to use Cosmos to develop their own operating system.
Cosmos uses Syslinux as a bootloader. Syslinux is not used other than to load a secondary Cosmos boot loader. After that point, Cosmos runs on its own with no support from Syslinux or the BIOS.
Contents
Writing Cosmos code
An operating system built on Cosmos begins life as a .NET project (specifically a console application). The developer first adds special pieces of code which allow the Cosmos system to be compiled and run. The user adds the following code to the application's Main() method:
Cosmos.Compiler.Builder.BuildUI.Run()
This code opens the Cosmos Builder Window, which is used by the developer to compile the code into machine opcode. It is called when the .NET application is run, but is excluded from the eventual operating system.
The developer then adds a new method to the Program class, called Init(). The method goes as follows:
public static void Init() { Cosmos.Sys.Boot xBoot = new Cosmos.Sys.Boot(); xBoot.Execute(); //Add further code here... }
This method is the first to be called when the operating system is booted. The first two lines set up the system, loading drivers and preparing the machine. In a practical operating system, the developer would replace //Add further code here... with the code of his/her own operating system. This code can use any objects in the .NET Framework library that are supported by Cosmos (either a translation of the object into machine code has been created, or every part of it is already supported). It may also call any of Cosmos' built-in public libraries.
The Cosmos User Kit and Visual Studio
The Cosmos User Kit is a part of Cosmos designed to make Cosmos easier to use for developers using Microsoft Visual Studio. When installed, the user kit adds a new project type to Visual Studio, called a Cosmos Project. This is a modified version of a console application, with the Cosmos compiler and bootup stub code already added.
Compiling a project
Once the code is complete, a user would compile the project using their preferred .NET compiler. This converts the application from the original source code (C# or otherwise) into Common Intermediate Language (CIL), the native language of the .NET Framework. Next the application is run, showing the Cosmos Builder Window, which presents the developer with options which determine exactly how the project is compiled. These options include how to boot the project - via emulators such as QEMU, Virtual PC and VMWare, writing to a disk image (ISO) file that can later be written to a CD-ROM, or via PXE network booting - as well as debug options using Cosmos' built-in debugger, and other options.
When the user has chosen their desired options, they press the Build button. This invokes the IL2CPU compiler which systematically scans through all of the applications CIL code (excluding the Cosmos compiler code), converting it into assembly language for the selected processor architecture. (Currently only x86 is supported.) Next, Cosmos invokes the selected assembler to convert this assembly language code into native CPU opcode. Finally, the desired output option is activated, be this starting an emulator, starting a PXE engine, or producing an ISO disk image file from the binary code opcode.
Debug options
Cosmos offers several options as to how to debug the output.
Virtualization
Cosmos allows the user to boot their operating system in an emulated environment using a virtual machine. This lets the developer test the system on their own computer without having to reboot, giving the advantages of requiring no extra hardware nor requiring the developer to leave their development environment. To allow this, Cosmos makes use of three emulators. QEMU, the default boot option, is a free emulator that comes pre-loaded with Cosmos. VMWare is another emulator that can be downloaded from the VMWare website, with both free and paid versions available. Virtual PC is another free emulator that can be downloaded from Microsoft's website [1]. As well as these emulators, the compile to disk image option allows a Cosmos project to be booted in any emulator that allows booting from disk images.
Another feature available with QEMU is the Cosmos debugger which allows the user to step through source code like in Visual Studio while running their OS in QEMU. This works by adding code into the operating system, which communicates with the Cosmos debugger via a virtual network.
Disk images
This option writes the operating system to a disk image (ISO) file, which can be loaded into some emulators (such as Virtual PC) or written to a CD-ROM and booted on real hardware.
PXE network boot
This option allows the operating system to be booted on real hardware. The data is sent via a LAN network to the client machine. This requires two computers - one as the client machine (on which the OS is booted) and one as the server (usually the development machine). It also requires a network connecting the two computers, and the client machine must have a network card and BIOS that is capable of PXE booting.
Cosmos assembler
The Cosmos Project team have also created an assembler that is eventually designed to become the main assembler for the Cosmos system. However, the assembler is as of yet inefficient and slow, and so the NASM assembler is used instead.
See also
- IL2CPU
- .NET Framework
- Mono (software)
- SharpOS
- Singularity
- Phantom OS
External links
- Official website
- Project Page at Codeplex
- Cosmos Overview article at CodeProject
- Cosmos Dev Yahoo Group
- Cosmos Fan Page on Facebook
News coverage
Categories:- Embedded operating systems
- Operating system kernels
- Free software operating systems
- Beta software
Wikimedia Foundation. 2010.