Page 1 of 1

Questions about OS [NEWBIE]

Posted: Wed Apr 13, 2005 11:00 pm
by Petertje
Hi,

I'm new to OS-development and I finally write my own PMODE OS. It's very basic with some 80*25 video functions.
I got some questions about the A20 gate:

Code: Select all

enable_A20:
	[BITS 16]

	cli				;; Interrupts uit
	
	call a20wait
	mov al, 0xAD		  	;; Disable keyboard
	out 0x64, al

	call a20wait
	mov al, 0xD0			;; Read
	out 0x64, al	

	call a20wait2
	in al, 0x60			;; lees status in al
	push eax			;; Push naar de stack, bij de volgende call gaat het verloren

	call a20wait
	mov al,0xD1			;; Write
	out 0x64, al

	call a20wait
	pop eax				;; status weer van de stack halen
	or al, 2			;; Check of A20 gate aanspreekbaar is
	out 0x60, al			;; nieuwe waarde in het keyboard status register plaatsen

	call a20wait
	mov al, 0xAE
	out 0x64, al			;; enable keyboard

	call a20wait
	sti				;; enable interrupts
	ret

a20wait:
.10:	mov ecx, 65536			;; kleine delay 
.11:	in al, 0x64
	test al, 2			;; testen op bit 2, kijk of de output buffer leeg is
	jz .12
	loop .11
	jmp .10
.12:	ret

a20wait2:
.10:	mov ecx, 65536			;; kleine delay
.11:	in al, 0x64
	test al, 1			;; testen op bit 1, kijk of de keyboard-controller klaar is
	jnz .12
	loop .11
	jmp .10	
.12:	ret
My question is why does the A20 gate is ORed. I don't get the point why you need to OR to get the A20 bit.

Thanks, Peter

Re: Questions about OS [NEWBIE]

Posted: Sun Apr 17, 2005 11:00 pm
by Petertje
Does nobody know why?
why does it is ORed the A20 gatebit is 02, but why is it ORed???
please, :)

Re: Questions about OS [NEWBIE]

Posted: Sun Apr 17, 2005 11:00 pm
by gaf
Hey,
the bit that enables the a20 is stored in the 'output port' of the keyboard controller. The asm code you posted (basically) works as following:
1) Read the value from the (keyboard controller's) output-port in
2) Set the a20 bit
3) Write the (modified) value back to the output-port

You can find a definition of the output-port's fields aswell as a listing of the various keyboard controller commands on this site (http://www.computer-engineering.org/ps2keyboard/).

I hope you do know how an OR operation works in general ?

An OR-disjunction is always true if (at least!) one of the two operands is true. Don't get mixed up because in everyday language "or" is mostly used to express "either a or b". In logic this would be called "exclusive or" (XOR).

Z = X OR Y
X = 0101b
Y = 1001b
--------------
Z = 1101

Just compare X and Y bit by bit:
X = 0___b
Y = 1___b
Z = 1___b

X = _1__b
Y = _0__b
Z = 11__b

...

From the code snippet:
(al = out-port = ??????0?)
or al, 10b
(al = ??????1? - a20 bit set)

Have a look at en.wikipedia.org/wiki/Logical_disjunction for some more details..

regards,
gaf

Re: Questions about OS [NEWBIE]

Posted: Mon Apr 18, 2005 11:00 pm
by [AlAdDiN]
Petertje wrote: My question is why does the A20 gate is ORed. I don't get the point why you need to OR to get the A20 bit.
Do you have a simpler solution ;) ??

Re: Questions about OS [NEWBIE]

Posted: Tue Apr 19, 2005 11:00 pm
by Petertje
Thanks alot!
I do now understand :)

Re: Questions about OS [NEWBIE]

Posted: Tue Apr 19, 2005 11:00 pm
by Petertje
And it is not 64 decimal because its in big endian, right?

2 = 00000010
64=01000000

Re: Questions about OS [NEWBIE]

Posted: Tue Apr 19, 2005 11:00 pm
by Petertje
I no, I was a little confused. 00000010 the 1 is bit 2.

Thanks :D,

Peter