[Solved] V86 mode and UD exception

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
kelemenorosz
Posts: 4
Joined: Fri Jan 17, 2025 2:30 pm

[Solved] V86 mode and UD exception

Post by kelemenorosz »

Hi, I have been working on a virtual 8086 monitor.
With IOPL = 0 and CR4.VME = 0 all the illegal instructions in VM86 go to the GP handler, which then calls the monitor.

Not all instructions are handled yet, however when this happens the EIP is not incremented so it just hangs at that instruction, raising the GP handler over and over again.

For the moment I just want the BIOS INT 0x10 function to switch video modes.

When the monitor sees an INT instruction, it looks up the segment:offset pair in the IVT and sets it as CS:EIP.

For all other instructions that are handled by the monitor so far the EIP is incremented by 1: PUSHF(16); POPF(16); OUT(AL) and CLI. These are all one opcode instructions. (If I'm not mistaken)

After a while, the VM86 code raises a UD exception.
At the CS:EIP location is opcode 0x63 which is the ARPL instruction.

I would like to know if anyone has encountered something similar.
The Intel manual states that in both Real Mode and V86 Mode ARPL is not a recognized instruction and it raises UD.
As this is in BIOS interrupt code I don't think an ARPL instruction would be written there.

Which leads me to think that I somehow incremented the EIP of PUSHF, POPF, etc. incorrectly and it messed with how the CPU reads the instructions.
kelemenorosz
Posts: 4
Joined: Fri Jan 17, 2025 2:30 pm

Re: [Solved] V86 mode and UD exception

Post by kelemenorosz »

My mistake, I was decrementing the stack pointer in POPF instead of incrementing.
This seems to have solved whatever was causing the issue.
Post Reply