Page 1 of 1

Keyboard interrupts crash the kernel

Posted: Sat Jan 30, 2021 1:01 am
by catOS
I tried to add keyboard interrupts to my OS (https://github.com/ackOS-project/dev), but now the OS reboots when I press any key.

I don't know what's wrong and I have left it for a few months now.

Please help

Re: Keyboard interrupts crash the kernel

Posted: Sat Jan 30, 2021 7:59 am
by Klakap

Code: Select all

void idt_initialize()
{
_idt[1] = idt_entry_create((uint64_t)&interrupt_irq1, 0, INTERRUPT_GATE);
PS/2 keyboard interrupt is not entry 1 in IDT table. First 32 items in IDT table are ISR interrupts. It is highly recommended to remap PIC for sort all IRQ interrupts after ISR interrupts like that:

Code: Select all

 ;remapping PIC
 OUTB 0x20, 0x11
 OUTB 0xA0, 0x11
 OUTB 0x21, 0x20
 OUTB 0xA1, 40
 OUTB 0x21, 0x04
 OUTB 0xA1, 0x02
 OUTB 0x21, 0x01
 OUTB 0xA1, 0x01
 OUTB 0x21, 0xF8 ;unmask irq 0, 1, 2
 OUTB 0xA1, 0xEF ;unmask irq 12
IRQ 0 (timer interrupt) is in 32 IDT entry and PS/2 keyboard interrupt is on 33 IDT entry. You must rewrite your code for this. You can also see my driver for setting IDT. Feel free to ask any question.

Re: Keyboard interrupts crash the kernel

Posted: Sat Jan 30, 2021 6:58 pm
by austanss
As the above post mentioned, PS/2 keyboard is not entry 1 in the IDT.

Also, ensure that your keyboard handler is sending an EOI to the PIC, and also reading from port 0x60 (keyboard).

Issues with interrupts are extremely common on this forum.

Also, I feel the need to explain that the reason the kernel crashes, is because the CPU is trying to send exceptions and they are going unhandled.

Re: Keyboard interrupts crash the kernel

Posted: Sat Jan 30, 2021 10:16 pm
by nullplan
Yeah, I would also suggest getting the exception handlers going post-haste. And if all they do is print "exception x at IP y" and then hang indefinitely, that is still better than tripple faulting.