<s>
In	O
the	O
80386	B-General_Concept
microprocessor	B-Architecture
and	O
later	O
,	O
virtual	B-Application
8086	I-Application
mode	I-Application
(	O
also	O
called	O
virtual	B-Application
real	I-Application
mode	I-Application
,	O
V86-mode	B-Application
,	O
or	O
VM86	B-Application
)	O
allows	O
the	O
execution	O
of	O
real	B-Application
mode	I-Application
applications	O
that	O
are	O
incapable	O
of	O
running	O
directly	O
in	O
protected	B-Application
mode	I-Application
while	O
the	O
processor	O
is	O
running	O
a	O
protected	B-Application
mode	I-Application
operating	O
system	O
.	O
</s>
<s>
It	O
is	O
a	O
hardware	B-General_Concept
virtualization	I-General_Concept
technique	O
that	O
allowed	O
multiple	O
8086	O
processors	O
to	O
be	O
emulated	O
by	O
the	O
386	B-General_Concept
chip	O
.	O
</s>
<s>
It	O
emerged	O
from	O
the	O
painful	O
experiences	O
with	O
the	O
80286	O
protected	B-Application
mode	I-Application
,	O
which	O
by	O
itself	O
was	O
not	O
suitable	O
to	O
run	O
concurrent	O
real-mode	B-Application
applications	O
well	O
.	O
</s>
<s>
VM86	B-Application
mode	O
uses	O
a	O
segmentation	B-Device
scheme	O
identical	O
to	O
that	O
of	O
real	B-Application
mode	I-Application
(	O
for	O
compatibility	O
reasons	O
)	O
,	O
which	O
creates	O
20-bit	O
linear	O
addresses	O
in	O
the	O
same	O
manner	O
as	O
20-bit	O
physical	O
addresses	O
are	O
created	O
in	O
real	B-Application
mode	I-Application
,	O
but	O
are	O
subject	O
to	O
protected	B-Application
mode	I-Application
's	O
memory	B-Architecture
paging	I-Architecture
mechanism	O
.	O
</s>
<s>
The	O
virtual	B-Application
8086	I-Application
mode	I-Application
is	O
a	O
mode	O
for	O
a	O
protected-mode	B-Device
task	I-Device
.	O
</s>
<s>
Consequently	O
,	O
the	O
processor	O
can	O
switch	O
between	O
VM86	B-Application
and	O
non-VM86	O
tasks	O
,	O
enabling	O
multitasking	O
legacy	O
(	O
DOS	B-Device
)	O
applications	O
.	O
</s>
<s>
To	O
use	O
virtual	B-Application
8086	I-Application
mode	I-Application
,	O
an	O
operating	O
system	O
sets	O
up	O
a	O
virtual	B-Application
8086	I-Application
mode	I-Application
monitor	O
,	O
which	O
is	O
a	O
program	O
that	O
manages	O
the	O
real-mode	B-Application
program	O
and	O
emulates	O
or	O
filters	O
access	O
to	O
system	O
hardware	O
and	O
software	O
resources	O
.	O
</s>
<s>
The	O
monitor	O
must	O
run	O
at	O
privilege	B-Device
level	I-Device
0	O
and	O
in	O
protected	B-Application
mode	I-Application
.	O
</s>
<s>
Only	O
the	O
8086	O
program	O
runs	O
in	O
VM86	B-Application
mode	O
and	O
at	O
privilege	B-Device
level	I-Device
3	O
.	O
</s>
<s>
When	O
the	O
real-mode	B-Application
program	O
attempts	O
to	O
do	O
things	O
like	O
access	O
certain	O
I/O	O
ports	O
to	O
use	O
hardware	O
devices	O
or	O
access	O
certain	O
regions	O
in	O
its	O
memory	O
space	O
,	O
the	O
CPU	O
traps	O
these	O
events	O
and	O
calls	O
the	O
V86	B-Application
monitor	O
,	O
which	O
examines	O
what	O
the	O
real	B-Application
mode	I-Application
program	O
is	O
trying	O
to	O
do	O
and	O
either	O
acts	O
as	O
a	O
proxy	O
to	O
interface	O
with	O
the	O
hardware	O
,	O
emulates	O
the	O
intended	O
function	O
the	O
real-mode	B-Application
program	O
was	O
trying	O
to	O
access	O
,	O
or	O
terminates	O
the	O
real-mode	B-Application
program	O
if	O
it	O
is	O
trying	O
to	O
do	O
something	O
that	O
cannot	O
either	O
be	O
allowed	O
or	O
be	O
adequately	O
supported	O
(	O
such	O
as	O
reboot	O
the	O
machine	O
,	O
set	O
a	O
video	O
display	O
into	O
a	O
mode	O
that	O
is	O
not	O
supported	O
by	O
the	O
hardware	O
and	O
is	O
not	O
emulated	O
,	O
or	O
write	O
over	O
operating	O
system	O
code	O
)	O
.	O
</s>
<s>
The	O
V86	B-Application
monitor	O
can	O
also	O
deny	O
permission	O
gently	O
by	O
emulating	O
the	O
failure	O
of	O
a	O
requested	O
operationfor	O
example	O
,	O
it	O
can	O
make	O
a	O
disk	O
drive	O
always	O
appear	O
not	O
ready	O
when	O
in	O
fact	O
it	O
has	O
not	O
even	O
checked	O
the	O
drive	O
but	O
simply	O
will	O
not	O
permit	O
the	O
real-mode	B-Application
program	O
to	O
access	O
it	O
.	O
</s>
<s>
Also	O
,	O
the	O
V86	B-Application
monitor	O
can	O
do	O
things	O
like	O
map	O
memory	O
pages	O
,	O
intercept	O
calls	O
and	O
interrupts	O
,	O
and	O
preempt	O
the	O
real-mode	B-Application
program	O
,	O
allowing	O
real-mode	B-Application
programs	O
to	O
be	O
multitasked	O
like	O
protected-mode	B-Application
programs	O
.	O
</s>
<s>
By	O
intercepting	O
the	O
hardware	O
and	O
software	O
I/O	O
of	O
the	O
real-mode	B-Application
program	O
and	O
tracking	O
the	O
state	O
that	O
the	O
V86	B-Application
program	O
expects	O
,	O
it	O
can	O
allow	O
multiple	O
programs	O
to	O
share	O
the	O
same	O
hardware	O
without	O
interfering	O
with	O
each	O
other	O
.	O
</s>
<s>
So	O
V86	B-Application
mode	I-Application
provides	O
a	O
way	O
for	O
real-mode	B-Application
programs	O
designed	O
for	O
a	O
single-tasking	O
environment	O
(	O
like	O
DOS	B-Device
)	O
to	O
run	O
concurrently	O
in	O
a	O
multitasking	O
environment	O
.	O
</s>
<s>
FlexOS	B-Operating_System
386	I-Operating_System
(	O
since	O
1987	O
)	O
,	O
Concurrent	B-Operating_System
DOS	I-Operating_System
386	I-Operating_System
(	O
since	O
1987	O
)	O
,	O
Windows/386	B-Application
2.10	I-Application
(	O
since	O
1987	O
)	O
,	O
DESQview	O
386	B-General_Concept
(	O
since	O
1988	O
)	O
,	O
Windows	B-Application
3.x	I-Application
(	O
since	O
1990	O
)	O
,	O
Multiuser	B-Operating_System
DOS	I-Operating_System
(	O
since	O
1991	O
)	O
,	O
Windows	O
for	O
Workgroups	O
3.1x	O
(	O
since	O
1992	O
)	O
,	O
OS/2	B-Application
2.x	O
(	O
since	O
1992	O
)	O
,	O
4690	B-Language
OS	I-Language
(	O
since	O
1993	O
)	O
,	O
REAL/32	O
(	O
since	O
1995	O
)	O
running	O
in	O
386	B-Application
Enhanced	I-Application
Mode	I-Application
as	O
well	O
as	O
in	O
Windows	B-Application
95	I-Application
,	O
98	B-Device
,	O
98	B-Device
SE	O
and	O
ME	B-Device
through	O
virtual	O
DOS	B-Device
machines	O
,	O
in	O
SCO	B-Operating_System
UNIX	I-Operating_System
through	O
Merge	O
,	O
and	O
in	O
Linux	B-Application
through	O
DOSEMU	B-Application
.	O
</s>
<s>
(	O
Other	O
DOS	B-Device
programs	O
which	O
use	O
protected	B-Application
mode	I-Application
execute	O
using	O
user	O
mode	O
under	O
the	O
emulator	O
.	O
)	O
</s>
<s>
NTVDM	O
in	O
x86	B-Operating_System
Windows	O
NT-based	O
operating	O
systems	O
also	O
use	O
VM86	B-Application
mode	O
,	O
but	O
with	O
very	O
limited	O
direct	O
hardware	O
access	O
.	O
</s>
<s>
GRUB	B-Application
)	O
use	O
the	O
protected	B-Application
mode	I-Application
,	O
and	O
execute	O
the	O
BIOS	B-Device
interrupt	I-Device
calls	I-Device
in	O
Virtual	B-Application
8086	I-Application
mode	I-Application
.	O
</s>
<s>
The	O
most	O
common	O
problem	O
by	O
running	O
8086	O
code	O
from	O
protected	B-Application
mode	I-Application
is	O
memory	B-General_Concept
addressing	I-General_Concept
which	O
is	O
totally	O
different	O
between	O
protected	B-Application
mode	I-Application
and	O
real	B-Application
mode	I-Application
.	O
</s>
<s>
As	O
mentioned	O
,	O
by	O
working	O
under	O
VM86	B-Application
mode	O
the	O
segmentation	B-Device
mechanism	O
is	O
reconfigured	O
to	O
work	O
just	O
like	O
under	O
real	B-Application
mode	I-Application
,	O
but	O
the	O
paging	B-Architecture
mechanism	O
is	O
still	O
active	O
,	O
and	O
it	O
is	O
transparent	O
to	O
the	O
real	B-Application
mode	I-Application
code	O
;	O
thus	O
,	O
memory	B-General_Concept
protection	I-General_Concept
is	O
still	O
applicable	O
,	O
and	O
so	O
is	O
the	O
isolation	O
of	O
the	O
address	O
space	O
.	O
</s>
<s>
When	O
interrupts	O
(	O
hardware	O
,	O
software	O
and	O
int	O
instruction	O
)	O
occur	O
,	O
the	O
processor	O
switches	O
off	O
the	O
VM86	B-Application
mode	O
and	O
returns	O
to	O
work	O
in	O
full	O
protected	B-Application
mode	I-Application
to	O
handle	O
the	O
interrupt	O
.	O
</s>
<s>
The	O
Pentium	O
architecture	O
added	O
a	O
number	O
of	O
enhancements	O
to	O
the	O
virtual	B-Application
8086	I-Application
mode	I-Application
.	O
</s>
<s>
These	O
were	O
however	O
documented	O
by	O
Intel	O
only	O
starting	O
with	O
the	O
subsequent	O
P6	B-Device
(	O
microarchitecture	O
)	O
;	O
their	O
more	O
recent	O
formal	O
name	O
is	O
Virtual-8086	O
Mode	O
Extensions	O
,	O
abbreviated	O
VME	O
(	O
older	O
documentation	O
may	O
use	O
"	O
Virtual	B-Application
8086	I-Application
mode	I-Application
enhancements	O
"	O
as	O
the	O
VME	O
acronym	O
expansion	O
)	O
.	O
</s>
<s>
Before	O
the	O
extensions	O
were	O
publicly	O
documented	O
in	O
the	O
P6	B-Device
documentation	O
,	O
the	O
official	O
documentation	O
referred	O
to	O
the	O
famed	O
Appendix	B-Device
H	I-Device
,	O
which	O
was	O
omitted	O
from	O
the	O
public	O
documentation	O
and	O
shared	O
only	O
with	O
selected	O
partners	O
under	O
NDA	O
.	O
</s>
<s>
Because	O
the	O
VME	O
interrupt	O
speed-up	O
enhancements	O
were	O
found	O
useful	O
for	O
non-VM86	O
protected	O
tasks	O
,	O
they	O
can	O
also	O
be	O
enabled	O
separately	O
by	O
setting	O
only	O
bit	O
number	O
1	O
(	O
0x2	O
in	O
value	O
)	O
,	O
which	O
is	O
called	O
PVI	O
(	O
Protected	B-Application
Mode	I-Application
Virtual	O
Interrupts	O
)	O
.	O
</s>
<s>
Detecting	O
whether	O
a	O
processor	O
supports	O
VME	O
(	O
including	O
PVI	O
)	O
is	O
done	O
using	O
the	O
CPUID	B-Architecture
instruction	O
,	O
with	O
an	O
initial	O
EAX	O
value	O
of	O
0x1	O
,	O
by	O
testing	O
the	O
value	O
of	O
second	O
bit	O
(	O
bit	O
number	O
1	O
,	O
0x2	O
in	O
value	O
)	O
in	O
EDX	O
register	O
,	O
which	O
is	O
set	O
if	O
VME	O
is	O
supported	O
by	O
the	O
processor	O
.	O
</s>
<s>
In	O
Linux	B-Application
,	O
this	O
latter	O
bit	O
is	O
reported	O
as	O
the	O
flag	O
in	O
the	O
file	O
,	O
under	O
the	O
"	O
flags	O
"	O
section	O
.	O
</s>
<s>
In	O
virtual	B-Application
8086	I-Application
mode	I-Application
,	O
the	O
basic	O
idea	O
is	O
that	O
when	O
IOPL	O
is	O
less	O
than	O
3	O
,	O
PUSHF/POPF/STI/CLI/INT/IRET	O
instructions	O
will	O
treat	O
the	O
value	O
of	O
VIF	O
in	O
the	O
real	O
32-bit	O
EFLAGS	O
register	O
as	O
the	O
value	O
of	O
IF	O
in	O
the	O
simulated	O
16-bit	O
FLAGS	O
register	O
(	O
32-bit	O
PUSHFD/POPFD	O
continues	O
to	O
GP	O
fault	O
)	O
.	O
</s>
<s>
Virtual	B-Application
8086	I-Application
mode	I-Application
is	O
not	O
available	O
in	O
x86-64	B-Device
long	B-Application
mode	I-Application
,	O
although	O
it	O
is	O
still	O
present	O
on	O
x86-64	B-Device
capable	O
processors	O
running	O
in	O
legacy	O
mode	O
.	O
</s>
<s>
Intel	O
VT-x	O
brings	O
back	O
the	O
ability	O
to	O
run	O
virtual	B-Application
8086	I-Application
mode	I-Application
from	O
x86-64	B-Device
long	B-Application
mode	I-Application
,	O
but	O
it	O
has	O
to	O
be	O
done	O
by	O
transitioning	O
the	O
(	O
physical	O
)	O
processor	O
to	O
VMX	O
root	O
mode	O
and	O
launching	O
a	O
logical	O
(	O
virtual	O
)	O
processor	O
itself	O
running	O
in	O
virtual	B-Application
8086	I-Application
mode	I-Application
.	O
</s>
<s>
Westmere	B-Device
and	O
later	O
Intel	O
processors	O
usually	O
can	O
start	O
the	O
virtual	O
processor	O
directly	O
in	O
real	B-Application
mode	I-Application
using	O
the	O
"	O
unrestricted	O
guest	O
"	O
feature	O
(	O
which	O
itself	O
requires	O
Extended	O
Page	O
Tables	O
)	O
;	O
this	O
method	O
removes	O
the	O
need	O
to	O
resort	O
to	O
the	O
nested	O
virtual	B-Application
8086	I-Application
mode	I-Application
simply	O
to	O
run	O
the	O
legacy	O
BIOS	O
for	O
booting	O
.	O
</s>
<s>
AMD-V	O
can	O
do	O
virtual	B-Application
8086	I-Application
mode	I-Application
in	O
guests	O
,	O
too	O
,	O
but	O
it	O
can	O
also	O
just	O
run	O
the	O
guest	O
in	O
"	O
paged	O
real	B-Application
mode	I-Application
"	O
using	O
the	O
following	O
steps	O
:	O
you	O
create	O
a	O
SVM	O
(	O
Secure	O
Virtual	O
Machine	O
)	O
mode	O
guest	O
with	O
CR0.PE	O
=	O
0	O
,	O
but	O
CR0.PG	O
=	O
1	O
(	O
that	O
is	O
,	O
with	O
protected	B-Application
mode	I-Application
disabled	O
but	O
paging	B-Architecture
enabled	O
)	O
,	O
which	O
is	O
ordinarily	O
impossible	O
,	O
but	O
is	O
allowed	O
for	O
SVM	O
guests	O
if	O
the	O
host	O
intercepts	O
page	O
faults	O
.	O
</s>
