]> git.dujemihanovic.xyz Git - nameless-os.git/blob - boot/x86/stage3/a20.s
Compile stage3 in ELF format
[nameless-os.git] / boot / x86 / stage3 / a20.s
1 bits 16
2 section .text
3
4 %macro in_wait 0
5 push ax
6 %%loop:
7 in al, 0x64
8 test al, 2
9 jnz %%loop
10 pop ax
11 %endmacro
12
13 %macro out_wait 0
14 push ax
15 %%loop:
16 in al, 0x64
17 test al, 1
18 jz %%loop
19 pop ax
20 %endmacro
21
22 ; CF set = A20 enabled
23 check_a20:
24 push esi
25 push edi
26 push ax
27 mov esi, 0x500
28 mov edi, 0x100500
29
30 mov al, [esi]
31 mov ah, [edi]
32
33 mov [esi], byte 0
34 mov [edi], byte 0xff
35 cmp [esi], byte 0xff
36
37 mov [esi], al
38 mov [edi], ah
39
40 pop ax
41 pop edi
42 pop esi
43 ret
44
45 enable_a20:
46 push ax
47 mov ax, 0x2401
48 int 0x15
49 jc .i8042_method
50 call check_a20
51 jnc .i8042_method
52 pop ax
53 ret
54 .i8042_method:
55 in_wait
56 mov al, 0xad
57 out 0x64, al
58 in_wait
59 mov al, 0xd0
60 out 0x64, al
61 out_wait
62 in al, 0x60
63 or al, 2
64 push ax
65 in_wait
66 mov al, 0xd1
67 out 0x64, al
68 in_wait
69 pop ax
70 out 0x60, al
71 in_wait
72 mov al, 0xae
73 out 0x60, al
74 call check_a20
75 pop ax
76 ret
77