GRUB master boot record

Like the Boot Records of an OS, the first three bytes could be called the Jump Instruction. But only the first two bytes are being used to form the actual JMP (Jump) instruction to the rest of the executable code; the third byte (90h) is just a NOP instruction ('No Op' do nothing). So the execution jumps over the 71 next bytes which can be thought of as a BIOS Parameter Block (or BPB); BIOS parameter block (BPB) is a description of the physical medium (hard disk or floppy) that might be stored in a file system=E2=80=99s Volume Boot Record. File systems with a BIOS parameter block include FAT16, FAT32, HPFS, and NTFS. ECMA-107 or ISO/IEC 9293 (which describes FAT as for flexible/floppy and optic distal disk cartridges) also describes this as an FDC Descriptor or an FDC Extended Descriptor.

00000000 EB48 jmp short 0x4a 00000002 90 nop Jump to the start of the program at 0x7c00 and is jumped to with CS:IP 0:0x7c00. Jump over BPB data area to main body of code. This BPB Data Area (BIOS Parameter Block) is filled with useful data for any program examining it as a normal Volume Boot Record.

The BYTES in the BPB which are referenced in the code below are:

[00000005] -> 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE ("Disk Address Packet" for LBA mode.) [00000040] -> 80 ("Boot Drive") NOTE: For those of you with multi- OS booting systems, if your Linux installation with GRUB's remaining software (stage2, menu file, etc.) is located somewhere other than on the Primary Master drive, this value will be 81, 82, etc. depending upon which drive that Linux OS's /boot/grub directory is located. [00000041] -> 00 ("Force LBA mode byte") [00000042] -> 00 80 (8000h) Memory location where GRUB stores the next stage of the code to execute. [00000044] -> Note: A very important location for anyone using GRUB! This (4-byte) Quad-Word contains the location of GRUB's stage2 file in sectors! You will always see the bytes 01 00 00 00 in this location whenever GRUB has been installed in the first track (Sectors 1 ff.) of an HDD; immediately following the GRUB MBR in Absolute Sector 0. [00000048] -> 00 08 (800h) [Don't confuse this with the 8000 at 00000042.]

00000003 10

00000004 8E 00000005 D0 00000006 BC 00000007 00 00000008 B0 00000009 B8 0000000A 00 0000000B 00 0000000C 8E 0000000D D8 0000000E 8E 0000000F C0 00000010 FB 00000011 BE 00000012 00 00000013 7C 00000014 BF 00000015 00 00000016 06 00000017 B9 00000018 00 00000019 02 0000001A F3 0000001B A4 0000001C EA 0000001D 21 0000001E 06 0000001F 00 00000020 00 00000021 BE 00000022 BE 00000023 07 00000024 38 00000025 04 00000026 75 00000027 0B 00000028 83 00000029 C6 0000002A 10 0000002B 81 0000002C FE 0000002D FE 0000002E 07 0000002F 75 00000030 F3 00000031 EB 00000032 16 00000033 B4 00000034 02 00000035 B0 00000036 01 00000037 BB 00000038 00 00000039 7C 0000003A B2 0000003B 80 0000003C 8A 0000003D 74 0000003E 03 0000003F 02 00000040 80 00000041 00 00000042 00 00000043 80 00000044 8B 00000045 82 00000046 00 00000047 00 00000048 00 00000049 08

General setup:

0000004A FA cli This line will Clear Interrupt Flag This is a workaround for buggy BIOSes which don't pass boot drive correctly. If GRUB is installed into a HDD, check if DL is masked correctly. If not, assume that the BIOS passed a bogus value and set DL to 0x80, since this is the only possible boot drive. If GRUB is installed into a floppy, this does nothing (only jump).

0000004B EA507C0000 jmp 0x0:0x7c50 Long Jump to the next instruction because some bogus BIOSes jump to

07C0:0000 instead of 0000:7C00.

00000050 31C0 xor ax,ax

00000052 8ED8 mov ds,ax 00000054 8ED0 mov ss,ax set up %ds and %ss as offset from 0

00000056 BC0020 mov sp,0x2000 set up the REAL stack

00000059 FB sti Set Interrupt Flag This instruction sets the interrupt flag (IF) in the EFLAGS register. After the IF flag is set, the processor begins responding to external, mask able interrupts after the next instruction is executed.

0000005A A0407C mov al,[0x7c40]

Reply to
Navid Shakibapour
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.