]> git.dujemihanovic.xyz Git - nameless-os.git/blob - boot/x86/a20.s
f6a292ba6bd23bbf2e24564b1351d530836930ae
[nameless-os.git] / boot / x86 / a20.s
1 ; Some routines for managing the A20 line
2
3 ; Check if A20 is enabled
4 ; Based on <https://wiki.osdev.org/A20_Line#Testing_the_A20_line>, slightly modified
5 check_a20
6 pushf ; save EFLAGS
7 ; save segment and index registers
8 push ds
9 push es
10 push di
11 push si
12
13 cli ; disable interrupts
14 xor ax, ax ; ax = 0
15 mov es, ax ; es = 0
16
17 not ax ; ax = FFFFh
18 mov ds, ax ; ds = FFFFh
19
20 mov di, 500h
21 mov si, 510h
22
23 mov al, [es:di] ; preserve contents of 0:500h
24 mov ah, [ds:si] ; preserve contents of FFFFh:510h
25 push ax ; push all that to stack
26
27 mov byte [es:di], 0 ; set 0:500h to 0
28 mov byte [ds:si], 0FFh ; set FFFFh:510h to FFh
29
30 cmp byte [es:di], 0FFh ; compare 0:500h with FFh
31 ; if A20 is enabled, this will not be equal, but if A20 is disabled it will be
32
33 pop ax ; pop old contents of the 2 addresses
34 mov [ds:si], ah ; restore contents of FFFFh:510h
35 mov [es:di], al ; restore contents of 0:500h
36
37 xor ax, ax ; clear ax
38 je .exit ; if A20 is disabled, return 0
39 mov ax, 1 ; otherwise return 1
40
41 .exit
42 pop si
43 pop di
44 pop es
45 pop ds
46 popf
47 sti
48 ret
49