NOTE: this was wrote in 2023 during my second year at collegue, the new commits are updates to the README mostly to make it more "pretty" for ppl that does not know me (you)
An x86 32-bit kernel and bootloader written from scratch in NASM assembly and C.
The name comes from the English boot and Spanish bota (a shoe) -- I'm stupid nvm me.
# Build the toolchain image (one-time)
docker build -t boota-env .
# Compile the kernel
docker run --rm -v "$(pwd)/src:/boota/src" boota-env make -C src
# Run in terminal
docker run --rm -it -v "$(pwd)/src:/boota/src" \
boota-env qemu-system-i386 -drive format=raw,file=src/os-image.bin,if=floppy -display curses
# Clean
docker run --rm -v "$(pwd)/src:/boota/src" boota-env make -C src clean BIOS POST
|
v
bootsect.asm [16-bit real mode, loaded at 0x7C00]
|-- Sets up stack at 0x9000
|-- Loads 31 sectors from disk into 0x1000
|-- Calls switch
|
v
switch.asm [real -> protected mode transition]
|-- cli (disable interrupts)
|-- Enable A20 line (fast gate, port 0x92)
|-- lgdt (load GDT descriptor)
|-- Set CR0 bit 0
|-- Far jump to 32-bit code segment
|
v
init_pm [32-bit protected mode]
|-- Initialize segment registers (DS, SS, ES, FS, GS)
|-- Set up protected mode stack at 0x90000
|-- call KERNEL_OFFSET (0x1000)
|
v
kernel_entry.asm [kernel entry point]
|-- call kernel_main()
|
v
kernel.c [C kernel]
|-- init_memory() -> Heap init from _kernel_end
|-- isr_install() -> IDT gates + PIC remapping
|-- irq_install() -> Timer (50 Hz) + Keyboard
|-- terminal() -> Interactive shell loop
Address Size Description
──────────────────────────────────────────────────────
0x00000 1.25 KB Real mode IVT + BIOS data area
0x01000 ~15.5 KB Kernel image (31 sectors)
0x07C00 512 B Bootloader (MBR)
0x09000 -- Real mode stack base
_kernel_end grows up Kernel heap (kmalloc, page-aligned)
0x90000 grows down Protected mode stack
0xB8000 4000 B VGA text mode buffer (80x25x2)
| Range | Type | Description |
|---|---|---|
| 0-31 | ISR (CPU) | CPU exceptions (Divide by Zero, Page Fault, GPF, etc.) |
| 32 | IRQ0 | Programmable Interval Timer (50 Hz) |
| 33 | IRQ1 | PS/2 Keyboard |
| 34-47 | IRQ2-IRQ15 | Available (not currently used) |
POC.mp4
- Nick Blundell, Writing a Simple Operating System -- from Scratch
- OSDev Wiki -- an invaluable reference for x86 OS development