From ca70ceb048bcde0d5f2fc228b0762021a5de3e6a Mon Sep 17 00:00:00 2001 From: gfk Date: Mon, 29 Apr 2002 23:24:14 +0000 Subject: [PATCH] FreeBSD's i386_get_ioperm implemented. --- configure.in | 12 +++++++++++- server/drivers/port.h | 44 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/configure.in b/configure.in index c9e4f2d..8db5d38 100644 --- a/configure.in +++ b/configure.in @@ -83,10 +83,20 @@ AC_CHECK_LIB(kvm, kvm_open,[ dnl NetBSD, OpenBSD and FreeBSD AC_CHECK_HEADERS(sched.h sys/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 i386_get_ioperm on NetBSD&OpenBSD +AC_CHECK_LIB(i386, i386_get_ioperm, + AC_DEFINE([HAVE_I386_IOPERM_NETBSD],[1], + [Define if you have the NetBSD&OpenBSD version of i386_ioperm functions.]),[ + dnl i386_get_ioperm on FreeBSD + AC_CHECK_LIB(c, i386_get_ioperm, + AC_DEFINE([HAVE_I386_IOPERM_FREEBSD],[1], + [Define if you have the FreeBSD version of the i386_ioperm functions.]), + [])] +) + dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC diff --git a/server/drivers/port.h b/server/drivers/port.h index f388263..fb538b0 100644 --- a/server/drivers/port.h +++ b/server/drivers/port.h @@ -83,8 +83,8 @@ static inline int port_deny_full (unsigned short int port) { } /* ------------------------------------------------------------- */ -/* 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 +/* Use i386_get_ioperm, i386_set_ioperm, inb and outb from (NetBSD&OpenBSD) */ +#elif defined HAVE_I386_IOPERM_NETBSD && defined HAVE_MACHINE_PIO_H && defined HAVE_MACHINE_SYSARCH_H #include #include #include @@ -170,7 +170,45 @@ static inline int port_deny_full (unsigned short int port) { return 0; } -/* #endif // defined HAVE_LIBI386 && defined HAVE_SYS_TYPES_H && defined HAVE_MACHINE_PIO_H */ +/*#endif // defined HAVE_I386_IOPERM_NETBSD && defined HAVE_MACHINE_PIO_H && defined HAVE_MACHINE_SYSARCH_H +------------------------------------------------------------- +Use i386_get_ioperm, i386_set_ioperm and ASM inb and outb from (FreeBSD) */ +#elif defined HAVE_I386_IOPERM_FREEBSD && defined HAVE_MACHINE_SYSARCH_H +#include + +/* 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; +} + +/* 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 */ +static inline int port_access (unsigned short int port) { + return i386_set_ioperm(port, 1, 1); +} + +/* Get access 3 to ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */ +static inline int port_access_full (unsigned short int port) { + return i386_set_ioperm(port, 3, 1); +} + +/* Close access to a specific port */ +static inline int port_deny (unsigned short int port) { + return i386_set_ioperm(port, 1, 0); +} + +/* Close access to 3 ports: port (CONTROL), port+1 (STATUS) and port+2 (DATA) */ +static inline int port_deny_full (unsigned short int port) { + return i386_set_ioperm(port, 3, 0); +} /* ------------------------------------------------------------- */ /* Last chance! Use /dev/io and i386 ASM code (BSD4.3 ?) */