Index: cmos_lowlevel.c =================================================================== --- cmos_lowlevel.c (revision 3704) +++ cmos_lowlevel.c (working copy) @@ -28,7 +28,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. \*****************************************************************************/ +#if defined(__GLIBC__) #include +#endif + +#if defined(__FreeBSD__) +#include +#include +#endif + #include "common.h" #include "cmos_lowlevel.h" @@ -176,8 +184,8 @@ port_1 = 0x73; } - outb(index, port_0); - return inb(port_1); + OUTB(index, port_0); + return INB(port_1); } /**************************************************************************** @@ -204,8 +212,8 @@ port_1 = 0x73; } - outb(index, port_0); - outb(value, port_1); + OUTB(index, port_0); + OUTB(value, port_1); } /**************************************************************************** @@ -248,8 +256,35 @@ * level is therefore somewhat dangerous. ****************************************************************************/ void set_iopl (int level) - { assert((level >= 0) && (level <= 3)); + { +#if defined(__FreeBSD__) + static int io_fd = -1; +#endif + assert((level >= 0) && (level <= 3)); + +#if defined(__FreeBSD__) + if (level == 0) + { + if (io_fd != -1) + { + close(io_fd); + io_fd = -1; + } + } + else + { + if (io_fd == -1) + { + io_fd = open("/dev/io", O_RDWR); + if (io_fd < 0) + { + perror("/dev/io"); + exit(1); + } + } + } +#else if (iopl(level)) { fprintf(stderr, "%s: iopl() system call failed. You must be root to do " @@ -257,6 +292,7 @@ prog_name); exit(1); } +#endif } /**************************************************************************** Index: common.h =================================================================== --- common.h (revision 3704) +++ common.h (working copy) @@ -43,6 +43,25 @@ #include #include +#if defined(__FreeBSD__) +#include +#include +#define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0) +#define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0) +#define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0) +#define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); }) +#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); }) +#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); }) +#else +#define OUTB OUTB +#define OUTW outw +#define OUTL outl +#define INB INB +#define INW inw +#define INL inl +#endif + + #define FALSE 0 #define TRUE 1