virtual 8086 mode of operation of 80386
In its protected mode of operation, 80386 provides a virtual 8086 operating environment to execute the 8086 programs. An 8086 program runs in this environment as part of a V86 (virtual 8086) task. V86 tasks take advantage of the hardware support of multitasking offered by the protected mode.
- The hardware provides a virtual set of registers (via the TSS), a virtual memory space and directly executes all instructions that deal with these registers and with this address space.
- The software controls the external interfaces of the virtual machine (I/O, interrupts, and exceptions) in a manner consistent with the larger environment in which it executes. In the case of I/O, software can choose either to emulate I/O instructions or to let the hardware execute them directly without software intervention.
The most common problem by running 8086 code from protected mode is memory addressing which is totally different between protected mode and real mode. As mentioned, by working under VM86 mode the segmentation mechanism is reconfigured to work just like under real mode, but the paging mechanism is still active, and it is transparent to the real mode code; thus, memory protection is still applicable, and so is the isolation of the address space.
When interrupts (both hardware, software and int instruction) occur, the processor switches off the VM86 mode and returns to work in full protected mode to handle the interrupt. And before servicing the interrupt, the DS, ES, FS, and GS registers are pushed on the new stack and zeroed.