<s>
The	O
A20	O
,	O
or	O
address	O
line	O
20	O
,	O
is	O
one	O
of	O
the	O
electrical	O
lines	O
that	O
make	O
up	O
the	O
system	B-Architecture
bus	I-Architecture
of	O
an	O
x86-based	O
computer	O
system	O
.	O
</s>
<s>
The	O
A20	B-Device
line	I-Device
in	O
particular	O
is	O
used	O
to	O
transmit	O
the	O
21st	O
bit	O
on	O
the	O
address	B-Architecture
bus	I-Architecture
.	O
</s>
<s>
A	O
microprocessor	O
typically	O
has	O
a	O
number	O
of	O
address	O
lines	O
equal	O
to	O
the	O
base-two	O
logarithm	O
of	O
the	O
number	O
of	O
words	O
in	O
its	O
physical	O
address	B-General_Concept
space	I-General_Concept
.	O
</s>
<s>
For	O
example	O
,	O
a	O
processor	O
with	O
4GB	O
of	O
byte-addressable	B-General_Concept
physical	O
space	O
requires	O
32	O
lines	O
(log2(4GB )	O
=	O
log2(232 B )	O
=	O
32	O
)	O
,	O
which	O
are	O
named	O
A0	O
through	O
A31	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
8086	I-General_Concept
,	O
Intel	B-Device
8088	I-Device
,	O
and	O
Intel	B-Device
80186	I-Device
processors	O
had	O
20	O
address	O
lines	O
,	O
numbered	O
A0	O
to	O
A19	O
;	O
with	O
these	O
,	O
the	O
processor	O
can	O
access	O
220	O
bytes	B-Application
,	O
or	O
1MB	O
.	O
</s>
<s>
To	O
access	O
a	O
20-bit	O
address	B-General_Concept
space	I-General_Concept
,	O
an	O
external	O
memory	O
reference	O
was	O
made	O
up	O
of	O
a	O
16-bit	O
offset	O
address	O
added	O
to	O
a	O
16-bit	O
segment	O
number	O
,	O
shifted	O
4	O
bits	O
so	O
as	O
to	O
produce	O
a	O
20-bit	O
physical	O
address	O
.	O
</s>
<s>
Therefore	O
,	O
there	O
were	O
various	O
ways	O
to	O
address	O
the	O
same	O
byte	B-Application
in	O
memory	O
.	O
</s>
<s>
For	O
example	O
,	O
here	O
are	O
four	O
of	O
the	O
4096	O
different	O
segment:offset	O
combinations	O
,	O
all	O
referencing	O
the	O
byte	B-Application
whose	O
physical	O
address	O
is	O
0x000FFFFF	O
(	O
the	O
last	O
byte	B-Application
in	O
1MB-memory	O
space	O
)	O
:	O
</s>
<s>
Referenced	O
the	O
last	O
way	O
,	O
an	O
increase	O
of	O
one	O
in	O
the	O
offset	O
yields	O
F800:8000	O
,	O
which	O
is	O
a	O
proper	O
address	O
for	O
the	O
processor	O
,	O
but	O
since	O
it	O
translates	O
to	O
the	O
physical	O
address	O
0x00100000	O
(	O
the	O
first	O
byte	B-Application
over	O
1MB	O
)	O
,	O
the	O
processor	O
would	O
need	O
another	O
address	O
line	O
for	O
actual	O
access	O
to	O
that	O
byte	B-Application
.	O
</s>
<s>
Since	O
there	O
is	O
no	O
such	O
line	O
on	O
the	O
8086	B-General_Concept
line	O
of	O
processors	O
,	O
the	O
21st	O
bit	O
above	O
,	O
while	O
set	O
,	O
gets	O
dropped	O
,	O
causing	O
the	O
address	O
F800:8000	O
to	O
"	O
wrap	O
around	O
"	O
and	O
to	O
actually	O
point	O
to	O
the	O
physical	O
address	O
0x00000000	O
.	O
</s>
<s>
When	O
IBM	O
designed	O
the	O
IBM	B-Operating_System
PC	I-Operating_System
AT	I-Operating_System
(	O
1984	O
)	O
machine	O
,	O
it	O
decided	O
to	O
use	O
the	O
new	O
higher-performance	O
Intel	B-General_Concept
80286	I-General_Concept
microprocessor	O
.	O
</s>
<s>
The	O
80286	B-General_Concept
could	O
address	O
up	O
to	O
16MB	O
of	O
system	O
memory	O
in	O
protected	B-Application
mode	I-Application
.	O
</s>
<s>
However	O
,	O
the	O
CPU	O
was	O
supposed	O
to	O
emulate	O
an	O
8086	B-General_Concept
's	O
behavior	O
in	O
real	B-Application
mode	I-Application
,	O
its	O
startup	O
mode	O
,	O
so	O
that	O
it	O
could	O
run	O
operating	B-General_Concept
systems	I-General_Concept
and	O
programs	O
that	O
were	O
not	O
written	O
for	O
protected	B-Application
mode	I-Application
.	O
</s>
<s>
The	O
80286	B-General_Concept
did	O
not	O
force	O
the	O
A20	B-Device
line	I-Device
to	O
zero	O
in	O
real	B-Application
mode	I-Application
,	O
however	O
.	O
</s>
<s>
To	O
remain	O
compatible	O
with	O
such	O
programs	O
,	O
IBM	O
decided	O
to	O
correct	O
the	O
problem	O
on	O
the	O
motherboard	B-Device
.	O
</s>
<s>
That	O
was	O
accomplished	O
by	O
inserting	O
a	O
logic	O
gate	O
on	O
the	O
A20	B-Device
line	I-Device
between	O
the	O
processor	O
and	O
system	B-Architecture
bus	I-Architecture
,	O
which	O
got	O
named	O
Gate-A20	O
.	O
</s>
<s>
Gate-A20	O
can	O
be	O
enabled	O
or	O
disabled	O
by	O
software	O
to	O
allow	O
or	O
prevent	O
the	O
address	B-Architecture
bus	I-Architecture
from	O
receiving	O
a	O
signal	O
from	O
A20	O
.	O
</s>
<s>
At	O
boot	B-Operating_System
time	I-Operating_System
,	O
the	O
BIOS	B-Operating_System
first	O
enables	O
Gate-A20	O
when	O
it	O
counts	O
and	O
tests	O
all	O
of	O
the	O
system	O
memory	O
,	O
and	O
then	O
disables	O
it	O
before	O
transferring	O
control	O
to	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
Originally	O
,	O
the	O
logic	O
gate	O
was	O
a	O
gate	O
connected	O
to	O
the	O
Intel	B-Device
8042	I-Device
keyboard	O
controller	O
.	O
</s>
<s>
There	O
are	O
multiple	O
methods	O
to	O
control	O
the	O
A20	B-Device
line	I-Device
.	O
</s>
<s>
Real-mode	B-Application
software	O
cared	O
only	O
about	O
the	O
area	O
slightly	O
above	O
1MB	O
,	O
so	O
the	O
Gate-A20	O
line	O
was	O
enough	O
.	O
</s>
<s>
Enabling	O
the	O
Gate-A20	O
line	O
is	O
one	O
of	O
the	O
first	O
steps	O
that	O
a	O
protected-mode	B-Application
x86	B-Operating_System
operating	B-General_Concept
system	I-General_Concept
does	O
in	O
the	O
bootup	B-Operating_System
process	O
,	O
often	O
before	O
control	O
has	O
been	O
passed	O
to	O
the	O
kernel	O
from	O
the	O
bootstrap	B-Operating_System
(	O
in	O
the	O
case	O
of	O
Linux	O
,	O
for	O
example	O
)	O
.	O
</s>
<s>
Virtual	B-Application
8086	I-Application
mode	I-Application
,	O
introduced	O
with	O
the	O
Intel	B-General_Concept
80386	I-General_Concept
,	O
allows	O
the	O
A20	O
wrap-around	O
to	O
be	O
simulated	O
by	O
using	O
the	O
virtual	B-Architecture
memory	I-Architecture
facilities	O
of	O
the	O
processor	O
;	O
physical	O
memory	O
may	O
be	O
mapped	O
to	O
multiple	O
virtual	O
addresses	O
.	O
</s>
<s>
Thus	O
,	O
the	O
memory	O
mapped	O
at	O
the	O
first	O
megabyte	O
of	O
virtual	B-Architecture
memory	I-Architecture
may	O
be	O
mapped	O
again	O
in	O
the	O
second	O
megabyte	O
of	O
virtual	B-Architecture
memory	I-Architecture
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
may	O
intercept	O
changes	O
to	O
Gate	O
A20	O
and	O
make	O
corresponding	O
changes	O
to	O
the	O
virtual-memory	O
address	B-General_Concept
space	I-General_Concept
,	O
which	O
also	O
makes	O
irrelevant	O
the	O
efficiency	O
of	O
Gate-A20	O
line	O
toggling	O
.	O
</s>
<s>
Controlling	O
the	O
A20	B-Device
line	I-Device
was	O
an	O
important	O
feature	O
at	O
one	O
stage	O
in	O
the	O
growth	O
of	O
the	O
IBM	B-Device
PC	I-Device
architecture	O
,	O
as	O
it	O
added	O
access	O
to	O
an	O
additional	O
65,520	O
bytes	B-Application
(	O
64KB	O
−	O
16bytes	O
)	O
of	O
memory	O
in	O
real	B-Application
mode	I-Application
,	O
without	O
significant	O
software	O
changes	O
.	O
</s>
<s>
In	O
what	O
was	O
arguably	O
a	O
"	O
hack	O
"	O
,	O
the	O
A20	O
gate	O
was	O
originally	O
part	O
of	O
the	O
keyboard	O
controller	O
on	O
the	O
motherboard	B-Device
,	O
which	O
could	O
open	O
or	O
close	O
it	O
depending	O
on	O
what	O
behavior	O
was	O
desired	O
.	O
</s>
<s>
The	O
A20	O
gate	O
is	O
still	O
present	O
on	O
many	O
modern	O
PCs	O
,	O
and	O
the	O
gate	O
is	O
initially	O
closed	O
right	O
after	O
boot	B-Operating_System
.	O
</s>
<s>
Modern	O
protected-mode	B-Application
operating	B-General_Concept
systems	I-General_Concept
typically	O
open	O
the	O
A20	O
gate	O
early	O
during	O
the	O
boot	B-Operating_System
process	I-Operating_System
and	O
never	O
close	O
it	O
again	O
.	O
</s>
<s>
Such	O
operating	B-General_Concept
systems	I-General_Concept
do	O
not	O
have	O
the	O
compatibility	O
reasons	O
for	O
keeping	O
it	O
closed	O
,	O
and	O
they	O
gain	O
access	O
to	O
the	O
full	O
range	O
of	O
physical	O
addresses	O
available	O
by	O
opening	O
it	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
80486	I-General_Concept
and	O
Pentium	B-General_Concept
added	O
a	O
special	O
pin	O
named	O
A20M#	O
,	O
which	O
when	O
asserted	O
low	O
forces	O
bit	O
20	O
of	O
the	O
physical	O
address	O
to	O
be	O
zero	O
for	O
all	O
on-chip	O
cache	O
-	O
or	O
external-memory	O
accesses	O
.	O
</s>
<s>
It	O
was	O
necessary	O
,	O
since	O
the	O
80486	B-General_Concept
introduced	O
an	O
on-chip	O
cache	O
and	O
so	O
masking	O
this	O
bit	O
in	O
external	O
logic	O
was	O
no	O
longer	O
possible	O
.	O
</s>
<s>
Software	O
still	O
needs	O
to	O
manipulate	O
the	O
gate	O
and	O
must	O
still	O
deal	O
with	O
external	O
peripherals	O
(	O
the	O
chipset	B-Device
)	O
for	O
that	O
.	O
</s>
<s>
Support	O
for	O
the	O
A20	O
gate	O
was	O
changed	O
in	O
the	O
Nehalem	B-Device
microarchitecture	I-Device
(	O
some	O
sources	O
incorrectly	O
claim	O
that	O
A20	O
support	O
was	O
removed	O
)	O
.	O
</s>
<s>
From	O
a	O
software	O
point	O
of	O
view	O
,	O
the	O
mechanism	O
works	O
exactly	O
as	O
before	O
,	O
and	O
an	O
operating	B-General_Concept
system	I-General_Concept
must	O
still	O
program	O
external	O
hardware	O
(	O
which	O
in-turn	O
sends	O
the	O
aforementioned	O
bus	O
cycles	O
to	O
the	O
CPU	O
)	O
to	O
disable	O
the	O
A20	O
masking	O
.	O
</s>
<s>
Intel	O
no	O
longer	O
supports	O
the	O
A20	O
gate	O
,	O
starting	O
with	O
Haswell	B-Device
.	O
</s>
<s>
3A	O
from	O
June	O
2013	O
states	O
:	O
"	O
The	O
functionality	O
of	O
A20M#	O
is	O
used	O
primarily	O
by	O
older	O
operating	B-General_Concept
systems	I-General_Concept
and	O
not	O
used	O
by	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
.	O
</s>
<s>
The	O
A20	O
handler	O
is	O
IBM	B-Device
PC	I-Device
memory	B-General_Concept
manager	I-General_Concept
software	O
that	O
controls	O
access	O
to	O
the	O
high	B-Device
memory	I-Device
area	I-Device
(	O
HMA	B-Device
)	O
.	O
</s>
<s>
Extended-memory	B-Device
managers	O
usually	O
provide	O
this	O
functionality	O
.	O
</s>
<s>
A20	O
handlers	O
are	O
named	O
after	O
the	O
21st	O
address	O
line	O
of	O
the	O
microprocessor	O
,	O
the	O
A20	B-Device
line	I-Device
.	O
</s>
<s>
In	O
DOS	B-Device
,	O
HMA	B-Device
managers	O
such	O
as	O
HIMEM.SYS	O
have	O
the	O
"	O
extra	O
task	O
"	O
of	O
managing	O
A20	O
.	O
</s>
<s>
HIMEM.SYS	O
provided	O
an	O
API	B-Application
for	O
opening/closing	O
A20	O
.	O
</s>
<s>
DOS	B-Device
itself	O
could	O
use	O
the	O
area	O
for	O
some	O
of	O
its	O
storage	O
needs	O
,	O
thereby	O
freeing	O
up	O
more	O
conventional	B-Device
memory	I-Device
for	O
programs	O
.	O
</s>
<s>
That	O
functionality	O
was	O
enabled	O
by	O
the	O
DOS	B-Device
=	O
HIGH	O
or	O
HIDOS	B-Device
=	O
ON	O
directives	O
in	O
the	O
CONFIG.SYS	B-Device
configuration	O
file	O
.	O
</s>
<s>
Since	O
1980	O
,	O
the	O
address	O
wrap	O
was	O
internally	O
used	O
by	O
86-DOS	B-Operating_System
and	O
MS-DOS	B-Application
to	O
implement	O
the	O
DOS	B-Device
CALL5	O
entry	O
point	O
at	O
offset	O
+5	O
to	O
+9	O
(	O
which	O
emulates	O
the	O
CP/M	O
-80-style	O
CALL	O
5	O
BDOS	O
API	B-Application
entry	O
point	O
at	O
offset	O
+5	O
to	O
+7	O
)	O
in	O
the	O
Program	O
Segment	O
Prefix	O
(	O
PSP	O
)	O
(	O
which	O
partially	O
resembles	O
CP/M	B-Application
-80	I-Application
'	O
s	O
zero	B-Operating_System
page	I-Operating_System
)	O
.	O
</s>
<s>
This	O
was	O
,	O
in	O
particular	O
,	O
utilized	O
by	O
programs	O
machine-translated	B-Application
from	O
CP/M	B-Application
-80	I-Application
through	O
assembly	O
language	O
translators	O
like	O
Seattle	O
Computer	O
Products	O
 '	O
TRANS86	O
.	O
</s>
<s>
The	O
CALL5	O
handler	O
this	O
entry	O
point	O
refers	O
to	O
resides	O
at	O
the	O
machine	O
's	O
physical	O
address	O
0x000000C0	O
(	O
thereby	O
overlapping	O
the	O
four	O
bytes	B-Application
of	O
the	O
interrupt	B-General_Concept
service	I-General_Concept
routine	I-General_Concept
entry	O
point	O
reserved	O
for	O
INT30h	O
and	O
the	O
first	O
byte	B-Application
of	O
INT31h	O
in	O
the	O
x86	B-Operating_System
real	B-Application
mode	I-Application
interrupt	B-General_Concept
vector	I-General_Concept
table	I-General_Concept
)	O
.	O
</s>
<s>
However	O
,	O
by	O
the	O
design	O
of	O
CP/M	B-Application
-80	I-Application
,	O
which	O
loaded	O
the	O
operating	B-General_Concept
system	I-General_Concept
immediately	O
above	O
the	O
memory	O
available	O
for	O
the	O
application	O
program	O
to	O
run	O
in	O
,	O
the	O
8080/Z80	O
16-bit	O
target	O
address	O
stored	O
at	O
offset	O
+6	O
to	O
+7	O
in	O
the	O
zero	B-Operating_System
page	I-Operating_System
could	O
deliberately	O
also	O
be	O
interpreted	O
as	O
the	O
size	O
of	O
the	O
first	O
memory	O
segment	O
.	O
</s>
<s>
In	O
order	O
to	O
emulate	O
this	O
in	O
DOS	B-Device
with	O
its	O
8086	B-General_Concept
segment:offset	O
addressing	O
scheme	O
,	O
the	O
far	O
call	O
entry	O
point	O
's	O
16-bit	O
offset	O
had	O
to	O
match	O
this	O
segment	O
size	O
(	O
i.e.	O
</s>
<s>
The	O
only	O
way	O
to	O
reconcile	O
these	O
requirements	O
was	O
to	O
choose	O
a	O
segment	O
value	O
that	O
,	O
when	O
added	O
to	O
0xFEF0	O
,	O
results	O
in	O
an	O
address	O
of	O
0x001000C0	O
,	O
which	O
,	O
on	O
an	O
8086	B-General_Concept
,	O
wraps	O
around	O
to	O
0x000000C0	O
.	O
</s>
<s>
A20	O
had	O
to	O
be	O
disabled	O
for	O
the	O
wraparound	O
to	O
occur	O
and	O
DOS	B-Device
programs	O
using	O
this	O
interface	O
to	O
work	O
.	O
</s>
<s>
Newer	O
DOS	B-Device
versions	O
which	O
can	O
relocate	O
parts	O
of	O
themselves	O
into	O
the	O
HMA	B-Device
,	O
typically	O
craft	O
a	O
copy	O
of	O
the	O
entry	O
point	O
at	O
FFFF:00D0	O
in	O
the	O
HMA	B-Device
(	O
which	O
again	O
resolves	O
to	O
physical	O
0x001000C0	O
)	O
,	O
so	O
that	O
the	O
interface	O
can	O
work	O
without	O
regard	O
to	O
the	O
state	O
of	O
A20	O
.	O
</s>
<s>
One	O
program	O
known	O
to	O
use	O
the	O
CALL5	O
interface	O
is	O
the	O
DOS	B-Device
version	O
of	O
the	O
Small-C	B-Language
compiler	O
.	O
</s>
<s>
Sun	O
Microsystems	O
 '	O
PC-NFS	B-Protocol
(	O
1993	O
)	O
requires	O
the	O
CALL5	O
fix-up	O
as	O
well	O
.	O
</s>
<s>
Also	O
,	O
to	O
save	O
program	O
space	O
,	O
a	O
trick	O
was	O
used	O
by	O
some	O
BIOS	B-Operating_System
and	O
DOS	B-Device
programmers	O
,	O
for	O
example	O
,	O
to	O
have	O
one	O
segment	O
that	O
has	O
access	O
to	O
program	O
data	O
(	O
such	O
as	O
from	O
F800:0000	O
to	O
F800:7FFF	O
,	O
pointing	O
to	O
the	O
physical	O
addresses	O
0x000F8000	O
–	O
0x000FFFFF	O
)	O
,	O
as	O
well	O
as	O
the	O
I/O	O
data	O
(	O
such	O
as	O
the	O
keyboard	O
buffer	O
)	O
that	O
was	O
located	O
in	O
the	O
first	O
memory	O
segment	O
(	O
with	O
addresses	O
F800:8000	O
to	O
F800:FFFF	O
pointing	O
to	O
the	O
physical	O
addresses	O
0x00000000	O
to	O
0x00007FFF	O
)	O
.	O
</s>
<s>
This	O
trick	O
works	O
for	O
as	O
long	O
as	O
the	O
code	O
is	O
n't	O
executed	O
in	O
low	B-Device
memory	I-Device
,	O
the	O
first	O
64KB	O
of	O
RAM	O
,	O
a	O
condition	O
that	O
was	O
always	O
true	O
in	O
older	O
DOS	B-Device
versions	O
without	O
load-high	O
capabilities	O
.	O
</s>
<s>
With	O
the	O
DOS	B-Device
kernel	O
relocated	O
into	O
higher	O
memory	O
areas	O
,	O
low	B-Device
memory	I-Device
increasingly	O
became	O
available	O
for	O
programs	O
,	O
causing	O
those	O
depending	O
on	O
the	O
wraparound	O
to	O
fail	O
.	O
</s>
<s>
The	O
executable	O
loaders	O
in	O
newer	O
versions	O
of	O
DOS	B-Device
attempt	O
to	O
detect	O
some	O
common	O
types	O
of	O
affected	O
programs	O
and	O
either	O
patch	O
them	O
on-the-fly	O
to	O
function	O
also	O
in	O
low	B-Device
memory	I-Device
or	O
load	O
them	O
above	O
the	O
first	O
64KB	O
before	O
passing	O
execution	O
on	O
to	O
them	O
.	O
</s>
<s>
For	O
programs	O
,	O
which	O
are	O
not	O
detected	O
automatically	O
,	O
LOADFIX	B-Device
or	O
MEMMAX-L	O
can	O
be	O
used	O
to	O
force	O
programs	O
to	O
be	O
loaded	O
above	O
the	O
first	O
64KB	O
.	O
</s>
<s>
The	O
trick	O
was	O
utilized	O
by	O
IBM/Microsoft	B-Language
Pascal	I-Language
itself	O
as	O
well	O
as	O
by	O
programs	O
compiled	O
with	O
it	O
,	O
including	O
Microsoft	O
's	O
MASM	B-Application
.	O
</s>
<s>
Other	O
commonly	O
used	O
development	O
utilities	O
using	O
this	O
were	O
executable	B-Application
compressors	I-Application
like	O
Realia	O
's	O
Spacemaker	O
(	O
written	O
by	O
Robert	O
B	O
.	O
K	O
.	O
Dewar	O
in	O
1982	O
and	O
used	O
to	O
compress	O
early	O
versions	O
of	O
the	O
Norton	B-Application
Utilities	I-Application
)	O
and	O
Microsoft	O
's	O
EXEPACK	O
(	O
written	O
by	O
Reuben	O
Borman	O
in	O
1985	O
)	O
as	O
well	O
as	O
the	O
equivalent	O
/E[XEPACK]	O
option	O
in	O
Microsoft	O
's	O
LINK	O
3.02	O
and	O
higher	O
.	O
</s>
<s>
Various	O
third-party	O
utilities	O
exist	O
to	O
modify	O
compressed	B-Application
executables	I-Application
either	O
replacing	O
the	O
problematic	O
uncompression	O
routine(s )	O
through	O
restubbing	O
,	O
or	O
attempting	O
to	O
expand	O
and	O
restore	O
the	O
original	O
file	O
.	O
</s>
<s>
Modern	O
Legacy	B-Operating_System
BIOS	I-Operating_System
boot	B-Application
loaders	I-Application
(	O
such	O
as	O
GNU	B-Application
GRUB	I-Application
)	O
use	O
the	O
A20	B-Device
line	I-Device
.	O
</s>
<s>
UEFI	O
boot	B-Application
loaders	I-Application
use	O
32-bit	O
protected	B-Application
mode	I-Application
or	O
64-bit	O
long	B-Application
mode	I-Application
.	O
</s>
