This is the forth in a series of patches that removes a bug and some glitches from GRUB stage 1. This is against grub-0.94 (alpha), my first three patches applied. Submitted by Wolf Lammen, ookami1gmxde I looked through the complete code of stage 1 and found some oddities. This patch addresses one: makes boot_drive_mask a variable at a fixed location. Impact: increases code by 1 byte, eases maintainance of the code. Details: Currently, the GRUB installer writes the value of boot_drive_mask (corrects buggy BIOSes which do not supply the HDD_FLAG) directly into the mid of an instruction. This method has its clear downsides: 1. Whenever somebody modifies the stage1.S code, s/he has to look whether the compiler moved the patch location and s/he has to keep stage1.h adjusted, all done by hand. For instance, I always had to compile stage 1 alone, make a hex dump from the produced code to see where the patch location moved, edit stage1.h to adjust the address for boot_drive_mask, and then compile the package again. These are obviously some steps too much. 2. It is difficult to maintain orthogonal patches, because if both move the patch location, they interfere with each other. 3. This is not a standard procedure, so programmers not familiar with GRUB may easily overlook a necessary adjusting of stage1.h. Instead of patching an instruction, make boot_drive_mask an ordinary variable at a fixed location and let's have the compiler do what it is build for: provide the hex math and address calculation. This patch comes along with another one patching stage1.h. Use them both. --- stage1.S 2004-02-09 06:27:23.000000000 +0100 +++ stage1.S.new 2004-02-09 06:42:12.000000000 +0100 @@ -93,14 +93,19 @@ boot_drive: .byte 0xff /* the disk to load stage2 from */ /* 0xff means use the boot drive */ -force_lba: - .byte 0 +boot_drive_mask: + .byte 0 /* workaround for buggy BIOSes that */ + /* do not pass the drive number */ + /* correctly. If GRUB is installed */ + /* on a HDD, set this to 0x80, else 0 */ stage2_address: .word 0x8000 stage2_sector: .long 1 stage2_segment: .word 0x800 +force_lba: + .byte 0 after_BPB: @@ -112,15 +117,7 @@ movw $STAGE1_STACKSEG, %sp sti /* just in case the BIOS or a chainloader disabled interrupts */ - - /* - * This is a workaround for buggy BIOSes which don't pass boot - * drive correctly. If GRUB is installed into a HDD, do - * "orb $0x80, %dl", otherwise "orb $0x00, %dl" (i.e. nop). - */ - .byte 0x80, 0xca -boot_drive_mask: - .byte 0x00 + orb ABS(boot_drive_mask), %dl /* workaround for buggy BIOSes */ /* * ljmp to the next instruction because some bogus BIOSes