Allow nvramtool to build and work on FreeBSD. Tested on FreeBSD 7.

Signed-off-by: Andriy Gapon <avg@icyb.net.ua>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3709 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Andriy Gapon 2008-10-30 15:41:39 +00:00 committed by Uwe Hermann
parent b076ced581
commit 6a4bf9886a
2 changed files with 57 additions and 6 deletions

View File

@ -28,7 +28,11 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/ \*****************************************************************************/
#include <sys/io.h> #if defined(__FreeBSD__)
#include <fcntl.h>
#include <unistd.h>
#endif
#include "common.h" #include "common.h"
#include "cmos_lowlevel.h" #include "cmos_lowlevel.h"
@ -176,8 +180,8 @@ unsigned char cmos_read_byte (unsigned index)
port_1 = 0x73; port_1 = 0x73;
} }
outb(index, port_0); OUTB(index, port_0);
return inb(port_1); return INB(port_1);
} }
/**************************************************************************** /****************************************************************************
@ -204,8 +208,8 @@ void cmos_write_byte (unsigned index, unsigned char value)
port_1 = 0x73; port_1 = 0x73;
} }
outb(index, port_0); OUTB(index, port_0);
outb(value, port_1); OUTB(value, port_1);
} }
/**************************************************************************** /****************************************************************************
@ -248,8 +252,35 @@ void cmos_write_all (unsigned char data[])
* level is therefore somewhat dangerous. * level is therefore somewhat dangerous.
****************************************************************************/ ****************************************************************************/
void set_iopl (int level) 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)) if (iopl(level))
{ fprintf(stderr, { fprintf(stderr,
"%s: iopl() system call failed. You must be root to do " "%s: iopl() system call failed. You must be root to do "
@ -257,6 +288,7 @@ void set_iopl (int level)
prog_name); prog_name);
exit(1); exit(1);
} }
#endif
} }
/**************************************************************************** /****************************************************************************

View File

@ -43,6 +43,25 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#if defined(__FreeBSD__)
#include <sys/types.h>
#include <machine/cpufunc.h>
#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
#include <sys/io.h>
#define OUTB outb
#define OUTW outw
#define OUTL outl
#define INB inb
#define INW inw
#define INL inl
#endif
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1