64-bit Kernel: Introduction

I have been working on a 32-bit kernel in my spare time for the last 2 years. I could not tell you why I wanted to take on such a task but, if you are reading this, then I probably don’t need to.

I found that there were plenty of resources at my disposal which made the 32-bit kernel rather enjoyable to work on. Then, one day, I decided to tackle 64-bit. I soon realized that I had my work cut out for me.

While many people had attempted 32-bit and provided access to their work, it seemed fewer people had done so with 64-bit. Perhaps those who worked on 32-bit moved on to bigger and better things before 64-bit was more widely available. Maybe they felt they had fulfilled their dream and had no desire to go further. Or did people get stuck and gave up? I nearly gave up. Many times, I got stuck and could not find any answers. Why did I even bother? I stopped working on it for nearly 6 months but it nagged me in the back of my mind. I was not one to be defeated by this.

I blew the dust off my source and decided to give it another go. I scoured the internet, picking apart the few 64-bit kernel sources I could find. I managed to struggle my way through each roadblock until I had something that worked. Now, I would like to share my findings in hopes that it may help someone else who is struggling.


Things to consider:

  • This kernel is written primarily in C with some Assembler when necessary.
  • This kernel expects 32-bit mode to be initialized by the bootloader.
  • This kernel expects Multiboot2 information to be provided by the bootloader.
  • This tutorial will not cover writing a custom bootloader.
    • I may write a tutorial in the future but there are plenty of tutorials on writing a custom bootloader. Feel free to contact me if you have questions or need direction.

What you will need:

  • A Multiboot2 compatible bootloader that initializes 32-bit mode.
    • I will be using GRUB2.
  • A 64-bit development system.
    • I will be using Ubuntu.
  • A 64-bit ELF toolchain.
    • I will be recompiling GCC to target our new operating system.
  • A 64-bit compatible virtual machine.
    • I will be using QEMU.
    • You could test on real hardware but I would recommend using a virtual machine until you have a relatively stable kernel.

Some prior experience in C and Assembler would be beneficial. However, I will do my best to explain what the code is doing and why it is necessary. Please contact me or leave a comment if you have any questions.


What we will cover:

  • Environment Setup
  • Makefile and Boot ISO
  • Jumping to Long Mode
  • Updating the Screen
  • Handling Interrupts
  • The Heap
  • Physical Memory Manager
  • Virtual Memory Manager
  • Task Switching
  • System Calls
  • The C Library
  • Ramdisk
  • Drivers
  • User Land
  • more to come…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s