Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why enable A20 line in Protected Mode?

In the bootloader's assembly source file of Linux 0.01, the A20 line is enabled.

From boot/boot.s:

| that was painless, now we enable A20

call     empty_8042
mov al,#0xD1

...

Afterwards the bootloader jumps into Protected Mode.

In Real Mode, enabling the A20 line grants us an address space expansion of 64 KiB - 16 bytes.
In Protected Mode, the address bus is unlocked automatically.

Why does the bootloader enable the A20 address line when the jump to Protected Mode would do that anyway?

like image 890
cadaniluk Avatar asked Nov 20 '15 13:11

cadaniluk


People also ask

How do I enable my A20 line?

Enabling the A20 line through the 8042 keyboard controllerDisable the keyboard (send command 0xad to the keyboard controller) Tell controller that we want to read input (send command 0xd0) Read one byte of input. Tell the controller that we want to write output (send command 0xd1)


1 Answers

In Real Mode, enabling the A20 line grants us an address space expansion of 64 KiB - 16 bytes.

Correct, in Real Mode (on a 286+) you could set a segment register to 0xFFFF, which would allow you to access memory up to (0xFFFF << 4) + 64K.

In Protected Mode, the address bus is unlocked automatically.

Protected mode is a CPU mode, so it doesn't "unlock" the bus, it simply allows additional address space to be used, which requires more pins on the address bus.

Why does the bootloader enable the A20 address line when the jump to Protected Mode would do that anyway?

Because it wouldn't. "A20" generally refers to a hardware hack, added in the PC-AT, that needs to be disabled before protected mode will function as expected.

First, recall that old old CPUs (through the 80186) could only access up to 1 MiB of memory, and thus had 20 address lines (A0 - A19). Some very old software took advantage of the fact that memory accesses above 1 MiB would wrap to the lower memory.

When the 286 added more address lines, IBM didn't want to break the compatibility with this old software, so they did the unimaginable: They put an external gate on the 21st address line (A20), and left it off by default, re-enabling the wrap-around behavior, so old software would still function correctly. So the 286 itself knows nothing about this hack - it is external to the CPU. To the CPU, A20 is no different than any other address line.

This gate, (the A20 gate), is controlled by a GPIO pin on the keyboard controller IC. Thus, you need to enable it before going into protected mode. If you didn't, (and say you flat-mapped all 4GB of physical memory), then as Micheal Petch indicated, "every odd numbered megabyte region will be inaccessible. So 1mb-2mb will actually reference 0-1mb, 3mb-4mb will reference 2mb-3mb etc." See also:

  • A20 Line (Wikipedia)
like image 91
Jonathon Reinhart Avatar answered Oct 28 '22 23:10

Jonathon Reinhart