From 046d2174207d79681fe98206ce92074ac610957e Mon Sep 17 00:00:00 2001 From: Andrey Korolyov Date: Tue, 5 Jan 2016 19:59:06 +0300 Subject: inteltool: add NetBSD compatibility Tested on NetBSD-7.0/i386 Change-Id: I6a693633d3a80ea07ade233b1b4fd1c5a1412032 Signed-off-by: Andrey Korolyov Reviewed-on: https://review.coreboot.org/12835 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/inteltool/Makefile | 8 ++++++++ util/inteltool/inteltool.c | 12 ++++++++++++ util/inteltool/inteltool.h | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) (limited to 'util') diff --git a/util/inteltool/Makefile b/util/inteltool/Makefile index 6e202cf81f..eec1ad766f 100644 --- a/util/inteltool/Makefile +++ b/util/inteltool/Makefile @@ -34,6 +34,10 @@ CFLAGS += -I/usr/local/include LDFLAGS += -L/usr/local/lib LIBS = -lz endif +ifeq ($(OS_ARCH), NetBSD) +CFLAGS += -I/usr/pkg/include +LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p) +endif all: pciutils dep $(PROGRAM) @@ -52,7 +56,11 @@ dep: define LIBPCI_TEST /* Avoid a failing test due to libpci header symbol shadowing breakage */ #define index shadow_workaround_index +#ifdef __NetBSD__ +#include +#else #include +#endif struct pci_access *pacc; int main(int argc, char **argv) { diff --git a/util/inteltool/inteltool.c b/util/inteltool/inteltool.c index 9fcf58d043..974db6fb71 100644 --- a/util/inteltool/inteltool.c +++ b/util/inteltool/inteltool.c @@ -24,6 +24,10 @@ #include #include "inteltool.h" +#ifdef __NetBSD__ +#include +#endif + /* * http://pci-ids.ucw.cz/read/PC/8086 * http://en.wikipedia.org/wiki/Intel_Tick-Tock @@ -344,6 +348,14 @@ int main(int argc, char *argv[]) #if defined(__FreeBSD__) if (open("/dev/io", O_RDWR) < 0) { perror("/dev/io"); +#elif defined(__NetBSD__) +# ifdef __i386__ + if (i386_iopl(3)) { + perror("iopl"); +# else + if (x86_64_iopl(3)) { + perror("iopl"); +# endif #else if (iopl(3)) { perror("iopl"); diff --git a/util/inteltool/inteltool.h b/util/inteltool/inteltool.h index 6845b4ef6d..abaac50a59 100644 --- a/util/inteltool/inteltool.h +++ b/util/inteltool/inteltool.h @@ -24,13 +24,38 @@ #define __DARWIN__ #include #endif +#ifdef __NetBSD__ +#include +#else #include +#endif /* This #include is needed for freebsd_{rd,wr}msr. */ #if defined(__FreeBSD__) #include #endif +#ifdef __NetBSD__ +static inline uint8_t inb(unsigned port) +{ + uint8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} +static inline uint16_t inw(unsigned port) +{ + uint16_t data; + __asm volatile("inw %w1,%0": "=a" (data) : "d" (port)); + return data; +} +static inline uint32_t inl(unsigned port) +{ + uint32_t data; + __asm volatile("inl %w1,%0": "=a" (data) : "d" (port)); + return data; +} +#endif + #define INTELTOOL_VERSION "1.0" /* Tested chipsets: */ -- cgit v1.2.3