From 1666ffd13d7e6721151b8005821ab2ed8e651e17 Mon Sep 17 00:00:00 2001 From: Sam Demeulemeester Date: Sun, 2 Aug 2026 18:09:47 +0200 Subject: [PATCH] Fix dead PS/2 KBs on AT-class 8042 controllers (ie: MSI MS-6167) Since e285fbb ('Ignore PS/2 mouse events') every scancode was discarded as a mouse event: AT-class KB Controllers set status bit 5 as a transmit timeout, not AUX data. Only honour the filter when the config byte enables AUX. --- system/keyboard.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/system/keyboard.c b/system/keyboard.c index 7079558..7b7901b 100644 --- a/system/keyboard.c +++ b/system/keyboard.c @@ -13,6 +13,8 @@ #include "keyboard.h" #include "config.h" +#include "unistd.h" + //------------------------------------------------------------------------------ // Private Constants //------------------------------------------------------------------------------ @@ -223,10 +225,25 @@ static const char usb_hid_keymap[] = { keyboard_types_t keyboard_types = KT_NONE; +// On AT-class 8042s status bit 5 is a transmit timeout flag, not AUX data. +static bool kbc_aux_enabled = true; + //------------------------------------------------------------------------------ // Private Functions //------------------------------------------------------------------------------ +// Check the 8042 config byte to see if the AUX (mouse) interface is enabled. +static void kbc_read_config(void) +{ + int t; + for (t = 0; t < 1000 && (inb(0x64) & 0x02); t++) usleep(10); // wait for IBF clear + if (t == 1000) return; + outb(0x20, 0x64); // read the config byte + for (t = 0; t < 1000 && !(inb(0x64) & 0x01); t++) usleep(10); + if (t == 1000) return; + kbc_aux_enabled = !(inb(0x60) & 0x20); +} + // This function is called when an ESC O prefix has been detected. static char get_vt220_sequence1(void) { @@ -369,6 +386,9 @@ void keyboard_init(void) if (keyboard_types & KT_USB) { find_usb_keyboards(keyboard_types == KT_USB); } + if (keyboard_types & KT_LEGACY) { + kbc_read_config(); + } } char get_key(void) @@ -399,7 +419,7 @@ char get_key(void) uint8_t status = inb(0x64); if (status & 0x01) { uint8_t c = inb(0x60); - if (status & 0x20) { + if ((status & 0x20) && kbc_aux_enabled) { // Ignore mouse events. return '\0'; }