This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Repository navigation
Kernel Architecture
dany edited this page Jan 15, 2026
·
1 revision
This guide explains how the kernel is made.
-
Bootloader (
boot.asm)- Starts in 32-bit mode and sets up basic paging structures.
- Switches CPU to long mode (64-bit) and sets up
CR0,CR3,CR4, and MSRs. - Loads GDT/IDT for CPU segmentation and interrupt handling.
- Passes multiboot information and control to
kernel_main().
-
Kernel Entry (
kernel_main)- Initializes core architecture:
- Constructors (
initialize_constructors()) - Terminal and serial output
- GDT and IDT
- Constructors (
- Reads multiboot tags for memory map and ramdisk info
- Initializes memory management (paging, heap, dynamic break)
- Initializes core subsystems (timer, threads, keyboard)
- Initializes core architecture:
-
Physical Memory Management:
pfa_init_from_multiboot2()sets up free page allocation. -
Virtual Memory Management: Paging is enabled and
VMM::sbrk()sets up kernel heap. -
Heap: Kernel heap initialized via
kheap_init(). -
RAM Disk: Mapped into virtual memory for
initrd(KeonFS).
Example: setting up the heap
VMM::kernel_dynamic_break = ((uintptr_t)&_kernel_end + 0xFFF) & ~0xFFF;
VMM::kernel_dynamic_break += 0x10000;
void* heap_start = (void*)VMM::kernel_dynamic_break;
VMM::sbrk(4 * 1024 * 1024);
kheap_init(heap_start, 4 * 1024 * 1024);- VFS Layer: Initialized with vfs_init().
- RootFS: Contains standard directories /dev, /mnt.
- Device Nodes: keon_disk under /dev.
- Mount Points:
- FAT32 partition mounted under /mnt/fat32 if available.
- Initrd RAMFS loaded under /initrd.
Example: registering
/devand a device
SimpleDirectory* dev_dir = new SimpleDirectory("dev");
root->register_node(dev_dir);
DeviceNode* disk = new DeviceNode("keon_disk");
dev_dir->add_child(disk);| Subsystem | Purpose |
|---|---|
| Threads | Scheduler and context switching |
| Timer | Kernel timer for preemption |
| Keyboard | Input handling via IRQ |
| Terminal | VGA text output |
| Serial | Debugging and output to serial console |
| Speaker | System beeps for feedback |
On boot, keonOS prints a splash screen and system information:
- Memory detected
- Version and copyright
- Shell prompt for user commands
Example: splash screen
terminal_clear();
terminal_setcolor(vga_color_t(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_BLACK));
printf(" _ ___ ____ \n");
printf(" | | _____ ___ _ __ / _ \\/ ___|\n");
printf(" | |/ / _ \\/ _ \\| '_ \\| | | \\___ \\\n");
printf(" | < __/ (_) | | | | |_| |___) |\n");
printf(" |_|\\_\\___|\\___/|_| |_|\\___/|____/\n\n\n");The shell is added as the first user thread (thread_add(shell_run, "shell")).
The kernel then enters a low-power idle loop, waiting for interrupts:
while (1) asm volatile("hlt");Context switches are triggered by the timer interrupt.
keonOS combines classic OSDev principles with modern C++:
- Monolithic kernel
- Preemptive multitasking with threads
- Virtual memory and dynamic heap
- Modular filesystem layer with FAT32 + RAMFS
- Clean boot process with multiboot2 support
Tip: For more low-level details, check kernel.cpp, boot.asm, and linker.ld in the source tree.