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

Re: How make an interrupt gate?



I had exactly the same problem when I was my user-process scheduler /
timer event handler, simply because you don't know how the compiler
generates the code, short of disassembling it (or yuck yuck yuck - compile
with -O0). I agree with Steve's suggestion of writing a small amount of
asm code that calls a C-generated function. My web page has some code that
show's you how to do this.

Return values are passed via the EAX register, and it is the caller's
responsbility to remove parameters from the stack.

 Thesis Defense Don'ts number 107: "I don't know - I didn't write this."
 ______________________________________________________________
| Voon-Li Chung	        | Star Trek Fan, PhD Student, Inline-  |
| vlchung@cs.uwa.edu.au | Hockey Player. TheatreSports Player  |
| Web Page: http://www.cs.uwa.edu.au/~vlchung	               |
 --------------------------------------------------------------

On Thu, 3 Feb 2000, stephen clawson wrote:

> Date: Thu, 3 Feb 2000 03:25:29 -0700 (MST)
> From: stephen clawson <sclawson@fast.cs.utah.edu>
> To: m_taghi@yahoo.com
> Cc: oskit-users@cs.utah.edu, Mohmod Taghizade <taghi@hadid.sharif.ac.ir>
> Subject: 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");
> > }
> 


References: