How haribytecode/blackpeakos works
Purpose and Boot Entry
MyOS is a freestanding 32-bit i386 educational kernel, packaged as a BIOS/GRUB bootable ISO. GRUB loads the kernel entry assembly, which establishes initial CPU state and transfers control to C kernel initialization.
• Boot entry: boot.S
• Kernel linker layouts: link.ld, linker.ld
• GRUB ISO configuration: iso_root/boot/grub/grub.cfg
Kernel Initialization and Console Boundary
The kernel initialization routine brings up descriptor tables, interrupt handling, devices, memory/task infrastructure, and initial execution. Early diagnostics are exposed through VGA text mode and serial UART; fatal failures terminate through the panic path.
• Main kernel control path: kernel.c
• VGA console: console.c, console.h
• Serial and fatal reporting: uart.c, panic.c
CPU Protection and Privilege State
Segmentation and task-state infrastructure define the protected-mode CPU environment. The GDT provides kernel descriptors, while the TSS supports task/privilege-transition state. Small assembly stubs perform CPU instructions that cannot be expressed directly in C.
• GDT setup and load: gdt.c, gdt_flush.s
• Task State Segment: tss.c, tss_flush.s
• Low-level context mechanisms: context.c, context_switch.s
Interrupt and IRQ Dispatch Pipeline
Hardware and CPU events enter assembly interrupt stubs, are normalized into C-level ISR/IRQ dispatch, then routed to device or scheduler handlers. The PIC is configured to remap and acknowledge legacy IRQs, separating CPU exception handling from external hardware interrupts.
• IDT and assembly gates: idt.c, idt_asm.s
• Exception/IRQ dispatch: isr.c, irq.c
• PIC control: pic.c, interrupt.h
Timer, Keyboard, and Device I/O
The PIT timer provides the periodic interrupt source used for preemption. Keyboard IRQ handling translates input for kernel consumption. Hardware register access is centralized around x86 port-I/O primitives, with VGA and UART as primary output devices.
• Timer/preemption source: timer.c, timer.h
• Keyboard driver: keyboard.c, keyboard.h
• Port I/O interface: io.h
Tasks, Threads, and Scheduling
The multitasking subsystem models executable work as tasks and threads, manages CPU context, and selects runnable execution on timer-driven preemption. The scheduler is the control boundary between an IRQ tick and a context switch; task/thread code owns lifecycle and execution-state structures.
• Scheduler policy and dispatch: scheduler.c, scheduler.h
• Task representation/lifecycle: task.c, task.h
• Thread and context state: thread.c, context.c
Memory Management and Image Delivery
The kernel includes basic physical heap/memory management. Paging sources exist, but the stated runtime model does not yet depend on virtual memory. The Makefile produces an ELF kernel and places it into the GRUB ISO tree for QEMU or compatible BIOS virtualization.
• Heap/physical allocation: heap.c, heap.h
• Paging foundation: paging.c, paging.h
• Build artifacts and delivery root: Makefile, iso_root/boot/kernel.elf
Main entry points: kernel.c Kernel initialization · isr.c ISR / IRQ dispatch · scheduler.c Scheduler · kernel.elf Kernel ELF
Components 19
Boot & Image
- Kernel build · Builds the ELF and ISO layout.
Makefile - GRUB boot config
iso_root/boot/grub/grub.cfg - Kernel ELF
iso_root/boot/kernel.elf - Boot entry · Establishes initial CPU state before C initialization.
boot.S
CPU Protection
- GDT setup
gdt.c - TSS state
tss.c - CPU context
context.c
Interrupts & Devices
- IDT gates
idt.c - ISR / IRQ dispatch · Separates exceptions from external IRQs.
isr.c - PIC control · Remaps and acknowledges hardware IRQs.
pic.c - PIT timer
timer.c - Keyboard driver
keyboard.c
Kernel Runtime
- Kernel initialization
kernel.c - Console output
console.c - Serial & panic
panic.c - Scheduler · Chooses execution at timer-driven preemption points.
scheduler.c - Tasks & threads
task.c - Physical heap
heap.c - Paging foundation · Present but not required by the current runtime model.
paging.c
Connections 23
- Kernel build → Kernel ELF: produces
- GRUB boot config → Kernel ELF: loads
- Kernel ELF → Boot entry: enters
- Boot entry → Kernel initialization: transfers control
- Kernel initialization → GDT setup: initializes
- Kernel initialization → TSS state: initializes
- Kernel initialization → IDT gates: installs
- Kernel initialization → PIC control: configures
- Kernel initialization → PIT timer: starts
- Kernel initialization → Keyboard driver: initializes
- Kernel initialization → Physical heap: initializes
- Kernel initialization → Paging foundation: initializes
- Kernel initialization → Console output: diagnostics
- Kernel initialization → Serial & panic: fatal diagnostics
- IDT gates → ISR / IRQ dispatch: routes events
- PIC control → ISR / IRQ dispatch: delivers IRQs
- ISR / IRQ dispatch → PIT timer: timer IRQ
- ISR / IRQ dispatch → Keyboard driver: keyboard IRQ
- PIT timer → Scheduler: preemption tick
- Scheduler → Tasks & threads: selects runnable work
- Tasks & threads → CPU context: owns execution state
- Scheduler → CPU context: switches context
- TSS state → CPU context: supports privilege state