From eb565e38400d7cbf7afbcc692fc3c173a09c4d68 Mon Sep 17 00:00:00 2001 From: Michael Steil Date: Mon, 4 Dec 2006 15:00:11 +0000 Subject: [PATCH] ReactOS Intel Mac compatibility commits, part 1/2, by Michael Steil. == A20 Gate and the Keyboard Controller == In order to turn on the A20 gate, the keyboard controller has to be emptied. This is done in freeldr by reading bytes until the keyboard controller signals it's empty. Intel Macs don't have PS/2 keyboard controller and the status register always reads back 0xFF, so the "there is data" bit will never be cleared. (The same problem has been in GRUB as well as in Darwin's BIOS loader.) Added code that doesn't bother to clear the keyboard buffer if the status port reads back 0xFF. == Serial Port BIOS Bug == Insyde's BIOS reports that there is a COM1 serial port at 0x3F8 (as stored in 0040:0000 in memory), but there is none in Intel Macs, so freeldr spins infinitely while trying to empty the serial port's buffer. Added code that makes sure the loop only gets executed up to 200 times svn path=/trunk/; revision=25062 --- reactos/boot/freeldr/freeldr/arch/i386/arch.S | 3 +++ .../boot/freeldr/freeldr/arch/i386/hardware.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/arch/i386/arch.S b/reactos/boot/freeldr/freeldr/arch/i386/arch.S index 71db4299397..66e9f5c6b17 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/arch.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/arch.S @@ -219,8 +219,11 @@ inrmode: empty_8042: .word 0x00eb,0x00eb // jmp $+2, jmp $+2 inb $0x64,%al + cmp $0xff, %al // legacy-free machine without keyboard + jz empty_8042_ret // controllers on Intel Macs read back 0xFF testb $0x02,%al jnz empty_8042 +empty_8042_ret: ret /* diff --git a/reactos/boot/freeldr/freeldr/arch/i386/hardware.c b/reactos/boot/freeldr/freeldr/arch/i386/hardware.c index ff3d33d52f3..a7c8a894abb 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/hardware.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/hardware.c @@ -987,7 +987,7 @@ DetectSerialMouse(ULONG Port) { CHAR Buffer[4]; ULONG i; - ULONG TimeOut = 200; + ULONG TimeOut; UCHAR LineControl; /* Shutdown mouse or something like that */ @@ -995,9 +995,19 @@ DetectSerialMouse(ULONG Port) WRITE_PORT_UCHAR((PUCHAR)Port + 4, (LineControl & ~0x02) | 0x01); StallExecutionProcessor(100000); - /* Clear buffer */ + /* + * Clear buffer + * Maybe there is no serial port although BIOS reported one (this + * is the case on Apple hardware), or the serial port is misbehaving, + * therefore we must give up after some time. + */ + TimeOut = 200; while (READ_PORT_UCHAR((PUCHAR)Port + 5) & 0x01) - READ_PORT_UCHAR((PUCHAR)Port); + { + if (--TimeOut == 0) + return MOUSE_TYPE_NONE; + READ_PORT_UCHAR((PUCHAR)Port); + } /* * Send modem control with 'Data Terminal Ready', 'Request To Send' and @@ -1009,6 +1019,7 @@ DetectSerialMouse(ULONG Port) StallExecutionProcessor(10000); /* Read first four bytes, which contains Microsoft Mouse signs */ + TimeOut = 200; for (i = 0; i < 4; i++) { while (((READ_PORT_UCHAR((PUCHAR)Port + 5) & 1) == 0) && (TimeOut > 0))