What is Real Mode? (Explained)

What is Real Mode?

Real mode basically refers to a particular type of operating mode used by the Intel 286 and later processors. This mode allows these processors to support the traits of other lower processors such as 8086 or 8088 processors.

Technically, operating in the real mode allows the processors to run older software programs and at the same time ensures that they operate at a reasonably higher clock speed.

KEY TAKEAWAYS

  • Real Mode is a simple operating mode design of 16 bits which is common in all x86 processors. The main reason behind it is to ensure compatibility of these processors with older software programs.
  • As for the operating systems, these are the reasons that most of the modern ones, such as Windows and Linux operating systems, run in protected mode. DOS and other older operating systems run in real mode.
  • The real mode can be activated in the Central Processing Unit or the CPU of the computer.

Understanding Real Mode

What is Real Mode

Real mode, also known as real address mode, is so called because the addresses in the real mode match the real locations in the memory all the time.

The program can access it irrespective of its location at any point in time and read or write anything.

This means that the system BIOS and the operating system can be overwritten easily, if there is lack of proper knowledge and management, by a program in the real mode.

Apart from that, it may also trigger an interrupt in the physical hardware and even send a signal accidentally to the peripheral device.

All these will have some serious adverse effects such as:

  • A data loss
  • Any kind of physical damage to the hardware
  • A system freeze
  • A system crash

The mode is also characterized as follows:

  • It allows unlimited and direct software access to all of the I/O addresses, addressable memory, and peripheral hardware
  • It does not offer any support for multitasking, memory protection, or code privilege levels.

In this specific mode, the RAM that can be accessed by a program is usually not buffered or managed by software, hardware, or the Basic Input Output System (BIOS) in any way.

This allows a program to access all reachable memory addresses irrespective of what purpose it is being used for.

Apart from that, it also means that every aspect of reading and writing to the memory should be managed by itself.

Before the protected mode was designed, the real mode was also used by several operating systems apart from the processors.

However, there is one specific aspect of this mode that is worth mentioning.

This operating mode restricts the use of RAM instructions by the processors to 16 bits and at least 1 MB of Random Access Memory in 20-bit address lines.

This is because in real mode the processor only supports addresses that are 20 bits in length.

This means that the processor can use only a part of the resources available in the computer.

Real addressing mode is also quite risky in the sense that it uses assembly language to write a program and executes it under a particular Disk Operating System (DOS), which normally does not switch to protected mode automatically during startup.

How Many Registers are Used in Real Mode?

Typically, there are four separate segment registers in the 8088, 8086, and 80286 processors that hold the segment addresses.

On the other hand, the 386 CPU and the later models have six of them in real mode. These processors and the later Intel x86 models still use segment registers of 16-bit size.

Read Also:  What is CPU Clock Speed? (Explained)

Ideally, the segment address of a memory location should be present in one of the registers irrespective of how this specific location of the memory is accessed.

These six segment registers are named differently and serve different purposes. These are:

  • CS or Code Segment – Here, the machine instructions reside at some offset. Also, the segment address of the instruction being executed currently is stored in the CS.
  • DS or Data Segment – Here, the different variables along with other data reside at some offset. There may be several data segments but the processor will use only one of them at a time. It will place the segment address in the register DS.
  • SS or Stack Segment – This is a very crucial part of the CPU. It is used mainly to store the addresses and data temporarily.
  • ES or Extra Segment – This is just what the name suggests- an additional segment that is used to specify a location in the memory.

The other two additional segment registers are named FS and GS, which are just clones of the Extra Segment or ES, and their nomenclature follows the order E, F, G.

There is no specialty in these registers that exists only in the 386 processors and the later x86 CPUs and are used for both data and codes.

There are also General Purpose Registers or GPRs that may contain data values as well as offset addresses.

These addresses may be paired with the segment addresses for locating data in the memory.

Can You Use 32 Bit Registers in Real Mode?

Yes, you can use 32-bit registers in real mode though it is a fact that when a processor boots, immediately after that it operates in real mode with its default to 16-bit code.

Still, this does not mean that you cannot use 32-bit instructions. Ideally, starting with the 80386, real-mode programs can use the 32-bit registers using the Address Size Override Prefix.

This override prefix of the size of an operand uses an address like the data segment, 66h.

This helps change the default mode of the single instruction by switching it to 32 bits when it is being executed in the 16-bit real mode.

On the other hand, when you use this override prefix with an instruction that is being executed in the 32-bit protected mode, it will switch the instruction to 16 bits as well, using a similar prefix, 67h, to override the sizes of the addresses.

Ideally, this prefix is emitted by the assembler automatically and almost certainly when you want to use a 32-bit operand with any instruction while assembling a 16-bit code.

This will allow you to use the 32-bit registers in 16-bit real mode.

However, if you wish to use a 64-bit instruction, you will not because there is no such override prefix available for it to be used in the real mode.

In that case, if you want to allow them, you will have to essentially switch to long mode.

However, when you try to do this or something similar to it, you must keep in mind that it is the instruction size prefix that allows the 32-bit instruction set, which is incompatible with the 16-bit, to work efficiently.

Typically, a 16-bit instruction set does not really care whether you are in the real mode or in the protected mode if you are not engaged with doing some segment arithmetic.

In that case, you will need to handle coding the 32-bit operations by using emit because the compiler will typically not generate them.

Virtual Real Mode

Virtual real mode is also known as V86 or 8086 mode. This specific mode allows the Intel 386 CPUs and the later models to hold a real mode 16-bit setting in the protected mode.

However, when a computer runs in the virtual real mode, it can access memory up to 1 MB, as it can in the original real mode.

Read Also:  What is Processor Register? Example, Functions & More

Ideally, an example of a computer running in this specific mode is when you open a Windows command-line window in the Microsoft Windows 98 operating system.

Virtual real mode typically refers to the third mode in which a processor can operate.

This specific mode of operation is simply an enhanced version of the protected mode, which comes with additional capabilities.

Typically, when you work with any particular graphic multitasking operating system like any one of the different versions of Windows, you will need to run it in the protected mode.

However, you may want to run DOS programs as well in it, but then, DOS programs typically run in the real mode rather in the protected mode.

When you use virtual real mode, this problem will be resolved. This is because it will imitate real mode in the protected mode. This will allow running the DOS programs.

In fact, there can be several machines in virtual real mode that can be created by a protected mode operating system like Windows.

It actually creates an illusion for the software running each of these machines which thinks that it is the only software running on it.

However, the benefit of using a virtual real mode is that each of the virtual machines has its own address space of 1 MB, an image of the actual hardware, Basic Input Output System routines, and more.

Ideally, when you run a DOS-based game or open a DOS box in the Windows 95 operating system, you are actually using it in virtual real mode.

When you start any such application in DOS, the operating system automatically creates a virtual DOS machine to run the DOS application on it.

Ideally, the virtual real mode was initiated with the 386 family of CPUs.

How Do You Switch to Real Mode?

You can switch from protected mode to real mode by creating a special program called the Ring 0 program. When you place this in the physical memory address, you can access real mode.

Here are the steps that you should follow to complete the entire process.

  • You must disable the interrupts by turning maskable interrupts off by using CLI, and optionally, disabling the Non-Maskable Interrupt or NMI.
  • You will also need to turn off paging by transferring control to the 1:1 page ensuring that the Interrupt Descriptor Table (IDT) and Global Descriptor Table (GDT) are on the 1:1 page. Also, clear the PG-flag in the 0 control register and set the third control register to 0.
  • If one is not already available, create and use a GDT with 16-bit tables, data and code segments. In order to create this, set limit 0xFFFFF, base 0x0, 16-bit, privilege level 0, granularity 0, and read and write to 1.
  • Load a new GDT but ensure selectors that are used currently have the same index. This means that the index in the DS, CS, and SS will simply be a copy.
  • Then, far jump to the 16-bit protected mode using the 16-bit segment index and 16-bit data segment as well as load DS, SS, ES, FS, and GS with a 16-bit data segment.
  • Follow it by loading the real-mode IDT with limit 0x3FF, Base 0x0 and use Load Interrupt Descriptor Table or LIDT.
  • Disable the protected mode and set the PE bit in CR0 to false then far jump to real mode using the real mode segment selector, which is usually 0.
  • Load the data segment registers DS, SS, ES, FS, and GS with the correct real mode values, which are usually 0, again.
  • Set the stack pointer to the correct value so that it does not interfere with the real-mode programs.
  • Enable the maskable interrupts using the Set Interrupt Flag.

Now you can continue working in real mode using all of the BIOS interrupts.

What is Real Mode Interrupt?

Real mode interrupt is an alternative to polling supported by the processors. Here, the CPU determines whether the interrupt is active or not after every instruction is executed.

Read Also:  What is i5 Processor? Uses, Lifespan, Works & More

This is checked by the following conditions, in the specific order:

  • Other instruction executions
  • Single-step
  • NMI
  • Coprocessor segment overrun
  • INTR
  • INT

If it is found that one or more of the above conditions exist, then the processor will ensure the following:

  • Flags are pushed back to the stack
  • Both the Trap Flag or TF and the Interrupt Flag IF are cleared which will disable the trap or single step aspect and the INTR
  • The IP and CS are pushed to the stack
  • The contents of the interrupt vector are fetched and loaded into the IP and CS
  • The execution starts again in the Interrupt Service routine (ISR)
  • IP, CS and Flags are popped on IRET and
  • TF and IF are set to the state before the interrupt.

Real Mode vs Protected Mode

  • Real mode offers all the features and works as fast as 8086 but protected mode offers all the benefits and features of 80386.
  • The RAM available for use in real mode is just 1 MB but there is no such limit in protected mode.
  • There is no scope for multitasking, paging or protection in the real mode but in protected mode all these are allowed.
  • The real mode is usually the default mode but protected mode can be enabled by setting PE in the control register to 1.
  • The operations in real mode typically happen in 16 bits but in protected mode they happen usually in 32 bits.
  • The General Purpose Registers or GPRs in real mode are of 16 bits size but in protected mode the GPRs are extended and are of 32 bits in size.
  • The GPRs in the real mode are denoted as AX, BX, CX, and DX but the Extended GPRs in the protected mode are denoted as EAX, EBX, ECX, and EDX.
  • Only the 8086 flags are available in real mode but in protected mode 3-bit flag registers are available.
  • Physical address in real mode is calculated by adding the offset register with the product of segment register and 10H but in protected mode it is calculated by advanced segmentations and paging.
  • Maximum size of a segment in real mode will be 64 KB (2^16) as per 16-bit offset register but in protected mode it will be 4 GB (2^32) as per 32-bit offset register.
  • There are no control registers available in the real mode but in protection mode all four control registers are available.

What is the Use of Real Mode?

The most significant use of real mode of operation is that it enables the newer processors starting from the Intel 286 variants to run other older versions of software using the attributes of the lower processors.

Do All Processors Go into Real Mode?

The processors that are built on the original 8086 architecture typically start in real mode, which allows them to run programs written for earlier hardware.

However, this will need the software simulation to be successful.

Conclusion

Real mode, or real addressing mode, is quite useful for the processors to use in order to run older software programs.

Most aspects of this specific mode actually handle those particular issues that are generally seen in those applications that are written in assembly language. This is due to their relatively atomic nature.

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