The 8042 microcontroller

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
BugHunter

The 8042 microcontroller

Post 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 ;)
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:The 8042 microcontroller

Post 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.
evincarofautumn

Re:The 8042 microcontroller

Post 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
bluecode

Re:The 8042 microcontroller

Post by bluecode »

Yes, but only if you're in real-mode and only if the bios is called upon irq0.
BugHunter

Re:The 8042 microcontroller

Post 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?
BugHunter

Re:The 8042 microcontroller

Post 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 :)
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:The 8042 microcontroller

Post by bubach »

Simply turn all LED's off, and you'll know in which state they are.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re:The 8042 microcontroller

Post 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
...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Kemp

Re:The 8042 microcontroller

Post 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.
Post Reply