Bona Fide OS Development

Keyboard IRQ Help
Page 1 of 1

Author:  jflanagan987 [ Sat Jul 16, 2011 12:44 pm ]
Post subject:  Keyboard IRQ Help

EDIT: I completely recoded my interrupt code and it works now.

I am currently developing a 32 bit C++ and assembly OS booted by grub 2. I have got as far as implementing the IDT, remapping the PIC and implementing test keyboard code. However, when I press a key I get IRQ 4(interrupt 36) instead of IRQ 1 and the cpu resets. I have debugged it in bochs and it seems to do a far jump to 246:000a during the iret instruction then resets. This is very strange because my code segment is 8 and my data segment is 16. Including the null segment, they are the only gdt selectors in the kernel.
My Keyboard code is here:
void kbd_isr()
  unsigned char scancode = inb(0x60);
  char tmp[5];

and my irq/isr handler is here:
#include <screen.h>
#include <string.h>
#include <system.h>
#include <keyboard.h>

//extern "C" void pit_isr();

struct registers
    unsigned int ds;                  // Data segment selector
    unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
    unsigned int int_no, err_code;    // Interrupt number and error code (if applicable)
    unsigned int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.

extern "C"
void isr_handler(struct registers regs)
    case 33:
      char tmp[3];
      error((char *) "interrupt: 0x");
  if(regs.int_no > 31)
  /*  if(regs.int_no == 39 || regs.int_no == 47)
    if(inb(0x20) & 0x80)
      if(regs.int_no == 47)
  if(regs.int_no >= 40)

My code is partly based on JamesM's tutorials, but modified a large amount.

Author:  brenden [ Tue Aug 23, 2011 1:10 am ]
Post subject:  Re: Keyboard IRQ Help

Glad you fixed it!

So, for the benefit of others in the future, what was the problem?

Author:  jflanagan987 [ Wed Aug 31, 2011 4:01 pm ]
Post subject:  Re: Keyboard IRQ Help

Most of the idt code was In assembly and was almost incomprihensible so I rewrote it and did more of it in c++. It was much easier to understand and I wouldn't have been able to find the problem in the asm. I don't know what the problem was. The idt code must have not set up the isrs correctly and caused a #GP when called. I'm guessing the asm code didn't split the isr addresses properly.

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group