Page 1 of 1

A20-Gate

Posted: Thu Apr 28, 2005 11:00 pm
by z4ck
Hi,
i have problems with my a20-gate. it seems that my code set the a20 gate not right. if so, then the testa20-code is wrong.. could anybody check it?

Code: Select all

;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;---------------------A20 Gate----------------------------------
SetupA20:
	.0:
		pusha
		
	.1:
		call	EnableA20Int
		
		call	TestA20
		cmp		ax, 1
		je		._Done
	
	.2:
		call	EnableA20Port

		call	TestA20
		cmp		ax, 1
		je		._Done
	
	.3:
		call	EnableA20KbdCom
		
		call	TestA20
		cmp		ax, 1
		je		._Done
	
	.4:
		call	EnableA20KbdStat
		
		call	TestA20
		cmp		ax, 1
		je		._Done
		
	._Fail:
		mov		si, msg_A20Fail
		call	PrintString
		cli
		hlt
		
	._Done:
		popa
		ret
		

;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Enable A20 Gate with Interrupt----------------------
EnableA20Int:
	.0:
		push	ax
	
	.1:
		mov		ax, 0x2401
		int		0x15
		
	.2:
		pop		ax
		ret
		

;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Enable A20 Gate with Keyboard Statusbyte------------
EnableA20KbdStat:
	.0:
		push	eax
		cli
	
	.1:
		call	WaitKbd
		
	.2:
		mov		al, 0xD0
		out		0x64, al
		
	.3:
		in		al, 0x64
		test	al, 0x1
		jz		.3
		
	.4:	
		in 		al, 0x60
		or		al, 00000010b
		push	eax
		
	.5:
		call	WaitKbd
		
	.6:	
		mov 	al, 0xD1
		out		0x64, al
		
	.7:
		call	WaitKbd

	.8:	
		pop		eax
		out		0x60, al
		call	WaitKbd
		
	.9:
		sti
		pop		eax
		ret

		
;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Enable A20 with Keyboard Commando-------------------	
EnableA20KbdCom:
	.0:	
		push	ax
	
	.1:
		call	WaitKbd
	
	.2:
		mov		al, 0xDF
		out 	0x64, al
		
	.3:
		call	WaitKbd
	
	.4:
		pop 	ax
		ret
		

;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Wait for the Keyboard-------------------------------	
WaitKbd:
	.0:
		pusha
	.1:
		jmp		.3
		
	.2:
		in 		al, 0x60
	
	.3:
		in		al, 0x64
		test	al, 0x1
		jnz		.2
		test 	al, 0x2
		jnz		.3
	
	.4:
		popa
		ret
		
			
;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Enable A20 with port 0x92---------------------------		
EnableA20Port:
	.0:
		push	ax
	
	.1:
		in		al, 0x92
		xor		ah, ah
		test	al, 0x2
		je		.3
	
	.2:
		and  	al, 0x0FD
		out		0x92, al
	
	.3:	
		pop		ax
		ret
		


;===============================================================
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;-----------Test if a20 is set----------------------------------
TestA20:
	.0:
		push	bx
		push	cx
		push 	es
		
	.1:
		mov		bx, 0xFFFF
		mov		es, bx
		push	bx
		mov		ax, [es:0x100]
		not		ax
		xor		bx, bx
		mov		es, bx
		mov 	[es:0x100], ax
		pop		bx
		mov		es, bx
		cmp		ax, [es:0x100]
		je		.2
		
		mov		ax, 1
		jmp		.3
	
	.2:
		mov		ax, 0
	
	.3:
		pop		es
		pop		cx
		pop		bx
		ret
thx

Re: A20-Gate

Posted: Thu Apr 28, 2005 11:00 pm
by frizzz
Your code runs only on very old machines because of the
"or al,10b", send to the keyboard-controller.
You need:
mov ax,0DFh

But the easiest way is:
Look at my homepage
www.rcfriz.de
...download my operating system "FDOS1" and find in line 600,
what You want. The code is very well tested on machines from 1980-2004 and derived from linux-code.