Reputation: 11
I'm a newbie at x86 assembly programming and I've come across this problem during one of my assignments. My aim is to write Interrupt Descriptor Table entries for certain interrupts (say INT 32 or INT 35, both being user defined interrupts). I looked at the Intel x86 Developers Manual and I've found the structure of the IDT entries. For the purpose of this question, lets consider my program to have the following structure:
myCodeGeneratingInterrutpt35:
...
...
...
someOtherCode:
..
..
..
myInterruptHandlerForInterrupt35:
.
.
.
IRET
someOtherInterruptHandlers:
... ..
This code lies in the code segment starting at address, say 0xa1000 (which is stored in CS). Let the IDTR be pointing to some address, say 0xe5000. And I have 8-byte entries corresponding to each of the IDT entries starting at [IDTR]. So by my calculations, the entry for INT 35 is at 0xe5118. (a). Could you guys give me a way to find out the address of the code starting with "myInterruptHandlerForInterrupt35: ... "? (b). Also, how do I find the offset of the code "myInterruptHandlerForInterrupt35" from CS ?
Upvotes: 1
Views: 720
Reputation: 58802
If you are in protected mode, you should know your CS
for the kernel. Even if you don't, you must already be in kernel mode to be able to modify the IDT, so assuming you only have a single code segment, the current CS
is going to be CS
for the interrupt handler. Note that CS
by itself has nothing to do with the base address, since that is stored in the GDT or LDT as applicable. As such starting at address 0xa1000 (which is stored in CS)
only makes sense if you meant that a selector for a segment starting at that address is in CS
.
As for the offset, that's of course just the address of the label.
Upvotes: 1