MS-DOS 6.22 A20 Line and High Memory Area Access

This article explains how MS-DOS 6.22 interacts with the processor's A20 address line to access the High Memory Area (HMA). It covers the historical necessity of the A20 gate, the memory addressing mechanics that make the HMA accessible in real mode, the role of the HIMEM.SYS driver in manipulating the gate, and how the DOS=HIGH directive frees conventional memory by relocating core operating system components.

The Origin of the A20 Line and Real-Mode Wrap-Around

The original Intel 8086 processor featured 20 address lines (A0 to A19), allowing it to address up to 1 MB (\(2^{20}\) bytes) of memory. Memory was addressed using a segment:offset model, where the physical address was calculated as:

\[\text{Physical Address} = (\text{Segment} \times 16) + \text{Offset}\]

With the maximum segment value of FFFFh and the maximum offset of FFFFh, the resulting address was:

\[(\text{FFFFh} \times 10\text{h}) + \text{FFFFh} = \text{10FFEFh}\]

Because the 8086 had only 20 physical address lines, any address exceeding 0FFFFFh discarded the 21st bit (address line A20). The address simply wrapped around back to the beginning of memory (0000:0000h). Many early DOS programs relied on this wrap-around behavior to function properly.

When IBM introduced the IBM PC/AT with the Intel 80286 processor, the processor featured 24 address lines, meaning memory did not naturally wrap at the 1 MB boundary. To preserve backward compatibility with software relying on the wrap-around bug, IBM added an external logic gate to the motherboard—controlled by an unused pin on the Intel 8042 keyboard controller—to selectively mask or pass the signal on the A20 line.

Defining the High Memory Area (HMA)

The High Memory Area (HMA) is the first 65,520 bytes (64 KB minus 16 bytes) of extended memory, spanning from physical address 100000h to 10FFEFh.

When the processor operates in 16-bit real mode with the A20 line enabled, addresses calculated from FFFF:0010h to FFFF:FFFFh target this region instead of wrapping to 0000:0000h. This allows the processor to access memory slightly beyond the traditional 1 MB limit without switching into protected mode.

The Role of HIMEM.SYS in MS-DOS 6.22

MS-DOS 6.22 itself does not manage the A20 line directly at boot. Instead, it relies on an extended memory manager conforming to the eXtended Memory Specification (XMS), typically HIMEM.SYS, loaded via CONFIG.SYS:

DEVICE=C:\DOS\HIMEM.SYS

During initialization, HIMEM.SYS determines the hardware method required to control the A20 line. Hardware variations implement A20 switching differently:

  • Keyboard Controller (Intel 8042): The standard method used by the original IBM PC/AT.
  • Fast A20 (Port 92h): Common on PS/2 systems and later chipsets, allowing rapid toggling via an I/O port instead of the slower keyboard controller.
  • BIOS Calls: Standardized system BIOS interrupts (e.g., INT 15h, AX=2401h).

Users can specify the exact switching mechanism using the /MACHINE: switch in HIMEM.SYS if automatic detection fails. Once initialized, HIMEM.SYS acts as the gatekeeper, asserting the A20 line when HMA or extended memory access is requested and deasserting it when standard wrap-around compatibility is required.

Relocating the DOS Kernel with DOS=HIGH

By default, MS-DOS 6.22 loads its kernel structures, tables, and internal drivers into conventional memory (the first 640 KB). To maximize conventional memory for user applications, MS-DOS 6.22 provides the DOS=HIGH configuration command:

DOS=HIGH

When this command is present:

  1. MS-DOS 6.22 checks for an active XMS driver (HIMEM.SYS).
  2. The DOS kernel requests ownership of the single available HMA block via XMS function calls.
  3. HIMEM.SYS enables the A20 line continuously to ensure persistent access to addresses above 100000h.
  4. The DOS initialization code moves the resident portion of the operating system—including parts of MSDOS.SYS, file control tables, and disk buffers—into the HMA.

By utilizing the A20 line to map the operating system into the HMA, MS-DOS 6.22 can reclaim approximately 40 to 60 KB of conventional memory, providing more lower-address space to run memory-intensive DOS programs.