The example code I pasted earlier didn't compile, and I made a few changes.

/*
 * iopl.c: very simple example of port I/O
 *
 * This code does nothing useful, just a port write, a pause,
 * and a port read. Compile with `gcc -O2 iopl.c -o iopl.o',
 * and run as root with `./iopl.o'.
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#include <stdlib.h>

#define BASEPORT 0x378 /* lp1 */

int main()
{
  /* Get access to the ports */
  if (iopl(3)) {perror("iopl"); exit(1);}

  /* Set the data signals (D0-7) of the port to all low (0) */
  outb(0, BASEPORT);

  /* Sleep for a while (100 ms) */
  usleep(100000);

  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n", inb(BASEPORT + 1));

  /* We don't need the ports anymore */
  if (iopl(3)) {perror("iopl"); exit(1);}

  exit(0);
}

/* end of iopl.c */

I get this error:

iopl: Function not implemented

So I switch to ioperm() using this code:

/*
 * ioperm.c: very simple example of port I/O
 *
 * This code does nothing useful, just a port write, a pause,
 * and a port read. Compile with `gcc -O2 ioperm.c -o ioperm.o',
 * and run as root with `./ioperm.o'.
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#include <stdlib.h>

#define BASEPORT 0x378 /* lp1 */

int main()
{
  /* Get access to the ports */
  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

  /* Set the data signals (D0-7) of the port to all low (0) */
  outb(0, BASEPORT);

  /* Sleep for a while (100 ms) */
  usleep(100000);

  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n", inb(BASEPORT + 1));

  /* We don't need the ports anymore */
  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}

  exit(0);
}

/* end of ioperm.c */

Then same thing except for ioperm:

ioperm: Function not implemented

Posting code here because I'm going to test this code on a Debian system.. Feel 
free to try this out on your end.. I'll post my results in a second.

I don't mean to flood the mailing list btw!

Alec


_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to