2 #include "cmos_lowlevel.h"
4 #if defined(__FreeBSD__)
6 #include <machine/cpufunc.h>
7 #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
8 #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
9 #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
10 #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
11 #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
12 #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
14 #if defined(__GLIBC__)
17 #if (defined(__MACH__) && defined(__APPLE__))
18 #include <DirectIO/darwinio.h>
28 static void cmos_hal_init(void* data);
29 static unsigned char cmos_hal_read(unsigned addr);
30 static void cmos_hal_write(unsigned addr, unsigned char value);
31 static void cmos_set_iopl(int level);
33 /* no need to initialize anything */
34 static void cmos_hal_init(__attribute__((unused)) void *data)
38 static unsigned char cmos_hal_read(unsigned index)
40 unsigned short port_0, port_1;
42 assert(!verify_cmos_byte_index(index));
56 static void cmos_hal_write(unsigned index, unsigned char value)
58 unsigned short port_0, port_1;
60 assert(!verify_cmos_byte_index(index));
75 /****************************************************************************
78 * Set the I/O privilege level of the executing process. Root privileges are
79 * required for performing this action. A sufficient I/O privilege level
80 * allows the process to access x86 I/O address space and to disable/reenable
81 * interrupts while executing in user space. Messing with the I/O privilege
82 * level is therefore somewhat dangerous.
83 ****************************************************************************/
84 static void cmos_set_iopl(int level)
86 #if defined(__FreeBSD__)
87 static int io_fd = -1;
90 assert((level >= 0) && (level <= 3));
92 #if defined(__FreeBSD__)
100 io_fd = open("/dev/io", O_RDWR);
109 fprintf(stderr, "%s: iopl() system call failed. "
110 "You must be root to do this.\n", prog_name);
116 cmos_access_t cmos_hal = {
117 .init = cmos_hal_init,
118 .read = cmos_hal_read,
119 .write = cmos_hal_write,
120 .set_iopl = cmos_set_iopl,