Kamis, 20 Februari 2014

How It Works -- Master Boot Record

   This article is a disassembly of a Master Boot Record (MBR).  The MBR is the sector at cylinder 0, head 0, sector 1 of a hard disk. An MBR is created by the FDISK program.  The FDISK program of all operating systems must create a functionally similar MBR. The MBR is first of what could be many partition sectors, each one containing a four entry partition table.

   At the completion of your system's Power On Self Test (POST), INT 19 is called.  Usually INT 19 tries to read a boot sector from the first floppy drive.  If a boot sector is found on the floppy disk, the that boot sector is read into memory at location 0000:7C00 and INT 19 jumps to memory location 0000:7C00. However, if no boot sector is found on the first floppy drive, INT 19 tries to read the MBR from the first hard drive.  If an MBR is found it is read into memory at location 0000:7c00 and INT 19 jumps to memory location 0000:7c00.  The small program in the MBR will attempt to locate an active (bootable) partition in its
partition table.  If such a partition is found, the boot sector of that partition is read into memory at location 0000:7C00 and the MBR program jumps to memory location 0000:7C00.  Each operating system has its own boot sector format.  The small program in the boot sector must locate the first part of the operating system's kernel loader program (or perhaps the kernel itself or perhaps a "boot manager program") and read that into memory.

INT 19 is also called when the CTRL-ALT-DEL keys are used.  On most systems, CTRL-ALT-DEL causes an short version of the POST to be executed before INT 19 is called.


=====

Where stuff is:

   The MBR program code starts at offset 0000.
   The MBR messages start at offset 008b.
   The partition table starts at offset 00be.
   The signature is at offset 00fe.

Here is a summary of what this thing does:

   If an active partition is found, that partition's boot record is read into 0000:7c00 and the MBR code jumps to 0000:7c00 with SI pointing to the partition table entry that describes the partition being booted.  The boot record program uses this data to determine the drive being booted from and the location of the partition on the disk. If no active partition table enty is found, ROM BASIC is entered via INT 18.  All other errors cause a system hang, see label HANG.

NOTES (VERY IMPORTANT):

   1) The first byte of an active partition table entry is 80. This byte is loaded into the DL register before INT 13 is called to read the boot sector.  When INT 13 is called, DL is the BIOS device number.  Because of this, the boot sector read by this MBR program can only be read from BIOS device number 80 (the first hard disk).  This is one of the reasons why it is usually not possible to boot from any other hard disk.

   2) The MBR program uses the CHS based INT 13H AH=02H call to read the boot sector of the active partition.  The location of the active partition's boot sector is in the partition table entry in CHS format.  If the drive is >528MB, this CHS must be a translated CHS (or L-CHS, see my BIOS TYPES document). No addresses in LBA form are used (another reason why LBA doesn't solve the >528MB problem).

=====
Version 1a by Hale Landis (landis@sugs.tware.com)

Tidak ada komentar:

Posting Komentar