PDA

View Full Version : Parallel Port (inb, outb, /sys/io.h)


Hornpipe2
September 1st, 2009, 06:04
I'm trying to port this old Linux tool to FreeBSD: http://outflux.net/software/pkgs/EPROM/

It controls an EPROM burner through the parallel port. But it uses inb, outb and ioperm functions and is not building properly on my FreeBSD-7.1 server. I get the error "cannot find sys/io.h", and when I modify that to ioctl.h instead, I get a new set of errors:

gcc -o 27c801 27c801.c -Wall -O2 -fomit-frame-pointer
27c801.c: In function 'write_from_file':
27c801.c:166: warning: implicit declaration of function 'outb'
27c801.c:229: warning: implicit declaration of function 'inb'
27c801.c: In function 'startup':
27c801.c:429: warning: implicit declaration of function 'ioperm'
/var/tmp//cc5OEHEF.o(.text+0xa6): In function `shutdown':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0xcd): In function `shutdown':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0xf4): In function `shutdown':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x11b): In function `shutdown':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x142): In function `shutdown':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x157): more undefined references to `outb' follow
/var/tmp//cc5OEHEF.o(.text+0x3d2): In function `read_to_file':
: undefined reference to `inb'
/var/tmp//cc5OEHEF.o(.text+0x40f): In function `read_to_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x436): In function `read_to_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x45d): In function `read_to_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x532): In function `read_to_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x559): In function `read_to_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x580): more undefined references to `outb' follow
/var/tmp//cc5OEHEF.o(.text+0x6bc): In function `startup':
: undefined reference to `ioperm'
/var/tmp//cc5OEHEF.o(.text+0x6d4): In function `startup':
: undefined reference to `inb'
/var/tmp//cc5OEHEF.o(.text+0x6f9): In function `startup':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x720): In function `startup':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x747): In function `startup':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x76e): In function `startup':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x795): In function `startup':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x7aa): more undefined references to `outb' follow
/var/tmp//cc5OEHEF.o(.text+0x1049): In function `write_from_file':
: undefined reference to `inb'
/var/tmp//cc5OEHEF.o(.text+0x1072): In function `write_from_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x10e2): In function `write_from_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x1109): In function `write_from_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x1130): In function `write_from_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x1157): In function `write_from_file':
: undefined reference to `outb'
/var/tmp//cc5OEHEF.o(.text+0x117e): more undefined references to `outb' follow
*** Error code 1

Stop in /root/27c801-programmer-1.2.

Can someone help me figure a quick fix to this? I know there is a parallel port library that is supposed to simplify this but I don't want to re-code the application if there's just a magic header file and library I'm missing.

ephemera
September 1st, 2009, 11:46
Try:

--- eeprom.orig.c 2009-09-01 15:05:06.000000000 +0530
+++ eeprom.c 2009-09-01 15:08:19.000000000 +0530
@@ -31,7 +31,7 @@

// scheduler prioriety
#include <sched.h>
-#include <sys/io.h>
+#include <machine/cpufunc.h>

// stat
#include <sys/types.h>
@@ -56,8 +56,8 @@
#define C3 (1<<3)
#define DIR_READ (1<<5)

-#define SET_BITS(value) { CTRL |= (value); outb(CTRL,CTRL_PORT); }
-#define CLR_BITS(value) { CTRL &= ~(value); outb(CTRL,CTRL_PORT); }
+#define SET_BITS(value) { CTRL |= (value); outb(CTRL_PORT,CTRL); }
+#define CLR_BITS(value) { CTRL &= ~(value); outb(CTRL_PORT,CTRL); }

#define START_READ SET_BITS(DIR_READ);
#define START_WRITE CLR_BITS(DIR_READ);
@@ -88,7 +88,7 @@
#define PROGRAM_ON { START_WRITE; SET_BITS(C3); }

#define DATA_GET (inb(DATA_PORT))
-#define DATA_PUT(byte) { outb(byte,DATA_PORT); }
+#define DATA_PUT(byte) { outb(DATA_PORT,byte); }

#define INIT { \
PROGRAM_OFF; \
@@ -402,7 +402,7 @@
INIT;

// reset control states
- outb(orig,CTRL_PORT);
+ outb(CTRL_PORT,orig);
}

void get_realtime()
@@ -426,7 +426,7 @@
void startup()
{
// get perms to the ports
- if (ioperm(PARALLEL_PORT,3,1)<0)
+ if (i386_set_ioperm(PARALLEL_PORT,3,1)<0)
{
perror("ioperm");
exit(1);


Warning: It should compile now but I don't know if the program will actually work as intended.

Hornpipe2
September 1st, 2009, 16:13
Thanks! That got it to build (I threw in a #include <machine/sysarch.h> which cured the "warning: implicit declaration of function 'i386_set_ioperm'")

I'm still building the burner so it may be a while before I can try it. The software does have a simple test mode, so I'll be able to figure out if it worked before I try it out on anything breakable : )