0. Introduction



Did you ever feel the urge to start from scratch? But then, what basic concepts should an operating system be based upon? Well, experimenting with system software is not that easy. One has to go back and forth between two different mindsets. Half of your brains need to visualize how all the constituents of a potentially very complex system are going to interact and make sure every possible scenario has been contemplated by the proposed design. This sort of model checking tour de force has to be intertwined, if the system is meant to work eventually, with the actual system programming that will bring it to life - reading obscure hardware documentation and doing hexadecimal arithmetic in your head included.

Building an operating system can be a fascinating adventure. A few years back, I got mixed up in the design of something dubbed a policy-free microkernel, named Sartoris after a little crazy character in a William Faulkner novel . This small piece of software implements a handful of useful but very basic (and perhaps intrinsecally uninteresting) hardware-oriented operations - not an operating system per se, but a lot of simple and useful abstractions, including the ability to easily boot and initialize a personal computer. It was designed with freedom of choice in mind: it should have enough features to allow the arbitrary construction of a full operating system in a (rather) unprivileged environment, but nothing more.

In this vein, the Sartoris microkernel works as a very thin library. For example, it is easy to context-switch from one thread to another, to manage address spaces or to handle interrupts. But that's about it. There is no default way to execute a program, no multiprogramming, nada. Plainly put, on boot the system doesn't handle any interrupt - not even the timer. In this sense, Sartoris differs from what is traditionally considered a microkernel, and this is the reason why I think it is a nice little tool to learn about operating systems. At a technical level, many things have been taken care of (but all the code is there, and is really short in case you want to take a look). But conceptually, everything is still as virginal as an acre of rainforest deep into the Brazilian jungle. Well, to be fair, we may have taken out a tree or two, but only because we really had to.

What follows is meant to be a hands-on introduction to system programming, using C and the Sartoris microkernel. If you just want to take a look at Sartoris and its API, you may prefer to download this document instead. Knowledge of the C programming language is assumed. If you are not familiar with C, but still feel like going on, an excelent reference - and a classic as well - is the Kernighan & Ritchie book.

This tutorial should have you writing, compiling and booting several little programs presto. In order to do this, you will need access to a *nix system and development tools. Linux is what we use over here, but if you are a windows user, Cygwin will do as well.



Go to next section.

