A20 enabled yet disabled

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

A20 enabled yet disabled

Post by instance »

Hey,
I'm trying to make and run a code for enabling the A20 address line. I've used the memory wraparound concept to test whether A20 is enabled. When I start bochs, it shows A20 is disabled. However, when I query the keyboard controller, I see that the output port has the value 0x03, which would mean A20 is enabled.
Using almost the same code as in the wiki, I tried enabling the A20 (which is redundant right now), and checking the wraparound. I'm unable to enable the A20.

The code I've used-
Check a20

Code: Select all

check_a20:   ; Returns 1 in ax if a20 is enabled
	cli
    xor ax,ax
    mov fs,ax
    not ax 		; AX=0xffff
    mov gs,ax

    mov di,0500h
    mov si,0510h		
    mov byte [fs:di],00h	; 0000:0500 =  00500h
    mov byte [gs:si],0FFh	; FFFF:0510 = 100500h Check wraparound
    cmp byte [fs:di],0FFh
    xor ax,ax
    je check_a20__exit
    mov al,1
check_a20__exit:
	sti
    ret
For enabling the A20

Code: Select all

enable_a20:
	cli
	call enable_a20__wait  ;clear
	mov al,0ADh    ; Disable keyboard
	out 064h,al
	call enable_a20__wait
	mov al,0D0h     ; Read from output port
	out 064h,al
	call enable_a20__waitob
	xor ax,ax
	in al,060h			; Read. Debugged to 0x03
	mov bl,al    ; Save
	call enable_a20__wait
	mov al,0D1h      ; Write to output port
	out 064h,al
	call enable_a20__wait
	mov al,bl
	or al,00000010b  ; Enable a20
	out 060h,al
	call enable_a20__wait
	mov al,0D0h          ; Last minute testing
	out 064h,al
	call enable_a20__waitob
	xor ax,ax
	in al,060h             ; same value
	call enable_a20__wait
	mov al,0AEh    ; Enable keyboard again
	out 064h,al
	sti
	ret
enable_a20__wait:
	in al,064h
	test al,2 	; wait for input buffer to be empty
	jnz enable_a20__wait
	ret
enable_a20__waitob:
	in al,064h
	test al,1		; wait for output buffer to be empty
	jz enable_a20__waitob
	ret

Could someone please help me. Thanks


EDIT:
Using int 15h BIOS function with ax: 2402h to check whether a20 is enabled, it showed that its already enabled.
Last edited by instance on Wed Mar 18, 2009 2:12 am, edited 1 time in total.
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: A20 enabled yet disabled

Post by Hyperdrive »

instance wrote: The code I've used-
Check a20

Code: Select all

check_a20:   ; Returns 1 in ax if a20 is enabled
	cli
    xor ax,ax
    mov fs,ax
    not ax 		; AX=0xffff
    mov gs,ax

    mov di,0500h
    mov si,0510h		
    mov byte [fs:di],00h	; 0000:0500 =  00500h
    mov byte [gs:si],0FFh	; FFFF:0510 = 100500h Check wraparound
    cmp byte [fs:di],0FFh
    xor ax,ax
    je check_a20__exit
    mov al,1
check_a20__exit:
	sti
    ret
With

Code: Select all

   xor ax,ax
   je <somewhere>
you'd always jump, because:
  • XOR affects the flags and sets ZF corresponding to the result - XOR ax,ax will always give 0 as the result and therefore ZF will be set
  • JE tests the zero flag (ZF) and jumps if ZF is set

As a consequence you always jump to check_a20__exit with ax cleared and that means the A20 is disabled, but that's not always true.

Also I would add a WBINVD at the appropriate position - just in case. But that's not your main problem here.

--TS


EDIT: Hm... So the wiki article is broken? ... What is true now: Am I right and the article broken or is the article correct and I missed something very bad?
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Re: A20 enabled yet disabled

Post by instance »

Your Right!! :D
Yea, I simply changed the xor ax,ax to a simple mov ax,0 , and it works perfectly. Thanks

btw, yea, the wiki article maybe broken, cause it says:

Code: Select all

 xor ax, ax
    je check_a20__exit
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: A20 enabled yet disabled

Post by Hyperdrive »

FYI - wiki is updated: A20_Line.
Post Reply