ARCHITECTURAL COMPATIBILITY
Because the address space
of
an
8086
is
one
megabyte, the logical addresses generated
by
a
Virtual 86 Mode task fall into the first megabyte
of
the 80386 linear address space. Multiple
Virtual 86
Mode
tasks could interfere with each
other, since they would all share the low megabyte
of the linear address space. An operating system
can
use
80386 paging to relocate the linear
address spaces
of
Virtual 86 Mode tasks to
different areas of the physical address space.
Using paging in this way not only prevents
interference among Virtual
86
Mode tasks, but
enables a virtual memory operating system to
swap the pages of Virtual
86
Mode tasks just
as if they
were
80386 tasks.
A Virtual
86
Mode task may execute a program
that
was
written for execution on a single-task
personal computer. Such a program can contain
instructions that are potentially disruptive if
executed in a multitasking environment.
For
example, allowing a Virtual 86
Mode
task to
execute .the Clear Interrupt Flag instruction,
thereby disabling interrupts, could bring the
entire system to a halt.
To
prevent such disrup-
tions, the
80386 raises
an
exception when a
Virtual 86 Mode task attempts to execute
an
I/O
or
interrupt-related instruction.
Preventing the execution
of
such instructions
protects the rest
of
the system from a Virtual 86
Mode task, but does not satisfy the Virtual
86
Mode task's need to execute the instructions.
The solution
is
to simulate the sensitive instruc-
tions
in
an
operating system procedure called a
virtual
machine
monitor. When
an
exception
handler
is
invoked,
it
can inspect the VM86 flag
in the Flags image
on
the stack to
see
if the source
of
the exception
is
a Virtual 86 Mode task;
if
so,
the exception handler can call the virtual machine
monitor which can simulate the instruction and
return to the Virtual 86 Mode task. Note that a
virtual machine monitor simulates only a few
8086 instructions
and
that both the simulated
instructions and those the
80386 executes directly
benefit from the much higher performance
of
the
4-2
80386 compared
to
the 8086.
Working together, the 80386 and a virtual
machine monitor implement the full 8086 instruc-
tion set, and paging can provide each Virtual
86
M ode task with its own protected address space.
However, most
8086 programs need additional
resources provided by
an
operating system and
peripheral hardware.
An
example
ofthe
former
type
of
resource
is
a file system;
an
example
of
the latter
is
a bit-mapped display controller
manipulated directly by
an
application program.
These resources may
not
exist in the same form
in the
80386-based system
as
they did in the
system for which the
8086 program was designed.
To
simplify the
job
of
providing these resources
in a different environment, the
80386 can trap
operating system
and
peripheral references made
by Virtual
86
Mode tasks.
For
example, most 8086 operating systems use
the Interrupt instruction to implement operating
system calls. The
80386 raises
an
exception when
a Virtual 86 Mode task attempts to execute
an
Interrupt instruction. The virtual machine moni-
tor
can then translate the 8086 operating system
call into a call on the
80386 operating system as
shown in Figure 4-I.-If a Virtual
86
Mode task's
10PL
is
set to
less
than 3, the 80386
will
likewise
trap any
I/O
instruction the 8086 program
executes. The
80386 paging facility can be used
to redirect references to memory-mapped periph-
erals to other addresses, if necessary. Such
references can also be trapped by marking the
corresponding pages read-only (to trap writes),
or
not-present (to trap both reads and writes).