[coreboot] [v2] r4624 - trunk/util/msrtool

svn at coreboot.org svn at coreboot.org
Tue Sep 1 12:03:02 CEST 2009


Author: stepan
Date: 2009-09-01 12:03:01 +0200 (Tue, 01 Sep 2009)
New Revision: 4624

Added:
   trunk/util/msrtool/darwin.c
Modified:
   trunk/util/msrtool/Makefile.in
   trunk/util/msrtool/configure
   trunk/util/msrtool/msrtool.c
   trunk/util/msrtool/msrtool.h
   trunk/util/msrtool/sys.c
Log:
port msrtool to darwin.

Signed-off-by: Stefan Reinauer <stepan at coresystems.de>
Acked-by: Peter Stuge <peter at stuge.se>

with minor changes to allow 32bit and 64bit compilation and (I hope), Peter's
concerns addressed.



Modified: trunk/util/msrtool/Makefile.in
===================================================================
--- trunk/util/msrtool/Makefile.in	2009-09-01 09:57:55 UTC (rev 4623)
+++ trunk/util/msrtool/Makefile.in	2009-09-01 10:03:01 UTC (rev 4624)
@@ -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,8 @@
 	$(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
+	mkdir -p $(DESTDIR)$(PREFIX)/sbin
+	$(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
 
 distprep: distclean Makefile.deps
 

Modified: trunk/util/msrtool/configure
===================================================================
--- trunk/util/msrtool/configure	2009-09-01 09:57:55 UTC (rev 4623)
+++ trunk/util/msrtool/configure	2009-09-01 10:03:01 UTC (rev 4624)
@@ -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" "-L/usr/local/lib -lpci -lz" "-framework DirectIO -lpci -lz"` || {
 	rm -f .config.c .config.o
 	exit 1
 }

Added: trunk/util/msrtool/darwin.c
===================================================================
--- trunk/util/msrtool/darwin.c	                        (rev 0)
+++ trunk/util/msrtool/darwin.c	2009-09-01 10:03:01 UTC (rev 4624)
@@ -0,0 +1,61 @@
+/*
+ * 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)
+{
+#ifdef __DARWIN__
+	return iopl(3) == 0;
+#else
+	return 0;
+#endif
+}
+
+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;
+}

Modified: trunk/util/msrtool/msrtool.c
===================================================================
--- trunk/util/msrtool/msrtool.c	2009-09-01 09:57:55 UTC (rev 4623)
+++ trunk/util/msrtool/msrtool.c	2009-09-01 10:03:01 UTC (rev 4624)
@@ -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 }
 };
 

Modified: trunk/util/msrtool/msrtool.h
===================================================================
--- trunk/util/msrtool/msrtool.h	2009-09-01 09:57:55 UTC (rev 4623)
+++ trunk/util/msrtool/msrtool.h	2009-09-01 10:03:01 UTC (rev 4624)
@@ -2,6 +2,7 @@
  * This file is part of msrtool.
  *
  * Copyright (c) 2008 Peter Stuge <peter at stuge.se>
+ * 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 **/
 

Modified: trunk/util/msrtool/sys.c
===================================================================
--- trunk/util/msrtool/sys.c	2009-09-01 09:57:55 UTC (rev 4623)
+++ trunk/util/msrtool/sys.c	2009-09-01 10:03:01 UTC (rev 4624)
@@ -2,6 +2,7 @@
  * This file is part of msrtool.
  *
  * Copyright (c) 2008 Peter Stuge <peter at stuge.se>
+ * 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;
+
+#if defined(__DARWIN__) && !defined(__LP64__)
+        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;
 }
 





More information about the coreboot mailing list