VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

What happens when an IRET is executed while both the NT(Nested Task) and VM(Virtual 8086 mode) flags in EFLAGS are set, while EFLAGS.IOPL is 3? Will the CPU perform a return to the parent task(undocumented behaviour)? Or will the CPU ignore the NT flag and perform a V86-mode IRET to the caller in V86 mode(just like in real mode)?

Edit: http://nicolascormier.com/documentation/hardw … 386/Chap15.html

Chapter 15.3.1:

A task switch to or from a V86 task may be due to any of three causes: […]
Show full quote

A task switch to or from a V86 task may be due to any of three causes:

1. An interrupt that vectors to a task gate.
2. An action of the scheduler of the 80386 operating system.
3. An IRET when the NT flag is set.

So the NT flag has higher priority than a normal V86 mode IRET to the same task's calling interrupt(when both VM and NT are set), instead of relying on IOPL to either throw a #GP(0) fault or plain real-mode style IRET?

Last edited by superfury on 2019-03-28, 09:56. Edited 1 time in total.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 2 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

Well, all documentation I can find says the VM flag has precedence over the NT flag. But that would make no sense, since you can use a task switch to switch to a VM task, but can't switch back when having done so if that's correct?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 7, by Stenzek

User metadata
Rank Newbie
Rank
Newbie

As far as I understand things, that's a limitation of the V86 mode. Plenty of other ways to exit V86 mode, I guess you could for example have a software interrupt which goes to a task gate.

Last edited by Stenzek on 2019-03-26, 07:29. Edited 1 time in total.

Reply 4 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

What I mean is that you can't, for example, use V86 mode to handle an interrupt(e.g. MS-DOS) and then return(IRET) from it back to the caller when it's finished. You'll have to go the long way, installing an INT instruction to call the monitor at the IRET return address(e.g. MS-DOS style exit program that's trapped)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 5 of 7, by Stenzek

User metadata
Rank Newbie
Rank
Newbie

I think what you're describing (handling software interrupts in DOS) is kind-of what the V86 Mode Extensions were added for. It allows you to specify a bitmap of interrupts which will not trap to the V86 monitor, instead branching to the location stored in the IVT (while remaining in V86 mode, even with an IOPL of 3).

See: https://github.com/stenzek/pce/blob/master/sr … u_x86.cpp#L2097 and https://github.com/stenzek/pce/blob/master/sr … u_x86.cpp#L2726. It also affects privileged instructions such as POPF/CLI/STI.

As far as I'm aware, Windows 95/98 do not use the V86 extensions, even if they are present. I remember reading somewhere that there was a reason (hardware bugs perhaps?). Not sure about NT-based OSes, I think they do. Pretty sure I used NT to verify my implementation of VME.

Reply 6 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

NT having lower priority than V86 is proven by EMM386 when loaded. If NT has higher priority, EMM386 crashes with a #NP fault(error #11) and asks for a reboot due to segment 11E trying to task switch incorrectly.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 7 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

So, if the NT flag is essentially unsupported in V86 mode(only being cleared/set during task switches, but having no effect on IRET), is it affected by task switches to V86 tasks? So a CALL to a V86 task, will that set the NT flag of said task? Will it have effect on the V86 task(besides it being cleared when switching using an interrupt to another task)?

What happens when an interrupt occurs in V86 mode? Is NT always cleared in that case(except when switching to a different task because of it)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io