Interrupt handling and tss
Interrupt handling and tss
My code is running in ring 2. Interrupt from keyboard or timer arrives. There is a interrupt gate on IDT that points to kernel code to ring 0. CPU loads sp and ss from tss becose the dpl switch. I have only one TSS. And my question is: Where goes the old values of ss and sp? I want to use and restore them.
Re: Interrupt handling and tss
From the manual 6.12:
So, when stack switch the old SS:E/RSP is pushed on ring0 stack, it's usually restored with IRET when the handler exit.If the handler procedure is going to be executed at a numerically lower privilege level, a stack switch occurs. When the stack switch occurs:
a. The segment selector and stack pointer for the stack to be used by the handler are obtained from the TSS for the currently executing task. On this new stack, the processor pushes the stack segment selector and stack pointer of the interrupted procedure.
Re: Interrupt handling and tss
So the stack state at begin of the handler is:
SS
SP
FLAGS
CS
IP
--TOP--
How CPU knows that there is stack segment and pointer on the stack? Eg: Kernel is running. Interrupt arruves DPL switch will not occur so SS SP is not on stack and handler does a IRET. I cannot find the IRET instruction in manual.
SS
SP
FLAGS
CS
IP
--TOP--
How CPU knows that there is stack segment and pointer on the stack? Eg: Kernel is running. Interrupt arruves DPL switch will not occur so SS SP is not on stack and handler does a IRET. I cannot find the IRET instruction in manual.
Re: Interrupt handling and tss
My guess would be it looks at the RPL in the CS selector found on the stack, if != current then it assumes SS and ESP are also there
Re: Interrupt handling and tss
DO NOT GUESS. I suggest you check IRET with the manual, the behavior of the instruction is well documented.
PS. Instructions are listed on volume2, if you got a decent computer I recommend to download the 1+2+3 combo.
PS. Instructions are listed on volume2, if you got a decent computer I recommend to download the 1+2+3 combo.
Re: Interrupt handling and tss
Thank you. I was looking
RETI instruction. Now i understand privilege level switch. Unluckyly getting 3rd exception in some other code.
How can i mark this thread solved, or dont reply if it is not necessary.
Thank you a lot.
RETI instruction. Now i understand privilege level switch. Unluckyly getting 3rd exception in some other code.
How can i mark this thread solved, or dont reply if it is not necessary.
Thank you a lot.
Re: Interrupt handling and tss
Edit the original post and change the subject line.tomasbrod wrote:How can i mark this thread solved
Re: Interrupt handling and tss
Why?tomasbrod wrote:My code is running in ring 2.
And what about handling kernel panic? I have two additional TSSes. One (per core) for handling kernel panic (kernel stack overflow). And one (per system) for NMI handling.I have only one TSS.
If you have seen bad English in my words, tell me what's wrong, please.