IDT Examples

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
PlayOS

IDT Examples

Post 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?
Warmaster199

Re:IDT Examples

Post 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...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:IDT Examples

Post 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 ...
Warmaster199

Re:IDT Examples

Post by Warmaster199 »

oops... I forgot a "call eax". Thanks.

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

Re:IDT Examples

Post 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.
Post Reply