System Architecture
The system has five layers: a 512-byte bootloader in 16-bit real mode, a protected-mode switch, the C kernel entry, a VGA text-mode driver, and the build system that ties them together. Every component is minimal by design.
Memory Layout
0x00000000BIOS Data Area (IVT + BDA)1 KB0x00007C00Bootloader (loaded by BIOS)512 B0x00007E00Free memory / Disk cache~544 KB0x00090000Stack (16 KB, grows down)64 KB0x000A0000Video memory / reserved128 KB0x000B8000VGA text buffer (80x25)4 KB0x00100000Kernel (.text section)~32 KB0x00108000Kernel (.data + .bss)~8 KB0x0010A000Free memory16 KB0x0010E000Heap (64 KB, grows up)64 KBMemory map from 0x00000000 to 0x0011E000. The kernel is loaded at the 1 MB mark, a common convention inherited from Unix. The VGA buffer lives at 0xB8000 in the reserved video memory region.
Components
Bootloader (bootloader.asm)
A 512-byte stage-1 bootloader written in 16-bit NASM assembly. It fits in the first sector of a floppy disk image, loads the kernel from disk via BIOS interrupt 0x13, sets up a minimal GDT with code and data segments, switches the CPU to 32-bit protected mode, and jumps to the kernel at 0x00100000.
- Assembled with NASM to a flat binary
- MBR signature 0xAA55 at byte 510
- Uses BIOS int 0x13 to read 32 sectors
- GDT: null, code (0x08), data (0x10)
- Protected mode via CR0 bit 0
Kernel Entry (kernel.c)
The C entry point, compiled with -ffreestanding and -nostdlib. No runtime, no libc, no startup code. The first C function called after the bootloader jumps to protected mode. It initializes the VGA driver, prints a welcome message to screen, and halts the CPU.
- Compiled with i686-elf-gcc -ffreestanding
- Linker script places it at 0x00100000
- No CRT, no startup, no libc
- Halts via inline __asm__("hlt")
- Entry is kernel_entry (NOT main)
VGA Driver (vga.c / vga.h)
A minimal driver for the VGA text-mode buffer at physical address 0xB8000. The buffer is an 80x25 grid of 2-byte cells: one byte for the ASCII character, one byte for foreground/background color attributes.
- Writes directly to VGA memory at 0xB8000
- 80 columns x 25 rows = 4000 bytes of chars
- Each cell: char byte + attribute byte
- Supports \n, \r, scrolling
- 16 colors, configurable per-print
Linker Script (linker.ld)
Controls the memory layout of the kernel ELF binary. Places the kernel entry point at exactly 0x00100000 (1 MB), which is the conventional load address for OS kernels. Sections are ordered .text, .rodata, .data, .bss.
- OUTPUT_FORMAT: elf32-i386
- ENTRY: kernel_entry
- Base address: 0x00100000
- Standard section layout
- No C library linkage
Build System (Makefile)
Orchestrates the assembly, compilation, and linking of the kernel into a bootable floppy disk image (os-image.bin). Uses NASM for assembly, a cross-compiler GCC for C, and produces a final image loadable by QEMU or a real PC.
- nasm -> ELF object files
- gcc -ffreestanding -m32 -O2
- ld with custom linker script
- Concatenates bootloader + kernel
- Pads to 1.44 MB for QEMU