How stpoen/hedgehogos works
Project Type and Purpose
• HedgehogOS is a teaching‐oriented, 64-bit open-source operating system written in C and x86-64 Assembly (NASM). It implements a Multiboot2‐compatible boot sequence, basic paging support (PAE), interrupt handling, a minimal CLI shell via VGA text mode, and parts of a custom libc.
Main Components
a. Host/Build Environment
• Cross-Compiler Toolchain (GCC, binutils)
• Makefiles and Build Scripts (root Makefile, kernel/Makefile, libc/Makefile, make.config)
• Output Artifacts: object files (*.o), kernel binary (k.bin), ISO image (hgh.iso)
b. Boot & Loader Layer
• BIOS or QEMU (emulated hardware)
• GRUB Multiboot2 Stage (grub.cfg + grub modules)
c. Kernel Entry & Initialization
• Assembly Boot Code (kernel/arch/x86/boot.asm, init_long_mode.asm)
• Linker Script (kernel/arch/x86/linker.ld)
• C Entry Point (kernel/boot/kmain.c)
d. Core Kernel Subsystems
• CPU & Interrupt Setup: IDT (kernel/interrupts/idt.c/h), ISR (isr.c), interrupt.asm
• Memory Management: Frame Allocator (kernel/memory/frame_alloc.c/h), PAE paging prep
• Syscalls / I/O Primitives: inb/outb/io_wait (kernel/sys/io/*.c)
e. Device Drivers & Services
• VGA Text Driver (kernel/drivers/tty/vga.c/h)
• PS/2 Keyboard Driver (kernel/drivers/keyboard/ps2/*.h)
• Terminal Services (kernel/services/tty.c)
f. User Interface Layer
• Simple CLI Shell (invoked in kmain via print/scan routines using VGA & keyboard)
• libc Stubs (libc/{stdlib,stdio,string,math} implementations used by kernel shell)
Relationships and Data Flows
• Build Flow: Source → (Makefiles) → Cross-Compiler → Object Files → Kernel Binary & ISO → Boot Medium
• Boot Flow: BIOS/QEMU → GRUB → Loads k.bin → jump to Assembly init → switch to 64-bit → call kmain
• At Runtime:
• Hardware Interrupt → ISR → Keyboard Driver → Terminal Service → Shell Input Logic
• Shell Output → printf (libc) → VGA Driver → Video Memory → Display
• Memory Requests → Frame Allocator → Page Tables (PAE)
Architectural Patterns & Design Principles
• Layered Architecture: separation between boot stage (assembly), kernel core (C), drivers, and shell.
• Monolithic Kernel: all subsystems (interrupts, memory, drivers, CLI) compiled into one binary.
• Minimal libc integration: deep in‐kernel use of standard library routines for string, math, I/O.