From: Brett Gmoser <aftli@optonline.net>
To: linux-kernel@vger.kernel.org
Subject: Raw I/O Problems with inb()
Date: Thu, 15 Jan 2004 21:52:43 -0500 [thread overview]
Message-ID: <20040115215243.39fcb0fd.aftli@optonline.net> (raw)
Hello everybody.
I apologize if this is off topic, but I have seen relevant information posted to this list, even though this isn't actually a kernel programming problem. And believe me, I have searched everywhere else for a solution to this problem.
To give some short background information, I am programming the Linux client for a project that basically counts a users keystrokes, and sends the amount to a server which displays the count for all the world to see. Teams and individuals compete from around the world, and we are approaching 5000 members.
At any rate, the application is written in C/C++. I am using iopl() for permissions management, and inb() for reading raw data directly from the PS/2 keyboard to test if a key has been pressed. All of this works great, and the program is complete, except for one problem.
It seems that on Athlon XP systems using PS/2 mice, inb(0x64) always says there is data waiting from the keyboard, when it is in fact mouse data. I assume that different architecture on AMD systems is the cause of the problem, but is there a solution? There must be. Here is a snippet of the code I am using currently. I apologize for the sloppiness of it - it's been modified about 30 times with 30 different solutions to the problem, all of which did not seem to fix it. Commented out are solutions that I have tried and have not worked.
#define KEYBOARD_PORT 0x60
#define KEYBOARD_STATUS_PORT 0x64
bool keycounter::count(/*wplog* l*/) { // some very simple code to see if a key is being pressed or not.
const unsigned char kbd_read_mask = 0x01;
unsigned char status = inb_p(KEYBOARD_STATUS_PORT);
/* unsigned char status = inb(KEYBOARD_STATUS_PORT);
/* mouse data? */
// if (status == 20 && ((status & kbd_read_mask) != 0x01) || (status & 0x21)) { fflush(0); return false; }
// if(status & kbd_read_mask & 0x20) { fflush(0); return false; }
// if(!(status & kbd_read_mask & 0x01)) { fflush(0); return false; }
// if(!((inb(0x379) & 0x20) == 0x20)) { fflush(0); return false; }
if(status!=20) { fflush(0); return false; }
unsigned char c = inb(KEYBOARD_PORT);
if(status==20 && c < TABLE_SIZE) {
if(c==lastc) {
fflush(0);
return false;
}
lastc=c;
fflush(0);
return true;
}
else { // key has been lifted
lastc=0;
fflush(0);
return false;
}
}
Thanks in advance for any insight you all may be able to give me
--
Brett Gmoser
aftli@optonline.net
next reply other threads:[~2004-01-16 2:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-16 2:52 Brett Gmoser [this message]
2004-01-16 11:27 ` Matthias Urlichs
2004-01-16 14:51 ` Brett Gmoser
2004-01-16 17:41 ` Matthias Urlichs
2004-01-17 2:12 ` [linuxkernel] " Brett Gmoser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040115215243.39fcb0fd.aftli@optonline.net \
--to=aftli@optonline.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®