Page 1 of 1

Enabling A20

Posted: Fri May 27, 2005 3:31 pm
by vile
Hello all,

I was curious about how to enable the A20 gate, and when I should do so, and what it is exactly. Thanks! :)

Re:Enabling A20

Posted: Fri May 27, 2005 6:36 pm
by Uncanny Dude
Hi!

1) There are a couple ways. Most modern BIOS provide a service. The keyboard controller has a spare pin so can do that as well.

2) Before you access a byte in memory whose bit 20 is set, otherwise it will wrap down at one mega. Will be a lot easier if you enable the A20 gate before entering protected mode or loading other sectors from disk(in case you read to 0x100000). Or let somebody else do that for you(use GRUB, etc.).

3) See #2. It is there to emulate the behavior expected in older programs. Just do that thing and forget.

Using the BIOS:

Code: Select all

        mov     ax, 0x2401
        int     0x15
        jnc     .done
Using the keyboard controller to enable gate A20:

Code: Select all

        ; empty keyboard input buffer
    .read:
        in      al, 0x60
    .out:
        in      al, 0x64
        test    al, 0x01
        jnz     .read

        ; send command
        call    .cmd_wait
        mov     al, 0xd1
        out     0x64, al

        call    .cmd_wait
        mov     al, 0xdf
        out     0x60, al

    .cmd_wait:
        in      al, 0x64
        test    al, 0x02
        jnz     .cmd_wait
        ret
Test is enabled:

Code: Select all

        xor     ax, ax
        mov     fs, ax
        dec     ax
        mov     gs, ax
        mov     al, byte [fs:0x0]
        mov     ah, al
        not     al
        xchg    al, byte [gs:0x10]
        cmp     ah, byte [fs:0x0]
        mov     [gs:0x10], al

        jnz     .error
    .done:
Cheers.

Re:Enabling A20

Posted: Sat May 28, 2005 7:43 am
by Warrior