The sequence of CPU's pushing register when interrupt occur?

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
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

The sequence of CPU's pushing register when interrupt occur?

Post by oohayulin »

When a interrupt occurs, in what sequence CPU push the registers???

In the bochs I traced the stacks: before "int 3" excution and before "cli" in a isr stub function. I found it just pushed eflags(first), cs(second), eip(third) registers into the stack.

Is it right?

Maybe you can tell me in what sequence "pushad" push the general registers by the way.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

That's right. When it does a ring change it also pushes SS (first) and ESP (second), followed by the rest as normal.

Pusha pushes eax, ecx, edx, ebx, esp, ebp, esi, edi in that order.

More info available here.

Cheers,

James
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

Post by oohayulin »

OK. 3Q.

JamesM, I am reading your tutorial and got the problem. :)

maybe you can add some information about the "struct resgisters" because I found the member sequence in this struct is according to the sequence of "ring change pushing" , "pushing int_no and errcode" and "pushad".

It was my confused problem yesterday. I drawed a long stack diagram to understand it.
Krox
Posts: 23
Joined: Fri Mar 21, 2008 3:52 am
Location: Germany

Post by Krox »

http://www.sandpile.org/
Really nice reference for all stackframes, other "CPU-structs" and some more stuff...
21 is only half the truth...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

oohayulin wrote:OK. 3Q.

JamesM, I am reading your tutorial and got the problem. :)

maybe you can add some information about the "struct resgisters" because I found the member sequence in this struct is according to the sequence of "ring change pushing" , "pushing int_no and errcode" and "pushad".

It was my confused problem yesterday. I drawed a long stack diagram to understand it.
Hi,

You're right, the registers structure is tailored to the stack frame created in my tutorials. It works for inter ring changes and non ring changes, because in the second case the last two members actually just point to junk, but the rest are good. Draw a diagram and work out why :)
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

Post by oohayulin »

JamesM wrote:Draw a diagram and work out why :)
Yeah. Drawing a diagram is great and helpful to understand. Now I have known much from drawing it.
Maybe others can try drawing too!
Post Reply