Page 1 of 1

IDT

Posted: Sat Aug 31, 2002 7:57 am
by PlayOS
I am after a good tutorial on th IDT, I need something that shows you what to do and explains it as it goes, I have the Intel manuals and I have seen some source code, however I need a good explanation.

Re:IDT

Posted: Sat Aug 31, 2002 9:49 am
by Tim
There's not much to explain beyond what the Intel manuals tell you.

The IDT provides a mapping from an interrupt number to the segment and offset of that interrupt's handler. That is, when it needs to handle an interrupt, exception or fault, the processor looks up the number in the IDT, gets the segment and offset from the descriptor, and jumps to it.

Before it makes the jump, however, the CPU pushes some information onto the stack to allow it to resume from the interrupt afterwards. The amount of information varies depending on what ring is currently executing and what ring will handle the interrupt. You are most likely to see transitions from ring 3 to ring 0, in which most information is pushed onto the stack. Note that if the interrupt is handled in a more-privileged ring than is currently executing, the CPU switches to the stack for that ring. That is, if an interrupt is handled in ring 0 and you're running in ring 3 at the time, the CPU looks up the SS0 and ESP0 values from the current TSS and uses those instead of the current stack.

In the case of a ring 3 to ring 0 interrupt, the CPU will push SS, ESP, EFLAGS, CS and EIP, in that order, so that EIP ends up first in memory and SS is last (assuming an expand-down stack). A ring 0 to ring 0 interrupt (which you'll see if you make your kernel re-entrant) will only push EFLAGS, CS and EIP (it doesn't need to switch stacks). Additionally, some interrupts push an error code too -- to know which ones, look in the Intel docs -- and if you want to keep the stack frame the same, you'll need to push a dummy error code for the interrupts that don't provide one already. You will always need to skip over the error code before you IRET: although IRET will pop the relevant stuff off the stack, it won't pop the error code.

Comprendez?

Re:IDT

Posted: Sun Sep 01, 2002 12:54 am
by PlayOS
I now have a semi working IDT, I have remapped the IRQ's to int 32 (dec) upto int 47 (dec). I just have a couple of questions

First, I am not getting anything from IRQ12 which is the mouse, I think. I am definately getting the system timer and keyboard IRQ's, but nothing from the mouse. Is there anything that I have to do to setup the mouse? I have unmasked all IRQ's by doing

xor al, al
out 0x21, al
out 0xa1, al

Second, I have read that there are 32 (0-31) interrupts that are used by the system, however the same info only lists the first 19, are the rest up to 31 reserved? What should I set them up to have in them?

Third, could someone please give me an example of how to install my own interrupt handler, I sort of have an idea on how this would be done I would just like to see what you guys think.

Thanks

---------------------------------

I have realize that I am using a serial mouse and IRQ12 is a PS\2 Mouse, does this matter? if so how do I get the serial mouse events?

Also, IRQ8 the real time clock how often does this one fire? and what is it used for?

Re:IDT

Posted: Sun Sep 01, 2002 5:16 am
by Tim
You will only get interrupts from devices if you set them up to give you interrupts.

At boot time, the BIOS sets up the PIT and keyboard controller to start delivering interrupts. If you want to start getting PS/2 mouse interrupts you will need to play with the keyboard controller aux port (warning: no documentation available -- steal source code!). For the serial mouse, set up the serial port properly (more documentation available but I don't know where).

Re:IDT

Posted: Fri Oct 18, 2002 11:28 am
by paul
I'm having the same problem (except i *DO* have
a ps/2 mouse.) I know my IRQs are working cause
IRQ1 works so so do my own ISR routines. I just
get nothing at all on irq12 when ie move the PS/2
mouse.