Page 1 of 1

The 8042 microcontroller

Posted: Wed Aug 16, 2006 7:21 am
by BugHunter
Last days I've been working on a keyboard handler for my OS.

I've come across a problem (who won't ;)) while working with the 8042 microcontroller. :)

At startup of my OS, I want to save the current keyboard LED's state directly after the bootstrap that loads the kernel transfers control to the kernel.

When sending 0xED to keyboard port 0x60, then waiting, and sending LED's status to port 0x60 will update the LED's status on the keyboard. But what I want is to READ the current LED's status from the keyboard, then turn off all LED's except Num Lock, so I can save the status and still let the user have preference on if Num Lock should be ON / OFF at startup (this is changeable in the BIOS as most here will know).

I've read this thread, it gave me good insight on how the which ports do what and where the 8042 is located.

A note on the thread mentioned above, the thread starter posts that KB_CAPS_LOCK equals to 1 binary, but it should be 100 binary, is that right? Also he posts KB_SCROLL_LOCK equals to 101 binary, but it should be 1 binary, is that right too? AFAIK, the KB_NUM_LOCK equate is right, correct me if I'm wrong.

Also I would like to know what the bits in status byte in 0x64 really mean and how to use it (a link to a good document would be great)

EDIT: I've found this page, seems to have interesting information, I saved it to my USB stick and I will read it at home since I moved and have no Internet conn. yet.

Many thanks ;)

Re:The 8042 microcontroller

Posted: Thu Aug 17, 2006 2:08 am
by durand
For a detailed explanation of which bits mean what on almost all ports, have a look at Ralf Brown's Interrupt List (RBIL) which also includes ports & stuff.

http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html

That will help you with your port 0x64 question and maybe some more.

Re:The 8042 microcontroller

Posted: Thu Aug 17, 2006 7:53 pm
by evincarofautumn
Isn't it true that the values of the keyboard modifiers are saved at 0x0000:0417? (or something like that, iirc something involving the number 1047) I don't recall whether this is a system thing or something found only in DOS. :D

Re:The 8042 microcontroller

Posted: Thu Aug 17, 2006 11:44 pm
by bluecode
Yes, but only if you're in real-mode and only if the bios is called upon irq0.

Re:The 8042 microcontroller

Posted: Fri Aug 18, 2006 6:45 am
by BugHunter
durand wrote: For a detailed explanation of which bits mean what on almost all ports, have a look at Ralf Brown's Interrupt List (RBIL) which also includes ports & stuff.

http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html

That will help you with your port 0x64 question and maybe some more.
Great, thanks, I already had RBIL but never saw information on ports, can you tell me in which section I can find it? This question might look stupid but maybe I had a crippled RIBL...

EDIT: Got it ;)
EDIT2: Is there any good way/tool to view the PORTS.A / PORTS.B files?

Re:The 8042 microcontroller

Posted: Fri Aug 18, 2006 7:07 am
by BugHunter
Now I've checked docs but can't find information on how to READ the current LED status from keyboard :(

Does anyone know how to do this? Or can I read the Num Lock ON/OFF option from the Bios Data Area and use that, because basically that is all I want, I want to know if Num Lock is set to ON or OFF by the user option in BIOS or by reading it from keyboard.

If anyone can help me with it, great thanks :)

Re:The 8042 microcontroller

Posted: Fri Aug 18, 2006 6:28 pm
by bubach
Simply turn all LED's off, and you'll know in which state they are.

Re:The 8042 microcontroller

Posted: Sat Aug 19, 2006 3:50 am
by Combuster
I once had some qbasic code that changed kb leds individually, but it actually uses the BDA for that

http://www.sysbin.com/files/hard/keyboardfaq.rar (RAR, sry linux folks)
the document in the url hints there is no standard way to directly read led status from the keyboard/KBC and the only way to get keyboard info is by reading from the BDA.

So yes, you can read the status from the BDA

from the document
Address Size Contents
...
0:0497 1 AT Keyboard flag for LED 'key lock' display
bits 0-2 are ScrollLock, NumLock, CapsLock respectively
...

Re:The 8042 microcontroller

Posted: Sat Aug 19, 2006 8:59 am
by Kemp
RAR, sry linux folks
The (admittedly few) distros I've seen have never had problems with rars, just using tools that shipped with them.