[prev in list] [next in list] [prev in thread] [next in thread]
List: bochs-dev
Subject: Re: [Bochs-developers] Keyboard interception question
From: Russell Miller <rmiller () duskglow ! com>
Date: 2005-06-21 19:51:03
Message-ID: 200506211251.03945.rmiller () duskglow ! com
[Download RAW message or body]
On Tuesday 21 June 2005 12:30, Daniel Gryniewicz wrote:
> possible. The problem is that DOS drivers access the hardware directly
> by invoking BIOS function mapped into specific locations in memory.
> These BIOS functions directly poke the harware. That kind of hardware
> access is not possible in protected mode in userspace, only in kernel
> space. You'd have to write a kernel level driver to directly emulate
> the DOS hardware interface, and then export that to userpsace, and then
> hook the output of the bochs BIOS to it. My guess is that would require
> enough information to write a real driver for Linux for the keyboard.
>
Regarding the access to the hardware not being possible in protected mode in
userspace, I respectfully say BS. :) Because I've done it, and I even have a
little program to do it. All you have to do is have permission to
access /dev/port. I wrote the proof of concept last night.
Basically, you read from position 0x64 and 0x60 in /dev/port, and write to
0x60.
Attached is the sample program that works under linux, just to prove it.
So now that that is out of the way, how do I hook the output of the BOCHS bios
to the userspace program?
Thanks.
--Russell
--
Russell Miller - rmiller@duskglow.com - Agoura, CA
["prg.c" (text/x-csrc)]
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#define CMD_E9 0xE9
#define ENABLE_KBD 0xF4
#define DISABLE_KBD 0xF5
#define ECHO_KBD 0xEE
#define RST_SELFTST_KBD 0xFF
void wait_for_kbd(int fd) {
char data;
do {
lseek(fd, 0x64, 0);
read(fd, &data, 1);
} while ((data & 2) == 2);
}
void write_kbd(int fd, unsigned char data) {
fprintf(stderr, "writing keyboard\n");
wait_for_kbd(fd);
lseek(fd, 0x60, 0);
write(fd, &data, 1);
}
void read_kbd(int fd, unsigned char *data) {
lseek(fd, 0x60, 0);
read(fd, data, 1);
}
void enable_kbd(int fd) {
fprintf(stderr, "enabling keyboard\n");
write_kbd(fd, 0xf4);
}
void disable_kbd(int fd) {
fprintf(stderr, "disabling keyboard\n");
write_kbd(fd, 0xf5);
}
int main(int argc, char **argv) {
int fd;
int tries = 0;
unsigned char data;
if ((fd = open("/dev/port", O_RDWR)) < 0) {
fprintf(stderr, "Cannot open /dev/port: %s\n", strerror(errno));
exit(1);
}
/* disable_kbd(fd);*/
data = RST_SELFTST_KBD;
write_kbd(fd, data);
data = 0;
fprintf(stderr, "reading keyboard\n");
do {
read_kbd(fd, &data);
if (tries == 200000) {
break;
}
tries++;
} while (data != ECHO_KBD);
/* enable_kbd(fd);*/
if (data == 0xaa) {
printf("test succeeded!\n");
} else {
printf("test failed! (data is %d)\n", data);
}
}
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
bochs-developers mailing list
bochs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bochs-developers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic