/kernel-tutorial

A step-by-step tutorial for building a simple kernel

Primary LanguageCMIT LicenseMIT

Kernel Tutorial

I really enjoy learning about and understanding lower-level computer systems. While OSDEV wiki is a fantastic resource, I've really struggled with many of their tutorials. So, I thought it would be nice to take things that I've gotten working and put them into a git-based tutorial. This makes it much easier to follow along, and correct mistakes.

This series isn't even close to as thorough as what you'll find over at OSDev. There is tons of theory and lots of details that aren't covered. Typically, I've found those bits to the easiest to learn on your own. This is geared towards getting something working, with macOS as your development environment. If you're a linux user, I think you'll be able to adapt most of these instructions to your system fairly easily.

Tooling

While each tutorial part will include installation steps, here's a list of everything needed for all steps in one place. First and foremost, install Xcode to get its suite of command line tools.

brew install qemu
brew install xorriso
brew install nasm

macOS We're going to be building an ELF executable, but macOS uses Mach-O. Clang is a really great cross-compiler, but we also need a cross-linker, which macOS does not include by default. At one point, I was able to install the gcc ELF bintuils directly from homebrew, but lately I've been unable to find a default that works. I'd love some pointers here. I used this:

brew install https://raw.githubusercontent.com/Gallopsled/pwntools-binutils/master/osx/binutils-i386.rb

For build automation, my personal preference is Rake. It has been pre-installed on macOS for ages, and is far more user-friendly than Make. That said, please use what you prefer! I know Ruby isn't for everyone.

Tutorial Parts

Everything is broken up into a series of steps, which you can find under tutorial-parts.

  1. Basic Bootloader
  2. Basic 32-bit Kernel
  3. Making a full ISO
  4. Checking for 64-bit support

Contributing

It would be wonderful to see issues/PRs opened for problems you experience with this tutorial. I'd be excited even to just hear you tried it out.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The project is available as open source under the terms of the MIT License.