I am working on writing my own operating system. So far, my code exceeds 512 bytes, which is too large to fit in a simple boot sector.
I understand that I now have to write a bootloader that reads arbitrary code that may or may not be greater than a single 512-byte sector.
The bootloader would need to:
- Function as a boot record with disk signature 0xaa55.
- Read a second stage (the test code) start from LBA 1 (LBA 0 is boot sector) of arbitrary length starting at memory address 0x7E00.
- Transfer control to it using a FAR JMP to 0x0000:0x7E00.
- Be usable as a 1.44 MiB floppy disk image for use in emulators like QEMU, BOCHS, VirtualBox etc.
- Can be transferred and used on a USB stick to test on real hardware with the BIOS set to boot USB using Floppy Disk Drive (FDD) emulation. Note: Some bootloaders do not work well when placed on USB drives.
- Pass the boot drive to the second stage in DL.
- Zero out all the segment registers and set SS:SP to 0x0000:0x7C00 (grows down from just under the bootloader).
This would also serve as a good starting point for asking questions on Stack Overflow that involve OS development. Programmers often struggle to create a Minimal, Complete, and Verifiable Example. A common boilerplate/template would allow other Stack Overflow users wishing to help to test the code with a limited amount of fuss.
How would I go about building such a reusable bootloader?