Why do we need to disable interrupts while turning on the A20?

In some code snippets in the OSDev wiki to enable the A20 line , we have clicommand interrupts. In some others we do not have them.

eg. when configuring the A20 line through the old keyboard controller method, all code is surrounded by a combination of cliand sti. I can imagine that this should happen because we use keyboard communication through the ports, and interrupting the keyboard can also change data on the ports. But it's true? I only guessed ...

enable_A20:
    cli

    call    a20wait
    mov     al,0xAD
    out     0x64,al

    call    a20wait
    mov     al,0xD0
    out     0x64,al

    call    a20wait2
    in      al,0x60
    push    eax

    call    a20wait
    mov     al,0xD1
    out     0x64,al

    call    a20wait
    pop     eax
    or      al,2
    out     0x60,al

    call    a20wait
    mov     al,0xAE
    out     0x64,al

    call    a20wait
    sti
    ret

a20wait:
    in      al,0x64
    test    al,2
    jnz     a20wait
    ret


a20wait2:
    in      al,0x64
    test    al,1
    jz      a20wait2
    ret

A20 ( ) , . , ? , , , , ?

check_a20:
pushf
push ds
push es
push di
push si
cli

xor ax, ax ; ax = 0
mov es, ax

not ax ; ax = 0xFFFF
mov ds, ax

mov di, 0x0500
mov si, 0x0510

mov al, byte [es:di]
push ax

mov al, byte [ds:si]
push ax

mov byte [es:di], 0x00
mov byte [ds:si], 0xFF

cmp byte [es:di], 0xFF

pop ax
mov byte [ds:si], al

pop ax
mov byte [es:di], al

mov ax, 0
je check_a20__exit

mov ax, 1

check_a20__exit:
pop si
pop di
pop es
pop ds
popf

ret

, A20- . ( ). , , , 0x92 , , ? , .

fast_a20_gate:
in al, 0x92
test al, 2
jnz after
or al, 2
and al, 0xFE
out 0x92, al
after:

- , , cli, ? , .

+4
1

, . , (!) .

fast_a20_gate . , - . - , .

0

Source: https://habr.com/ru/post/1612055/


All Articles