COSEC: six months

This spring my assembly coding experiments grew to something more: I moved from the x86 real mode to first steps in the protected mode environment, which seemed hostile and quite unusual. A lot of intricate and arcane assembly code needed to fit opportunities of a full 32bit mode really puzzled me first, but my slow progress was persistent enough to run first C code examples and to see a “Hello world” message in an OSless emulator.

I’ve been really impressed by Linux and its kernel and, like a child, wanted to know “how does this thing work”, so writing a linux-like kernel was a pleasant and useful challenge for my programming skills. My guidelines are not fancy: system clearness and simplicity, minimal POSIX-compatibility and experiments inspired by Plan 9 from Bell Labs, like network transparency and resources unification through files. Also I lean to microkernel design as far as it does not complicate the picture.

I haven’t had a definite goal of my project for a long time, I fluctuated between considering this OS just a training ground for system programming and exaggerated expectations for a new OS architecture and language-based features (resembling Singularity software stack), although my experience in writing code for managed platforms and writing interpreters/virtual machines itselves is miserable (and this is my first large project in pure C). Now I came to a definite goal: I want to have a minimal self-hosting POSIX-like OS using C (roughly corresponding to Linux 0.01 functionality, but a bit more slim, there are two decades of history after Linux creation).

Now my system is still quite nascent, but the experiments now involve much more mature things. Now my tiny OS contains:

  • a basic context switching (which is still not used);
  • basic userspace capabilities (and a single system call, SCS_DBG_PRINT, which print a message from userspace);
  • draft of Virtual File System;
  • my own implementation of heap using the firstfit algorithm;
  • implementation of some libc functions.
  • some drivers: keyboard, timers, serial port, PCI probing;

The system is still a single binary with simplest built-in kernel shell (userspace is waiting for FS implementation on order to be able host a functional shell). It is loaded with GRUB according to GNU mutliboot specification, though I have my own bootloader and switch-to-protected-mode code snippets.

Plans for the future are:

  • to add paging and modern-style memory protection;
  • to implement functional VFS and some popular FS drivers like FAT/ext2/iso9660;
  • to make the userspace really work: full-featured process with own address spaces, pipes, sockets;
  • to port Newlib (a C library implementation) and write a system-dependent userspace code for launching bash/gcc/vim on top of it;
  • an ELF loader;
  • to make it cross-platform with ARM support;
  • to start writing a simple network stack (arp, icmp, ip, tcp/udp, telnet/http/ftp);

Here is the source code:

COSEC on Github

In Ukrainian | Українською


3 thoughts on “COSEC: six months

    1. dmytrish Post author

      I am flattered at such a pleasant comparison, but the situation has changed a lot from the time of Linux 0.01:
      – now there is plenty of well-written unix-like open-source OSes for x86(-64), that is quite opposite to Torvalds’s situation (my OS will hardly be in demand unless some new ideas will be broght, and even such beauty as Plan 9 still is not popular);
      – now there is a lot of OSdev tutorials and Internet has made it much more accessible than in Linus time;
      – the system design is old-fashioned and thoroughly copied from Linux/BSD at the moment and that is done in a not very good way.

      I have a strong feeling that a new kind of OS won’t be needed unless a completely new hardware architecture emerges. This one is just a study of things which are already done.

      1. dnipropirate

        I don`t agree with you.

        Linus Torvalds lived in Europe because he easy to get book from USA and communicate with other world. Secondly, Linus reading Tanenbaum and some evil tongues say, what Linux steal idea. Thirdly, What material need programmist to create OS? Computer specification, OS Design and … Nothing more! UNIX-like system in that time creating not only Linus(even USSR have many unix clone for many platforms and not only created by professional computer`s scientificts, but homemade amateur).

        the system design is old-fashioned and thoroughly copied from Linux/BSD at the moment and that is done in a not very good way.
        Linux copies architecture his own system from University`s mainframe)) For example, what reactOS copied WindowsNT. It`s not heroism.
        Where do you see good way?)) In Intel architecture where in same port keyboard and protected mode flag? There are not question about mikro-, monolith-, ekzo- and other kernels, only question about what it make to working:-)

        Yes, Linus Torvalds is signed person of compurer science, but he is not greatest hero of computer revolution, how about him say some peoples.

        Sorry for my Niggaz English:)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s