/joh'liks/ n.,adj. 386BSD

Porting Unix to the 386: A Practical Approach



William & Lynne Jolitz


Dealing with PC reverse compatibility requires defeating logic like Gate A20, which forces address rollover to a single megabyte for ancient 8086/8088 compatibility.




GATE A20
Another feature which deserves mention involves the PC hardware feature known as GATE A20. Because the original IBM PC had only 20 bits of address (2{10} or 1 Mbyte, denoted as A19 < -- > A0), newer machines possessing greater physical address space (80286 with 16 Mbytes and the 80386 with 4 gigabytes) might exhibit a small difference when executing in real mode.
Listing 3: DOS GATE A20 (file: gatea20.asm)
        title   _gatea20
;  Copyright (c) 1989, 1990 William Jolitz. All rights reserved.
;  Written by William Jolitz, July 1989
;  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
;  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
;  WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
;       (void) gatea20();
;       Enable Address Bit 20 that was disabled by BIOS for MSDOS
;       We need it off to use entire memory space of the AT.
;       We do this just prior to entering protected mode, never to return.
;

_TEXT   segment byte public 'CODE'
        assume  cs:_TEXT,ds:_TEXT
_TEXT   ends

Status_Port     equ     64h             ; 8042 Status Port
Cmd_rdy         equ     2               ;  Keyboard is ready?
Write_outpt     equ     0d1h            ;  Write next data to output port
Port_A          equ     60h             ; 8042 Keyboard Scan and Diagnostic
EnableA20       equ     0dfh            ; Enable Address bit 20 for use

_TEXT   segment byte public 'CODE'

;       Wait for Keyboard controller to be ready for command
wait42  proc    near
chkrdy:
        in      al, Status_Port
        and     al, Cmd_rdy
        jnz     chkrdy
        ret
wait42  endp

;       Turn on A20 again.
_gatea20        proc far
        call    wait42
        mov     al, Write_outpt
        out     Status_Port, al
        call    wait42
        mov     al, EnableA20
        out     Port_A, al
        call    wait42
        ret
_gatea20        endp

        public  _gatea20
_TEXT   ends
        end
GATE A20 was designed to mitigate this problem. Without it, a reference at the topmost address incrementing up would actually reference outside of the 20-bit address space, because the rollover would be carried up instead of being wrapped around to address zero. GATE A20 would not be necessary were it not for the presence of a considerable body of ancient MS-DOS applications that rely on the address space execution, assuming that this would rollover to the same address space occupied by the bottom of physical memory.

Thus, the urgent need for GATE A20 (short for "Gate the A20 address line to logic zero"). With our UNIX system, we will want to grab all available RAM memory, especially that above 1 Mbyte, so we need to defeat the GATE A20 feature and allow all the processor's address lines to be functional. We did this with our gatea20.asm module in Listing 3 invoked by boot.c (see Unix Kernel Load Program).




<<BACK NEXT >>



Copyright 1989, 1990, 2006 TeleMuse Partners, William Jolitz and Lynne Jolitz