bbqribs wrote: ↑Mon Sep 15, 2025 11:23 am
I just used the first sector to write BPB headers and read stage 2 off reserved sectors, no driver. Stage 2 is where I'm planning to enter protected mode and read the kernel as that has a 31 sector limit, which should be enough to get me up and running at least.
Without sounding like I am discouraging you from doing that, here are two advantages to do it slightly different.
First, since you state you will have a BPB, you are using FAT, correct? There are some systems (though very few today) that assume the reserved area of a FAT volume is a single sector. Not much a big deal today, but was in the past.
Second, I suggest that you create your 2nd stage loader as a file in the root directory. If you can assume the root directory and the file name, with a little bit of effort, you can write a FAT loader within the almost 475 bytes remaining in the first sector of the volume that will find and load the file. This gives the advantage that when you update the code, you can simply write to the media as a file. No need to write as sectors, and you don't have the 31-sector limit you mention.
To contradict my first comment, I did this in three sectors, but by doing so, I had plenty of space for error handling, checked for a 32-bit machine, checked for BIOS Extended Disk services, allowed fragmented files, as well as the code first looked for the loader file in the root directory. If not found, it tried the \BOOT directory, and finally if not found, it tried the \SYSTEM\BOOT directory. Not really a big deal since your first stage loader should know where your second stage loader is, right? But as an example, it shows that it can be done within the first few sectors of the volume and in assembly.
I won't point you to that code, because it would be too easy to "steal" it, not saying that you would, but it is quite easy to copy, paste, and modify to fit your needs, am I wrong? :-)
There is another advantage to this technique. If your compiler is capable of making a (somewhat) flat executable, the second stage can be written in a higher-level language. Even a simple DOS .EXE file can be easily loaded and "jumped to".
Ben