Skip to content

So, you've decided to write a kernel.

Welcome to the world of kernel development! It's not easy, but this article should help set you up on the right track.

First of all, you need to know the following:

  • The Architecture you are targetting
  • The Assembly for that Architecture
  • Another compiled language (C/C++, Zig, Rust, etc)
  • What kernel type your kernel will be (Monolithic, microkernel, exokernel, hybrid, etc)
  • What goal you have for your kernel (Research, education, fun, hobby, etc)

Assembly is a strict requirement if you want to make a kernel. Most of your kernel's low-level components will be written in Assembly. C is the most recommended when doing kernel development. (Or if you want a challenge, you could do it all in Assembly. The BareMetal kernel took this path. It's not recommended to do so though unless you have lots of experience in Assembly.)

What you cannot do is:

  • Write a real kernel in a runtime/interpreter language (Python, Lua, JavaScript, etc)
  • Write a real kernel/OS for a web browser (Puter, ProzillaOS, Pluto, etc)
  • Make a Linux distro as it's not the same thing as making your own kernel

What you shouldn't do is:

  • Write your own bootloader before you write your OS
  • Write a kernel for a platform that lacks a Memory Management Unit (MMU)
  • Start with an obscure CPU architecture for your kernel
  • Use Artificial Intelligence tools to write or debug your kernel (ChatGPT, Gemini, Claude, other AI models, etc)
  • Use other's code without adhering to the license applied to it
  • Expect to run full programs or graphical user interfaces with your kernel in a small amount of time
  • Expect that others will come in and contribute code because you posted about it

You shouldn't attempt to write your own bootloader before your OS works and you have a good grasp of how the boot process works.

To quote Kevin Lange (klange), the creator of ToaruOS:

 

There's always this question from people who start out when building an Operating System is "Well, surely the first part of building an Operating System is writing a bootloader."

Bootloaders are terrible and if you ever decide that you want to write an Operating System, do not start by writing a bootloader ever.

x86 is very weird, has lots of little things, legacy features that actually turn out to be misfeatures and bootloaders are all just about getting rid of that.

So what a lot of people will do when they realize that bootloaders are dumb and no one should be writing their own bootloader is they use a bootloader called GRUB.

Limine is a much better bootloader than GRUB and it supports the x86(_64), AARCH64, RV64 and LA64 architectures. Plus it has multiboot(2), Linux and its own boot protocol too.

When starting your kernel, start with printing to the serial console/UART or the screen (whether that be VGA text mode using multiboot(2) or a framebuffer with Limine). After that, you should expand with memory, GDT, IDT and continue from there on out.

You should use QEMU to test your kernel. You shouldn't test on real hardware until your kernel reaches a usable stage.

During development, it's also recommended to study how other kernels do certain things.

Here is a list of OS/Kernel projects that you can study:

If you need help with your kernel, you can join our Discord and ask us about questions you may have.

Good luck with your kernel!