LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2010, 03:26 AM   #1
ankur0921
LQ Newbie
 
Registered: May 2009
Posts: 25

Rep: Reputation: 0
Thumbs up Writing on keyboard port via inb(), outb() system calls


Hi All,

I am working with fedora 6 , i386 architecture.I am trying to write on keyboard port via program.On inspation i come to know that 0x0060 to 0xz006f are used for keyboard in linux 2.6 kernel in the i/o space from kernel.

#include<sys/io.h>
#include<stdio.h>
#include</usr/lib/syslinux/com32/include/sys/io.h>
#include<unistd.h>
//#define
/*
Port Rd/Wte Function
0x60 Read Read Input Buffer
0x60 Write Write Output Buffer
0x64 Read Read Status Register
0x64 Write Send Command

0060-006f : keyboard */
/*
#define I8042_COMMAND_REG 0x64
#define I8042_STATUS_REG 0x64
#define I8042_DATA_REG 0x60
*/
//inb(value,port)
int main()
{
printf("%c",0x50);
printf("Accessing Permission = %d",iopl(3));
outb(0x50,0x0060);
//printf("\n Accessing Permission = %d",iopl(3));
printf("\n Read Character, data = %c,\tstatus = %d,\t command = %d",inb(0x0060),inb(0x0064),inb(0x0064));
}

compiling command is :gcc -O2 -o port port.c
where port.c : program
port : target object file

In this program i am not able to write on the keyboard port.

Can anybody help in this matter ? What could be the flaw, where is the issue?

Thanks.

Ankur
 
Old 04-05-2010, 11:38 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

The commands you're talking about are implemented in the BIOS (not in the x86 processor per se).

The whole purpose of an OS is to *insulate* you from the BIOS (and other low-level, hardware details).

Short answer: you can do it ... but it'll take considerably more effort than you might think.

Strong suggestion:
If you want "unbuffered keyboard I/O", then I strongly urge you to consider using a library like SDL (for "games-like" interfaces), or ncurses (for text-mode).

IMHO .. PSM
 
Old 04-06-2010, 12:30 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
What paulsm4 said...
Do you know what writing to the keyboard will accomplish? If you really want to write to x86 IO ports, you can use the ioperm() + outb() family of functions, or the /dev/port interface. You will require root privileges to do this. There is quite likely an existing driver accessing that hardware, and you may be disallowed access altogether, or at best you will be competing for access to the hardware by said driver.

If this is more than just a target to practice throwing bytes at, I would be most interested in your application, especially if it is to for some novel way of using a PC keyboard interface.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel Port to USB controller and outb() eteck Programming 8 06-05-2009 06:35 AM
Capturing Keystrokes in linux. APIs or System calls to capture keyboard strokes abhinav.zoso Programming 3 01-10-2009 11:14 AM
outb() unable to write on the registered port. avinashkharbanda Programming 4 08-27-2008 05:30 AM
different ports for use in inb, outb prashmohan Programming 0 11-23-2004 12:39 AM
inb,outb macro help prashmohan Programming 2 11-22-2004 12:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration