#include "cmos_lowlevel.h"
/* Hardware Abstraction Layer: lowlevel byte-wise write access */
-typedef struct {
- void (*init)(void* data);
- unsigned char (*read)(unsigned addr);
- void (*write)(unsigned addr, unsigned char value);
-} cmos_access_t;
-
-static void cmos_hal_init(void* data);
-static unsigned char cmos_hal_read(unsigned addr);
-static void cmos_hal_write(unsigned addr, unsigned char value);
-
-static cmos_access_t cmos_hal = {
- .init = cmos_hal_init,
- .read = cmos_hal_read,
- .write = cmos_hal_write
-};
+extern cmos_access_t cmos_hal, memory_hal;
static cmos_access_t *current_access = &cmos_hal;
-/* no need to initialize anything */
-static void cmos_hal_init(__attribute__((unused)) void *data)
-{
-}
-
-static unsigned char cmos_hal_read(unsigned index)
+void select_hal(hal_t hal, void *data)
{
- unsigned short port_0, port_1;
-
- assert(!verify_cmos_byte_index(index));
-
- if (index < 128) {
- port_0 = 0x70;
- port_1 = 0x71;
- } else {
- port_0 = 0x72;
- port_1 = 0x73;
+ switch(hal) {
+ case HAL_CMOS:
+ current_access = &cmos_hal;
+ break;
+ case HAL_MEMORY:
+ current_access = &memory_hal;
+ break;
}
-
- OUTB(index, port_0);
- return INB(port_1);
-}
-
-static void cmos_hal_write(unsigned index, unsigned char value)
-{
- unsigned short port_0, port_1;
-
- assert(!verify_cmos_byte_index(index));
-
- if (index < 128) {
- port_0 = 0x70;
- port_1 = 0x71;
- } else {
- port_0 = 0x72;
- port_1 = 0x73;
- }
-
- OUTB(index, port_0);
- OUTB(value, port_1);
+ current_access->init(data);
}
/* Bit-level access */
****************************************************************************/
void set_iopl(int level)
{
-#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 this.\n", prog_name);
- exit(1);
- }
-#endif
+ current_access->set_iopl(level);
}
/****************************************************************************