GRUB src code: forced reference?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kikou
Posts: 2
Joined: Sat Jun 23, 2012 10:42 pm

GRUB src code: forced reference?

Post by kikou »

I was looking at grub2 stage1 source code and saw this:

Code: Select all

        /*
         *  Check if we have a forced disk reference here
         */
        movb   boot_drive, %al
        cmpb    $0xff, %al
        je      1f
        movb    %al, %dl
1:
"boot_drive" is defined in the same file as follows:

Code: Select all

boot_drive:
        .byte 0xff      /* the disk to load kernel from */
                        /* 0xff means use the boot drive */
First of all what is a "forced disk reference"?
The code above doesn't make sense to me. It loads %al with 0xff, then compares the same %al with 0xff, then jumps to 1. In what case movb %al, %dl is executed?
By the way, is 0xff a drive code used in INT 13H? Is there a list of those codes somewhere?

Here is the complete source code, just in case: http://paste.ideaslabs.com/show/VekL2gH914
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: GRUB src code: forced reference?

Post by sounds »

The stage1 loader is compiled with 0xff at the location boot_drive:

As an option, the installer (also known as grub) will patch the 0xff there and write a different byte. Then when the stage1 loader runs, it will prefer that value and ignore the value in %dl

This is to fix bugs where the value supplied in %dl sends stage1 off looking for stage1.5 someplace where it can't find it, and preventing grub from booting.
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: GRUB src code: forced reference?

Post by shikhin »

Hi,
sounds wrote:As an option, the installer (also known as grub) will patch the 0xff there and write a different byte. Then when the stage1 loader runs, it will prefer that value and ignore the value in %dl.

This is to fix bugs where the value supplied in %dl sends stage1 off looking for stage1.5 someplace where it can't find it, and preventing grub from booting.
Then, shouldn't that be

Code: Select all

jne 1f
, so that when the installer has patched the 0xFF and written a different byte, it prefers the different byte, and in case it is 0xFF, it uses the value in %dl?

Just asking..

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: GRUB src code: forced reference?

Post by jnc100 »

Shikhin wrote:Then, shouldn't that be

Code: Select all

jne 1f
, so that when the installer has patched the 0xFF and written a different byte, it prefers the different byte, and in case it is 0xFF, it uses the value in %dl?
It's gas syntax. The 'output' from this little snippet is in dl. If boot_drive is not 0xff then dl is overwritten with whatever it contains, otherwise dl is left as it was set up by the bios.

Regards,
John.
kikou
Posts: 2
Joined: Sat Jun 23, 2012 10:42 pm

Re: GRUB src code: forced reference?

Post by kikou »

sounds wrote:This is to fix bugs where the value supplied in %dl sends stage1 off looking for stage1.5 someplace where it can't find it, and preventing grub from booting.
But how does the grub installer know that a wrong value will be passed to %dl? And does the value it puts on boot_drive address corresponds to the device it is being installed, like 0x80 for hdd?
Post Reply