Page 1 of 1

IDT Examples

Posted: Sun Sep 01, 2002 7:43 pm
by PlayOS
Hi,

I have a working IDT and I am getting the interrupts but if I install my own interrupt handler I cannot get any other int's it just seems to freeze, does anyone know of some source code that has custom interrupts installed, that I could look at and see how it is done.

Also, am I supposed to pop an error code off of the stack when certain system int's fire?

Re:IDT Examples

Posted: Sun Sep 01, 2002 10:03 pm
by Warmaster199
You don't HAVE to pass an error code... especially if you don't have that arguement in your C source ;D

Try making a stub that calls your C codes... install the stub as the vector:

Code: Select all

GLOBAL _stublet
_stublet:
   push gs      
   push fs      
   push es      
   push ds
   push ss
   pusha      
   mov eax, KERNEL_DS   
   mov ds,eax      
   mov es,eax      
   mov fs,eax      
   mov gs,eax
   sti
   mov eax, _da_cvector
   cli
   popa
   pop ss
   pop ds      
   pop es
   pop fs
   pop gs
   iret

void da_cvector()
{
   printk("da cvector has fired\n");
}
Basically, you save all the registers incase a user process is working while the interrupt fires. by pushing them onto the stack. Interrupts are handled by the kernel, so you restore the kernel's DS(CS is handled by the processor automagically ;)), call the C codes(da_cvector), then restore everything the way it was before the interrupt was called and return to where the processor was with "iret". Return from interrupt.

Install by doing set_intr_gate(0x??, &stublet); or similar...

Re:IDT Examples

Posted: Mon Sep 02, 2002 1:32 am
by Pype.Clicker
i don't see why you do a mov eax, _da_cvector ... why not call _da_cvector instead ?

moreover, enabling interrupts in an interrupt handler and disabling it after is certainly a dangerous idea : nesting interrupts and stack overflows are floating over your head ...

Re:IDT Examples

Posted: Mon Sep 02, 2002 3:28 pm
by Warmaster199
oops... I forgot a "call eax". Thanks.

It's supposed to keep cleaner registers this way(Or so I am told)

Re:IDT Examples

Posted: Mon Sep 02, 2002 5:12 pm
by Tim
No, it's just slower.

Oh, and it does reduce wear and tear on the CPU's registers. If eveyone used call eax, you could send the CPU for service every twelve months (or 8?10[sup]15[/sup] cycles) instead of every six months. But be sure to check the oil level weekly either way.