A simple 32-bit "Hello World" kernel written in C++ and assembly.
- VGA Text Mode Driver: A simple driver to print characters to the screen.
- Terminal Driver: A higher-level driver for writing strings to the terminal.
- Multiboot Header: A basic multiboot header to be compliant with bootloaders.
- 32-bit Protected Mode: The kernel runs in 32-bit protected mode.
boot.asm: This file contains the assembly code that boots the kernel. It sets up a 32-bit protected mode environment and then calls the C++ kernel's main function. It also contains the multiboot header.kernel.cpp: This is the main kernel file. It contains thekmainfunction, which is the entry point for the C++ part of the kernel. It initializes the terminal and prints a message to the screen.terminal.handterminal.cpp: These files implement a simple terminal driver that allows writing strings to the VGA text buffer.vga.h: This file contains definitions for the VGA text mode colors and buffer.linker.ld: This is the linker script. It tells the linker how to arrange the different sections of the kernel in memory. It places the boot code at the beginning, followed by the rest of the kernel, and sets the starting memory address to 1MB.Makefile: This file contains the instructions for building the kernel. It compiles the assembly and C++ code, links them together, and provides aruncommand to execute the kernel in QEMU.README.md: This file.
- Bootloader: A bootloader (like GRUB, or in this case, QEMU's built-in bootloader) loads the
kernel.binfile into memory. boot.asm:- The execution starts at the
startlabel inboot.asm. - It first sets up the Global Descriptor Table (GDT) to switch the CPU into 32-bit protected mode.
- It then jumps to the
protected_modelabel. - In protected mode, it sets up the segment registers.
- It then calls the
kmainfunction inkernel.cpp.
- The execution starts at the
kernel.cpp:- The
kmainfunction is executed. - It calls
terminal_initialize()to clear the screen. - It then calls
terminal_writestring()to print "Hello, Kernel!\n" to the screen.
- The
- Halt: After
kmainreturns, theboot.asmcode executes thehltinstruction, which halts the CPU.
To build and run the kernel, you will need nasm, zig, and qemu.
make runThis will compile the kernel and run it in QEMU.