Virtual Real Mode

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.

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:

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:

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:

Read Also:  What is CPU Multiplier? (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:

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:

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:

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:

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.

Read Also:  What is Xeon Processor? Works, Types, Uses & More

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

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.

Read Also:  What is MIPS Architecture? (Explained)

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

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

Advantages

Virtual Mode vs Real Mode

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.