Skip to contentSkip to conversation

Workaround for the keyboard hang problem in intel mac

PATCH In review Bean 3 participants 5 messages May 6, 2008 – May 7, 2008

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 Workaround for the keyboard hang problem in intel mac

Hi,

This patch fix the keyboard hang problem when using boot camp to load legacy system.

kern/i386/pc/startup.S +13 -0
index 5d4bbcb..455233a 100644
@@ -1240,6 +1240,19 @@ FUNCTION(grub_console_getkey)
 	call	prot_to_real
 	.code16
 
+	pushfw
+	sti
+
+1:
+	movb	$1, %ah
+	int	$0x16
+	jnz	2f
+	hlt
+	jmp	1b
+
+2:
+	popfw
+	movb	$0, %ah
 	int	$0x16
 
 	movw	%ax, %dx		/* real_to_prot uses %eax */
Signature · 1 line
Bean
#1 lore raw
Quoted 16 lines · Bean

Hi,

This patch fix the keyboard hang problem when using boot camp to load legacy system.

kern/i386/pc/startup.S +3 -0
index 5d4bbcb..455233a 100644
@@ -1240,6 +1240,19 @@ FUNCTION(grub_console_getkey)
 	call	prot_to_real
 	.code16
 
+	pushfw
+	sti
+

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1255

Quoted 10 lines
kern/i386/pc/startup.S +10 -0
+1:
+	movb	$1, %ah
+	int	$0x16
+	jnz	2f
+	hlt
+	jmp	1b
+
+2:
+	popfw
+	movb	$0, %ah

I think it'd be nice to have a comment there explaining why this is done.

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 /.)
author
#2 lore raw
Quoted 1 line · Robert Millan

I think it'd be nice to have a comment there explaining why this is done.

Hi,

You're right, here is the patch with comment:

kern/i386/pc/startup.S +20 -0
index 5d4bbcb..a67bf6d 100644
@@ -1240,6 +1240,26 @@ FUNCTION(grub_console_getkey)
 	call	prot_to_real
 	.code16
 
+	/*
+	 * Due to a bug in apple's bootcamp implementation, INT 16/AH = 0 would
+	 * cause the machine to hang at the second keystroke. However, we can
+	 * work around this problem by ensuring the presence of keystroke with
+	 * INT 16/AH = 1 before calling INT 16/AH = 0.
+	 */
+
+	pushfw
+	sti
+
+1:
+	movb	$1, %ah
+	int	$0x16
+	jnz	2f
+	hlt
+	jmp	1b
+
+2:
+	popfw
+	movb	$0, %ah
 	int	$0x16
 
 	movw	%ax, %dx		/* real_to_prot uses %eax */
Signature · 1 line
Bean
#3 lore raw

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1248

Quoted 6 lines · Bean
kern/i386/pc/startup.S +6 -0
+	/*
+	 * Due to a bug in apple's bootcamp implementation, INT 16/AH = 0 would
+	 * cause the machine to hang at the second keystroke. However, we can
+	 * work around this problem by ensuring the presence of keystroke with
+	 * INT 16/AH = 1 before calling INT 16/AH = 0.
+	 */

Can it be because interrupts are not enabled during the call?

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1251

Quoted 2 lines
kern/i386/pc/startup.S +2 -0
+	pushfw
+	sti

...

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1261

Quoted 1 line
kern/i386/pc/startup.S +1 -0
+	popfw

I would prefer explicit sti and cli without saving flags on the stack, unless we want the code work with both enabled and disabled interrupts.

Robustness is not always handling unexpected situations. Sometimes it's enforcing the rules and being clear about it.

It's just a suggestion, not an invitation for a long discussion about three instructions :-)

Signature · 2 lines
Regards,
Pavel Roskin
author
#4 lore raw
Quoted 10 lines · Pavel Roskin

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1248

Quoted 6 lines · Bean
kern/i386/pc/startup.S +6 -0
+     /*
+      * Due to a bug in apple's bootcamp implementation, INT 16/AH = 0 would
+      * cause the machine to hang at the second keystroke. However, we can
+      * work around this problem by ensuring the presence of keystroke with
+      * INT 16/AH = 1 before calling INT 16/AH = 0.
+      */

Can it be because interrupts are not enabled during the call?

I just check, enabling interrupt alone doesn't solve the problem. According to the discussion at:

https://www.opensolaris.org/jive/thread.jspa?threadID=7554&tstart=0

Some I/O port is not implemented, I guess this cause INT 16/AH = 0 to wait forever.

Quoted 6 lines

kern/i386/pc/startup.S FUNCTION(grub_console_getkey) · line 1251

Quoted 3 lines
kern/i386/pc/startup.S +2 -0
+     pushfw
+     sti

...

Quoted 1 line

+ popfw

Quoted 8 lines

I would prefer explicit sti and cli without saving flags on the stack, unless we want the code work with both enabled and disabled interrupts.

Robustness is not always handling unexpected situations. Sometimes it's enforcing the rules and being clear about it.

It's just a suggestion, not an invitation for a long discussion about three instructions :-)

Yep, actually, I think even the ending cli can be omitted, because it will jump right back to protected mode after the keystroke is received.

Signature · 1 line
Bean