World Library  
Flag as Inappropriate
Email this Article

Virtual 8086 mode

Article Id: WHEBN0000641324
Reproduction Date:

Title: Virtual 8086 mode  
Author: World Heritage Encyclopedia
Language: English
Subject: Protected mode, Long mode, Memory management, IBM TopView, Intel 80386
Collection: Intel Products, Programming Language Implementation, Virtualization Software, X86 Operating Modes
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Virtual 8086 mode

In the 80386 microprocessor and later, virtual 8086 mode (also called virtual real mode, V86-mode or VM86) allows the execution of real mode applications that are incapable of running directly in protected mode while the processor is running a protected mode operating system. It is a hardware virtualization technique that allowed multiple 8086 processors to be emulated by the 386 chip; it emerged from the painful experiences with the 80286 protected mode, which by itself was not suitable enough to run concurrent MS-DOS applications well.[1]

VM86 mode uses a segmentation scheme identical to that of real mode (for compatibility reasons) which creates 20-bit linear addresses in the same manner as 20-bit physical addresses are created in real mode, but are subject to protected mode's memory paging mechanism.

Contents

  • Overview 1
  • Usage 2
  • Memory addressing and interrupts 3
  • Virtual 8086 mode enhancements (VME) 4
  • 64-bit and VMX support 5
  • Notes 6
  • References 7
  • See also 8

Overview

The virtual 8086 mode is a mode for a protected-mode task. Consequently, the processor can switch between VM86 and non-VM86 tasks, which is what enables multitasking of legacy (MS-DOS) applications.

To use virtual 8086 mode, an operating system sets up a virtual 8086 mode monitor, which is a program that manages the real-mode program and emulates or filters access to system hardware and software resources. The monitor must run at privilege level 0 and in protected mode. Only the 8086 program runs in VM86 mode and at privilege level 3. When the real-mode program attempts to do things like access certain I/O ports to use hardware devices or access certain regions in its memory space, the CPU traps these events and calls the V86 monitor, which examines what the real mode program is trying to do and either acts as a proxy to interface with the hardware, emulates the intended function the real-mode program was trying to access, or terminates the real-mode program if it is trying to do something that cannot either be allowed or be adequately supported (such as reboot the machine, set a video display into a mode that is not supported by the hardware and is not emulated, or write over operating system code).

The V86 monitor can also deny permission gently by emulating the failure of a requested operation—for example, it can make a disk drive always appear not ready when in fact it has not even checked the drive but simply will not permit the real-mode program to access it. Also, the V86 monitor can do things like map memory pages, intercept calls and interrupts, and preempt the real-mode program, allowing real-mode programs to be multitasked like protected-mode programs. By intercepting the hardware and software I/O of the real-mode program and tracking the state that the V86 program expects, it can allow multiple programs to share the same hardware without interfering with each other.[1] So V86 mode provides a way for real-mode programs designed for a single-tasking environment (like MS-DOS[2]) to run concurrently in a multitasking environment.

Usage

It is used to execute certain DOS programs in Windows/386, Windows 3.x, Windows 9x/Me, and OS/2 2.x and later through virtual DOS machines, in SCO UNIX through Merge, and in Linux through DOSEMU. (Other DOS programs which use protected mode execute using user mode under the emulator.) NTVDM in x86 Windows NT based operating systems also use VM86 mode,[2] but with very limited direct hardware access.

Memory addressing and interrupts

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.

Virtual 8086 mode enhancements (VME)

The Pentium architecture added a number of enhancements to the virtual 8086 mode. These were however documented by Intel only starting with the subsequent P6 (microarchitecture);[3] their more recent formal name is Virtual 8086 Mode Enhancements, abbreviated VME;[4] (Older documentation may use "Extensions" as the last word in the VME acronym expansion.[3] Some late-released embedded 486 chips also support it.[5][6]) The enhancements address mainly the 8086 virtualization overhead, with a particular focus on (virtual) interrupts.[3][7] Before the extensions were publicly documented in the P6 documentation, the official documentation referred to the famed Appendix H, which was omitted from the public documentation and shared only with selected partners under NDA.

Activating VME is done by setting bit number 0 (0x1 in value) of CR4. Because the VME interrupt speed-up enhancements were found useful for non-VM86 protected tasks, they can also be enabled separately by setting only bit number 1 (0x2 in value), which is called PVI (Protected Mode Virtual Interrupts).[3][6] Detecting whether a processor supports VME (including PVI) is done using the cpuid instruction, by testing the value of second bit (bit number 1, 0x2 in value) in EDX register, which is set if VME is supported by the processor.[4][3] In Linux, this latter bit is reported as the vme flag in the /proc/cpuinfo file, under the "flags" section.

64-bit and VMX support

Support for virtual 8086 mode is not available in x86-64 long mode, although it is still present on 64-bit capable processors running in legacy mode.

The addition of VT-x has added back the ability to run virtual 8086 mode from x86-64 long mode, but it has to be done by transitioning the (physical) processor to VMX root mode and launching a logical (virtual) processor itself running in virtual 8086 mode.[8]

Westmere and later Intel processors usually[9] can start the logical processor directly in real mode using the "unrestricted guest" feature (which itself requires Extended Page Tables); this method removes the need to resort to the nested virtual 8086 mode simply to run some MS-DOS applications.[10][11]

Notes

  1. ^ For example, if one program writes to a display, then another program gets control and writes to the same display, and then the first program gets control back, it will try to use the display as if the second program had not changed it. The V86 monitor can intercept the display writes, keep track of the display state for each program, and switch the real display between them according to which program the user has selected to interact with presently. The V86 monitor emulates independent displays for each program using only one real display.
  2. ^ MS-DOS is mentioned because it was especially the extensive library of existing MS-DOS programs that Intel had in mind when they designed V86 mode.

References

  1. ^ Yager, Tom (November 5, 2004). "Sending software to do hardware's job".  
  2. ^ "Windows NT 4.0 Workstation Architecture". 
  3. ^ a b c d e T. Shanley (1998). Pentium Pro and Pentium II System Architecture. Addison-Wesley. pp. 427, 465–480.  
  4. ^ a b http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf "Virtual 8086 Mode Enhancements. Virtual 8086 mode enhancements, including CR4.VME for controlling the feature, CR4.PVI for protected mode virtual interrupts, software interrupt indirection, expansion of the TSS with the software indirection bitmap, and EFLAGS.VIF and EFLAGS.VIP flags."
  5. ^ "Mailing List Archive: Re: 2.6.14: CR4 not needed to be inspected on the 486 anymore?". Gossamer-threads.com. Retrieved 2014-02-20. 
  6. ^ a b "Pentium Protected Mode Virtual Interrupts (PVI)". Rcollins.org. Retrieved 2014-02-20. 
  7. ^ "Virtual Mode Extensions on the Pentium Processor". Rcollins.org. Retrieved 2014-02-20. 
  8. ^ http://www.intel.com/Assets/en_US/PDF/manual/253669.pdf "a VM entry is allowed only to guests with paging enabled that are in protected mode or in virtual-8086 mode. Guest execution in other processor operating modes need to be specially handled by the VMM"; see also lesson 24 how to do this from Linux (not that the code is pretty dated, so might not work as-is with current kernels) more up-to-date code can be found here. Also beware that this sample code is more complicated than strictly booting the logical processor in virtual 8086 mode; its ultimate goal is make some real-mode BIOS calls.
  9. ^ "Intel Virtualization Technology List". Ark.intel.com. Retrieved 2014-02-20. A list of Intel processors that support VT-x but not EPT 
  10. ^ "Intel added unrestricted guest mode on Westmere micro-architecture and later Intel CPUs, it uses EPT to translate guest physical address access to host physical address. With this mode, VMEnter without enable paging is allowed."
  11. ^ "If the “unrestricted guest” VM-execution control is 1, the “enable EPT” VM-execution control must also be 1"

See also

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.