A simple boot sector for a single disk/single OS


How much can you squeeze in to the 512 bytes of a boot sector? Do you place just enough to get some sort of file system going, loading the rest of your loader in to another area, or do you try to place all of your loader in the boot sector and hope the 512 bytes is enough?

By the time you count the word at the end of the 512-byte page, a possible BPB at the start, your register set up, and any other code that you might need to begin with, you have cut the 512-byte page down to about 450 bytes.

What is it that has to be done to get our OS up and running and can it fit in this now 450-byte area? Since the BIOS only loaded the boot sector, now needed is to load the files for the OS, or load a loader, which when executed, will load these files. With these 450 bytes, there should be plenty of room to code a loader of some kind, right? Now, where are the OS files on the disk?

What if it is assumed that these files are always in the same place on the disk each time? Once the OS is loaded and the user has control, what if the user moves one of these files? Now the OS file is in a new location on the disk. The next time the boot process takes place, the loader no longer can find the OS files in its defined position, and guess what happens? With this in mind, the best thing to do is create a loader that can look for the OS files on the disk. Now the loader will get a little larger. What about the File System on the disk, the loader now has to know what type of file system is on the disk to be able to load the OS. Will this loader still fit in 450 bytes of disk space?

Loading a loader? If the loader can be found, loaded, and executed in this 450-byte block, why can't the OS file(s) be found, loaded, and executed in 450 bytes? Which came first, the Chicken or the Egg?

What is my conclusion? I take part of each choice above and created a small loader that fits in a 512-byte boot sector. Since there are 512 bytes per disk sector and I have 32-byte ROOT entries, this gives me 16 ROOT entries to store up to 16 OS files. Then I mark each used entry's FAT entry as "used by the OS". Knowing this, my loader can assume that it only has to load and look in the first sector of the ROOT Table, and the first sector of the FAT, with each sector pointed to by the BPB in the first part of the boot sector. Now the only thing assumed is that there are not more than 16 files that must be loaded, and these files do not take more than 256 sixteen-bit FAT entries.

What if the user moves one of the files to another sector, you ask? Since the FAT entry's for each file are marked as "used by the OS", the OS will not delete them from the ROOT Table, or mark their FAT table entries as free entries, thus not being able to move them.

I have done this in the given 512 bytes with 97 bytes to spare. I even use LBA addressing ... see you next time.