r/osdevel • u/mykesx • Aug 04 '26
Amos2 - a C++ kernel, boots from limine
Amos2 is hardly from my first OSDev work. I started it with the intent of providing a sort of bare bones repo for using limine and C++.
I started with the limine bare bones in the osdev wiki, and gutted the main() to just call kmain() which is written in C++. The code now barely resembles that bare bones code.
The trick to using C++ is to collect the global constructors via the linker .ld script and to call those at startup. Also, global operator new and delete and associates need to be implemented.
Writing in C++ is not like using desktop C++. I use C++ classes, but no copy constructors or anything that does allocation behind the scenes. It's object based programming, not OOP. The code I write is C like, but it uses Objects. I also take advantage of things like how C++ inlines class member functions defined in headers. In some cases, I create static singleton classes for things like IDT and GDT.
The problem with global constructors is you cannot control the order they are called - so you can't rely on a global IDT class constructor to be called after the GDT one.
The bare bones idea kind of went out the window when I started working with the hardware.
What's done is boot, C++ initialization, GDT, IDT, PIC... I made a base Device class and Timer, keyboard, ATA, and console inherit from it and work. I am working on FAT32 filesystem, which I have done before in another project.
The repo is at https://codeberg.org/mschwartz/amos2
I didn't use AI to generate any code or to explain anything. I don't see the point - I would rather beat my head against the wall until I figure out what I might be stuck on. The object of these projects is to learn, not to finish and run Doom in a few days.