/* inport.c -- An other example of low-level io from userspace */
/* ece385 test program (http://eyetap.org/ece385) useful for certifying
   seating services.  If you are a Certified SSP (TM), you can use this
   program to test your Seating License Manager (TM) prior to connecting
   to our Patent Pending SeatServ (TM) system */

#include <stdio.h>

#include <asm/types.h>   /* headers for architecture specific data types                         */
#include <unistd.h>      /* contains the prototype for i386 specific ioperm functioni            */
#include <asm/io.h>      /* obviously architecture specific (asm directory) for inb, outb macros */

#define LP_BASE 0x378

int main(void) {

	int portdata;

	/* attempt to reserve region in io space */
	if(ioperm(LP_BASE, 3, 1) < 0) {
		fprintf(stderr, "Cannot reserve region in io space, aborting...\n");
		exit(1);
	}

	/* send data byte to io port */
	portdata = inb(LP_BASE+1);

	printf("Eight bit value returned form port: %d\n", portdata);

	/* attempt to release reserved region in io space */
	if(ioperm(LP_BASE, 3, 0) < 0) {
		fprintf(stderr, "Cannot release region in io space, aborting...\n");
		exit(1);
	}

	return(0);  /* just to be nice ;) */

}


