Patchwork Re: PS/2 mouse emulation problems

login
register
mail settings
Submitter Kevin O'Connor
Date March 13, 2010, 8:23 p.m.
Message ID <20100313202315.GA25967@morn.localdomain>
Download mbox | patch
Permalink /patch/47719/
State New
Headers show

Comments

Kevin O'Connor - March 13, 2010, 8:23 p.m.
On Sat, Mar 13, 2010 at 10:44:46PM +0800, Roy Tam wrote:
> 2010/3/13 Natalia Portillo <claunia@claunia.com>:
> > Ok so in resume we have the following PS/2 mouse bugs:
> >
> > NeXTStep and OpenStep PS/2 driver receives no movement at all from the mouse
> > (Darwin PS/2 driver seems to be made from scratch so no helpful here).
> > MS-DOS Mouse driver hangs the whole machine.
> > Windows Me Setup mouse driver receives no movement at all from the mouse.
> > Old XFree86 PS/2 mouse driver receives no movement at all from standard
> > protocols (PS/2, IMPS/2) or random movements (Microsoft).
> > Hydrogen OS mouse driver does not work.
> >
> > While the NeXTStep PS/2 bug is known from QEMU 0.7.0 (which used Bochs
> > BIOS), the other ones are new (as far as I know) so they may be or may not
> > be caused by SeaBIOS.
> >
> 
> for Hydrogen OS, when I use QEMU BIOS (yes with my -old-bios hack) it
> works in git head.

Can you test with:

http://linuxtogo.org/~kevin/SeaBIOS/test/bios.bin-0.5.1-debug-20100313

Change summary in this test image:
* int 1601 / int 1a00 should enable irqs - fixes several boot hangs
* Backup/restore registers on mouse/keyboard callbacks - fixes
  d090723b.zip
* The mouse getid command may only return 1 byte - fixes msdos mouse
  hang
* Always process key event in irq 09 handler - restores keyboard in
  ghost and fdos0138.img

This image is based off stable-0.5.1 (image debug-20100311 was
mistakenly based off of git head which had an additional regression of
enabling mouse irqs by default).

Interestingly, a ghost 11.5 image I found now works with mouse where
it used to fail with bochs bios.

The code changes I've used are below.  These changes are for testing -
I'm still looking into a full fix.

-Kevin
Roy Tam - March 14, 2010, 2:49 a.m.
2010/3/14 Kevin O'Connor <kevin@koconnor.net>:
> On Sat, Mar 13, 2010 at 10:44:46PM +0800, Roy Tam wrote:
>> 2010/3/13 Natalia Portillo <claunia@claunia.com>:
>> > Ok so in resume we have the following PS/2 mouse bugs:
>> >
>> > NeXTStep and OpenStep PS/2 driver receives no movement at all from the mouse
>> > (Darwin PS/2 driver seems to be made from scratch so no helpful here).
>> > MS-DOS Mouse driver hangs the whole machine.
>> > Windows Me Setup mouse driver receives no movement at all from the mouse.
>> > Old XFree86 PS/2 mouse driver receives no movement at all from standard
>> > protocols (PS/2, IMPS/2) or random movements (Microsoft).
>> > Hydrogen OS mouse driver does not work.
>> >
>> > While the NeXTStep PS/2 bug is known from QEMU 0.7.0 (which used Bochs
>> > BIOS), the other ones are new (as far as I know) so they may be or may not
>> > be caused by SeaBIOS.
>> >
>>
>> for Hydrogen OS, when I use QEMU BIOS (yes with my -old-bios hack) it
>> works in git head.
>
> Can you test with:
>
> http://linuxtogo.org/~kevin/SeaBIOS/test/bios.bin-0.5.1-debug-20100313
>
> Change summary in this test image:
> * int 1601 / int 1a00 should enable irqs - fixes several boot hangs
> * Backup/restore registers on mouse/keyboard callbacks - fixes
>  d090723b.zip
> * The mouse getid command may only return 1 byte - fixes msdos mouse
>  hang
> * Always process key event in irq 09 handler - restores keyboard in
>  ghost and fdos0138.img
>
> This image is based off stable-0.5.1 (image debug-20100311 was
> mistakenly based off of git head which had an additional regression of
> enabling mouse irqs by default).
>
> Interestingly, a ghost 11.5 image I found now works with mouse where
> it used to fail with bochs bios.
>
> The code changes I've used are below.  These changes are for testing -
> I'm still looking into a full fix.
>

Tested. Results belows:
+ NeXTStep/OpenStep bootloader no longer stalls.
+ EDR-DOS 7.01.08 WIP boots.
+ Paragon PTS-DOS 6.51CD/2000 Pro, GHOST, GW-BASIC, FreeDOS/V, MS-DOS
6.22 (Korean Edition), ET3 Chinese System, KC Chinese System, CCDOS97
Chinese System, etc. keyboard works.
+ CuteMouse driver no longer waits, MS Mouse Driver no longer freezes.
+ Hydrogen OS Mouse works.
- OpenStep 4.2 installs but mouse only works for 1 second.

Natalia Portillo:
Do you have a working config switches for NeXTStep 3.3? As it don't
have (E)IDE/ATATPI driver in driver disks.

> -Kevin
>
>
>
> diff --git a/src/clock.c b/src/clock.c
> index e32bf1b..241119e 100644
> --- a/src/clock.c
> +++ b/src/clock.c
> @@ -228,6 +228,7 @@ timer_setup(void)
>  static void
>  handle_1a00(struct bregs *regs)
>  {
> +    yield();
>     u32 ticks = GET_BDA(timer_counter);
>     regs->cx = ticks >> 16;
>     regs->dx = ticks;
> diff --git a/src/config.h b/src/config.h
> index 6297a48..9a3a165 100644
> --- a/src/config.h
> +++ b/src/config.h
> @@ -16,9 +16,9 @@
>  #define CONFIG_COREBOOT 0
>
>  // Control how verbose debug output is.
> -#define CONFIG_DEBUG_LEVEL 1
> +#define CONFIG_DEBUG_LEVEL 8
>  // Send debugging information to serial port
> -#define CONFIG_DEBUG_SERIAL 0
> +#define CONFIG_DEBUG_SERIAL 1
>  // Screen writes are also sent to debug ports.
>  #define CONFIG_SCREEN_AND_DEBUG 1
>
> diff --git a/src/kbd.c b/src/kbd.c
> index 6f3ae15..7e3434a 100644
> --- a/src/kbd.c
> +++ b/src/kbd.c
> @@ -73,6 +73,7 @@ enqueue_key(u8 scan_code, u8 ascii_code)
>  static void
>  dequeue_key(struct bregs *regs, int incr, int extended)
>  {
> +    yield();
>     u16 buffer_head;
>     u16 buffer_tail;
>     for (;;) {
> @@ -552,9 +553,19 @@ process_key(u8 key)
>         // allow for keyboard intercept
>         u32 eax = (0x4f << 8) | key;
>         u32 flags;
> +#if 0
>         call16_simpint(0x15, &eax, &flags);
>         if (!(flags & F_CF))
>             return;
> +#else
> +        struct bregs br;
> +        memset(&br, 0, sizeof(br));
> +        br.eax = eax;
> +        call16_int(0x15, &br);
> +        flags = br.flags;
> +        if (!(flags & F_CF))
> +            return;
> +#endif
>         key = eax;
>     }
>     __process_key(key);
> diff --git a/src/mouse.c b/src/mouse.c
> index 52e225c..92fb16a 100644
> --- a/src/mouse.c
> +++ b/src/mouse.c
> @@ -305,15 +305,17 @@ process_mouse(u8 data)
>         return;
>     }
>
> -    //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
>     u16 status = GET_EBDA2(ebda_seg, mouse_data[0]);
>     u16 X      = GET_EBDA2(ebda_seg, mouse_data[1]);
>     u16 Y      = GET_EBDA2(ebda_seg, mouse_data[2]);
>     SET_EBDA2(ebda_seg, mouse_flag1, 0);
>
>     struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer);
> +    dprintf(16, "mouse farcall s=%04x x=%04x y=%04x func=%04x:%04x\n"
> +            , status, X, Y, func.seg, func.offset);
>
>     asm volatile(
> +        "pusha\n"
>         "sti\n"
>
>         "pushl %0\n"
> @@ -326,6 +328,7 @@ process_mouse(u8 data)
>
>         "cli\n"
>         "cld\n"
> +        "popa\n"
>         :
>         : "r"(func.segoff), "r"(status), "r"(X), "r"(Y)
>         : "cc"
> diff --git a/src/ps2port.c b/src/ps2port.c
> index fb9d24a..759ad37 100644
> --- a/src/ps2port.c
> +++ b/src/ps2port.c
> @@ -226,8 +226,11 @@ ps2_command(int aux, int command, u8 *param)
>     if (ret)
>         return ret;
>
> +    // Flush any interrupts already pending.
> +    yield();
> +
>     if (command == ATKBD_CMD_RESET_BAT) {
> -        // Reset is special wrt timeouts.
> +        // Reset is special wrt timeouts and bytes received.
>
>         // Send command.
>         ret = ps2_sendbyte(aux, command, 1000);
> @@ -244,6 +247,29 @@ ps2_command(int aux, int command, u8 *param)
>             // Some devices only respond with one byte on reset.
>             ret = 0;
>         param[1] = ret;
> +    } else if (command == ATKBD_CMD_GETID) {
> +        // Getid is special wrt bytes received.
> +
> +        // Send command.
> +        ret = ps2_sendbyte(aux, command, 200);
> +        if (ret)
> +            goto fail;
> +
> +        // Receive parameters.
> +        ret = ps2_recvbyte(aux, 0, 500);
> +        if (ret < 0)
> +            goto fail;
> +        param[0] = ret;
> +        if (ret == 0xab || ret == 0xac || ret == 0x2b || ret == 0x5d
> +            || ret == 0x60 || ret == 0x47) {
> +            // These ids (keyboards) return two bytes.
> +            ret = ps2_recvbyte(aux, 0, 500);
> +            if (ret < 0)
> +                goto fail;
> +            param[1] = ret;
> +        } else {
> +            param[1] = 0;
> +        }
>     } else {
>         // Send command.
>         ret = ps2_sendbyte(aux, command, 200);
> @@ -336,7 +362,8 @@ handle_09(void)
>         return;
>
>     debug_isr(DEBUG_ISR_09);
> -    process_ps2irq();
> +//    process_ps2irq();
> +    process_ps2byte(inb(PORT_PS2_STATUS), inb(PORT_PS2_DATA));
>     eoi_pic1();
>  }
>
>
Roy Tam - March 14, 2010, 3:11 a.m.
2010/3/14 Roy Tam <roytam@gmail.com>:
> 2010/3/14 Kevin O'Connor <kevin@koconnor.net>:
>> On Sat, Mar 13, 2010 at 10:44:46PM +0800, Roy Tam wrote:
>>> 2010/3/13 Natalia Portillo <claunia@claunia.com>:
>>> > Ok so in resume we have the following PS/2 mouse bugs:
>>> >
>>> > NeXTStep and OpenStep PS/2 driver receives no movement at all from the mouse
>>> > (Darwin PS/2 driver seems to be made from scratch so no helpful here).
>>> > MS-DOS Mouse driver hangs the whole machine.
>>> > Windows Me Setup mouse driver receives no movement at all from the mouse.
>>> > Old XFree86 PS/2 mouse driver receives no movement at all from standard
>>> > protocols (PS/2, IMPS/2) or random movements (Microsoft).
>>> > Hydrogen OS mouse driver does not work.
>>> >
>>> > While the NeXTStep PS/2 bug is known from QEMU 0.7.0 (which used Bochs
>>> > BIOS), the other ones are new (as far as I know) so they may be or may not
>>> > be caused by SeaBIOS.
>>> >
>>>
>>> for Hydrogen OS, when I use QEMU BIOS (yes with my -old-bios hack) it
>>> works in git head.
>>
>> Can you test with:
>>
>> http://linuxtogo.org/~kevin/SeaBIOS/test/bios.bin-0.5.1-debug-20100313
>>
>> Change summary in this test image:
>> * int 1601 / int 1a00 should enable irqs - fixes several boot hangs
>> * Backup/restore registers on mouse/keyboard callbacks - fixes
>>  d090723b.zip
>> * The mouse getid command may only return 1 byte - fixes msdos mouse
>>  hang
>> * Always process key event in irq 09 handler - restores keyboard in
>>  ghost and fdos0138.img
>>
>> This image is based off stable-0.5.1 (image debug-20100311 was
>> mistakenly based off of git head which had an additional regression of
>> enabling mouse irqs by default).
>>
>> Interestingly, a ghost 11.5 image I found now works with mouse where
>> it used to fail with bochs bios.
>>
>> The code changes I've used are below.  These changes are for testing -
>> I'm still looking into a full fix.
>>
>
> Tested. Results belows:
> + NeXTStep/OpenStep bootloader no longer stalls.
> + EDR-DOS 7.01.08 WIP boots.
> + Paragon PTS-DOS 6.51CD/2000 Pro, GHOST, GW-BASIC, FreeDOS/V, MS-DOS
> 6.22 (Korean Edition), ET3 Chinese System, KC Chinese System, CCDOS97
> Chinese System, etc. keyboard works.
> + CuteMouse driver no longer waits, MS Mouse Driver no longer freezes.
> + Hydrogen OS Mouse works.
> - OpenStep 4.2 installs but mouse only works for 1 second.
>

forget to mention:
- DOS 1.1x - 1.25 still freeze after pressing [Enter] in date/time
prompt or in shell prompt.

> Natalia Portillo:
> Do you have a working config switches for NeXTStep 3.3? As it don't
> have (E)IDE/ATATPI driver in driver disks.
>
>> -Kevin
>>
>>
>>
>> diff --git a/src/clock.c b/src/clock.c
>> index e32bf1b..241119e 100644
>> --- a/src/clock.c
>> +++ b/src/clock.c
>> @@ -228,6 +228,7 @@ timer_setup(void)
>>  static void
>>  handle_1a00(struct bregs *regs)
>>  {
>> +    yield();
>>     u32 ticks = GET_BDA(timer_counter);
>>     regs->cx = ticks >> 16;
>>     regs->dx = ticks;
>> diff --git a/src/config.h b/src/config.h
>> index 6297a48..9a3a165 100644
>> --- a/src/config.h
>> +++ b/src/config.h
>> @@ -16,9 +16,9 @@
>>  #define CONFIG_COREBOOT 0
>>
>>  // Control how verbose debug output is.
>> -#define CONFIG_DEBUG_LEVEL 1
>> +#define CONFIG_DEBUG_LEVEL 8
>>  // Send debugging information to serial port
>> -#define CONFIG_DEBUG_SERIAL 0
>> +#define CONFIG_DEBUG_SERIAL 1
>>  // Screen writes are also sent to debug ports.
>>  #define CONFIG_SCREEN_AND_DEBUG 1
>>
>> diff --git a/src/kbd.c b/src/kbd.c
>> index 6f3ae15..7e3434a 100644
>> --- a/src/kbd.c
>> +++ b/src/kbd.c
>> @@ -73,6 +73,7 @@ enqueue_key(u8 scan_code, u8 ascii_code)
>>  static void
>>  dequeue_key(struct bregs *regs, int incr, int extended)
>>  {
>> +    yield();
>>     u16 buffer_head;
>>     u16 buffer_tail;
>>     for (;;) {
>> @@ -552,9 +553,19 @@ process_key(u8 key)
>>         // allow for keyboard intercept
>>         u32 eax = (0x4f << 8) | key;
>>         u32 flags;
>> +#if 0
>>         call16_simpint(0x15, &eax, &flags);
>>         if (!(flags & F_CF))
>>             return;
>> +#else
>> +        struct bregs br;
>> +        memset(&br, 0, sizeof(br));
>> +        br.eax = eax;
>> +        call16_int(0x15, &br);
>> +        flags = br.flags;
>> +        if (!(flags & F_CF))
>> +            return;
>> +#endif
>>         key = eax;
>>     }
>>     __process_key(key);
>> diff --git a/src/mouse.c b/src/mouse.c
>> index 52e225c..92fb16a 100644
>> --- a/src/mouse.c
>> +++ b/src/mouse.c
>> @@ -305,15 +305,17 @@ process_mouse(u8 data)
>>         return;
>>     }
>>
>> -    //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
>>     u16 status = GET_EBDA2(ebda_seg, mouse_data[0]);
>>     u16 X      = GET_EBDA2(ebda_seg, mouse_data[1]);
>>     u16 Y      = GET_EBDA2(ebda_seg, mouse_data[2]);
>>     SET_EBDA2(ebda_seg, mouse_flag1, 0);
>>
>>     struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer);
>> +    dprintf(16, "mouse farcall s=%04x x=%04x y=%04x func=%04x:%04x\n"
>> +            , status, X, Y, func.seg, func.offset);
>>
>>     asm volatile(
>> +        "pusha\n"
>>         "sti\n"
>>
>>         "pushl %0\n"
>> @@ -326,6 +328,7 @@ process_mouse(u8 data)
>>
>>         "cli\n"
>>         "cld\n"
>> +        "popa\n"
>>         :
>>         : "r"(func.segoff), "r"(status), "r"(X), "r"(Y)
>>         : "cc"
>> diff --git a/src/ps2port.c b/src/ps2port.c
>> index fb9d24a..759ad37 100644
>> --- a/src/ps2port.c
>> +++ b/src/ps2port.c
>> @@ -226,8 +226,11 @@ ps2_command(int aux, int command, u8 *param)
>>     if (ret)
>>         return ret;
>>
>> +    // Flush any interrupts already pending.
>> +    yield();
>> +
>>     if (command == ATKBD_CMD_RESET_BAT) {
>> -        // Reset is special wrt timeouts.
>> +        // Reset is special wrt timeouts and bytes received.
>>
>>         // Send command.
>>         ret = ps2_sendbyte(aux, command, 1000);
>> @@ -244,6 +247,29 @@ ps2_command(int aux, int command, u8 *param)
>>             // Some devices only respond with one byte on reset.
>>             ret = 0;
>>         param[1] = ret;
>> +    } else if (command == ATKBD_CMD_GETID) {
>> +        // Getid is special wrt bytes received.
>> +
>> +        // Send command.
>> +        ret = ps2_sendbyte(aux, command, 200);
>> +        if (ret)
>> +            goto fail;
>> +
>> +        // Receive parameters.
>> +        ret = ps2_recvbyte(aux, 0, 500);
>> +        if (ret < 0)
>> +            goto fail;
>> +        param[0] = ret;
>> +        if (ret == 0xab || ret == 0xac || ret == 0x2b || ret == 0x5d
>> +            || ret == 0x60 || ret == 0x47) {
>> +            // These ids (keyboards) return two bytes.
>> +            ret = ps2_recvbyte(aux, 0, 500);
>> +            if (ret < 0)
>> +                goto fail;
>> +            param[1] = ret;
>> +        } else {
>> +            param[1] = 0;
>> +        }
>>     } else {
>>         // Send command.
>>         ret = ps2_sendbyte(aux, command, 200);
>> @@ -336,7 +362,8 @@ handle_09(void)
>>         return;
>>
>>     debug_isr(DEBUG_ISR_09);
>> -    process_ps2irq();
>> +//    process_ps2irq();
>> +    process_ps2byte(inb(PORT_PS2_STATUS), inb(PORT_PS2_DATA));
>>     eoi_pic1();
>>  }
>>
>>
>
Kevin O'Connor - March 14, 2010, 3:43 a.m.
On Sun, Mar 14, 2010 at 11:11:30AM +0800, Roy Tam wrote:
> 2010/3/14 Roy Tam <roytam@gmail.com>:
> > Tested. Results belows:
> > + NeXTStep/OpenStep bootloader no longer stalls.
> > + EDR-DOS 7.01.08 WIP boots.
> > + Paragon PTS-DOS 6.51CD/2000 Pro, GHOST, GW-BASIC, FreeDOS/V, MS-DOS
> > 6.22 (Korean Edition), ET3 Chinese System, KC Chinese System, CCDOS97
> > Chinese System, etc. keyboard works.
> > + CuteMouse driver no longer waits, MS Mouse Driver no longer freezes.
> > + Hydrogen OS Mouse works.

Thanks!

> > - OpenStep 4.2 installs but mouse only works for 1 second.

Are the OpenStep CDs available somewhere?

> forget to mention:
> - DOS 1.1x - 1.25 still freeze after pressing [Enter] in date/time
> prompt or in shell prompt.

Is that a regression from Bochs BIOS?  Can you point me to an image I
can try?


BTW, I've pushed a cleaned up set of fixes to latest SeaBIOS git.

-Kevin
Roy Tam - March 14, 2010, 5:28 a.m.
2010/3/14 Kevin O'Connor <kevin@koconnor.net>:
> On Sun, Mar 14, 2010 at 11:11:30AM +0800, Roy Tam wrote:
>> 2010/3/14 Roy Tam <roytam@gmail.com>:
>> > Tested. Results belows:
>> > + NeXTStep/OpenStep bootloader no longer stalls.
>> > + EDR-DOS 7.01.08 WIP boots.
>> > + Paragon PTS-DOS 6.51CD/2000 Pro, GHOST, GW-BASIC, FreeDOS/V, MS-DOS
>> > 6.22 (Korean Edition), ET3 Chinese System, KC Chinese System, CCDOS97
>> > Chinese System, etc. keyboard works.
>> > + CuteMouse driver no longer waits, MS Mouse Driver no longer freezes.
>> > + Hydrogen OS Mouse works.
>
> Thanks!
>
>> > - OpenStep 4.2 installs but mouse only works for 1 second.
>
> Are the OpenStep CDs available somewhere?
>
>> forget to mention:
>> - DOS 1.1x - 1.25 still freeze after pressing [Enter] in date/time
>> prompt or in shell prompt.
>
> Is that a regression from Bochs BIOS?  Can you point me to an image I
> can try?
>

Yes this is a regression. with Bochs BIOS DOS 1.1x - 1.25 works fine.

>
> BTW, I've pushed a cleaned up set of fixes to latest SeaBIOS git.
>
> -Kevin
>
Kevin O'Connor - March 14, 2010, 7:11 a.m.
On Sun, Mar 14, 2010 at 01:28:01PM +0800, Roy Tam wrote:
> 2010/3/14 Kevin O'Connor <kevin@koconnor.net>:
> > On Sun, Mar 14, 2010 at 11:11:30AM +0800, Roy Tam wrote:
> >> - DOS 1.1x - 1.25 still freeze after pressing [Enter] in date/time
> >> prompt or in shell prompt.
> >
> > Is that a regression from Bochs BIOS?  Can you point me to an image I
> > can try?
> 
> Yes this is a regression. with Bochs BIOS DOS 1.1x - 1.25 works fine.

The early DOS image is failing due to lack of stack space.  It's
calling int 1600 with ~150 bytes of stack space and SeaBIOS uses more.

-Kevin

Patch

diff --git a/src/clock.c b/src/clock.c
index e32bf1b..241119e 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -228,6 +228,7 @@  timer_setup(void)
 static void
 handle_1a00(struct bregs *regs)
 {
+    yield();
     u32 ticks = GET_BDA(timer_counter);
     regs->cx = ticks >> 16;
     regs->dx = ticks;
diff --git a/src/config.h b/src/config.h
index 6297a48..9a3a165 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,9 +16,9 @@ 
 #define CONFIG_COREBOOT 0
 
 // Control how verbose debug output is.
-#define CONFIG_DEBUG_LEVEL 1
+#define CONFIG_DEBUG_LEVEL 8
 // Send debugging information to serial port
-#define CONFIG_DEBUG_SERIAL 0
+#define CONFIG_DEBUG_SERIAL 1
 // Screen writes are also sent to debug ports.
 #define CONFIG_SCREEN_AND_DEBUG 1
 
diff --git a/src/kbd.c b/src/kbd.c
index 6f3ae15..7e3434a 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -73,6 +73,7 @@  enqueue_key(u8 scan_code, u8 ascii_code)
 static void
 dequeue_key(struct bregs *regs, int incr, int extended)
 {
+    yield();
     u16 buffer_head;
     u16 buffer_tail;
     for (;;) {
@@ -552,9 +553,19 @@  process_key(u8 key)
         // allow for keyboard intercept
         u32 eax = (0x4f << 8) | key;
         u32 flags;
+#if 0
         call16_simpint(0x15, &eax, &flags);
         if (!(flags & F_CF))
             return;
+#else
+        struct bregs br;
+        memset(&br, 0, sizeof(br));
+        br.eax = eax;
+        call16_int(0x15, &br);
+        flags = br.flags;
+        if (!(flags & F_CF))
+            return;
+#endif
         key = eax;
     }
     __process_key(key);
diff --git a/src/mouse.c b/src/mouse.c
index 52e225c..92fb16a 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -305,15 +305,17 @@  process_mouse(u8 data)
         return;
     }
 
-    //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
     u16 status = GET_EBDA2(ebda_seg, mouse_data[0]);
     u16 X      = GET_EBDA2(ebda_seg, mouse_data[1]);
     u16 Y      = GET_EBDA2(ebda_seg, mouse_data[2]);
     SET_EBDA2(ebda_seg, mouse_flag1, 0);
 
     struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer);
+    dprintf(16, "mouse farcall s=%04x x=%04x y=%04x func=%04x:%04x\n"
+            , status, X, Y, func.seg, func.offset);
 
     asm volatile(
+        "pusha\n"
         "sti\n"
 
         "pushl %0\n"
@@ -326,6 +328,7 @@  process_mouse(u8 data)
 
         "cli\n"
         "cld\n"
+        "popa\n"
         :
         : "r"(func.segoff), "r"(status), "r"(X), "r"(Y)
         : "cc"
diff --git a/src/ps2port.c b/src/ps2port.c
index fb9d24a..759ad37 100644
--- a/src/ps2port.c
+++ b/src/ps2port.c
@@ -226,8 +226,11 @@  ps2_command(int aux, int command, u8 *param)
     if (ret)
         return ret;
 
+    // Flush any interrupts already pending.
+    yield();
+
     if (command == ATKBD_CMD_RESET_BAT) {
-        // Reset is special wrt timeouts.
+        // Reset is special wrt timeouts and bytes received.
 
         // Send command.
         ret = ps2_sendbyte(aux, command, 1000);
@@ -244,6 +247,29 @@  ps2_command(int aux, int command, u8 *param)
             // Some devices only respond with one byte on reset.
             ret = 0;
         param[1] = ret;
+    } else if (command == ATKBD_CMD_GETID) {
+        // Getid is special wrt bytes received.
+
+        // Send command.
+        ret = ps2_sendbyte(aux, command, 200);
+        if (ret)
+            goto fail;
+
+        // Receive parameters.
+        ret = ps2_recvbyte(aux, 0, 500);
+        if (ret < 0)
+            goto fail;
+        param[0] = ret;
+        if (ret == 0xab || ret == 0xac || ret == 0x2b || ret == 0x5d
+            || ret == 0x60 || ret == 0x47) {
+            // These ids (keyboards) return two bytes.
+            ret = ps2_recvbyte(aux, 0, 500);
+            if (ret < 0)
+                goto fail;
+            param[1] = ret;
+        } else {
+            param[1] = 0;
+        }
     } else {
         // Send command.
         ret = ps2_sendbyte(aux, command, 200);
@@ -336,7 +362,8 @@  handle_09(void)
         return;
 
     debug_isr(DEBUG_ISR_09);
-    process_ps2irq();
+//    process_ps2irq();
+    process_ps2byte(inb(PORT_PS2_STATUS), inb(PORT_PS2_DATA));
     eoi_pic1();
 }