x86 - I can't trigger my interrupts?

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
Mikumiku747
Member
Member
Posts: 64
Joined: Thu Apr 16, 2015 7:37 am

x86 - I can't trigger my interrupts?

Post by Mikumiku747 »

Hi, I'm currently trying to get input for my kernel up and running, but I'm having problems getting the keyboard to send interrupts to the CPU. I'm 99% sure I've set up the interrupts correctly, because if I do an "INT $0x21" it runs my interrupt service routine(which is just a simple printf("Key pressed\n") and an end of interrupt signal.)

Currently I'm on a Win8.1 Host using cygwin and a cross compiler, and emulating in bochs. I'm loading the kernel through GRUB (Grub 2 I think?).

I think I've followed all the steps required to get interrupts up and running, which is:
  • - Make and load my own GDT (Just a flat 4GiB code and flat 4GiB data entry)
    - Make and load my own IDT, with an entry at 0x21 for my routine (I haven't written handlers to service any of the other interrupts)
    - Re-mapped the interrupts on the PICS with an offset of 0x20 and 0x28, so the hardware IRQs range from 0x20 to 0x2f
    - Cleared the mask for line 1 on the master PIC
    - And finally, to test the interrupt, I do asm("INT $0x21") and my routine runs (it outputs "Key pressed\n")
    - Then I put the kernel in an infinite loop, which I'm hoping to handle keyboard interrupts from, just to test them out.
I'm at a loss for any steps that I've missed, but one of my theories is that the keyboard isn't configured to send interrupts (maybe this is off by default, or GRUB disables it, and never re-enables it?) I'm hoping somebody can give me some suggestions to test this theory, or at least help me find a wiki page or forum post (I've already looked at the PS/2 Keyboard page, but I'm a bit confused as to how that even works, and whether I'm even using a PS/2 Keyboard.) I can provide my code if people need it, but I'm hoping I've just missed some minor detail, such as sending a command to the keyboard to begin sending interrupts.

I also have a slight hunch that maybe a virtual machine isn't the best thing to test this on, seeing as when I ran it on real hardware, I had to use a USB keyboard, my PS/2 one didn't do anything, even in the GRUB menu. I'm going to do some tests by writing an ISR for the Timer, which apparently fires 18 times every second? So hopefully, if that works, I'll make an edit which talks about the results, and I'll know it's an issue with the keyboard. In the meantime, if you think you have a solution or any other tests I could try, let me know. (Try to keep in mind I'm a bit new to this, so you may need to explain something to me if I'm not sure what you're talking about.)

In summary, I think I set up interrupts correctly, but the keyboard won't fire an IRQ? Any ideas?

Thanks for the nice forum,
Mikumiku747
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: x86 - I can't trigger my interrupts?

Post by iansjack »

Have you included a "STI" instruction to enable hardware interrupts?
User avatar
Mikumiku747
Member
Member
Posts: 64
Joined: Thu Apr 16, 2015 7:37 am

Re: x86 - I can't trigger my interrupts?

Post by Mikumiku747 »

iansjack wrote:Have you included a "STI" instruction to enable hardware interrupts?
I can't believe I didn't think of something so simple. #-o Thanks for the suggestion. I added an STI, and now I'm getting a triple fault, but at least I know that hardware interrupts are now working. I'm pretty sure it's because I never added any other interrupt handlers, so any other interrupt is causing an exception due to there being no entry for it, which causes another exception, which causes a triple fault. In any case big thanks for the help, I had a hunch it was a minor mistake, thanks for helping out.
Post Reply