What is the proper way to write a BIOS Parameter B

2019-07-16 20:46发布

问题:

After writing some basic code for a bootloader, I made an .img image to test it. On Bochs, it ran just as expected; however, when I wrote the image to a USB and tried to test it on a real device, I suddenly got a No bootable device found message. After a bit of web crawling on the internet, I found out that I may need a BIOS Parameter Block (BPB). I copied and pasted a BPB that I found, and suddenly everything worked. Here is the code, in case it is needed:

bpbBytesPerSector:      DW 512
bpbSectorsPerCluster:   DB 1
bpbReservedSectors:     DW 1
bpbNumberOfFATs:        DB 2
bpbRootEntries:         DW 224
bpbTotalSectors:        DW 2880
bpbMedia:               DB 0xF0
bpbSectorsPerFAT:       DW 9
bpbSectorsPerTrack:     DW 18
bpbHeadsPerCylinder:    DW 2
bpbHiddenSectors:       DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber:          DB 0
bsUnused:               DB 0
bsExtBootSignature:     DB 0x29
bsSerialNumber:         DD 0xa0a1a2a3
bsVolumeLabel:          DB "AOS Floppy "
bsFileSystem:           DB "FAT12   "

From my understanding, the BPB describes the physical properties of a storage device. I also understand the individual components of the BPB. However, I do not see how a single BPB could describe the many file systems that the bootloader can be loaded from.

That is, wouldn't some of these values change depending on the device that the end-user decided to use for installing and running the operating system? Does the BPB describe the volume that the bootloader is found on? And if so, would these properties also not vary depending on the user's device?