Page 1 of 1

Confused about stack during isr calling

Posted: Sat Aug 11, 2007 2:35 am
by Gizmo
I am confused about what happens when my isr's get called on when in both protection rings 0 and 3.

Here is what I think I know:

cpl0 no cpl change in protected mode

Code: Select all

push eflags
push cs
push cip
cpl3 to cpl0 cpl change in protected mode and everytime in long mode

Code: Select all

push ss
push esp
push eflags
push cs
push cip
push error code
Is this correct?
How do you code an isr that is going to know if a cpl change occurred or not so I can correctly get this stuff from the stack? (ie stick these regs into a threads register storage in a thread control structure for software task switching)

I see plenty of examples but none of them explain how to know whats on the stack (most just print some message and iret) and the intel docs just don't seem to clearly explain this to me.

Any help would be greatly appreciated. :)

Posted: Sat Aug 11, 2007 3:14 am
by kataklinger
You can comapre pushed CS with current CS and see if there has beeen pl change.

Posted: Sat Aug 11, 2007 5:00 am
by AJ
Hi,

Alternatively, if you have a custom process control structure with a flags field, you could create a flag for 'user mode'.

Also, yYou don't need to check the current CS against the pushed CS - just check the lower 2 bits of the pushed CS.

Cheers,
Adam

Posted: Sat Aug 11, 2007 5:31 am
by Gizmo
Thanks, I will cod ethis sometime tommarow.

Posted: Sat Aug 11, 2007 5:32 am
by JamesM
AJ wrote: Also, yYou don't need to check the current CS against the pushed CS - just check the lower 2 bits of the pushed CS.
Just to clarify, in case you don't know what he meant, the lower 2 bits of any segment selector is the RPL (requested privilege level) - Will be 3 for user code, 0 for kernel code.

JamesM

Posted: Sat Aug 11, 2007 8:11 am
by kataklinger
AJ wrote: Alternatively, if you have a custom process control structure with a flags field, you could create a flag for 'user mode'.
There could be a problem with this method. If interrupt is trigered during execution of sys. call (called from user mode code), then if you only look user-mode flag in your task structure you will PL tranisition even if it has not happened, but still it depends on what you want to do.

Posted: Mon Aug 13, 2007 3:01 am
by AJ
OK - hadn't thought of that :oops: . Maybe check the PL flags of the CS, then!

Cheers,
Adam