What is Virtual Real Mode? (Explained)

What is Virtual Real Mode?

Virtual real mode, also known as 8086 mode, refers to the mode which allows the Intel 386 and higher CPUs to contain a 16-bit environment in real mode but in a protected mode. It refers to a hardware virtualization method which allows the 386 processors to emulate the 8086 processors.

Technically, this means that in this particular mode the processor will allow you to execute real mode applications but the processor will be running a protected mode operating system.

KEY TAKEAWAYS

  • The virtual real mode was developed so that this issue is resolved effectively since it will imitate real mode while running in a protected mode, which will eventually allow the DOS programs to run on it.
  • Typically, V86 mode signifies the third mode of processor operation which is in fact an extra capability or an enhancement of the protected mode.
  • In virtual 8086 mode the computer system is divided into several different address spaces and there is a register maintained for each of these address spaces.
  • Ideally, the VM86 mode was created so that it allowed multitasking DOS Real Mode applications with 32-bit Windows applications side by side.
  • Using a computer in virtual real mode will allow it to access memory of only up to 1 MB.

Understanding Virtual Real Mode

What is Virtual Real Mode

Virtual real mode signifies the particular operational state of an Intel processor which helps it to function just like multiple 8086 or 8088 processors. This was ideally the architecture of the first x86 chip.

Ideally, this specific mode, which allows a protected-mode task, consequently allows the processor to switch between virtual mode 8086 tasks and non-VM86 tasks quite easily, eventually allowing multitasking for legacy DOS applications.

The virtual real mode used in 80386 CPUs and later is known by different names such as:

  • Virtual 8086 mode
  • V86 mode
  • VM86 mode

In a protected mode operating system such as Windows, there can actually be several virtual real mode machines created.

Each of these machines creates an illusion for the software running them. This makes the software feel like it is the only one running on a particular machine.

Each of these virtual machines comes with the following:

  • Its own address space of 1 MB
  • An image of the real hardware BIOS routines

Background:

It all started with the 386 family of processors in 1985. The concept of virtual real mode was the result of the agonizing experience of using the 80286 chips in protected mode.

These chips were not suitable at all to run real mode applications concurrently quite well.

In an ideal world, the protected mode is used when a user needs to run graphical multitasking operating systems such as the different flavors of Windows.

In such situations, the users often wish to run DOS programs and applications under Windows.

However, the DOS programs typically need real mode to run instead of protected mode.

Subsequently, the virtual mode bit at the register set was developed by John Crawford, which eventually paved the way to the development and use of virtual real mode.

Working:

In order to make the virtual 8086 mode usable, the operating system sets up a monitor. This is actually a program that performs several important tasks such as:

Typically, this specific program needs to operate in a protected mode and at privilege level 0.

Remember, it is only the 8086 program that typically runs in the virtual real mode as well as at a privilege level 3.

The working process can be summarized as follows when the real mode program tries to access specific I/O ports for using hardware devices or particular areas in the memory space:

  • The processor traps such events
  • It then calls the V86 monitor
  • The monitor then examines what exactly is being done by the real mode program.
Read Also:  What is Westmere Processor? (Explained)

Based on the examination results, the V86 monitor accordingly performs as a proxy to interface with the particular hardware by emulating the function, which the real mode programs intend to access.

It may also terminate the real-mode program if it tries to do anything that is either not supported adequately or not allowed. Some of these actions include the following:

  • Rebooting the machine
  • Setting a video display to an un-emulated and unsupported mode by the hardware
  • Writing over operating system code

Sometimes, permissions may also be denied by the V86 monitor gently by imitating the failure of an operation asked for. This can be done in different ways by the V86 monitor.

It can create a disk drive which will always appear to be unready and simply not allow the real mode program to access it. This can be done even without checking the drive.

The V86 monitor may also do a few other particular things such as:

  • Map memory pages
  • Preempt the real-mode program
  • Intercept calls and interrupts

All these will allow multitasking with the real mode programs just like a protected mode program.

When the software and hardware I/O of the real mode program are intercepted and the state which is expected by the V86 program is tracked, it will allow several programs to share the same hardware but not interfere with each other.

Usage:

Several virtual DOS machines use virtual 8086 mode implementations in Windows. This includes NTVDM or NT Virtual DOS Machine as well as by other operating system such as:

A few good examples of virtual real mode will be:

  • When a user opens a Windows command line window in Microsoft Windows 98
  • When a user uses a DOS box
  • When a user runs a DOS game in Windows 95

A virtual DOS machine is created by the operating system when you start a DOS application so that it can be run on it.

Virtual mode 8086 is typically used to run specific DOS programs and others on different platforms such as:

  • FlexOS 386
  • Concurrent DOS 386
  • Windows/386 2.10
  • DESQview 386
  • Windows 3.x
  • Multiuser DOS
  • Windows for Workgroups 3.1x
  • OS/2 2.x
  • 4690 OS
  • REAL/32 in 386 Enhanced Mode
  • Windows 95, 98, 98 SE and ME in virtual DOS machines
  • SCO UNIX through Merge
  • Linux through DOSEMU

It is also used by other DOS programs that run in protected mode and implement user mode under the emulator.

Some boot loaders, such as GRUB, run in the protected mode but employ the BIOS interrupt calls in the VM86 mode.

Entering and Leaving Virtual Mode

The processor can enter or leave virtual 8086 mode by using different menus. It can do so by making a switch in the TSS or Task State Segment or with the help of an IRET or Interrupt Return.

Entering the virtual real mode:

When the processor wants to enter the virtual real mode, it needs to set the VM bit or the bit 17 in the 32-bit EFLAGS register. This can be done in different ways.

  • One of the ways is to modify the EFLAG register by using the pushf and popf instructions. These particular instructions will push and pop the EFLAGS registers, respectively, on the stack. However, the popf instruction will not modify the 16 and 17 bits in the EFLAGS register.
  • The other way is to set the VM flag by using the IRET or Interrupt Return instruction. This specific instruction will usually return an interrupt. When the IRET instruction is used, the processor will pop EIP, CS, EFLAGS, ESP, and SS from the stack and continue to carry out the new EIP.
Read Also:  What is CPU Case? Lifespan, Types & Works & More

The process of entering the virtual 8086 mode by the processor can be summarized as follows.

  • In a task switch, the image of the EFLAGS is loaded to the 80386 task from the new TSS. The new TSS needs to be an 80386 TSS and not an 80286 TSS. The reason behind this is that the 80286 TSS is not able to store the word of EFLAGS of high order, which typically holds the VM flag.
  • In the VM bit, the value of one of the new EFLAGS signifies the execution of the 8086 instructions by the new task. This means that the CPU outlines base addresses during loading the section registers from the TSS, just as the 8086 would have done.

On the other hand, while using an Interrupt Return from a process of an 80386 task, the EFLAGS image is loaded from the stack.

In this case, the value of one in the VM bit implies that the control that is being returned to the procedure is typically an 8086 procedure.

When the IRET is carried out, the CPL needs to be zero at that time, or else the CPU will not change VM.

Leaving the virtual real code:

And, when the processor leaves the virtual real mode during the occurrence of an exception or interruption, there are two particular cases that may happen.

One, the exception or the interrupt may cause a task switch from a VM86 task to any other type of task.

If the TSS of the new task is an 80386 TSS and the VM bit is zero in the EFLAGS image, or if it is an 80286 TSS, then the CPU will need to clear the VM bit in EFLAGS.

It will also have to load the section registers from the new TSS by using an address formation similar to the 80386.

This will start the execution of the instructions for the new task based on the semantics of the protected mode of the 80386.

On the flip side, the CPU stores the existing setting of the EFLAGS on the stack when the exception or interrupt vectors to a zero procedure at the privilege level.

It then clears the VM bit as well. This means that the exception or interrupt handler will perform as native 80386 protected-mode code.

On the contrary, if the exception or interrupt vectors to a compliant segment or to a privilege level excluding three, the CPU causes a general protection exception.

Here, the error code selects the executable segment to which an attempt for a transfer is to be made.

Remember, the VM flag is not manipulated by the system software directly. Rather, the image of the EFLAGS register is manipulated, which is stored either in the TSS or on the stack.

It is the VM86 monitor that sets the VM flag in the EFLAGS image stored in the TSS or on the stack when the first VM86 task is created.

The VM flag thus created on the stack is checked by the interrupt and exception handlers.

If it is found that the interrupted procedure was being carried out in the V86 mode, the handler may have to invoke the V86 monitor.

Features of Virtual Real Mode

The virtual real mode is a unique operating mode used by the Pentium processors. It is the subset of protected mode wherein two 8086 application programs can be carried out at the same time.

One of the most significant features of the virtual real mode is that it typically uses a segmentation system which is very much the same as the real mode.

In addition to that, there are also a few other specific features that make the VM86 mode so useful.

All these features have diversely beneficial effects. For example, it makes things compatible. Here they are for you.

  • It helps in creating 20-bit linear addresses just in the same way as the 20-bit physical addresses are created in a real mode. However, in this process, the memory paging mechanism of the protected mode is used.
  • Also, the virtual mode 8086 offers a way for the real mode programs created for a single-tasking operation, such as DOS, to run at the same time in a multitasking environment.
  • In this mode, the control registers control the paging unit. When it is OFF, the linear address acts as the physical address, and when the paging is ON, it is converted by the paging unit into the physical address.
  • The V86 mode supports running one or more 8086, 8088, 80186, or 80188 programs in the protected mode setting of an 80386 as a part of a virtual 8086 task.
  • In the virtual real mode, hardware support is offered by the protected mode while multitasking. There can be several of these VM86 tasks, each of which executes an 8086 program and they can also be multiprogrammed with further 80386 tasks.
  • The register set in this specific mode includes all those defined for the 8086 as well as a set of new ones available in the 80386. These include the control registers, debug registers, FS, GS, and test registers. The instructions in this mode typically use 32-bit operands with the help of the operand size prefix.
Read Also:  Dual Core & Quad Core Processor: 7 Differences

It can also use new application-oriented instructions such as:

  • Push all and Pop all
  • Multiply
  • Shift and rotate
  • LSS, LGS, LFS
  • Conditional jumps
  • Single-bit instructions
  • Double-shift instructions
  • Bit scan
  • Byte set on state
  • Move with sign or zero extension and more.

Advantages

  • A virtual operating environment that helps in executing programs in protected mode
  • A more dynamic mode of operation
  • Allows switching between modes rapidly and repeatedly
  • CPU can leave or enter this mode to carry on executing a native 80386 program
  • Offers better paging mechanism
  • Provides better protection capabilities
  • All programs executed at privilege level 3
  • Allows multiprogramming of 8086 applications

Virtual Mode vs Real Mode

  • Virtual mode allows processes to run in it by default, while, in comparison, real mode is planned for file system administration purposes only.
  • In the virtual mode, only the content of the specifically labeled partitioned subdirectory is visible to the process and not the partitioned directory accessed by it, but in comparison, it is visible to the process running in real mode.
  • In the virtual mode, there are some limits on the partitioned directory, but in comparison, there aren’t any such restrictions on it in the real mode.
  • In the virtual mode, there is also an operating system running in the background in the protected mode that sets up the virtual part which determines the devices and memory you can access. However, in comparison, in real mode it runs on the real hardware directly offering unlimited access to all memory and hardware.

Conclusion

So, coming to the end of this article, you now know the role played by virtual real mode in the operation of a processor and the computer system as a whole.

The best part of it is that it will allow you to run real mode applications that cannot be run in the protected mode directly. Several systems and CPUs use this mode.

About Taylor Swift

Taylor SwiftTaylor Swift, a UOPEOPLE graduate is a freelance technology writer with in-depth knowledge about computers. She loves to play video games and watch movies when she has no writing assignments. Follow Her at Linkedin