Finding out which drive was booted in x86 bootload

2020-05-09 05:53发布

问题:

I'm writing a game bootloader for x86. At one point, early in the booting, I need to load some sectors from my boot drive into memory. I do this with interrupt 0x13 (ah=02), and when I try it in my virtual machine it works like a charm. However when I burn the image to a usb drive, the machine fails to boot, and I pinned it down to the sector loading instructions, apparently my usb drive isn't drive 0 (Floppy A), so the read fails.

How can I determine which drive was used to boot?

Thanks!

回答1:

BIOS loads number of drive bootloader was loaded from to register dl. Source: OSDev Wiki, section MBR Bootstrap.