Skip to content

lou-16/krnl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

krnl

a WIP kernel created from scratch in C.

Alt text

krnl — A Simple x86 Kernel

Welcome to krnl, a minimal 32-bit x86 kernel built from scratch. It boots using GRUB, prints via serial, and lays the foundation for more advanced OS concepts like memory management, paging, and drivers.


✨ Features

  • Freestanding x86 kernel written in C and NASM, with no reliance on a hosted runtime
  • Multiboot-compliant boot flow, loaded via GRUB, with validated Multiboot structures
  • Early serial debugging (COM1) for low-level logging prior to console initialization
  • Global Descriptor Table (GDT) initialization with flat kernel segments and correct selector semantics
  • Interrupt Descriptor Table (IDT) with handcrafted ISR stubs and a unified exception handling path
  • Correct CPU exception stack-frame handling, including precise separation of error-code and non-error-code exceptions
  • Deterministic ISO build pipeline using CMake and shell tooling
  • Physical memory map parsing from Multiboot for early memory introspection and allocator groundwork

🚀 Booting the Kernel

qemu-system-i386 -cdrom krnl.iso -serial stdio -vga std

Build & ISO Generation

./build_iso.sh

The following script will run this kernel in debug mode, so you may need to:

  • run gdb
  • connect to remote :1234
  • open file build/kernel.elf to load symbols
./run_vm.sh

History / Devlog


Hi! I got the Interrupts working, and now have a working PIT. Now i will proceed with getting a proper context set up for a primitive task that can be scheduled. however, fixing the ISRs and IDTs have taught me a lot of assembly, and nuances of x86 Architecture. I don't really feel THAT comfortable with the architecture yet, however i'm moving towards a decent understanding. enough of gloating. Got the kernel to dump the registers upon an exception reception. I may also write a simple PS/2 keyboard driver, and maybe make a shell application later. and i also have the idea of making a bit of a GUI using the BGA. later who knows, maybe a compositor or whatever its called.

  • lou-16 (1-1-2026) (cool, happy new years)

Got the Bochs Graphics Adapter (BGA) working with a simple driver — enough to get a framebuffer up and running. Added a basic PCI config reader to detect devices like the BGA.

Cleaned up the project quite a bit: removed old video and fs headers, simplified CMakeLists.txt, and trimmed unused files.

Set up the first version of memory management, with kmalloc and kfree handling full-page allocations for now. This will later evolve into a proper heap allocator.

Implemented some basic interrupts — the first 32 CPU exceptions are stubbed, while the PIC handles IRQs 32–47. Not using APIC yet, just the legacy setup.

Next up: IRQ0 (timer) and IRQ1 (keyboard) for the PIT and PS/2 input, which should finally get a TTY working. Also added two early syscalls (sleep and abort) — no syscall table yet, just enough to test the mechanism.

  • lou-16 (1-11-2025)

I also implemented some simple interrupts. for the first 32 interrupts, which are CPU's own internal IRQs, i simply created a stub that resets them to 0 for now. but the later 8, and then 8 ISRs are for the Master and Slave PIC. which obviously means that this isn't relying on the modern APIC microcontrollers. which is fine.

Next i aim to use the IRQ0 and IRQ1, which are essentially the IRQ32, and IRQ33 if we look at the IDT, for timing (using PIT), and for a PS/2 Keyboard that will allow me to get some input. which means in the near future, i'll be able to get a tty working. Meanwhile i implemented 2 syscalls, although i have not added a syscall_table that i can use to create a table for my syscalls. so if im being honest, its really just a sleep and a abort function for now.

  • lou-16 (30-10-2025)

About

a WIP kernel created from scratch in C.

Resources

Stars

Watchers

Forks

Packages

No packages published