Simon Kaufmann

Operating System 'Viennice'

×

Operating System 'Viennice'

Dec 3, 2018

I have been interested in the inner workings of a computer system for a while and am particularly fascinated by every piece of software running very close to hardware. Major software known for running very low level is the operating system - hence I created one.

The whole project is written in C with some code written in assembly where necessary. Architecture used is x86 - the 32 bit Intel architecture used in essentially all of today’s PCs and laptops (unless very new hybrid tablets which are running on an ARM processor instead).

Every operating system has a crucial problem while starting up: there isn’t any operating system yet to assist with this process. To solve this problem bootloaders are used. Some people writing their own operating system try to also develop a custom bootloader. However, this can be an unnecessary hassle with some pitfalls (for example the custom bootloader needs to switch the processor from the default 16 bit real mode to the 32 bit protected mode). Thus, in this project Grub is used as a bootloader.

The bootloader’s task is to load and start the kernel of the operating system. Now, we need some file format to compile the kernel to that Grub understands. An simple one to adopt is the so called multiboot standard.

To compile the operating system code to a format conform with the Multiboot standard, we need to be in control of all specific bytes of our output file to set the correct magic numbers, spaces for stack etc. To achieve this the core is developed in assembly and then calls functions written in C. In the end everything is connected by the linker after compilation. Look at os.asm to see the multiboot implementation.

The os.asm file then calls the C function init, located in init.c which then sets up the necessary interrupt table and enables paging for the system memory.

Finally, the keyboard driver is initialised and sets up the keyboard communication using the corresponding interrupts of the ps2 connection.

To display content on the screen the VGA text mode is used. The setup is done by Grub, we can simply write into memory which will immediately be displayed on the screen.

Code for the project and instruction on how to run the OS in an emulator can be found on Github.

The parts implemented in this project have been very useful to learn about computers and their basic architecture and to get a feeling of what it means to run code directly on the hardware without abstraction layers on top. Debugging can sometimes be a nightmare since the most basic methods are not available (for example you obviosuly cannot print reliably while trying to figure out why your self written print function is not working).

Still there are many interesting extensions for the projects, like implementing a USB driver, a more advanced graphics driver, getting a filesystem working or implementing ways to load your own userspace programs. I might very well come back to this when having a bit more free time.

© Simon Kaufmann 2021 | Theme powered by w3.css