I have decided to implement v86 mode into the kernel I have been writing.
I've been looking at how to do this, and something has been bugging me.
Suppose that the CPU is executing in v86 mode and hits an INT instruction/a hardware interrupt occurs.
When in v86 mode the stack is at SS:SP as in SS * 4 + SP.
In the interrupt handler the stack is at a totally different location based on the same SS:SP registers.
Is this right? Am I supposed to check whether the CPU was just executing v86 code and if it was flatten the stack address and fix the stack segment register?
(I'm not using paging/Don't know if that would matter here)
Virtual 8086 stack with interrupt handlers
-
- Posts: 1
- Joined: Fri Jan 17, 2025 2:30 pm
- Libera.chat IRC: kelemenorosz
Re: Virtual 8086 stack with interrupt handlers
I highly suggest you read the Intel SDM or AMD APM for more details on this. I am using the AMD APM, and it describes in volume 2, chapter 8.8 exactly how that all works. In particular under what circumstances it invokes what handler in response to an interrupt in Virtual 8086 mode.
In this case, if it does invoke a protected-mode handler, it will read SS:ESP from the TSS even if the CPL is already 0. So there is no problem; the interrupt will be taken on the normal kernel stack.
In this case, if it does invoke a protected-mode handler, it will read SS:ESP from the TSS even if the CPL is already 0. So there is no problem; the interrupt will be taken on the normal kernel stack.
Carpe diem!
-
- Member
- Posts: 5609
- Joined: Mon Mar 25, 2013 7:01 pm