1 year ago
#355768
TheCPPNoob
a20 gate is enabled, after disabling attempts
I've encountered a problem with disabling (for learning purpose) a20 gate.
Here is my bootloader code:
onboot:
xorw %ax, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x7c00, %ax
movw %ax, %bp
movw %ax, %sp
/* reading disk */
xorw %bx, %bx
movw %bx, %es
movw $0x7e00, %bx
movw $0x0201, %ax
movw $0x0002, %cx
movb $0x00, %dh
int $0x13
/* Disable a20 through bios */
movw $0x2400, %ax
int $0x15
/* clear through keyboard controller */
call clear_8042
movb $0xd1, %al
outb %al, $0x64
call clear_8042
movb $0b11011101, %al /* bit 0 = reset, must be 1,
bit 1 = a20 gate */
outb %al, $0x60
call clear_8042
movb $0xff, %al
outb %al, $0x64
call clear_8042
/* 0xffff0 + 0x7e0e = 0x107dfe*/
movw $0xffff, %bx
movw %bx, %es
movw %es:0x7e0e, %dx
pushw %dx
call printhex
addw $0x2, %sp
loop:
jmp %cs:loop
clear_8042:
pushw %ax
in $0x64, %al
test $2, %al
jnz clear_8042
popw %ax
ret
.= onboot+510
.word 0xaa55 /* little endian will reverse */
printhex:
pusha
movw %sp, %bp
movw 18(%bp), %dx
movw $0x0404, %cx /* ch = nibbles count, cl = iterator */
printhex_loop:
movw $0x0e0f, %ax
rol $4, %dx /* dl = nibble to show */
andb %dl, %al /* take a copy of dl in lowwer al nibble */
addb $0x90, %al /* if al is decimal nibble = 0x90 - 0x99
else = 0x9A - 0x9F */
daa /* if decimal = 0x90 - 0x99
else 0x0 - 0x5 w/ CF */
adc $0x40, %al /* if decimal = 0xD0 - 0xD9
else 0x41 - 0x46 */
daa /*if decimal = 0x30 = 0x39
else 0x41 - 0x46 */
int $0x10
dec %cl
jnz printhex_loop
popa
ret
The output from following instruction
movw %es:0x7e0e, %dx
must be 0xaa55 (if a20 gate is DISABLED), but for some reason it acts like a20 gate is enabled (output is 0x0000).
What am i doing wrong? I've been trying disabling it with bios interrupts, and kbc controller as you see.
Using manjaro and qemu, if makes difference.
assembly
x86
bootloader
0 Answers
Your Answer