After a couple years gap, I've started os dev again. I've started from scratch, and after a few weeks my new OS reached the first milestone, it can boot!
It can't do much more than drawing color boxes on screen, but this post isn't about OS/Z (not to confuse with z/OS). It's about the boot loader.
Have you ever wondered how good it would be if the firmware'd set up long mode, load your initrd and start executing your kernel right away? It was just a dream, you had to roll your own loader or learn to use one. But BIOS is ancient, needs lots of assembly; GRUB is a beast, almost an OS on it's own; and EFI is a real interface nightmare. Who want to struggle with all that stuff just to start the kernel?
I've solved that in an elegant way: my boot loader resides in ROM. On boot, it will locate the kernel text segment in the first ELF64 executable on the first init ramdisk on the first bootable partition of the first drive (hope you can follow
). It's doing it by looking for file magic, so file system independently. After that it sets up a minimal, well defined long mode environment (with framebuffer) and calls the kernel's entry point. The whole procedure is described in detail atBOOTBOOT Protocol
(the name refers to 64 bits) The reference implementations for BIOS and EFI can be found there as well. My basic principle is K.I.S.S., so the code base is minimal with the least dependencies possible.
And the best part is, it's Public Domain! So you can use those ROM images to boot your own kernel from your own filesystem without the need of writing an fs driver! Never been easier to start OS development! They work with qemu, bochs and real hardware as well (at your own risk). If you don't want to mess with ROMs, you can boot the loader from disk too, as it supports:
- Standard MBR booting on GPT disks (real mode)
- MultiBoot (prot mode)
- BIOS Expansion ROM (real mode)
- UEFI OS loader application (long mode)
- PCI Option ROM (long mode)
It doesn't matter which one is used, your kernel will start with the same, well-known long mode environment.
Tested with FAT12, cpio, tar and FS/Z (not to confuse with Zfs) initrd formats on FAT12, FAT16 and FAT32 EFI System Partitions.
Hope it helps somebody,
ps.: any testing result would be appreciated! Let me know how it worked for you!