x86 NT(Nested Task) flag in Virtual 8086 mode?

Emulation of old PCs, PC hardware, or PC peripherals.

x86 NT(Nested Task) flag in Virtual 8086 mode?

Postby superfury » 2019-3-24 @ 15:12

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 ... hap15.html

Chapter 15.3.1:
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-3-28 @ 09:56, edited 1 time in total.
superfury
l33t
 
Posts: 3230
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 NT(Nested Task) flag vs VM flag?

Postby Stenzek » 2019-3-25 @ 00:10

VM flag has precedence over the NT flag according to the Intel manual. I'm assuming real hardware functions the same, but you could always write a test to confirm.
Stenzek
Newbie
 
Posts: 58
Joined: 2017-12-08 @ 08:30

Re: x86 NT(Nested Task) flag vs VM flag?

Postby superfury » 2019-3-25 @ 17:06

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?
superfury
l33t
 
Posts: 3230
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 NT(Nested Task) flag vs VM flag?

Postby Stenzek » 2019-3-26 @ 06:12

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-3-26 @ 07:29, edited 1 time in total.
Stenzek
Newbie
 
Posts: 58
Joined: 2017-12-08 @ 08:30

Re: x86 NT(Nested Task) flag vs VM flag?

Postby superfury » 2019-3-26 @ 06:31

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)?
superfury
l33t
 
Posts: 3230
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 NT(Nested Task) flag vs VM flag?

Postby Stenzek » 2019-3-26 @ 07:34

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/mas ... .cpp#L2097 and https://github.com/stenzek/pce/blob/mas ... .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.
Stenzek
Newbie
 
Posts: 58
Joined: 2017-12-08 @ 08:30

Re: x86 NT(Nested Task) flag vs VM flag?

Postby superfury » 2019-3-27 @ 10:11

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.
superfury
l33t
 
Posts: 3230
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 NT(Nested Task) flag vs VM flag?

Postby superfury » 2019-3-28 @ 09:40

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)?
superfury
l33t
 
Posts: 3230
Joined: 2014-3-08 @ 11:25
Location: Netherlands


Return to PC Emulation

Who is online

Users browsing this forum: MSN [Bot] and 2 guests