Tiny C++ boot loader
Repo AgentD/hausboot, read from GitHub 5 h ago. AgentD has not joined Take My Repo.
AgentD/hausboot is a public repo on GitHub by AgentD. Tiny C++ boot loader. It declares the ISC license on GitHub. It is written mainly in C++, has 82 stars and last changed on 2023-06-14. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
"I wrote a bootloader in C++, I AM A CHAMPION!"
Here is a pre-compiled version: https://goliath32.com/hausboot/hausboot.tar.xz
It includes a disk image, scripts to run it and the individual components as separate binaries.
The abomination in this repository consists of:
The MBR & VBR were initially written as a proof-of-concept and "told you so" to show off that a boot sector could be written in what's mostly high-level C++.
The second stage FAT32 kernel loader is the result of unhealthy obsession to see this through, no matter how stupid the whole thing is.
This is not intended, nor in any way, shape or form fit for any real world use.
TODO: make the weird ramblings less incoherent and turn it into a blog post?
I learned to program with QBASIC and 8086 assembly under MS-DOS. I later learned how a CPU works from the gate level up, before I learned C. Over the years, I used C++ on-again-off-again, having to re-learn it every time since 2011, because the standards commedy keeps changing the darn thing.
On your typical beginner forums, there were many who ambitiously wanted to write a computer game, or an OS. For both there are many dedicated websites, with tutorials. If you go down the OS route, you end up being told that OS development is all about the nookies and crannies of the x86 architecture. Instead of learning about scheduling, memory management or filesystems, you learn about the intricacies of the protected mode and the A20 gate.
Among other things, you are told that boot loaders are hand written in assembly. You cannot write a boot sector in C, C is too big and FAT. Booting happens below C level.
Even after many years of C programming, a real eye-opener for me was attending a (now sadly discontinued) masters course on compiler construction. Turns out, compilers are really good. Even my toy optimizing compiler I wrote that semester could churn out surprisingly efficient assembly. And I'm pretty sure the gcc people are a lot smarter than me, in addition to a 30 year head start.
To a degree, it changed my way of thinking about programming. Source code should first and foremost be written for people to read. Source code should convey high level meaning, both to people, as well as to the compiler. Bit twiddling hacks are an utter waste of time and make the job harder for the compiler as well. Keeping down asymptotic complexity is your job, optimizing the coefficient is the compilers job (but you should really be thinking in terms of data structures anyway, rather than algorithms).
Programming languages really are a formal language based calculus that describes meaning. A compiler is essentially a term-rewriting system and you are operating with the semantics of that calculus. Adages like "C is just an assembly pre-processor" are not just nonsense, but outright dangerous. The chasm between C semantics and machine semantics are what gives rise to fear and misunderstanding around the dreaded undefined-behavior-boogy-man that HN loves to gossip about so much.
Pondering further on that, I concluded that an expressive, strong type system is really key to expressing such high level meaning and semantics. A modern, high-level language should IMO not have bit manipulation at all. Flag fields are really just composite data types in disguise, model them as such and gain type safety! I'd go as far as claim that memory-safety issues are themselves really just a symptom of flaws in the type system.
Anyway, revisiting C++ once again, it made me realize that you can model all of those high level type semantics really well with classes. Thinking about classes as user defined types is an immensely powerful concept, and C++ even allows you to micro manage memory layout if need be. If leveraged, C++ effectively hands you tools of Ada like proportions, you just need to use them.
Thinking about C++ and compiler construction gave me the shower-thought realization that it should absolutely be possible to write a boot sector in C++. And after all, C++ is a "systems programming language", right? :-P
I found the idea especially funny, because much of the criticism I heard/read about C++ over the years pertained to C++ programs being big, bloated resource hogs. Also I found the idea to be an interesting challenge/exercise. Which is what brings us here.
You need a very recent version of g++, as well as the 32 bit version
of libstdc++ if you are on x86_64 (if you are on "Apple Silicon": sorry...).
The project uses the Meson build system, to compile the sources, simply run:
meson setup ./build
cd build
meson compile
A sample disk image, along with a Bochs
config file are generated in test/ in the build directory.
To run it in bochs simply run:
bochs -q -f /path/to/bochsrc.txt
Alternatively, you can try running it in Qemu:
qemu-system-i386 -drive format=raw,file=/path/to/disk.img
With any luck, it might work on your machine as well :-). I have only tested it with Bochs and Qemu on two Fedora installations and an OpenSuSE machine so far.
When you turn on an (legacy BIOS) PC, we are basically transported back to the 1980s again. The CPU pretends to be a 16 bit mode 8086 that can address up to 1M of memory using segmentation.
After reset, the 8086 starts execution at FFFF:0000, or some such, i.e. at linear address 0xFFFF0. The IBM PC hardware has a ROM chip mapped at that region that contains the BIOS. The lower 640k of address space are left to the operating system, including stuff like memory mapped hardware (e.g. video RAM). This is called "conventional memory" for some reason (as opposed to unconventional memory?).
The boot strap code in the BIOS simply looks for a floppy or hard drive that has the magic signature 0xAA55 at the end of the first sector. This magic value indicates a bootable drive. The BIOS simply copies the first sector to the magic address 0x7C00 and jumps into it.
This would typically contain an OS boot loader in hand written assembly that fetches a bigger executable from the same disk. This would possibly be a second stage loader that can read the file system and load the OS kernel.
Eventually somebody figured, it would be a jolly idea to have partitioned
hard disks on the IBM too! This was implemented by storing a partition table
at the end of the first sector. Instead of the original boot strap program,
the first sector now contains the "Master Boot Record" that is
loaded & executed by the BIOS. It relocates itself (typically to 0x0600;
that's what Microsoft went with), inspects the partition table and chain
loads the actual boot loader from the first sector of a partition marked
as bootable.
The BIOS code was left untouched, and doesn't need to know about partitions. It's completely an OS feature, but the partition boot loader needs to be aware of it, hence we started calling those "Volume Boot Record" (VBR).
The "standard" layout of the partition table is simply what DOS et al settled on, using 4 entries, each 16 byte. Later schemes like GPT with UUID partition labels and additional, extended partitions are built on top of that in a backwards compatible way, which is why you can still only have up to 4 regular, non-extended partitions there.
But with a typical, old DOS MBR, this leaves us with 446 bytes of payload area for the MBR program. For comparison: if we used 80-column IBM cards, that would be roughly 6 or 7 punched cards (depending on the format).
In the directory mbr, there is C++ source for a program that fits in this
space and does the task described above. The bulk of the implementation is
actually in C++ classes defined in headers in the include directory.
The volume boot record sits in the first sector of the partition and is chain-loaded by the MBR.
It typically shares the sector with the super block of a filesystem. For instance, FAT32 uses the first 90 bytes for filesystem information. The first 3 bytes hold a jump instruction, so we don't accidentally try to execute the filesystem information.
Subtracting the super block and 2 byte boot signature, that leaves a FAT32 VBR with 420 bytes of payload for a program (6 punched cards).
So what the FAT32 VBR does, is chain-load a much larger program, stored in reserved sectors between the super block and the first FAT. We are guaranteed at least 32 reserved sectors, but this count includes the first sector itself, the special FS information sector, and a backup copy of the first sector (can be disabled).
If we disable the backup copy and relocate the FS information sector, we can max that out to 30 sectors, or a whopping 15k for our second stage boot loader.
In the vbr directory, there is a C++ program that should fit into
that 420 byte region, and chain loads the second stage. The installfat
program from the tools directory contains C++ source for a program that
modifies a FAT image as described and installs the VBR, as well as the
second stage binaries.
The second stage boot loader has enough breathing space to do some more hardware initialization and information gathering (e.g. getting the memory layout and enabling the A20 line).
It implements an actual FAT32 reader, reads a config file from disk that tells it from where to load the kernel.
The kernel is copied to high memory, the BSS is zeroed out, and a multiboot information structure is setup up, before finally switching into protected mode and calling the kernel.
The code for this sits in stage2, but once again, most of the magic happens
in the headers included from include. In the tools directory, there is a
program called fatedit that can fumble files into a FAT32 image, so we don't
have to mount the silly thing.
The FAT32 parser is currently limited to short names only.
The multiboot code is also fairly limited. It does not support parsing ELF files and insists that the kernel provides memory layout information instead.
The FAT (flatulent, archaic trash) filesystem was the original, native filesystem for DOS (dead operating system) and has over the years become the lingua franca of filesystems, supported by practically every relevant OS, typically used on external storage media that can be exchanged between them. At it's core it is idiotically simple, but full of quirks and semi backwards compatible extensions.
For those interested: Microsoft published a white paper on it
It mainly consists of a super block and a "file allocation table" that manages the data blocks on the disk. Because power can fail during writes, there are typically 2 of those.
The data blocks are called clusters, indexing starts after the allocation table (the first one has index 2 for some reason).
Data belonging to a file is stored using a linked list of clusters. The links are stored in the allocation table, which is simply an array of cluster indices. Basically if you know the cluster index that you are currently looking at, you use that as an index into the array and the value stored there is the index of the next cluster where you should continue reading.
There are special sentinel values to indicate that there is no next cluster (the one you are holding is the last one). Unused clusters are marked with special value 0 in the table.
A directory is basically a file that contains a sequence of entry records, storing a name, the first cluster where the entry data begins, how big it is, and some flags (e.g. this is not a file but actually a directory). The super block tells us the cluster index of the root directory, so we can recursively scan our way through the tree.
The main difference between FAT12, FAT16 and FAT32 is the number of bits used for the cluster indices in the table, i.e. 12, 16 and "28 out of 32" respectively. Also, FAT12 and FAT16 had some special case handling for the root directory. This probably has boot loader related reasons, FAT32 instead simply has a reserved region between the VBR and the first FART, where we can park a second stage boot loader.
You should note, that you cannot choose which FAT type you are using! It depends entirely on the number of clusters. If your disk has up to 4085 clusters, you are using FAT12, for up to 65525 clusters, you are using FAT16, and for higher numbers, FAT32.
You cannot format a floppy with FAT16 or a 10M hard disk with FAT32. What you can do, is dial up the number of sectors per cluster to fudge the cluster count below a threshold and use a smaller FAT for a bigger disk.
A disk must have at least some circa 32M to be FAT32 formatted. With 1 sector per cluster (giving us 65536 clusters). For 4k clusters it would be somewhere around 256M. In both cases, you should bump it up a little further tough. The Microsoft spec says, you should stay away from the threshold numbers, because different implementations are subtly broken in different ways.
The Multiboot specificiation is something the GNU people came up with. It describes a bootloader-to-kernel binary interface.
AgentD/hausboot is a public repo on GitHub by AgentD. Tiny C++ boot loader.
It declares the ISC license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2023-06-14. Take My Repo does not judge from that whether it is maintained.

Learning operating system development using Linux kernel and Raspberry Pi
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run hausboot. What is known comes from GitHub. It declares the ISC license on GitHub. Its last change was on 2023-06-14. It has 82 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.