Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: confused by the several lines of source code in mbr.S



On Tue, Jan 08, 2008 at 10:01:29PM +0800, abutter gao wrote:
> First, I am confused by the following lines of code from the mbr.S in
> i386/stand/mbr directory.

If you understand the rest of the code - well done :-)

> ---------------------------------- snip
> --------------------------------------------------------
> 216     movw    $lba_info, %si
> 217     movb    $0x42, %ah
> 218     pop     %dx                     /* recover drive # */
> 219     push    %dx                     /* save drive */
> 220     int     $0x13
> 221     jc      wait_key                /* abort menu on read fail */
> 222     cmpw    $MBR_MAGIC, LOADADDR + MBR_MAGIC_OFFSET
> 223     movw    $nametab - LOADADDR + BOOTADDR, %bx
> 224     je      next_extended
> ---------------------------------- snip
> --------------------------------------------------------
> 
> Moreover, the BOOTADDR and LOADADDR are defined as below:
> 
> ---------------------------------- snip
> --------------------------------------------------------
> 65 #define BOOTADDR     0x7c00
> 66 #define LOADADDR     0x0600          /* address were are linked to */
> ---------------------------------- snip
> --------------------------------------------------------
> 
> When we call INT 0x13, BIOS will transfer the PBR code to the address
> BOOTADDR included in the lba_info struct, and then we should check
> whether the PBR code is valid.
> 
> The address LOADADDR + MBR_MAGIC_OFFSET in line 222 is 0x0600 +
> MBR_MAGIC_OFFSET, which is just the magic number's address of the mbr
> code but not the PBR code, and no process will modify the mbr's magic
> number, so, there is alwasy a jump to next_extended.
> 
> So, is there any other purpos or just a bug because of incaution?

Certainly the intention is to look for the 0x55aa in the extended
partition table in order to validate it.
OTOH it does indeed look as the wrong location is checked.

I'll either fix it, or delete the test - since no one has reported any
problems with the code processing invalid sectors.

        David

-- 
David Laight: david%l8s.co.uk@localhost



Home | Main Index | Thread Index | Old Index