Repository navigation
master_boot_record.md
The master boot record is built from v4.0/src/CMD/FDISK/FDBOOT.ASM. The binary is then incorporated into FDISK.EXE, which writes this image to the first sector of a hard disk.
The BIOS loads this image at 0000:7C00.
The master boot record sets the stack to begin at 0000:7C00. It then copies itself to 0000:0600 and jumps to the new copy, because it will load the system boot record at 0000:7C00.
It then scans the four partition table entries. These are documented elsewhere. The boot record code uses only the first four bytes of each entry.
The first byte is the boot flag. This must be 0x00 or 0x80, and at most one boot flag may be 0x80; this marks the entry that will be booted. If no table entry is marked bootable, the boot code issues INT 0x18; the source code says this goes to "ROM BASIC", but most PCs do not have ROM BASIC and the effect of INT 0x18 is undefined.
The next three bytes give the CHS coordinates of the system boot record. No attempt is made to use the LBA coordinates.
The boot code will try at most five times to load the system boot record at 0000:7C00. This record must have the signature (0x55 and 0xAA) at offset 0x01FE. It then jumps to the boot record, with DL set to 0x80 (actually the boot flag, but used as the physical drive number) and DS:SI pointing to the relevant partition table entry.