Unreal mode

From Wikipedia, the free encyclopedia

For efficiency reasons, the 80286 and later X86 processors use the base address stored in their internal "descriptor" cache whenever accessing memory, regardless if they are operating in real or protected mode. The "selector", i.e. the 16-bit "segment number" visible to the programmer is used once, while reloading a segment register, to update the various fields of the respective "descriptor" , and then is simply disregarded.

Unlike real mode, protected mode and long mode, unreal mode is not a separate addressing mode the x86 processors or x86-64 processors can operate in. Rather, unreal mode (also big real mode, huge real mode, flat real mode) is a variant of real mode (PE=0), in which one or more data segment registers have been loaded with 32-bit addresses and limits.

To enable unreal mode, the program has to enter protected mode, locate a flat descriptor in the GDT or LDT or create such, load some of the segment registers with the respective protected mode "selector" , then cancel back protected mode. When jumping back to RM, the processor will continue using the cached descriptors as established in PM, at least until the segment registers are reloaded - thus allowing access to 4 GiB of "extended" memory from inside real mode.

The catch however is that the reloading of the segment descriptor caches now holding "unreal" values might occur asynchronously inside an exception/interrupt handler, and then even if the handler correctly attempts to reload the segment before IRET (returning from the interrupt/exception), it will fail as the hidden descriptor would be reloaded under the rules of the real mode resulting in the loss of the flat descriptor and imminent catastrophe! Hence one must either forbid interrupts while accessing "unreal" addresses - which can be for a small duration only, - or use a segment register (FS or GS) that the OS/BIOS/any drivers are absolutely guaranteed not to touch.

This mode was first considered a bug, but it has later on become a standard technique[citation needed] for x86 and x86-64 processors.

Some DOS extenders use this feature to address the high memory. It was used by many computer games in the 1990 to 1995 time frame, since it allowed programmers to use more memory than in real mode, which is restricted to 1 MB (640 KB usable), but still access the DOS operating system, which doesn't work in protected mode. After the introduction of Windows 95 unreal mode quickly fell out of favour as programs using it cannot be run in the DOS prompt of Microsoft Windows; they require a "Restart in MS-DOS mode" in Windows 95 and 98, and cannot be run at all on Windows NT, 2000, Me, and XP systems. For those operating systems, an emulator such as DOSBox is the only way to run programs designed for unreal mode.

[edit] See also

In other languages