timer isr

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
Poseidon

timer isr

Post by Poseidon »

What does a timer isr exactly do and in what order when used for switching tasks, what is done with the tss.. I also read something about switching from ring 0 to 3 and back. Could somebody please explain me what's exactly happening?

Thanks
AR

Re:timer isr

Post by AR »

The timer interrupt occurs at an interval that you can configure in the PIT. It in itself doesn't do any task switching but usually the scheduler is invoked in the timer interrupt since the OS wants to control the ammount of CPU time each process gets.

The task switch method depends on whether you're using hardware or software switching, software is generally faster and hardware isn't supported on x86-64 (in long mode, not pmode). When interrupts occur, the CPU gets the kernel stack out of the current TSS (SS0 and ESP0) in order to switch to the handler to deal with the interrupt.
Poseidon

Re:timer isr

Post by Poseidon »

i already have set the call to my isr, but i read somewhere you can't just go from ring 3 to ring 0, and I'm also not sure about pushing and popping the registers, aren't they pushed on a wrong stack when I just push them? and points ss to where the cpu currently is with executing code?

thanks :)
AR

Re:timer isr

Post by AR »

When interrupts occur the CPU loads CS with the value from the interrupt descriptor, it then uses the ring number to look up the stack segment in the TSS (SS0/ESP0). Once that's done it jumps to the address given in the descriptor.

When the CPU starts the ISR, the stack has already been loaded from the TSS so when you push stuff it goes on the Kernel stack.

A basic ISR:

Code: Select all

isr0:
pusha
push ds
push es
push fs
push gs
mov ax, ss
mov ds, ax
mov es, ax

push dword 0  ;Interrupt number
[EXTERN CInterruptHandler]
call CInterruptHandler
add esp, 4

pop gs
pop fs
pop es
pop ds
popa
iret
Post Reply