Confused about stack during isr calling

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
Gizmo
Member
Member
Posts: 41
Joined: Fri Aug 03, 2007 3:41 am

Confused about stack during isr calling

Post 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. :)
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Post by kataklinger »

You can comapre pushed CS with current CS and see if there has beeen pl change.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
Gizmo
Member
Member
Posts: 41
Joined: Fri Aug 03, 2007 3:41 am

Post by Gizmo »

Thanks, I will cod ethis sometime tommarow.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

OK - hadn't thought of that :oops: . Maybe check the PL flags of the CS, then!

Cheers,
Adam
Post Reply