[go: nahoru, domu]

Jump to content

Cosmos (operating system)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Ahellwig (talk | contribs) at 11:31, 11 February 2014 (→‎News coverage: corr). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Cosmos
Screenshot of an OS made with COSMOS, presenting a GUI creation possibility
DeveloperCosmos Project
Working stateActive
Source modelOpen-source
Latest previewRelease 106027 / 24 December 2013; 10 years ago (2013-12-24)
Repository
Kernel typeMicrokernel
LicenseBSD
Official websitecosmos.codeplex.com

Cosmos (C# Open Source Managed Operating System) is an open-source operating system toolkit written primarily in C# as well as small amounts of a high level assembly language called X#. It encompasses an AOT compiler known as IL2CPU to translate Common Intermediate Language (CIL) into native instructions. Cosmos compiles user-made programs and associated libraries using IL2CPU to create a bootable native executable that can be run with no support. The resulting output can be booted from a floppy disk, USB flash drive, CD-ROM, over a network via PXE, or inside a virtual machine. While C# is the primary language used by developers (both on the backend and by the users of Cosmos themselves), many CLI languages can be used, provided they compile to pure CIL without the use of P/Invokes. Cosmos is primarily intended for use with .NET Framework, with Mono support 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.

Older versions of Cosmos were released in "Milestones", with the last being Milestone 5 (released August, 2010). More recently, the project switched to simply naming new releases after the latest commit number. Releases of Cosmos are divided into two types: the "userkit", and the "devkit". The Cosmos "userkit" is a pre-packaged release that is updated every so often, as new and improved features are added. The "devkit" simply refers to the source code of Cosmos, and must be built manually. Most work on Cosmos is currently aimed at improving debugger functionality and Visual Studio integration. Kernel work is focused on implementing file systems, memory management, and developing a reliable network interface. Syslinux serves as the project's bootloader.

Developing with Cosmos

Cosmos has many facilities to improve the experience of developing operating systems with it, designed to make the process as fast and painless as possible.

Visual Studio Integration

A key feature of Cosmos (which separates it from other operating systems of its type) it its tight integration with Microsoft Visual Studio. Code can be written, compiled, debugged, and run entirely through Visual Studio, with only a few key presses. Currently, only Visual Studio 2010 is supported, though work to port to later versions is under way.

Debugging

Cosmos can be seamlessly debugged through Visual Studio, when running over PXE or in a virtual machine. Many standard debugging features are present, such as breakpoints, tracing, and logging. Additionally, debugging can be done via serial cables, if running on physical hardware. When running in VMWare, Cosmos supports stepping and breakpoints, even while an operating system is running.

Running

Cosmos uses virtualization to help speed development by allowing developers to test their operating systems without having to restart their computers as often. By default, VMWare Player is used, due to its ease of use in terms of integration with the project. Other virtualization environments are supported as well, such as Bochs and VirtualPC. An ISO disk image may also be generated that can be burned to a USB flash drive, CD-ROM, or similar media.

PXE booting is also supported, allowing for remote machines to run Cosmos over a network connection.

Compile Process

IL2CPU

To compile .NET CIL into assembly language, Cosmos developers created an ahead-of-time compiler known as IL2CPU, designed to parse CIL and output x86 opcodes

Writing Cosmos code

Cosmos Builder UI

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

Default Cosmos boot screen as seen in QEMU.

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 still inefficient and slow, and so the NASM assembler is used instead.

See also

News coverage