Kernel 101 – Let’s write a Kernel logo

Kernel 101 – Let’s write a Kernel

Free

Let's write a simple kernel for x86 using GRUB

FreeFree tier
Type
Open Source

About Kernel 101 – Let’s write a Kernel

Kernels 101 is a detailed tutorial by Arjun Sreedharan that guides readers through writing a simple kernel for x86 systems using the GRUB bootloader. It explains the boot process, real mode and protected mode, and provides step-by-step assembly and C code. The kernel is loaded at address 0x100000, displays a message on screen, and then halts. The article covers essential tools (NASM, gcc, ld, GRUB) and includes a linker script to produce the final executable. All source code is available on the author's GitHub repository (mkernel).

Key Features

Assembly entry point using NASM
C kernel code with external function kmain
Linker script to load kernel at 0x100000
Utilizes GRUB bootloader for booting
Supports switch from real mode to protected mode
Disables interrupts and sets up stack
Hangs after printing message

Pros & Cons

Pros
  • Clear, step-by-step explanation of boot sequence
  • Minimal and focused code (easy to understand)
  • Uses free tools (NASM, gcc, GRUB)
  • Source code available on GitHub
  • Teaches real mode to protected mode transition
Cons
  • Only targets x86 architecture
  • Kernel does nothing beyond printing and halting
  • Requires prior knowledge of assembly and C
  • No error handling or advanced features
  • Assumes GRUB as bootloader (not universal)

Best For

Learning operating system development fundamentalsEducational project for understanding boot processHands-on exercise for x86 assembly and C integrationBuilding a minimal bootable kernel

FAQ

What is the reset vector?
The reset vector is the memory address 0xFFFFFFF0, where the x86 CPU begins execution after power-on. It contains a jump instruction to the BIOS code.
How does the bootloader load the kernel?
The BIOS copies the first sector of the bootable device to address 0x7C00 and jumps to it. The bootloader (e.g., GRUB) then loads the kernel at physical address 0x100000.
Why do we need assembly in the kernel?
Assembly is needed to set up the entry point, switch to protected mode (if not done by bootloader), configure the stack pointer, and invoke the C main function.
What tools are required to build the kernel?
NASM assembler, gcc, ld (GNU Linker), and GRUB (for booting) are required.
Where can I get the source code?
The source code is available on Arjun Sreedharan's GitHub repository called 'mkernel'.