
CHAPTER 4
ARCHITECTURAL COMPATIBILITY
The 80386 is compatible at the object code level with both the 80286 and the 8086. While it is possible to use the 80386 simply as a fast 80286 or a very fast 8086, its compatibility facilities are substantially more versatile. The 80386 can execute 80286 and 80386 programs concurrently, and, using the 80386's Virtual 86 Mode, existing 8086 programs can also be run concurrently. With the 80386, then, it is possible to build systems that can concurrently execute software written for three generations of Intel 86 family microprocessors.
4.1 80286 Compatibility
The 80286 architecture is a proper subset of the 80386 architecture. Because the 80386 recognizes all 80286 instructions, registers, descriptors, and so on, an 80286 operating system and application programs can be ported to comparable 80386- based hardware without changing a bit.
Direct porting, as described above, is the quickest way to get existing 80286 software running on an
4.2 Real and Virtual 86 Modes
The 80386 can execute 8086 object code in either of two modes, Real Mode or Virtual 86 Mode. The 80386 enters Real Mode when it is reset. In Real Mode, the processor provides fast execution in an unprotected environment like that of an
8086. Most operating systems will switch from Real Mode to Protected Mode after initiali- zation, but it is also possible to run 8086 software in Real Mode. The principal difference between
80386 Real Mode and an actual 8086 is speed:
8086 programs that are
Virtual 86 Mode establishes an 8086 execution environment within the protected multitask envi- ronment of the 80386. Where Real Mode governs everything the processor does, Virtual 86 Mode can be applied to selected 80386 tasks. When executing a Virtual 86 Mode task, the processor behaves like an 8086, but upon a switch to a normal task, the processor operates as an 80386 (which, of course, can interpret both 80286 and 80386 programs). Thus, Virtual 86 Mode enables an operating system to support the execution of 8086, 80286, and 80386 programs concurrently.
Chapter 3 described how a task's Task State Segment represents the state of its virtual pro- cessor. The VM86 flag in the Flags register, which is loaded from the TSS, defines the running task's virtual processor as an 8086 or an 80386. When the 80386 loads its registers from a TSS whose VM86 flag is set, the processor enters Virtual 86 Mode. When, on a subsequent task switch, the processor loads register values from a TSS whose VM86 flag is clear, it leaves Virtual 86 Mode. Thus, on a task by task basis, the processor emulates an 80386 or an 8086 according to the value of the VM86 flag. The 80386 also leaves Virtual 86 Mode when it raises an excep- tion or is interrupted, making the full resources of the architecture available to interrupt and exception handlers. On return from a handler invoked in Virtual 86 Mode, the 80386 auto- matically