Keyboard interrupts crash the kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Keyboard interrupts crash the kernel

Post 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
Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: Keyboard interrupts crash the kernel

Post 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.
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: Keyboard interrupts crash the kernel

Post 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.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Keyboard interrupts crash the kernel

Post 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.
Carpe diem!
Post Reply