Menu

Runtime Environment

Phillip Kilgore

This page discusses peculiarities of the DOS runtime environment which should be taken into consideration when doing low-level programming against the data structures presented by WDMF.

X86 Operational Modes

Since the 80286 (286), x86 processors have additional operational modes which affect the behavior of the processor. Every x86 processor resets in real mode, which reflects the operating environment of an 8086 processor. In real mode, there is a flat 20-bit address space from which the first 1MiB of memory space may be accessed. The processor may manipulate the memory and execute any instruction in real mode; however, it is constrained to this region of memory because of a peculiar addressing scheme utilized in the 8086.

Real Mode

Like its predecessor, the 8-bit 8080, the 8086 natively operates on 16-bit pointers. This supports an absolute address range of 64KiB, which would leave 15 pages of the total address space unreachable. One way of getting around this is to provide an additional register which determines the high-order bits of the actual address. This is form of addressing is not uncommon in other processors which need to extend their address space. For instance, the WDC 65C816 and eZ80 both provide high bank select registers to form an extended address.

The 8086 itself provides four 16-bit segment registers for this purpose: CS (code segment), DS (data segment), SS (stack segment), and ES (extra segment). The combination thereof is called a far pointer, and effectove addresses are calculated by adding an offset to the segment. What is unsual about the segmentation mechanism on the 8086 is that it does not append the segment register to form a far pointer. Instead, the far point's effective address is calculated as follows:

addr = (segment << 4) + offset

The reason for this may not be as clear now as it was then: memory was much more expensive than it is now, and having 32 address pins on the package would represent wasted capacity. This allowed the entire 1MB space to be addressed in 16-byte slices, and then some: the last effective address in this addressing scheme is actually 10FFEFh, (a little under 1MiB + 64KiB), but since the 8086 has a 20-bit address bus, this caused the address to wrap the boundary. The 286 has a 24-bit address bus, so when it was released, the A20 gate (which has to be explicitly enabled) was added to allow the entire range to be addressed in real mode.


Related

Wiki: GFX Module

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.