Building a basic X86 kernel part 1 - Introduction

Welcome to the first part of a series of blog posts which serves as a tutorial on how to build a 32 bit protected mode kernel loaded by a 16 bit bootloader on the X86 architecture. While the resulting kernel will do nothing spectacular (in fact, it does nothing but print a message), the journey that leads to this result is what it’s all about. To me, this was something I’ve always wanted to learn and do and something I finally embarked upon. Because there is so much information on this subject, I hope these posts will be a concise story on how it can be done.

A note beforehand: while working on this and reading about some low level bits and pieces, I started wondering how this was actually translated to hardware behaviour and while reading more about that, I eventually ended up reading about quantum electrodynamics. While it is not strictly necessary for the rest of this series, if you are interested in a (hopefully) concise overview of the components of computer hardware and some of the physics behind them, I have created a preliminary series called hardware fundamentals.

I would suggest you tag along and experiment yourself with everything you read about, as this is the most fun way to approach it and the best way to learn most from it.

Preparation

This first post will be about preparing your system so you can actually write code, build, debug and test your efforts. If you already work in Linux, just check the commands below to see if you miss any software. If not: I encourage you to move on to part 2 directly.

While this can be done on any system with the right tools, to me it felt most natural to do this in Linux. Feel free to deviate here and do whatever you like, but the rest of the series will assume Linux as an environment and the tooling described below. If you don’t already have a Linux environment ready, I suggest grabbing a copy of Ubuntu from the official site. It can be installed as a virtual machine or in dual boot.

The advantage of working in Linux is that many useful utilities for analysis of binary files, hex dumps, etc. will already be available to you out of the box. However, you will probably still need to install some things yourself that are not installed by default (as normal people don’t really use them).

If you don’t already have the following tools installed, they can be installed as follows:

$ sudo apt-get update
$ sudo apt-get install gcc gcc-multilib gdb nasm qemu qemu-system-i386

Apart from this, all you need is a text editor to edit your source files. Because there is so much personal preference involved there, I’m gonna leave that up to you.

This pretty much concludes the initial setup of your system!

Let’s move on to part 2