inb(0x60) always gives zero on the IRQ1
Posted: Thu Jan 15, 2026 3:42 am
So I have been developing my kernel a little bit and while testing I noticed something. When I press a key it appears as a blank character on the screen. When I checked for the value, inb(0x60) was always returning zero, no matter which key I pressed. I couldn't find any problem with the inb() function, as the keyboard was initialized. The values seem to be read by the kernel as can be seen on the QEMU log. The wiki says that it's a key detection error or internal buffer overrun but I couldn't figure out why it's happening.
The QEMU log:
The PS/2 initialization code:
The QEMU log:
Code: Select all
pckbd_kbd_read_status 0x1c
pckbd_kbd_read_status 0x1c
pckbd_kbd_read_status 0x1c
pckbd_kbd_write_command 0xae
ps2_keyboard_event 0x557537a2ac58 qcode 23 down 1 modifier 0x0 modifiers 0x0 set 2 xlate 0
ps2_put_keycode 0x557537a2ac58 keycode 0x15
ps2_read_data 0x557537a2ac58
pckbd_kbd_read_data 0x15
ps2_keyboard_event 0x557537a2ac58 qcode 23 down 0 modifier 0x0 modifiers 0x0 set 2 xlate 0
ps2_put_keycode 0x557537a2ac58 keycode 0xf0
ps2_put_keycode 0x557537a2ac58 keycode 0x15
ps2_read_data 0x557537a2ac58
pckbd_kbd_read_data 0xf0
ps2_read_data 0x557537a2ac58
pckbd_kbd_read_data 0x15
Code: Select all
int initialize_ps2(){
uint8_t status = 0;
outb(PS2_COMMAND, 0xAD);
wait_ps2();
outb(PS2_COMMAND, 0xA7);
wait_ps2();
int timeout = 0;
for(; timeout < 1024; ++timeout){
inb(PS2_DATA);
if(!(inb(PS2_COMMAND) & 1)){
break;
}
}
if(timeout == 1023) return -1;
outb(PS2_COMMAND, 0x20);
wait_ps2();
status = inb(PS2_DATA);
wait_ps2();
status |= 0b0101001;
outb(PS2_COMMAND, 0x60);
wait_ps2();
outb(PS2_DATA, status);
wait_ps2();
outb(PS2_COMMAND, 0xAE);
set_irq_function(1, &ps2_handler);
return 0;
}