Return to BSD News archive
Xref: sserve comp.unix.bsd.freebsd.misc:2707 comp.unix.programmer:26660
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!nexus.coast.net!news.kei.com!news.mathworks.com!news.ultranet.com!news.sprintlink.net!howland.reston.ans.net!Germany.EU.net!zib-berlin.de!news.tu-chemnitz.de!irz401!uriah.heep!bonnie.heep!not-for-mail
From: j@bonnie.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc,comp.unix.programmer
Subject: Re: Direct access to I/O ports
Date: 22 Jun 1995 12:20:42 +0200
Organization: Private U**x site, Dresden.
Lines: 53
Message-ID: <3sbg5q$snj@bonnie.tcd-dresden.de>
References: <3s75qm$fn@spice.eppet.pt> <JKH.95Jun21143629@whisker.internet-eireann.ie>
Reply-To: joerg_wunsch@uriah.heep.sax.de
NNTP-Posting-Host: 192.109.108.139
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Jordan K. Hubbard <jkh@whisker.internet-eireann.ie> wrote:
> I'm currently running FreeBSD 2.x and I'd like to develop some C
> applications that directely access specific hardware ports.
>
>No problem. Just open /dev/io in your application and you'll then
>be granted the priviledge of executing the inb/outb instructions
>directly.
Umm Jordan, are you sure it's actually working right now? This one
used to be commented out with a /* broken */ comment in
sys/i386/i386/mem.c.
Anyway, one thing you can always do (as long as the machine has some
sort of video card and a configured syscons or pcvt driver) is the
following (basically also what the X server is doing):
#include <sys/file.h>
#include <machine/console.h>
#include <stdio.h>
#define GRFX_DEVICE "/dev/ttyv0"
int main(void)
{
int fd;
if((fd = open(GRFX_DEVICE, O_RDWR)) == 1) {
perror("open(GRFX_DEVICE)");
return 1;
}
if(ioctl(fd, KDENABIO, 0) == -1) {
perror("ioctl(KDENABIO)");
return 1;
}
printf("got IO privilege now, wow!\n");
return 0;
}
Of course, this process requires an effective UID of 0 (i.e. root
privilege), otherwise you'll get an ``Operation not permitted'' error
for the ioctl.
I'd also ask you to think about your problem; it's normally no good
practice to program IO ports directly from userland, this is rather
restricted to kernel drivers.
--
cheers, J"org private: joerg_wunsch@uriah.heep.sax.de
http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)