How to set address of the interrupt handler

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
Alexander

How to set address of the interrupt handler

Post by Alexander »

hello all,

     i'm developing out a 32-bit OS. i have installed a gdt. while installing an idt, i'm confused in giving the address of the interrupt handler to the interrupt descriptor. the structure for the descriptor is given below:

--------------------------------------------------------------------
idt_0:    |
   |
offset0_15 dw 0 ; low word of handler offset    |
selector0_15 dw 08h ; segment selector    |
zero_byte db 0 ; unused in this descriptor format |
iflags db 8eh ; flag-byte    |
offset16_31 dw 0 ; high word of handler offset    |
   |
idt_end:    |
--------------------------------------------------------------------


Assume that the interrupt 0 is a restart interrupt.

----------------------------------
int_0_handler: |
jmp 0xFFFF:0x0000 |
----------------------------------

My question is how to give the address of the int_0_handler to the int_0 ?


Thanks in advance
Xenos

RE:How to set address of the interrupt handler

Post by Xenos »

Giving the address of the BIOS entry point to the interrupt handler won't work. When your in pmode and jump to the real mode BIOS, it will probably chrash or cause an exception.
Anyway, how to give an address to the interrupt gate: You need the offset of the handler in its code segment. If you know the segment base (a linear address) and the linear address of the handler, it is just (handler address - segment base). This is a 32bit value, and has to be split into two parts which are put into the interrupt gate structure.

By the way: This will cause a restart.

restart:
in al,64h
test al,02h
jnz restart
mov al,0fch
out 64h,al ;keyboard controller sets reset pin
jmp $
Post Reply