Page 1 of 1

difficulty activating A20

Posted: Sun Feb 03, 2008 1:33 pm
by suthers
Can any body tell me why this code doesn't work, it attempts to activate A20, i've been trying to run it on vmware but it doesn't do any output and it just seems to loop (vmware normally tell you when it reaches a hlt instruction which it doesn't)

Code: Select all

bits 16
org 0x7c00
start:
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov ax, 0x1D0
mov ss, ax
mov sp, 0x200
mov si, init
call PutStr
cli
call waitkeyclear
mov al, 0xd1
out 0x64, al
call waitkeyclear
mov al, 0xdf
out 0x60, al
call waitkeyclear
mov cx, 0x10
.waisttime
nop
nop
xor ax, ax
loop .waisttime
mov al, 0xd0
out 0x64, al
call waitkeyfull
in al, 0x60
test al, 2
jnz .A20_on
mov al, 'A'
call halt
.A20_on
sti
mov si, A20_success
call PutStr
hlt


waitkeyclear:
xor al, al
mov al, 0x64
test al, 2
jnz waitkeyclear
ret

waitkeyfull:
xor cx, cx
mov al, 0x64
test al, 1
jz waitkeyfull
ret



halt:
cli
hlt

PutStr:		
 mov ah,0x0E	
 mov bh,0x00	
 mov bl,0x07	
.nextchar	
 lodsb		
 or al,al			
 jz .return			
 int 0x10	 
 jmp .nextchar	
.return		
 ret		


drive dw ''
A20_success db 'A20 Enabled', 13, 10, 0
init db 'initiation started', 13, 10, 0

times 510-($-$$) db 0
dw 0xAA55
I assembled it with nasm

Thanks in advance,

Jules

Posted: Sun Feb 03, 2008 2:43 pm
by rv6502
its "in al, 0x64" not "mov al, 0x64"

waitkeyfull:
xor cx, cx
mov al, 0x64 <---------------------- here
test al, 1
jz waitkeyfull
ret


same thing in waitkeyclear

Posted: Sun Feb 03, 2008 2:46 pm
by rv6502
also, I think you're supposed to disable the keyboard and auxiliary device (ps/2 mouse) when doing this in the off-chance that a key is pressed between the time you check if the key buffer is empty and the time you reprogram the A20 line.

Posted: Sun Feb 03, 2008 2:51 pm
by rv6502
if you want an easy way to debug this kind of stuff next time, you can use the VGA palette color 0 to show where the program jams

make a macro of:

push dx
push ax
mov dx, 0x3C8
xor al, al
out dx, al
inc dx
mov al, 63 ; red 0-63
out dx, al
mov al, 0 ; green 0-63
out dx, al
mov al, 0 ; blue 0-63
out dx, al
pop ax
pop dx

it will change color 0 (usually the background color that's all over the screen in text mode) to red in this case

use different colors in different places in the code to find out where in the code it crashes.

good luck

Posted: Sun Feb 03, 2008 3:02 pm
by suthers
Thanks I did the changes that you sudjested, but this time all it did is make the pc beep, any ideas why that is?, any ideas why did the output function not work? and also how do i disable the keyboard?
(sorry for all the newbie questions)
Thanks,

Jules

Posted: Sun Feb 03, 2008 6:01 pm
by Shalted
There is a bios function to Enable the A20 for you.

Code: Select all

A20:	;Attempt to enable the A20 using the bios
	mov	ax, 0x2401
	int	0x15
If it fails, it sets the Carry flag, and if it's not supported it'll return 0x86 in ah.

Of course, if this call isn't supported, it won't enable the A20 gate, but I use it regardless, because my computer supports it. (And that's all I really care about, since I don't plan to use my OS on other computers.)

Posted: Mon Feb 04, 2008 8:43 am
by jal
Or, one reads the Wiki.


JAL

Posted: Mon Feb 04, 2008 10:30 pm
by bewing
There are several ways of setting A20, besides the methods that have been mentioned. (BTW, since you did the CLI, you don't need to worry about keystrokes.)

The Standard way. Do like you are doing -- send the 0xD0 command to port 0x64, read the byte at port 0x60, if bit with value=2 is not set, then set it, then send 0xD1 to port 0x64, and send the updated byte (with that "2" bit turned on) back to port 0x60.

The Compaq way (that should work on all machines). Do the same as the standard way, except send 0x20 to 0x64, read 0x60, check bit with value=1, set the bit, send value 0x60 to port 0x64, send updated byte to port 0x60.

Start with those two. If your machine is an HP Vectra, then you need to use still another way.