Page 1 of 1

Is Dell Keyboard Controller acting odd?

Posted: Tue Mar 24, 2009 8:10 pm
by vbbrett
Or is it my code?

I have several Dell computers here which I'm testing my OS on. The keyboard is a standard USB keyboard. Whenever I type, the interrupt fires perfectly and I read the proper input port (btw, my code works fine on other computers). Everything goes smoothly until I try to type quickly. I then seem to fill up some buffer somewhere and not enough interrupts are fired (???) for me to read out all the characters. Anywho, the next time I strike a key, my interrupt fires and I read out a character which I obviously typed awhile ago. If I keep typing the same character (or a sentence), I keep receiving old characters until my new text starts coming through. In other words, the buffer somewhere stays permanently behind from that point forward.

I tried reading the keyboard status port whenever I get an interrupt, but it shows that the keyboard buffer is empty as soon as I read one character. Obviously, there are more characters somewhere.

So, then I tried always reading 10 characters every time I got an interrupt no matter what the status port said. This doesn't fix the problem either since the keyboard always returns the same character all 10 times. In other words, this buffer somewhere is only incremented one character no matter how many times I read it per interrupt.

Is something seriously wrong with my code? I've been doubting whether the whole OS has been loaded into memory by my bootsector. I recently switched to loading my OS from a USB stick using the same bootsector which I've used for my HD and floppy loads. The bootsector obviously loads something, but my stage 2 code keeps telling me that the load was only partial.

So, my question is: is the keyboard behaviour that I am experiencing normal on some systems, or should I look towards the obvious (my code isn't all loaded == quirky bugs)?

Brett

Re: Is Dell Keyboard Controller acting odd?

Posted: Tue Mar 24, 2009 11:07 pm
by vbbrett
Ahh, I just verified that my code is fully loaded and everything is excellent there. I still have the problem with the keyboard. What is happening and how can I fix it?

Re: Is Dell Keyboard Controller acting odd?

Posted: Tue Mar 24, 2009 11:53 pm
by Brendan
Hi,
vbbrett wrote:Or is it my code?
Or is it both? ;)
vbbrett wrote:The keyboard is a standard USB keyboard.
This probably means that the BIOS is using SMM to emulate the PS/2 controller.
vbbrett wrote:Whenever I type, the interrupt fires perfectly and I read the proper input port (btw, my code works fine on other computers). Everything goes smoothly until I try to type quickly.
Which implies it's not a problem with your keyboard code.

I'm guessing that the BIOS has a problem in it's PS/2 emulation code. I'm also guessing that nobody has realized there's a problem in the BIOS before because other OSs either use USB (instead of PS/2 emulation), or they get bytes out of the emulated PS/2 controller's buffer fast enough that the PS/2 emulation code doesn't need to buffer many bytes. Therefore, I'm also wondering if your OS might be getting bytes out of the emulated PS/2 controller's buffer slower than it could/should. For example, maybe there's a problem with interrupt latency in your OS, which makes the problem in the BIOS more likely to occur in practice.


Cheers,

Brendan

Re: Is Dell Keyboard Controller acting odd?

Posted: Wed Mar 25, 2009 3:00 am
by AJ
Hi,

If it is a problem with the BIOS (software?) emulation, it may be possible that someone else has found the same thing and reported it, in which case, look for the latest BIOS firmware on Dell's own site.

Cheers,
Adam

Re: Is Dell Keyboard Controller acting odd?

Posted: Wed Mar 25, 2009 3:12 am
by ThymeCypher
Hate to say it flat out, but Dell sucks :)
Wouldn't hurt to also try another keyboard or a USB using PS/2 emulation to see if the problems persist, but it probably is a BIOS issue.

Re: Is Dell Keyboard Controller acting odd?

Posted: Wed Mar 25, 2009 11:33 am
by Dex
I would say as the same as above, there is some lag some where, it could be in your IRQ response or the usb to PC/2.
You could try someone elses OS to see if you get the same problem
Eg: Kill two birds with one stone
http://forum.osdev.org/viewtopic.php?f=2&t=19462

Re: Is Dell Keyboard Controller acting odd?

Posted: Wed Mar 25, 2009 12:39 pm
by IanSeyler
I had the exact same issue on Dell systems. It was a long time ago so I don't quite remember the fix.. I'm pretty sure it was in the Interrupt routine. See the code below:

Code: Select all

; -----------------------------------------------------------------
keyboard:
	push rax
	push rbx
	
	mov al, 0xad
	out 0x64, al ; disable keyboard
	
	in al, 0x61	; get the scancode
	mov [scancode], al	; store the scancode
	xor al, 0x80	; next five lines are for acknowledging the scancode
	out 0x61, al
	mov al, [scancode]
	and al, 0x7f
	out 0x61, al
	
	xor eax, eax
	in al, 0x60	; get the key

	test al, 0x80
	jz keydown
	jmp keyup

keydown:
	mov ebx, keylayoutlower
	add ebx, eax
	mov bl, [ebx]
	mov [kkey], bl
	mov al, [kkey]
	jmp donekey
	
keyup:
	; else we got a valid key
	
;	mov byte [0xB8f9c], al	; put the typed character in the bottom right hand corner


donekey:
	mov al, 0xae
	out 0x64, al ; enable keyboard
	
	mov al, 20h
	out 20h, al
	pop rbx
	pop rax
	iretq

scancode: db 0x00
kkey: db 0x00
; -----------------------------------------------------------------	
The fix may have involved the disable and enable of the keyboard.. give that a try.