Fix keyboard init: add timeout to controller flush loop
The PS/2 keyboard controller flush loop could hang infinitely on some VMs (UTM) where the controller keeps reporting data. Add a 1024-byte timeout to prevent the kernel from hanging during keyboard_init(). Also add debug prints showing flush progress for diagnostics.
This commit is contained in:
@@ -101,11 +101,21 @@ void keyboard_init(void) {
|
|||||||
kb_waiting_pid = 0;
|
kb_waiting_pid = 0;
|
||||||
shift_pressed = 0;
|
shift_pressed = 0;
|
||||||
|
|
||||||
/* Flush any pending data from the keyboard controller */
|
offset_print(" KEYBOARD: flushing controller...\n");
|
||||||
while (inb(0x64) & 0x01) {
|
|
||||||
|
/* 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);
|
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 */
|
/* Unmask IRQ1 (keyboard) in the PIC */
|
||||||
pic_clear_mask(1);
|
pic_clear_mask(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user