Musings of a Fondue

James Molloy OS Tutorial

I wanted to get my feet wet with regards to writing operating systems from the ground up. I came across this awesome tutorial by James Molloy. In it, he walks through the creation of an ultra minimal unix-like operating system.

— Setup —

Setting up my environment took quite a bit of time. The setup instructions are aimed at a Linux/macOS environment whereas I am running Windows. Luckily, Windows Subsystem for Linux (WSL) is a thing and I was able to continue along. However, there was a catch - WSL does not have a graphical user interface (GUI).1 This meant I could not use Bochs (the emulator used in the setup instructions).2

I had previously come across another unix-like teaching operating system called xv6. It is far meatier than Molloy’s but more on it in future posts. I managed to run xv6 without issues on WSL by using its no GUI option so I figured why not setup a similar environment for Molloy’s tutorial.

To do this I used QEMU (the emulator used by xv6) instead of Bochs. I referenced these two makefiles, to adapt Molloy’s makefile to QEMU.

Molloy’s tutorial uses VGA in text mode where ASCII characters (instead of pixel rendering information) are sent to the screen. To render VGA in text mode, QEMU uses curses (a library for creating text user interfaces). Luckily for me, curses was already included with WSL and required no additional effort on my part to work.

The xv6 setup also incorporates the GNU Debugger (GDB). GDB is essential for debugging the OS. Here is a playlist of videos I found helpful for getting up to speed with it.

With the environment setup, I finally got on with the tutorial.

— Results —

Here’s a screenshot showing the workflow. It is from the hello world chapter of the tutorial. In the image, GDB is about to be used to to step through the hello world program one instruction at a time. The hello world program places 0xdeadbeef into the eax register.

Here’s a screenshot from the file system chapter. The image shows the tail end of a dump of the files present in the disk. (My terminal has a blue background, and the VGA screen has black. The weird overflow of black (beyond the boundaries of the VGA screen) is probably due to curses not playing well with WSL. I suspect it will render correctly on Linux/macOS.)

I skipped the last two chapters on ‘Multitasking’ and ‘User Mode’ for now. Though both are features I would love to have on the Homebrew Computer, they are not an immediate priority.

The chapters I did complete gave me invaluable insight! Concepts like what a file system is, how a computer communicates with a screen, and how interrupts are handled were made more concrete. Theory is one thing, but implementing it really makes things sink in.

Working through the tutorial would not have been possible without the help I got from the people at the OSDev forums! The OSDev Wiki is also indispensable. You will inevitably stumble across one of their articles if you start looking into writing an operating system.

I thoroughly recommend Molloy’s tutorial for anyone who wants to get a practical (though tip of the iceberg) glimpse into how operating systems work!

All my code is on Github. Included are instructions on how to get it running and a cheatsheet for common commands.



1 A GUI is possible on WSL by using Xming however it’s a bit clunky and the workflow is not convenient.
2 Hindsight is 20/20. Now that I am more knowledgeable, I realize that I could have just used Bochs in text mode.

Comments