mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Raw I/O Problems with inb()
@ 2004-01-16  2:52 Brett Gmoser
  2004-01-16 11:27 ` Matthias Urlichs
  0 siblings, 1 reply; 5+ messages in thread
From: Brett Gmoser @ 2004-01-16  2:52 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Raw I/O Problems with inb()
  2004-01-16  2:52 Raw I/O Problems with inb() Brett Gmoser
@ 2004-01-16 11:27 ` Matthias Urlichs
  2004-01-16 14:51   ` Brett Gmoser
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Urlichs @ 2004-01-16 11:27 UTC (permalink / raw)
  To: linux-kernel

Hi, Brett Gmoser wrote:

> Thanks in advance for any insight you all may be able to give me

Reading port registers directly doesn't make sense. No USB keyboards, no
remote use, ... you need to drop your DOS programming mentaility. Fast.

You can use a PTY approach like script(1), or you can write a small kernel
module like evbug (see the kernel source, drivers/input/evbug.c) which
monitors everything the user is doing.

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
 - -
There are two distinct sorts of what we call bashfulness; this, the
awkwardness of a booby, which a few steps into the world will convert into the
pertness of a cox comb; that, a consciousness, which the most delicate
feelings produce, and the most extensive knowledge cannot always remove.
					-- Mackenzie


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Raw I/O Problems with inb()
  2004-01-16 11:27 ` Matthias Urlichs
@ 2004-01-16 14:51   ` Brett Gmoser
  2004-01-16 17:41     ` Matthias Urlichs
  0 siblings, 1 reply; 5+ messages in thread
From: Brett Gmoser @ 2004-01-16 14:51 UTC (permalink / raw)
  To: Matthias Urlichs; +Cc: linux-kernel


>Reading port registers directly doesn't make sense. No USB keyboards, no
>remote use, ... you need to drop your DOS programming mentaility. Fast.

Thanks for your input.  However, I do not want the application to work 
remotely.  I have examined all other options, and this is the best way to 
do it under the circumstances which I need this program to work.

The question is not one of "how" to accomplish all of this, it is how to 
get inb(0x64) to state that it is indeed mouse movement, and not keyboard 
data, on an AMD Athlon XP system with PS/2 mouse.

Thanks again!

Brett



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Raw I/O Problems with inb()
  2004-01-16 14:51   ` Brett Gmoser
@ 2004-01-16 17:41     ` Matthias Urlichs
  2004-01-17  2:12       ` [linuxkernel] " Brett Gmoser
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Urlichs @ 2004-01-16 17:41 UTC (permalink / raw)
  To: linux-kernel

Hi, Brett Gmoser wrote:

> The question is not one of "how" to accomplish all of this, it is how to 
> get inb(0x64) to state that it is indeed mouse movement, and not keyboard 
> data, on an AMD Athlon XP system with PS/2 mouse.

Well, as I said, I would solve the "how" problem with a kernel module
which monitors mouse movement or keyboard events. This happens to be a
whole lot more reliable, and it will also eat no CPU time when nothing's
happening.

Plus, it will work on any mouse or keyboard. People actually _use_ USB
critters these days, you know ...

-- 
Matthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
 - -
Sign my PETITION.
		-- Zippy the Pinhead


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [linuxkernel] Re: Raw I/O Problems with inb()
  2004-01-16 17:41     ` Matthias Urlichs
@ 2004-01-17  2:12       ` Brett Gmoser
  0 siblings, 0 replies; 5+ messages in thread
From: Brett Gmoser @ 2004-01-17  2:12 UTC (permalink / raw)
  To: Matthias Urlichs; +Cc: linux-kernel

Thanks very much for your insight.  I do appreciate it.

I do agree that the next step will be to write a kernel module.  However, I would like to see if it is feasible to do this with inb(), since I see no very easy way around the fact that I do not want the program to work remotely.

Really, the question boils down to this: Is the keyboard status port on AMD systems 0x64, or is it something else?  If so, what is it?

Thank you!

Brett

On Fri, 16 Jan 2004 18:41:25 +0100
Matthias Urlichs <smurf@smurf.noris.de> wrote:

> Well, as I said, I would solve the "how" problem with a kernel module
> which monitors mouse movement or keyboard events. This happens to be a
> whole lot more reliable, and it will also eat no CPU time when nothing's
> happening.
> 
> Plus, it will work on any mouse or keyboard. People actually _use_ USB
> critters these days, you know ...
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-01-17  2:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-16  2:52 Raw I/O Problems with inb() Brett Gmoser
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

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®