From 09b4ff9271e2dca70fd05e32d8f408f095846d95 Mon Sep 17 00:00:00 2001 From: gfk Date: Tue, 25 Dec 2001 19:28:54 +0000 Subject: [PATCH] Partial port of the server to OpenBSD and NetBSD/i386. --- acinclude.m4 | 56 +++++++++++- configure.in | 14 ++- server/drivers/lcd_sem.c | 8 +- server/drivers/port.h | 179 ++++++++++++++++++++++++++++++--------- 4 files changed, 212 insertions(+), 45 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 2d830dd..6e4e18f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -248,7 +248,6 @@ AC_DEFUN([AC_FIND_MTAB_FILE], [ fi ]) - dnl dnl Filesystem information detection dnl @@ -420,3 +419,58 @@ AC_DEFUN(AC_GET_FS_INFO, [ dnl fi ]) +dnl 1.1 (2001/07/26) -- Miscellaneous @ ac-archive-0.5.32 +dnl Warren Young +dnl This macro checks for the SysV IPC header files. It only checks +dnl that you can compile a program with them, not whether the system +dnl actually implements working SysV IPC. +dnl http://ac-archive.sourceforge.net/Miscellaneous/etr_sysv_ipc.html +AC_DEFUN([ETR_SYSV_IPC], +[ +AC_CACHE_CHECK([for System V IPC headers], ac_cv_sysv_ipc, [ + AC_TRY_COMPILE( + [ + #include + #include + #include + #include + #include + ],, ac_cv_sysv_ipc=yes, ac_cv_sysv_ipc=no) +]) + + if test x"$ac_cv_sysv_ipc" = "xyes" + then + AC_DEFINE(HAVE_SYSV_IPC, 1, [ Define if you have System V IPC ]) + fi +]) dnl ETR_SYSV_IPC + +dnl 1.1 (2001/07/26) -- Miscellaneous @ ac-archive-0.5.32 +dnl Warren Young +dnl This macro checks to see if sys/sem.h defines union semun. Some +dnl systems do, some systems don't. Your code must be able to deal with +dnl this possibility; if HAVE_STRUCT_SEMUM isn't defined for a given system, +dnl you have to define this structure before you can call functions +dnl like semctl(). +dnl You should call ETR_SYSV_IPC before this macro, to separate the check +dnl for System V IPC headers from the check for struct semun. +dnl http://ac-archive.sourceforge.net/Miscellaneous/etr_struct_semun.html +AC_DEFUN([ETR_UNION_SEMUN], +[ +AC_CACHE_CHECK([for union semun], ac_cv_union_semun, [ + AC_TRY_COMPILE( + [ + #include + #include + #include + ], + [ union semun s ], + ac_cv_union_semun=yes, + ac_cv_union_semun=no) +]) + + if test x"$ac_cv_union_semun" = "xyes" + then + AC_DEFINE(HAVE_UNION_SEMUN, 1, + [ Define if your system's sys/sem.h file defines union semun ]) + fi +]) dnl ETR_UNION_SEMUN diff --git a/configure.in b/configure.in index 255d083..22cf2e9 100644 --- a/configure.in +++ b/configure.in @@ -23,10 +23,10 @@ AC_ARG_ENABLE(debug, AC_MSG_RESULT($debug) if test $debug = "yes"; then -dnl Enable debugging information - CFLAGS="-g" +dnl Enable debugging information with minimal optimisation + CFLAGS="-g -O" else -dnl Maximum optimization +dnl Maximum optimisation CFLAGS="-O3" fi CFLAGS="-Wall $CFLAGS" @@ -65,10 +65,16 @@ AC_CHECK_LIB(kvm, kvm_open,[ fi ]) +dnl NetBSD, OpenBSD and FreeBSD +AC_CHECK_HEADERS(sched.h sys/types.h machine/pio.h machine/sysarch.h) +AC_CHECK_LIB(i386, i386_get_ioperm) +ETR_SYSV_IPC +ETR_UNION_SEMUN + dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC -AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h) +AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h sys/io.h) dnl Check for particular preprocessor macros diff --git a/server/drivers/lcd_sem.c b/server/drivers/lcd_sem.c index 787a5f5..f1e34cd 100644 --- a/server/drivers/lcd_sem.c +++ b/server/drivers/lcd_sem.c @@ -21,6 +21,7 @@ * $Id$ */ +#include #include #include #include /* for semaphore functions */ @@ -30,8 +31,9 @@ #include "lcd_sem.h" -#ifdef _SEM_SEMUN_UNDEFINED -/* according to X/OPEN we have to define it ourselves */ +// according to X/OPEN we have to define it ourselves +//#ifdef _SEM_SEMUN_UNDEFINED +#ifndef HAVE_UNION_SEMUN union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ @@ -148,6 +150,7 @@ sem_signal (int sid) int sem_remove (int sid) { +#ifdef EIDRM int i; union semun dummy; @@ -163,5 +166,6 @@ sem_remove (int sid) } } +#endif return 0; } diff --git a/server/drivers/port.h b/server/drivers/port.h index 20b4ec8..ce84f18 100644 --- a/server/drivers/port.h +++ b/server/drivers/port.h @@ -1,68 +1,171 @@ #ifndef PORT_H #define PORT_H -/*----------------------------------------------------------------------------- - * port.h (by damianf@wpi.edu) + +/* $id$ * Low level I/O functions taken from led-stat.txt - * - * Jan 22 95 + * Jan 22 95 copyright damianf@wpi.edu * * DOS part (tested only with DOS version of GCC, DJGPP) * by M.Prinke 3/97 + * + * FreeBSD support by Guillaume Filion and Philip Pokorny, copyright 05/2001 + * + * NetBSD port by Guillaume Filion, copyright 12/2001 */ -/* #define DOS */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include #endif -#ifndef DOS -static inline int -port_in (int port) -{ +#include + +/* +This file defines 4 static inline functions for port I/O: + +// Read a byte from port +static inline int port_in (unsigned short int port); +// Returns the content of the byte. + +// Write a char(byte) 'val' to port. +static inline void port_out (unsigned short int port, unsigned char val); +// Returns nothing. + +// Get access to a specific port +static inline int port_access (unsigned short int port); +// Returns 0 if successful, -1 if failed + +// Get access 3 to ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) +static inline int port_access_full (unsigned short int port); +// Returns 0 if successful, -1 if failed +*/ + +// ------------------------------------------------------------- +// Use ioperm, inb and outb in (Linux) +#if defined HAVE_IOPERM && HAVE_SYS_IO_H +#include + +// Read a byte from port +static inline int port_in (unsigned short int port) { + return inb(port); +} + +// Write a byte 'val' to port +static inline void port_out (unsigned short int port, unsigned char val) { + outb(val, port); +} + +// Get access to a specific port +static inline int port_access (unsigned short int port) { + return ioperm(port, 1, 255); +} + +// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) +static inline int port_access_full (unsigned short int port) { + return ioperm(port, 3, 255); +} + +// ------------------------------------------------------------- +// Use i386_get_ioperm, i386_set_ioperm, inb and outb from (NetBSD) +#elif defined HAVE_LIBI386 && defined HAVE_MACHINE_PIO_H && defined HAVE_MACHINE_SYSARCH_H +#include +#include +#include + +// Read a byte from port +static inline int port_in (unsigned short int port) { + return inb(port); +} + +// Write a byte 'val' to port +static inline void port_out (unsigned short int port, unsigned char val) { + outb(port, val); +} + +static inline void setaccess(u_long * map, u_int bit, int allow) { + u_int word; + u_int shift; + u_long mask; + + word = bit / 32; + shift = bit - (word * 32); + + mask = 0x000000001 << shift; + if (allow) + map[word] &= ~mask; + else + map[word] |= mask; +} + +// Get access to a specific port +static inline int port_access (unsigned short int port) { + u_long iomap[32]; + + if (i386_get_ioperm(iomap) == -1) return -1; + + setaccess(iomap, port , 1); + + if (i386_set_ioperm(iomap) == -1) return -1; + + return 0; +} + +// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) +static inline int port_access_full (unsigned short int port) { + u_long iomap[32]; + + if (i386_get_ioperm(iomap) == -1) return -1; + + setaccess(iomap, port , 1); + setaccess(iomap, port+1, 1); + setaccess(iomap, port+2, 1); + + if (i386_set_ioperm(iomap) == -1) return -1; + + return 0; +} + +//#endif // defined HAVE_LIBI386 && defined HAVE_SYS_TYPES_H && defined HAVE_MACHINE_PIO_H + +// ------------------------------------------------------------- +// Last chance! Use /dev/io and i386 ASM code (BSD4.3 ?) +#else + +// Read a byte from port +static inline int port_in (unsigned short int port) { unsigned char value; __asm__ volatile ("inb %1,%0":"=a" (value) :"d" ((unsigned short) port)); return value; } -static inline void -port_out (unsigned short int port, unsigned char val) -{ +// Write a byte 'val' to port +static inline void port_out (unsigned short int port, unsigned char val) { __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port) ); } -/*** - *** Get access to a specific port - ***/ -#ifdef HAVE_IOPERM -/* Assume this is a LINUX system with ioperm */ -#include +// Get access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) +static inline int port_access_full (unsigned short int port) { + static FILE * port_access_handle = NULL ; -static inline int -port_access (unsigned short int port) -{ - return ioperm( port, 1, 255); -} - -#else -/* Assume this is a BSD system */ -#include - -FILE * port_access_handle = NULL ; - -static inline int -port_access (unsigned short int port) -{ if( port_access_handle || (port_access_handle = fopen("/dev/io", "rw")) != NULL ) { - return( 0 ); /* Success */ + return( 0 ); // Success } else { - return( -1 ); /* Failure */ + return( -1 ); // Failure }; + + return -1; } + +// Get access to a specific port +static inline int port_access (unsigned short int port) { + return port_access_full(port); // /dev/io gives you access to all ports. +} + #endif +/* #else #include @@ -80,6 +183,6 @@ port_out (unsigned int port, unsigned char val) outportb ((unsigned short) port, val); } #endif +*/ -/**** END OF FILE ****/ -#endif +#endif // PORT_H