The High Memory Area and the A20 Line

The high memory area (abbreviated HMA) is the first 65,520 bytes (64 KB less 16 bytes) of extended memory. Technically, it is memory from addresses 100000h to 10FFEFh. It is special because it is the only part of extended memory that can be used by the PC while operating in real mode.

PC memory addresses are referred to using a segment:offset addressing scheme; the segment is multiplied by 16 (shifted one hexadecimal digit to the left) and then the offset is added to it to get the real address. The original IBM PC had only 20 address lines and so its highest memory address was FFFFFh. However, the weird segment:offset addressing makes it possible to generate a linear address that is higher than this number.

Take the address FFFF:FFFF. To convert this to a linear address you take the segment and multiply it by 16, to get FFFF0. Then you add the offset, FFFF. FFFF0+FFFF in hexadecimal results in 10FFEFh. There's a problem with this: that "1" at the front requires a 21st address line to represent it, and that doesn't exist on the 8088 or 8086 processors used in the first PCs. They deal with this problem by ignoring the "1"--they treat the address simply as 0FFEFh. Software must be able to handle this "wrap around" of the memory addresses.

When Intel created the 80286 processor, it supported both protected mode and real mode. When in real mode the 80286 was supposed to behave exactly the same as an 8088 or 8086, for compatibility. However, the 80286 does have a 21st address line (it has 24), and due to a bug in its design it didn't do the wrap around in the same way as the 8088 when in real mode. When it used address FFFF:FFFF and came up with 10FFEFh for a linear address, it kept it as 10FFEFh instead of wrapping it around to 0FFEFh like on the older CPUs. This allowed the first FFEFh of extended memory (100000-10FFEFh) to be accessed by the chip even while still in real mode. This block of memory is the high memory area (HMA).

There was still the problem of ensuring compatibility of the 80286 when in real mode. IBM solved this in the original AT by using spare lines in the keyboard controller chip to manage the 21st address line (which is called the A20 line because address bits are numbered starting with zero). The keyboard controller turns off the A20 line when the processor is running in real mode, to allow for full compatibility with the older PCs. It turns it back on when running in protected mode.