Subject: Re: Direct I/O from user program
To: Peter C. Wallace <pcw@mesanet.com>
From: Andrew Gillham <gillhaa@ghost.whirlpool.com>
List: netbsd-help
Date: 06/23/2000 16:19:35
Peter C. Wallace writes:
> 	This may be the wrong way to do things... but... how do you do
> direct access to (i386) I/O locations from a userland program. (I want to
> write a quick demo for the A-D on one of our embedded cards, a 386SX
> running NetBSD from flash)

Cheap version:

#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <machine/sysarch.h>
#include <machine/pio.h>

main()
{
	if (i386_iopl(3) != 0) {
		perror("i386_iopl");
		return;
	}
	printf("inb: 0x%x\n", inb(0x100));
}		

Then:
# cc -o port port.c -li386

You need to be root to call i386_iopl(2), see the manpage.

-Andrew
-- 
-----------------------------------------------------------------
Andrew Gillham                            | NetBSD ist Affengeil.
gillham@whirlpool.com                     | Nachts ist es kaelter
I speak for myself, not for my employer.  | als draussen.