-
Notifications
You must be signed in to change notification settings - Fork 1
/
a20.asm
113 lines (81 loc) · 1.22 KB
/
a20.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
.code16
.text
.global enable_a20
enable_a20:
call a20_check
jnc .a20_enabled
call enable_a20_bios
call a20_check
jnc .a20_enabled
call enable_a20_fast
jnc .a20_enabled
call enable_a20_8042
call a20_check
.a20_enabled:
ret
enable_a20_bios:
mov $0x2401, %ax
int $0x15
ret
enable_a20_fast:
in $0x92, %al
test $2, %al
jnz .a20_fast_enabled
or $2, %al
and $0xfe, %al
out %al, $0x92
.a20_fast_enabled:
ret
enable_a20_8042:
call .a20_wait
mov $0xd1, %al
out %al, $0x64
call .a20_wait
mov $0xdf, %al
out %al, $0x60
call .a20_wait
mov $0xff, %al
out %al, $0x64
call .a20_wait
ret
.a20_wait:
out %al, $0x80
in $0x64, %al
test $1, %al
jne .a20_no_output
out %al, $0x80
in $0x60, %al
jmp .a20_wait
.a20_no_output:
test $2, %al
jne .a20_wait
ret
a20_check:
push %ds
push %es
xor %ax, %ax
mov %ax, %ds
mov $0xffff, %ax
mov %ax, %es
mov 0x1000(,1), %ax
mov $5, %cx
.a20_check_loop:
out %al, $0x80
mov 0x1000(,1), %bx
cmp %es:0x1010, %bx
jne .a20_8042_enabled
inc %bx
mov %bx, 0x1000(,1)
cmp %es:0x1010, %bx
jne .a20_8042_enabled
dec %cx
jnz .a20_check_loop
stc
jmp .a20_8042_return
.a20_8042_enabled:
clc
.a20_8042_return:
mov %ax, 0x1000(,1)
pop %es
pop %ds
ret