See attachments
--
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: [email protected] • http://www.coresystems.de/
Registergericht: Amtsgericht Freiburg • HRB 7656
Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866
Clean up Mac OS X support of inteltool
Signed-off-by: Stefan Reinauer <[email protected]>
Index: inteltool-r4620/inteltool.h
===================================================================
--- inteltool-r4620/inteltool.h
+++ inteltool-r4620/inteltool.h
@@ -18,12 +18,13 @@
*/
#include <stdint.h>
-#ifndef DARWIN
+
+#if defined(__GLIBC__)
#include <sys/io.h>
-#else
-/* DirectIO is available here:
- * http://www.coresystems.de/en/directio
- */
+#endif
+#if (defined(__MACH__) && defined(__APPLE__))
+/* DirectIO is available here: http://www.coresystems.de/en/directio */
+#define __DARWIN__
#include <DirectIO/darwinio.h>
#endif
#include <pci/pci.h>
@@ -55,7 +56,7 @@
#define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0])))
-#ifndef DARWIN
+#ifndef __DARWIN__
typedef struct { uint32_t hi, lo; } msr_t;
#endif
typedef struct { uint16_t addr; int size; char *name; } io_register_t;
Index: inteltool-r4620/cpu.c
===================================================================
--- inteltool-r4620/cpu.c
+++ inteltool-r4620/cpu.c
@@ -32,7 +32,7 @@
{
unsigned int ret;
unsigned int dummy2, dummy3, dummy4;
-#if DARWIN
+#ifdef __DARWIN__
asm volatile (
"pushl %%ebx \n"
"cpuid \n"
@@ -53,7 +53,7 @@
return ret;
}
-#ifndef DARWIN
+#ifndef __DARWIN__
int msr_readerror = 0;
msr_t rdmsr(int addr)
@@ -288,7 +288,7 @@
return -1;
}
-#ifndef DARWIN
+#ifndef __DARWIN__
fd_msr = open("/dev/cpu/0/msr", O_RDWR);
if (fd_msr < 0) {
perror("Error while opening /dev/cpu/0/msr");
@@ -309,7 +309,7 @@
close(fd_msr);
for (core = 0; core < 8; core++) {
-#ifndef DARWIN
+#ifndef __DARWIN__
char msrfilename[64];
memset(msrfilename, 0, 64);
sprintf(msrfilename, "/dev/cpu/%d/msr", core);
@@ -330,12 +330,12 @@
cpu->per_core_msrs[i].number, msr.hi, msr.lo,
cpu->per_core_msrs[i].name);
}
-#ifndef DARWIN
+#ifndef __DARWIN__
close(fd_msr);
#endif
}
-#ifndef DARWIN
+#ifndef __DARWIN__
if (msr_readerror)
printf("\n(*) Some MSRs could not be read. The marked values
are unreliable.\n");
#endif
Index: inteltool-r4620/inteltool.c
===================================================================
--- inteltool-r4620/inteltool.c
+++ inteltool-r4620/inteltool.c
@@ -50,7 +50,7 @@
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH, "ICH" }
};
-#ifndef DARWIN
+#ifndef __DARWIN__
static int fd_mem;
void *map_physical(unsigned long phys_addr, int len)
@@ -192,7 +192,7 @@
exit(1);
}
-#ifndef DARWIN
+#ifndef __DARWIN__
if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
perror("Can not open /dev/mem");
exit(1);
Index: inteltool-r4620/Makefile
===================================================================
--- inteltool-r4620/Makefile
+++ inteltool-r4620/Makefile
@@ -31,9 +31,7 @@
OS_ARCH = $(shell uname)
ifeq ($(OS_ARCH), Darwin)
-CFLAGS += -DDARWIN -I/usr/local/include
-LDFLAGS = -framework IOKit -framework DirectIO -L/usr/local/lib -lpci -lz
-# OBJS += darwinio.o
+LDFLAGS = -framework IOKit -framework DirectIO -lpci -lz
endif
all: pciutils dep $(PROGRAM)
port msrtool to darwin.
Signed-off-by: Stefan Reinauer <[email protected]>
Index: msrtool-r4620/Makefile.in
===================================================================
--- msrtool-r4620/Makefile.in
+++ msrtool-r4620/Makefile.in
@@ -27,7 +27,7 @@
LDFLAGS = @LDFLAGS@
TARGETS = geodelx.o cs5536.o k8.o
-SYSTEMS = linux.o
+SYSTEMS = linux.o darwin.o
OBJS = $(PROGRAM).o msrutils.o sys.o $(SYSTEMS) $(TARGETS)
all: $(PROGRAM)
@@ -39,9 +39,7 @@
$(CC) $(CFLAGS) -DVERSION='"@VERSION@"' -c $< -o $@
install: $(PROGRAM)
- $(INSTALL) $(PROGRAM) $(PREFIX)/sbin
- mkdir -p $(PREFIX)/share/man/man8
- $(INSTALL) $(PROGRAM).8 $(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
distprep: distclean Makefile.deps
Index: msrtool-r4620/darwin.c
===================================================================
--- msrtool-r4620/darwin.c (revision 0)
+++ msrtool-r4620/darwin.c (revision 102)
@@ -0,0 +1,57 @@
+/*
+ * This file is part of msrtool.
+ *
+ * Copyright (c) 2009 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "msrtool.h"
+
+int darwin_probe(const struct sysdef *system)
+{
+ return iopl(3) == 0;
+}
+
+int darwin_open(uint8_t cpu, enum SysModes mode)
+{
+ if (cpu > 0) {
+ fprintf(stderr, "%s: only core 0 is supported on Mac OS X right
now.\n", __func__);
+ return 0;
+ }
+ return 1;
+}
+
+int darwin_close(uint8_t cpu)
+{
+ return 1;
+}
+
+int darwin_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val)
+{
+ msr_t msr;
+
+ msr = rdmsr(addr);
+
+ val->hi = msr.lo;
+ val->lo = msr.hi;
+ return 1;
+}
Index: msrtool-r4620/sys.c
===================================================================
--- msrtool-r4620/sys.c
+++ msrtool-r4620/sys.c
@@ -2,6 +2,7 @@
* This file is part of msrtool.
*
* Copyright (c) 2008 Peter Stuge <[email protected]>
+ * Copyright (c) 2009 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -25,7 +26,18 @@
struct cpuid_t *cpuid(void) {
uint32_t outeax;
+
+#ifdef __DARWIN__
+ asm volatile (
+ "pushl %%ebx \n"
+ "cpuid \n"
+ "popl %%ebx \n"
+ : "=a" (outeax) : "a" (1) : "%ecx", "%edx"
+ );
+#else
asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx");
+#endif
+
id.stepping = outeax & 0xf;
outeax >>= 4;
id.model = outeax & 0xf;
@@ -40,6 +52,9 @@
id.model |= (id.ext_model << 4);
id.family += id.ext_family;
}
+ printf_verbose("CPU: family %x, model %x, stepping %x\n",
+ id.family, id.model, id.stepping);
+
return &id;
}
Index: msrtool-r4620/msrtool.c
===================================================================
--- msrtool-r4620/msrtool.c
+++ msrtool-r4620/msrtool.c
@@ -48,6 +48,7 @@
static struct sysdef allsystems[] = {
{ "linux", "Linux with /dev/cpu/*/msr", linux_probe, linux_open,
linux_close, linux_rdmsr },
+ { "darwin", "OS X with DirectIO", darwin_probe, darwin_open,
darwin_close, darwin_rdmsr },
{ SYSTEM_EOT }
};
Index: msrtool-r4620/configure
===================================================================
--- msrtool-r4620/configure
+++ msrtool-r4620/configure
@@ -155,7 +155,7 @@
rm -f .config.c
exit 1
}
-LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz"
"-L/usr/local/lib -lpci -lz" "-framework IOKit -L/usr/local/lib -lpci -lz"` || {
+LDFLAGS=`trylink "libpci (from pciutils)" "${pc_LDFLAGS}" "-lpci -lz" "-lpci
-lz" "-framework IOKit -framework DirectIO -lpci -lz"` || {
rm -f .config.c .config.o
exit 1
}
Index: msrtool-r4620/msrtool.h
===================================================================
--- msrtool-r4620/msrtool.h
+++ msrtool-r4620/msrtool.h
@@ -2,6 +2,7 @@
* This file is part of msrtool.
*
* Copyright (c) 2008 Peter Stuge <[email protected]>
+ * Copyright (c) 2009 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -22,6 +23,11 @@
#include <stdio.h>
#include <stdint.h>
+#if (defined(__MACH__) && defined(__APPLE__))
+/* DirectIO is available here: http://www.coresystems.de/en/directio */
+#define __DARWIN__
+#include <DirectIO/darwinio.h>
+#endif
#include <pci/pci.h>
#define HEXCHARS "0123456789abcdefABCDEF"
@@ -174,6 +180,11 @@
extern int linux_close(uint8_t cpu);
extern int linux_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
+/* darwin.c */
+extern int darwin_probe(const struct sysdef *system);
+extern int darwin_open(uint8_t cpu, enum SysModes mode);
+extern int darwin_close(uint8_t cpu);
+extern int darwin_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
/** target externs **/
nvramtool:
* Add OSX/Darwin support
* Add $DESTDIR support
* Clean up make install/spec
Signed-off-by: Stefan Reinauer <[email protected]>
Index: nvramtool-r4620/Makefile
===================================================================
--- nvramtool-r4620/Makefile
+++ nvramtool-r4620/Makefile
@@ -18,6 +18,11 @@
hexdump.o input_file.o layout.o layout_file.o lbtable.o \
nvramtool.o opts.o reg_expr.o
+OS_ARCH = $(shell uname)
+ifeq ($(OS_ARCH), Darwin)
+LDFLAGS = -framework DirectIO
+endif
+
all: dep $(PROGRAM)
$(PROGRAM): $(OBJS)
@@ -34,9 +39,9 @@
@$(CC) -MM *.c > .dependencies
install: $(PROGRAM)
- $(INSTALL) $(PROGRAM) $(PREFIX)/sbin
- mkdir -p $(PREFIX)/share/man/man1
- $(INSTALL) $(PROGRAM).8 $(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
+ mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
.PHONY: all clean distclean dep
Index: nvramtool-r4620/nvramtool.spec
===================================================================
--- nvramtool-r4620/nvramtool.spec
+++ nvramtool-r4620/nvramtool.spec
@@ -33,9 +33,9 @@
%install
rm -rf "$RPM_BUILD_ROOT"
mkdir -p "$RPM_BUILD_ROOT/usr/bin"
-mkdir -p "$RPM_BUILD_ROOT/usr/man/man1"
+mkdir -p "$RPM_BUILD_ROOT/usr/man/man8"
cp nvramtool "$RPM_BUILD_ROOT/usr/bin"
-cp nvramtool.1.gz $RPM_BUILD_ROOT/usr/man/man1
+cp nvramtool.8.gz $RPM_BUILD_ROOT/usr/man/man8
%clean
rm -rf "$RPM_BUILD_ROOT"
@@ -45,4 +45,4 @@
%doc ChangeLog README
%doc README
/usr/bin/nvramtool
-/usr/man/man1/nvramtool.1.gz
+/usr/man/man8/nvramtool.8.gz
Index: nvramtool-r4620/common.h
===================================================================
--- nvramtool-r4620/common.h
+++ nvramtool-r4620/common.h
@@ -53,7 +53,12 @@
#define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
#define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
#else
+#if defined(__GLIBC__)
#include <sys/io.h>
+#endif
+#if (defined(__MACH__) && defined(__APPLE__))
+#include <DirectIO/darwinio.h>
+#endif
#define OUTB outb
#define OUTW outw
#define OUTL outl
* Add OSX/Darwin support
* Add DESTDIR support
Signed-off-by: Stefan Reinauer <[email protected]>
Index: superiotool-r4620/superiotool.h
===================================================================
--- superiotool-r4620/superiotool.h
+++ superiotool-r4620/superiotool.h
@@ -4,6 +4,7 @@
* Copyright (C) 2007 Carl-Daniel Hailfinger
* Copyright (C) 2007 Uwe Hermann <[email protected]>
* Copyright (C) 2008 Robinson P. Tryon <[email protected]>
+ * Copyright (C) 2008-2009 coresystems GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,6 +32,10 @@
#if defined(__GLIBC__)
#include <sys/io.h>
#endif
+#if (defined(__MACH__) && defined(__APPLE__))
+/* DirectIO is available here: http://www.coresystems.de/en/directio */
+#include <DirectIO/darwinio.h>
+#endif
#if defined(__FreeBSD__)
#include <sys/types.h>
Index: superiotool-r4620/Makefile
===================================================================
--- superiotool-r4620/Makefile
+++ superiotool-r4620/Makefile
@@ -26,17 +26,22 @@
OBJS = superiotool.o ali.o fintek.o ite.o nsc.o smsc.o winbond.o
+OS_ARCH = $(shell uname)
+ifeq ($(OS_ARCH), Darwin)
+LDFLAGS = -framework IOKit -framework DirectIO -lpci -lz
+endif
+
all: $(PROGRAM)
superiotool.o: *.c superiotool.h
$(PROGRAM): $(OBJS) superiotool.h
- $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS)
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $(PROGRAM) $(OBJS)
install: $(PROGRAM)
- $(INSTALL) $(PROGRAM) $(PREFIX)/sbin
- mkdir -p $(PREFIX)/share/man/man8
- $(INSTALL) $(PROGRAM).8 $(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
+ mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
+ $(INSTALL) $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
clean:
rm -f $(PROGRAM) *.o
--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot