views:

247

answers:

2

I'm trying to alter my interrupt table to take over the keyboard interrupt. My end goal is to write my new interrupt routine, copy myself into RAM and make the real-mode interrupt table point to me.

I have found random sample code online but it is missing explanations on how to get the address of the original interrupt. They simply have variables in their place, and how to put itself into memory.

So my question is how do I figure out or print to my screen the real mode interrupt table?

And/OR if someone has any good code examples of doing this to either disable certain keys or beep on certain keys I'd really appreciate it.

Thanks!

+1  A: 

In 16-bit real mode, the interrupt table starts at address 0, with 256 4 byte entries. Each of the 256 interrupt vectors gets a 4 byte address (segment + offset) in that table.

http://en.wikipedia.org/wiki/Interrupt_descriptor_table has some more detail.

Michael
This is correct, with the exception that you can relocate the IDT using the `LIDT` instruction. You can see the current location of the IDT using the `SIDT` instruction. In real modes bits [15:0] of the result hold the IDT base. You access the relevant interrupt vector using that.
Nathan Fellman
Are they organized such that say I want address of int 16 it would be result of SIDT+(16*4bytes)? So every 4 bytes is the next sequential interrupt address?
Without Me It Just Aweso
+1  A: 

If your program is running under DOS, you can (and probably should) use the DOS-provided API:

  MOV  AH,35H    ; function 35H is Get Vector
  MOV  Al,9      ; slot in IDT for keyboard interrupt
  INT  21H       ; call DOS, contents of old vector in ES:BX (save them somewhere)
   .
   .
  MOV  AH,25H    ; function 25H is Set Vector
  MOV  AL,9
  PUSH CS        ; the new vector is passed in DS:DX, so copy CS to DS
  POP  DS        :  (assuming your new handler is in the same seg as other code)
  MOV  DX,NewHandler
  INT 21H
I. J. Kennedy