From 79adc9bd97ae644bd527a233ac8ecf57dffd73db Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 9 Oct 2025 21:00:39 -0400 Subject: kern/amd64: isa: Add i8042 read timeout Add a timeout so that if data never arrives, the system doesn't get locked up. Signed-off-by: Ian Moffett --- src/sys/arch/amd64/isa/i8042.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sys/arch/amd64/isa/i8042.c b/src/sys/arch/amd64/isa/i8042.c index 3036184..9bbd85d 100644 --- a/src/sys/arch/amd64/isa/i8042.c +++ b/src/sys/arch/amd64/isa/i8042.c @@ -198,10 +198,16 @@ static uint8_t i8042_read(void) { uint8_t status = 0x00; + uint8_t count = 0; while (!ISSET(status, I8042_OBUFF)) { status = inb(I8042_STATUS); clk->msleep(5); + + /* Timeout? */ + if ((count++) >= 20) { + return 0xFF; + } } clk->msleep(5); @@ -267,15 +273,16 @@ i8042_init(struct module *modp) return error; } - /* Disable both ports */ + /* Disable both ports and flush any data */ i8042_write(true, I8042_DISABLE_PORT0); i8042_write(true, I8042_DISABLE_PORT1); + i8042_read(); /* Initialize interrupts and taps */ i8042_init_intr(); i8042_init_tap(); - /* Enable the keyboard and flush it */ + /* Enable the keyboard */ i8042_write(true, I8042_ENABLE_PORT0); return 0; } -- cgit v1.2.3