I know that the BIOS goes through connected storage devices (floppy disks, CDs, hard drives ... etc) in the order it is configured to (which can be changed in the BIOS settings), looking for the magic 16-bit value (0xAA55) at the end of the first sector of each, and upon finding one it loads (what just became) the boot sector and calls it.
Let's name the device containing the loaded boot sector X. My question is: Instead of looping through all devices, can you identify X and use the BIOS' disk interrupt function to read from it without having to test every connected device? For instance, does BIOS store X's ID somewhere?
Thanks.
P.S. I'm working on an IA-32 machine emulated using BOCHS, I'm always loading from floppy disk #1 so I can hardcode the reading from it, but for the sake of writing clean code and learning I'm asking. I acknowledge that testing all devices is definitely practical.
When the BIOS passes control to the boot loader it stores "BIOS device ID" in the DL
register, so boot loader can just use the device ID it was told to use for all subsequent BIOS functions.
The main problem is that "BIOS device ID" is relatively useless after early boot (after the OS starts using its own disk drivers and stops using BIOS functions); because there's no easy way to determine which device happened to be given which "BIOS device ID"; especially for cases like "RAID 1 mirror" where you might have 2 mostly identical hard drives with mostly identical contents.
I acknowledge that testing all devices is definitely practical.
Heh, no. Install 2 separate copies of the OS on 2 different hard drives (so that you've got 2 boot loaders, one for each copy of the OS) and it becomes impossible for "test all devices" to tell the difference between the OS you booted and the OS you didn't boot.