diff --git a/src/keyboard.c b/src/keyboard.c index 27c0636..ea46e74 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -101,11 +101,21 @@ void keyboard_init(void) { kb_waiting_pid = 0; shift_pressed = 0; - /* Flush any pending data from the keyboard controller */ - while (inb(0x64) & 0x01) { + offset_print(" KEYBOARD: flushing controller...\n"); + + /* Flush any pending data from the keyboard controller. + * Use a timeout to avoid hanging if the controller keeps reporting data + * (some emulators/VMs behave differently). */ + int flush_count = 0; + while ((inb(0x64) & 0x01) && flush_count < 1024) { inb(KB_DATA_PORT); + flush_count++; } + offset_print(" KEYBOARD: flushed "); + print_hex((uint32_t)flush_count); + offset_print(" KEYBOARD: bytes, unmasking IRQ1...\n"); + /* Unmask IRQ1 (keyboard) in the PIC */ pic_clear_mask(1);