How iyush/cos works
Project type and purpose
• This is a tiny x86_64 monolithic operating system written in C.
• It uses the Limine bootloader, implements basic physical memory management, interrupt handling, ELF loading, preemptive scheduling, and syscalls.
• It ships with a minimal “hello-world” userland binary.
File structure
• Top-level:
• limine/ + limine.cfg – the standalone bootloader.
• kernel/ – all kernel sources, entry code, linker script, GDB init, subsystems.
• userland/ – small C runtime (crt0.asm) and simple “hello-world” app.
• build.sh, run.sh, debug.sh – build and execution scripts.
• .bochsrc, shell.nix – emulator and environment configs.
• kernel/src: groups by functionality (boot/init, GDT/IDT, PIC, PMM, scheduler, syscall, ELF loader, VMM stub, tests).
Key README insights
• Purpose: minimal lines of code to achieve interrupts, memory allocation, ELF loading, scheduling, syscalls.
• Build flow: nix-shell → make limine → build OS & userland.
• Run/debug via QEMU or Bochs with forwarded stdout.
Main components
a. Hardware layer
• CPU, physical RAM, chipset, chipset’s PIC/APIC.
• BIOS/UEFI invoking bootloader.
b. Bootloader (Limine)
• limine.cfg → loads kernel image & passes control.
c. Kernel space
• Early init (assembly entry, GDT, IDT, PIC remap).
• Memory manager (physical allocator “pmm.c”).
• ELF loader (“elf.c”)
• Interrupt & exception handlers.
• Syscall interface (syscall.asm/c).
• Scheduler (preemptive multitasking).
• I/O layer (kio.c, io.c).
• VMM stub (vmm.c – placeholder).
d. Userland
• crt0.asm → sets up stack/args, jumps to main.
• hello-world/main.c → invokes syscalls.
e. Host integration
• QEMU/Bochs emulator (controlled by run.sh).
• Logging piped to host stdout.
Relationships & interactions
• BIOS/UEFI → Limine → kernel entry
• Kernel init: GDT/IDT → enable interrupts → scheduler timer → context switch tasks
• Userland tasks loaded via ELF loader → scheduled by kernel → make syscalls → handled by syscall.c
• Kernel memory requests use PMM → updates physical free list
• Interrupts (timer) drive preemption → scheduler picks next task
• Kernel logging calls go through emulator’s console → host stdout
Architectural patterns & principles
• Monolithic kernel: all core services in one address space.
• Layered initialization: assembly entry → hardware setup → memory → interrupts → higher services.
• Modular C code per subsystem.
• Clear separation: bootloader vs. kernel vs. userland.
Detail
• Every essential kernel subsystem as its own block.
• External dependencies: Limine build, nix environment, emulator.