[Prev][Next][Index][Thread]

Re: How make an interrupt gate?



Mohmod Taghizade has been quoted as saying:
> hi every body,
> 	I want to put a interrupt gate in IDT, I dont like using
> 	oskit stub for it. I did it, 
> 	but in interrupt hadnler after asm("iret"), i got a trap_dump
> 	because of trap 13(#GPF).
> 	whats the problem?
> regards,
> --taghi

     The problem is that you're trying to do something in C that's
best done in assembly. =)

     If you disassemble timer, you should notice the bit of the
function prologue and epilogue dealing with setting up a stack frame
for the function.  

     It'll look like this:

       pushl %ebp
       movl  %esp, %ebp
       <...rest of function...>
       iret <---here's where it stuck your iret
       leave
       ret

     Basically, you've got extra junk on the stack when iret is
executed, causing the processor to return to some bogus address and
(rightfully) giving you a GP fault.

     If you add an asm("leave") before the iret, it should clean up
the stack so that it'll `work'.  On some architectures gcc knows about
the interrupt or interrupt_handler function attributes, but it dosen't
seem to do anything on the x86.  Unless the C compiler knows about the
`specialness' of this function, you're going to run into troubles.

     I'd suggest looking at kern/x86/pc/gdb_pc_com_intr.S and using
that as a template for an assembly interrupt handling function that
calls your C function.  That way there are no suprises.


steve


> void timer(void)
> {
> 	printf("in interrupt timer. \n");
> 	outb(0x20, 0x20);
> /* &&&&&&&&&&&& I got a trap dump after running this instruction */B
> 	asm ("iret");
> }


Follow-Ups: References: