From 3108a12e9b701e6c3daeb0ae629ecb603dd6509c Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Mon, 26 Jan 2009 17:18:31 +0000 Subject: msrtool: Allow MSR symbols (names) to also be used as addresses. Thanks for the idea Mart! Signed-off-by: Peter Stuge Acked-by: Peter Stuge git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3921 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/msrtool/msrtool.c | 4 ++-- util/msrtool/msrtool.h | 1 + util/msrtool/msrutils.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'util/msrtool') diff --git a/util/msrtool/msrtool.c b/util/msrtool/msrtool.c index 5742a1765c..bafb0908c0 100644 --- a/util/msrtool/msrtool.c +++ b/util/msrtool/msrtool.c @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) { 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 @@ int main(int argc, char *argv[]) { } 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); diff --git a/util/msrtool/msrtool.h b/util/msrtool/msrtool.h index 7b639f0657..23bc4b88d2 100644 --- a/util/msrtool/msrtool.h +++ b/util/msrtool/msrtool.h @@ -157,6 +157,7 @@ struct msr msr_shl(const struct msr a, const uint8_t bits); 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); diff --git a/util/msrtool/msrutils.c b/util/msrtool/msrutils.c index c5fcbea143..4a4782b687 100644 --- a/util/msrtool/msrutils.c +++ b/util/msrtool/msrutils.c @@ -137,6 +137,22 @@ const struct msrdef *findmsrdef(const uint32_t addr) { 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; -- cgit v1.2.3