how to write a keyboard ISR

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
chendsh

how to write a keyboard ISR

Post by chendsh »

I want to write a keyboard interrupt handler and wonder if there is
a sample and something like that. I know the first 32 entries in IDT
are reserved for CPU exceptions and the keyboard interrupt is from IRQ1.
which must have a handler for INT9. I am confused and do not know how to
arrange the IDT table.
Is there anyone who can help me with the hardware interrupts?
DaNo

Would like to know this 2

Post by DaNo »

I dont know how to do this either...does anybody??
carbonBased

RE:how to write a keyboard ISR

Post by carbonBased »

Well, ideally you want to remap your IRQs to above the processor exceptions... this means mapping them to 0x20 (32d) and above, therefore the keyboard int would be 0x21 (0x21 would be the timer).

Have you written an ISR before?  A basic keyboard ISR isn't much more than the skeleton code:

ISR:
  ; save registers used
  push eax

  ; put isr code here
  in al, 0x60

  ; save the scan code
  mov [keyScanCode], al

  ; acknowledge interrupt
  mov al, 0x20
  out al, 0x20

  ; restore registers
  pop eax

  ; and return
  iret

This is just off the top of my head, though.  I'm pretty sure the keyboard scan code read port is 0x60 (?).

Later on you'll want to convert the scancode to something more relavent to your OS, such as ascii, or unicode.  You can use look-up tables for this purpose.

Honestly, though, the keyboard driver is probably the _easiest_ drive you'll ever write.  Just download an OS's source code and take a look at the keyb driver for a full code implementation and you'll agree; it's quite simple.

Jeff
carbonBased

RE:how to write a keyboard ISR (oops)

Post by carbonBased »

0x20 is the timer, of course, in the above example.

Jeff
chendsh

RE:how to write a keyboard ISR (oops)

Post by chendsh »

thank you for your kindness.
Post Reply