VOGONS


First post, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

I am in protected mode, all is set up correctly. IRQ0 (timer) happens. How does the stack look like? I expected it to be like this, but I think that is wrong. Either I am off by 1 or wrong order.

[ESP+4] <= EIP of where the CPU was when the IRQ fired
[ESP+8] <= CS (descriptor) of where the CPU was when the IRQ fired
[ESP+12] <= EFLAGS
[ESP+16] <= ESP of where the CPU was when the IRQ fired
[ESP+20] <= ES descriptor

That does not seem correct right?

How does the stack look like immediately after an IRQ in PM is fired?

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/

Reply 1 of 3, by crazyc

User metadata
Rank Member
Rank
Member

That's right AFAICT. Except for the ES descriptor typo and ESP+4 should just be ESP, adjusting the others by 4 too. Oh, also the ESP and SS should only be pushed if there's a privilege change. If it's in V86 mode you have to push all the segments and if it's a task gate everything is plopped into the tss and you push nothing

Reply 2 of 3, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie
crazyc wrote:

That's right AFAICT. Except for the ES descriptor typo and ESP+4 should just be ESP, adjusting the others by 4 too. Oh, also the ESP and SS should only be pushed if there's a privilege change. If it's in V86 mode you have to push all the segments and if it's a task gate everything is plopped into the tss and you push nothing

Thank you. So what you are saying it will be something like this:

[ESP] <= EIP of where the CPU was when the IRQ fired
[ESP+4] <= CS (descriptor) of where the CPU was when the IRQ fired
[ESP+8] <= EFLAGS
[ESP+12] <= ESP of where the CPU was when the IRQ fired
[ESP+16] <= SS descriptor

So then, if I do something like

POP EAX
or
MOV EAX, [ESP]

that would put calling EIP in EAX. Am I correct?

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/