Is Dell Keyboard Controller acting odd?

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
vbbrett
Posts: 5
Joined: Sat May 07, 2005 11:00 pm

Is Dell Keyboard Controller acting odd?

Post 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
vbbrett
Posts: 5
Joined: Sat May 07, 2005 11:00 pm

Re: Is Dell Keyboard Controller acting odd?

Post 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?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is Dell Keyboard Controller acting odd?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Is Dell Keyboard Controller acting odd?

Post 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
ThymeCypher
Posts: 21
Joined: Tue Mar 24, 2009 10:59 am

Re: Is Dell Keyboard Controller acting odd?

Post 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.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Is Dell Keyboard Controller acting odd?

Post 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
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: Is Dell Keyboard Controller acting odd?

Post 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.
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Post Reply