#include <stdio.h>
#include <asm/types.h>
#include <unistd.h>
#include <asm/io.h>

#define LP_BASE 0x3bc

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);
	}

	portdata = inb(LP_BASE);

	printf("Data port:    0x%04x=0x%02x\n", LP_BASE,inb(LP_BASE));
	printf("Status port:  0x%04x=0x%02x\n", LP_BASE+1,inb(LP_BASE+1));
	printf("Control port: 0x%04x=0x%02x\n", LP_BASE+2, inb(LP_BASE+2));

	/* 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 ;) */

}
