3 ms·
Enabling A20 is just an or and an out opcode. It's all the stuff you have to do around it (because you're switching from 16 to 32 bit mode). For the purpose of
by iuguy 16y ago
Enabling A20 is just an or and an out opcode. It's all the stuff you have to do around it (because you're switching from 16 to 32 bit mode). For the purpose of making formerly lucky people now unlucky, here's some background on A20. Please correct any inaccuracies, it's been a long time since I've written toy OSes.
The Intel 8086 could only access 1MB of memory (using 20 bits). While this was great for the early 80s, it started to become a problem later on. This was fixed in the Intel 286 (which could address up to 16 MB of memory) but needed to be compatible with the 8086 at the time.
The 8086 had 20 individual gates or address lines numbers A0 - A19. This meant that there were different ways of referencing the same addresses in different numbering systems, most notably in hex. When you went over FFFFF, you'd actually wrap around. Some software relied on this (it was the 80s after all. For further examples of wrongness in the 80s see big hair and shoulder-padded suits).
For the 286 to access 16MB while enabling compatibility with the 8086 a kludge was invented. An extra logic gate (A20) was added to the keyboard controller that would enable or disable access to memory above 1MB. The bios enables it when it checks memory, then disables it when transferring it to the OS. The boot loader (normally) runs through a series of checks, reads the keyboard, makes sure the keyboard buffer is empty and sets the gate as part of switching into 32-bit mode on x86.
This still happens, even on your top of the range 64-bit quad core behemoth if you're running a 32-bit Operating System. I'm not sure whether this still applies to 64-bit Operating Systems as they were after my time, but if anyone here can tell me I'd love to know.
Personally I've always felt that the A20 part wasn't that hard - perhaps it's the wrong term but the hardest thing for me was all the checks for the right hardware, I kept finding stuff that works fine in bochs or qemu then barfs on real kit.
- a-priori 16y agoThanks for this description. An extra logic gate (A20) was added to the keyboard controller that would enable or disable access to memory above 1MB. Yes, the fact that it's on the keyboard controller is the single biggest WTF about the whole thing. This still happens, even on your top of the range 64-bit quad core behemoth if you're running a 32-bit Operating System. I'm not sure whether this still applies to 64-bit Operating Systems as they were after my time, but if anyone here can tell me I'd love to know. As far as I know, yes it's still part of the boot process even for operating systems that run in long mode (i.e, x86-64). Personally I've always felt that the A20 part wasn't that hard - perhaps it's the wrong term but the hardest thing for me was all the checks for the right hardware, I kept finding stuff that works fine in bochs or qemu then barfs on real kit. It's not so much that it's hard... if you're like me, you spend a good half an hour trying to make sense of what it is, then copy-paste some code to do it. I was just using it as an example of a seriously weird 'feature' of the architecture.