[coreboot] r3921 - trunk/util/msrtool

svn at coreboot.org svn at coreboot.org
Mon Jan 26 18:18:32 CET 2009


Author: stuge
Date: 2009-01-26 18:18:31 +0100 (Mon, 26 Jan 2009)
New Revision: 3921

Modified:
   trunk/util/msrtool/msrtool.c
   trunk/util/msrtool/msrtool.h
   trunk/util/msrtool/msrutils.c
Log:
msrtool: Allow MSR symbols (names) to also be used as addresses.

Thanks for the idea Mart!

Signed-off-by: Peter Stuge <peter at stuge.se>
Acked-by: Peter Stuge <peter at stuge.se>


Modified: trunk/util/msrtool/msrtool.c
===================================================================
--- trunk/util/msrtool/msrtool.c	2009-01-26 17:03:05 UTC (rev 3920)
+++ trunk/util/msrtool/msrtool.c	2009-01-26 17:18:31 UTC (rev 3921)
@@ -278,7 +278,7 @@
 			break;
 		case 'i':
 			input = 1;
-			addr = strtoul(optarg, NULL, 16);
+			addr = msraddrbyname(optarg);
 			optarg = strchr(optarg, '=');
 			if (NULL == optarg) {
 				fprintf(stderr, "missing value in -i argument!\n");
@@ -398,7 +398,7 @@
 	}
 
 	for (; optind < argc; optind++) {
-		addr = strtoul(argv[optind], NULL, 16);
+		addr = msraddrbyname(argv[optind]);
 		if (!sys->rdmsr(cpu, addr, &msrval))
 			break;
 		decodemsr(cpu, addr, msrval);

Modified: trunk/util/msrtool/msrtool.h
===================================================================
--- trunk/util/msrtool/msrtool.h	2009-01-26 17:03:05 UTC (rev 3920)
+++ trunk/util/msrtool/msrtool.h	2009-01-26 17:18:31 UTC (rev 3921)
@@ -157,6 +157,7 @@
 struct msr msr_shr(const struct msr a, const uint8_t bits);
 void msr_and(struct msr *a, const struct msr b);
 const struct msrdef *findmsrdef(const uint32_t addr);
+const uint32_t msraddrbyname(const char *name);
 void dumpmsrdefs(const struct targetdef *t);
 int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu);
 uint8_t str2msr(char *str, struct msr *msr);

Modified: trunk/util/msrtool/msrutils.c
===================================================================
--- trunk/util/msrtool/msrutils.c	2009-01-26 17:03:05 UTC (rev 3920)
+++ trunk/util/msrtool/msrutils.c	2009-01-26 17:18:31 UTC (rev 3921)
@@ -137,6 +137,22 @@
 	return NULL;
 }
 
+const uint32_t msraddrbyname(const char *name) {
+	uint8_t t;
+	const uint32_t addr = strtoul(name, NULL, 16);
+	const struct msrdef *m;
+	if (!targets)
+		return 0;
+	for (t = 0; t < targets_found; t++)
+		for (m = targets[t]->msrs; !MSR_ISEOT(*m); m++) {
+			if (addr == m->addr)
+				return m->addr;
+			if (!strcasecmp(name, m->symbol))
+				return m->addr;
+		}
+	return 0;
+}
+
 void dumpmsrdefs(const struct targetdef *t) {
 	const struct msrdef *m;
 	const struct msrbits *mb;





More information about the coreboot mailing list