Skip to contentSkip to conversation

grub2 code

DISCUSSION Robert Parnell 6 participants 8 messages Feb 2, 2014 – Feb 5, 2014

lore
Share & tools
lore
#0 lore raw

Hi

I was just looking at the grub2 source code and saw that
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO>
says to contact with questions.
I was looking at the source because I encountered a bug on my machine that has been previously reported
(https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1027694) and thought I'd have a look to see if I could find the problem. So I have 2 questions:
1. Is the code on launchpad the up to date code?
2. Line 177 of
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S>
is a function that flushes the keyboard buffer, could this be what is causing the bug?

Sorry if 2 seems like a stupid question- I've never looked at the grub source code before.

Thanks

Rob

#1 lore raw
Quoted 8 lines · Robert Parnell

Hi

I was just looking at the grub2 source code and saw that

https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO
<
https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO

Quoted 1 line
Quoted 7 lines

says to contact with questions.
I was looking at the source because I encountered a bug on my machine that has been previously reported
(https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1027694) and thought I'd have a look to see if I could find the problem. So I have 2 questions:
1. Is the code on launchpad the up to date code?

That is probably maintained by the Ubuntu people, so I'd consult them. This list is generally for general and not distribution specific code since every distro can potentially use their own modified copies of GRUB.

Quoted 22 lines

2. Line 177 of

https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S
<
https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S

Quoted 1 line

is a function that flushes the keyboard buffer, could this be what is causing the bug?

Sorry if 2 seems like a stupid question- I've never looked at the grub source code before.

Thanks

Rob

_______________________________________________
Grub-devel mailing list
[email protected] <javascript:;>
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
In reply to Robert Parnell
Quoted 10 lines · Robert Parnell

I was just looking at the grub2 source code and saw that
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO>
says to contact with questions.
I was looking at the source because I encountered a bug on my machine that has been previously reported
(https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1027694) and thought I'd have a look to see if I could find the problem. So I have 2 questions:
1. Is the code on launchpad the up to date code?

It's an automatically-imported version of the Ubuntu packaging. It's up-to-date with what we're shipping, yes, but we do our work in git these days. The upstream code is here:

http://git.savannah.gnu.org/gitweb/?p=grub.git

... and the packaging used by both Debian and Ubuntu is here (the "experimental" branch is most current):

http://anonscm.debian.org/gitweb/?p=pkg-grub/grub.git

Quoted 5 lines

2. Line 177 of
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S>
is a function that flushes the keyboard buffer, could this be what is causing the bug?

That seems unrelated.

Ben's patch referenced in https://savannah.gnu.org/bugs/?34547 touches code that I wrote and that I maintain as a patch, so this would presumably be my problem to fix. But I don't understand why Ben's patch fixes anything related to NumLock. The code being commented out is essentially:

        movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
        andb    $3, (%bx)

... followed by something that tests the condition flags. But all that does is test whether either Shift key is held down, not actually set the NumLock state (see http://www.bioscentral.com/misc/bda.htm). That is, it reads from the BIOS Data Area, but it doesn't write to it.

Ben (CCed), could you shed some light on why your patch would fix this?

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]
#3 lore raw
Quoted 40 lines · Colin Watson
Quoted 10 lines · Robert Parnell

I was just looking at the grub2 source code and saw that
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/TODO>
says to contact with questions.
I was looking at the source because I encountered a bug on my machine that has been previously reported
(https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1027694) and thought I'd have a look to see if I could find the problem. So I have 2 questions:
1. Is the code on launchpad the up to date code?

It's an automatically-imported version of the Ubuntu packaging. It's up-to-date with what we're shipping, yes, but we do our work in git these days. The upstream code is here:

http://git.savannah.gnu.org/gitweb/?p=grub.git

... and the packaging used by both Debian and Ubuntu is here (the "experimental" branch is most current):

http://anonscm.debian.org/gitweb/?p=pkg-grub/grub.git

Quoted 5 lines

2. Line 177 of
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S>
is a function that flushes the keyboard buffer, could this be what is causing the bug?

That seems unrelated.

Ben's patch referenced in https://savannah.gnu.org/bugs/?34547 touches code that I wrote and that I maintain as a patch, so this would presumably be my problem to fix. But I don't understand why Ben's patch fixes anything related to NumLock. The code being commented out is essentially:

        movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
        andb    $3, (%bx)
Quoted 6 lines

... followed by something that tests the condition flags. But all that does is test whether either Shift key is held down, not actually set the NumLock state (see http://www.bioscentral.com/misc/bda.htm). That is, it reads from the BIOS Data Area, but it doesn't write to it.

Ben (CCed), could you shed some light on why your patch would fix this?

Adding Roger Cruz, as he was the original author of this fix, where I was just trying to get it upstreamed - though, this was quite some time since he developed it (Oct 2011), so I'm sure this isn't exactly fresh in his mind.

Roger, could you shed some light on this?

Ben

Quoted 5 lines

Thanks,

--
Colin Watson [[email protected]]

#4 lore raw

This was a bug that was introduced into GRUB when the code to detect if the SHIFT key is being pressed was added. The symptom was that customers were complaining that even though they had turn on NUMLOCK in the BIOS, once we booted our software, NUMLOCK was off. It was easy to "see" when the bug was happening because the NUMLOCK LED would turn off sometime during GRUB running.

I tracked it down to that one line which ANDs the BIOS state area and blows away the NUMLOCK state in it (it stores the value in the address in BX via indirect addressing).

Hope this helps. If it is not clear, please feel free to ask for more details.

Roger R. Cruz

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Guthro
Sent: Monday, February 03, 2014 7:42 AM
To: Colin Watson
Cc: [email protected]; Roger Cruz
Subject: Re: grub2 code

Quoted 45 lines · Colin Watson
Quoted 4 lines · Robert Parnell

I was just looking at the grub2 source code and saw that
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/tru
sty/view/head:/TODO
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/

Quoted 8 lines

trusty/view/head:/TODO>
says to contact with questions.
I was looking at the source because I encountered a bug on my machine that has been previously reported
(https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1027694) and thought I'd have a look to see if I could find the problem. So I have 2 questions:
1. Is the code on launchpad the up to date code?

It's an automatically-imported version of the Ubuntu packaging. It's up-to-date with what we're shipping, yes, but we do our work in git these days. The upstream code is here:

http://git.savannah.gnu.org/gitweb/?p=grub.git

... and the packaging used by both Debian and Ubuntu is here (the "experimental" branch is most current):

http://anonscm.debian.org/gitweb/?p=pkg-grub/grub.git

Quoted 7 lines

2. Line 177 of
https://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/grub2/tru
sty/view/head:/grub-core/boot/i386/pc/startup_raw.S
<https://bazaar.launchpad.net/%7Eubuntu-branches/ubuntu/trusty/grub2/
trusty/view/head:/grub-core/boot/i386/pc/startup_raw.S>
is a function that flushes the keyboard buffer, could this be what is causing the bug?

That seems unrelated.

Ben's patch referenced in https://savannah.gnu.org/bugs/?34547 touches code that I wrote and that I maintain as a patch, so this would presumably be my problem to fix. But I don't understand why Ben's patch fixes anything related to NumLock. The code being commented out is
essentially:

        movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
        andb    $3, (%bx)
Quoted 6 lines

... followed by something that tests the condition flags. But all that does is test whether either Shift key is held down, not actually set the NumLock state (see http://www.bioscentral.com/misc/bda.htm).
That is, it reads from the BIOS Data Area, but it doesn't write to it.

Ben (CCed), could you shed some light on why your patch would fix this?

Adding Roger Cruz, as he was the original author of this fix, where I was just trying to get it upstreamed - though, this was quite some time since he developed it (Oct 2011), so I'm sure this isn't exactly fresh in his mind.

Roger, could you shed some light on this?

Ben

Quoted 5 lines

Thanks,

--
Colin Watson [[email protected]]

#5 lore raw
Quoted 10 lines · Roger Cruz

This was a bug that was introduced into GRUB when the code to detect if the SHIFT key is being pressed was added. The symptom was that customers were complaining that even though they had turn on NUMLOCK in the BIOS, once we booted our software, NUMLOCK was off. It was easy to "see" when the bug was happening because the NUMLOCK LED would turn off sometime during GRUB running.

I tracked it down to that one line which ANDs the BIOS state area and blows away the NUMLOCK state in it (it stores the value in the address in BX via indirect addressing).

Oh, of course, I missed the indirect store even on a second reading. I'm pretty sure that the correct fix isn't to remove the code, but rather to use testb instead of andb. I'll see about getting that fixed soon.

Signature · 1 line
Colin Watson                                       [[email protected]]
#6 lore raw

Yes, that certainly would be a better fix. Thanks for addressing it.

Roger

-----Original Message-----
From: Colin Watson [mailto:[email protected]]
Sent: Monday, February 03, 2014 10:51 AM
To: Roger Cruz
Cc: Ben Guthro; [email protected]
Subject: Re: grub2 code

Quoted 10 lines · Roger Cruz

This was a bug that was introduced into GRUB when the code to detect if the SHIFT key is being pressed was added. The symptom was that customers were complaining that even though they had turn on NUMLOCK in the BIOS, once we booted our software, NUMLOCK was off. It was easy to "see" when the bug was happening because the NUMLOCK LED would turn off sometime during GRUB running.

I tracked it down to that one line which ANDs the BIOS state area and blows away the NUMLOCK state in it (it stores the value in the address in BX via indirect addressing).

Oh, of course, I missed the indirect store even on a second reading.
I'm pretty sure that the correct fix isn't to remove the code, but rather to use testb instead of andb. I'll see about getting that fixed soon.

Signature · 1 line
Colin Watson                                       [[email protected]]
#7 lore raw
In reply to Colin Watson
Quoted 2 lines · Colin Watson
        movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
        andb    $3, (%bx)

andb $3, (%bx) is equivalent to C code:
*(grub_uint8_t *)bx &= 3;
andb modifies the value at (%bx). You probably meant to use testb which has same flag semantics but doesn't change operands