boot/a20.s (view raw)
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
.section .text
.code16
# check if A20 gate is enabled
.global enable_a20
enable_a20:
mov $a20_check_msg, %si
call print
call checkA20
je enabled
# A20 is disabled, we need to enable it
mov $disabled_msg, %si
call print
mov $a20_enable_msg, %si
call print
# A20 BIOS method
a20_bios:
mov $a20_enable_bios_msg, %si
call print
movw $0x2401, %ax
int $0x15
mov $0x0001, %cx
call delay
call checkA20
je enabled
mov $fail_msg, %si
call print
# A20 keyboard controller method
a20_keyboard:
mov $a20_enable_kb_msg, %si
call print
# TODO: implement
mov $0x0001, %cx
call delay
call checkA20
je enabled
mov $fail_msg, %si
call print
# fast A20 method
a20_fasta20:
mov $a20_enable_fasta20_msg, %si
call print
inb $0x92, %al
orb $0x02, %al
andb $0xFE, %al
outb %al, $0x92
mov $0x1000, %cx
call delay
call checkA20
je enabled
mov $fail_msg, %si
call print
mov $a20_fail, %si
call print
jmp error
enabled:
mov $enabled_msg, %si
call print
ret
# ############################################
# checkA20
# checks if A20 line is enabled
# equal flag: * clear, if A20 is enabled
# * set, if A20 is disabled
# ############################################
checkA20:
push %ds
push %es
push %si
push %di
mov $0x0000, %ax
mov %ax, %ds
mov $0xFFFF, %ax
mov %ax, %es
mov $0x0500, %si
mov $0x0510, %di
movw %ds:(%si), %cx
movw %es:(%di), %dx
cmp %cx, %dx
pop %di
pop %si
pop %es
pop %ds
ret
# delays for at least a given number of cycles.
# CX: number of cycles to delay
delay:
nop
loop delay
ret
.section .data
a20_check_msg:
.ascii "Checking A20..."
.byte 0
a20_enable_msg:
.ascii "Enabling A20 (BIOS)..."
.byte 13
.byte 10
.byte 0
a20_fail:
.ascii "Could not enable A20 gate. HALT"
.byte 13
.byte 10
.byte 0
a20_enable_bios_msg:
.ascii " BIOS: "
.byte 0
a20_enable_kb_msg:
.ascii " keyboard controller: "
.byte 0
a20_enable_fasta20_msg:
.ascii " fast A20 method: "
.byte 0