contradiction in boot/i386/pc/boot.S
boot/i386/pc/boot.S reads:
/*
* 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).
*/boot_drive_check:
jmp 1f /* grub-setup may overwrite this jump */
testb $0x80, %dl
jnz 1f
movb $0x80, %dl1:
However, if 0x80 is really "the only possible boot drive", that means the test is pointless and can be replaced with:
boot_drive_check:
jmp 1f /* grub-setup may overwrite this jump */
movb $0x80, %dl
1:
So AFAICT either the comment or the code needs adjusting.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 9 lines · Robert Millan
However, if
0x80is really "the only possible boot drive", that means the test is pointless and can be replaced with:
boot_drive_check:
jmp 1f /* grub-setup may overwrite this jump */
movb $0x80, %dl
1:So AFAICT either the comment or the code needs adjusting.
I think the code allows simplification regardless of what the comment says.
Actually, the shortest solution (and we really want to be short in the bootsector) would be to only have NOPs there without any jumps, and have grub-setup overwrite the NOPs with "movb $0x80, %dl" for hard drive installations.
Or the other way around - have "movb $0x80, %dl" in the code and have grub-setup overwrite it with NOPs if installing not on a hard drive.
And by the way, I would remove the "boot_drive_check" label where it is now and rename "real_start" to it, moving that "movb" there. That would save a us label, making the code easier to read.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 9 lines · Robert Millan
boot_drive_check:jmp 1f /* grub-setup may overwrite this jump */ testb $0x80, %dl jnz 1f movb $0x80, %dl1:
However, if
0x80is really "the only possible boot drive", that means the test is pointless and can be replaced with:
No, I was wrong, I misread "testb" as "cmpb". Values such as 0x81 are valid and should be preserved.
Please ignore my previous message.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 8 lines · Pavel Roskin
Quoted 7 lines · Robert Millan
boot_drive_check:jmp 1f /* grub-setup may overwrite this jump */ testb $0x80, %dl jnz 1f movb $0x80, %dl1:
Quoted 5 lines
Quoted 2 lines
However, if
0x80is really "the only possible boot drive", that means the test is pointless and can be replaced with:No, I was wrong, I misread "testb" as "cmpb". Values such as
0x81are valid and should be preserved.
Yeah I was going to point that..
Quoted 1 line
Please ignore my previous message.
All of it, or just partly ?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 12 lines · Robert Millan
Quoted 11 lines · Pavel Roskin
Quoted 9 lines · Robert Millan
boot_drive_check:jmp 1f /* grub-setup may overwrite this jump */ testb $0x80, %dl jnz 1f movb $0x80, %dl1:
However, if
0x80is really "the only possible boot drive", that means the test is pointless and can be replaced with:
Quoted 8 lines
Quoted 2 lines
No, I was wrong, I misread "testb" as "cmpb". Values such as
0x81are valid and should be preserved.Yeah I was going to point that..
Quoted 1 line
Please ignore my previous message.
All of it, or just partly ?
All of it, I'm afraid.
However, it's possible to save 2 bytes if we get rid of the first short jump and overwrite the whole section (testb, jnz, movb) with NOPs for the floppies.
We can save 4 more bytes if we do "orb $0x80, %dl" unconditionally for the hard drives. However, I'm not sure if there are BIOSes that pass 1 in %dl and how critical it would be if it becomes 0x81. That's something I'll rather not do without seeing the original bug reports.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 4 lines · Pavel Roskin
We can save 4 more bytes if we do "orb $0x80, %dl" unconditionally for the hard drives. However, I'm not sure if there are BIOSes that pass 1 in %dl and how critical it would be if it becomes
0x81.
I think the assumption is that if the BIOS passes 0x01, etc, it's garbage and should be ignored completely.
Quoted 2 lines
That's
something I'll rather not do without seeing the original bug reports.
Same here. Maybe Okuji will know..
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 5 lines · Robert Millan
Quoted 2 lines · Pavel Roskin
That's
something I'll rather not do without seeing the original bug reports.Same here. Maybe Okuji will know..
I have a box with this bug - sadly, I will not be able to reach it within the next 2 months - so I can test various proposals if provided with patches :) .
IIRC originaly this fix was dropped from gub to grub2, and I re-raised the issue. But that's all, I don't think I touched the code.
Vincent Pelletier
Quoted 1 line · Vincent Pelletier
within the next 2 months
Gah. "next 2 weeks".
Vincent Pelletier
Quoted 8 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
We can save 4 more bytes if we do "orb $0x80, %dl" unconditionally for the hard drives. However, I'm not sure if there are BIOSes that pass 1 in %dl and how critical it would be if it becomes
0x81.I think the assumption is that if the BIOS passes
0x01, etc, it's garbage and should be ignored completely.
I understand the assumption.
Quoted 4 lines
Quoted 2 lines
That's
something I'll rather not do without seeing the original bug reports.Same here. Maybe Okuji will know..
When I tried to actually change the code, it turned out that grub-mkimage doesn't change the boot sector, so grub-mkimage needs to be adjusted, and maybe some other tools.
Alternatively, the logic should not be reverted, i.e. the adjustments should be done for the hard drive installs. This means that grub-setup should write valid x86 code over NOPs. It gets too complicated to bother without having a very good incentive to save those 2 bytes.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 2 lines · Pavel Roskin
[...]. It gets too complicated to
bother without having a very good incentive to save those 2 bytes.
Heh, you have a point here.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)