Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of msrtool. |
| 3 | * |
| 4 | * Copyright (c) 2008 Peter Stuge <peter@stuge.se> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <unistd.h> |
| 23 | #include <string.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <errno.h> |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 28 | #include <pci/pci.h> |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 29 | |
| 30 | #include "msrtool.h" |
| 31 | |
| 32 | #define DEFAULT_CPU 0 |
| 33 | static uint8_t cpu = DEFAULT_CPU; |
| 34 | |
| 35 | uint8_t targets_found = 0; |
| 36 | const struct targetdef **targets = NULL; |
| 37 | const struct sysdef *sys = NULL; |
| 38 | uint8_t reserved = 0, verbose = 0, quiet = 0; |
| 39 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 40 | struct pci_access *pacc = NULL; |
| 41 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 42 | static struct targetdef alltargets[] = { |
Nils Jacobs | 58a901f | 2010-01-15 10:06:39 +0000 | [diff] [blame] | 43 | { "geodegx2", "AMD Geode(tm) GX2", geodegx2_probe, geodegx2_msrs }, |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 44 | { "geodelx", "AMD Geode(tm) LX", geodelx_probe, geodelx_msrs }, |
| 45 | { "cs5536", "AMD Geode(tm) CS5536", cs5536_probe, cs5536_msrs }, |
Marc Jones | 8f21076 | 2009-03-08 04:37:39 +0000 | [diff] [blame] | 46 | { "K8", "AMD K8 Family", k8_probe, k8_msrs }, |
Anton Kochkov | 7c634ae | 2011-06-20 23:14:22 +0400 | [diff] [blame] | 47 | { "intel_pentium3_early", "Intel Pentium III family", intel_pentium3_early_probe, intel_pentium3_early_msrs }, |
| 48 | { "intel_pentium3", "Intel Pentium III Xeon Processor, Intel Pentium III Processor", intel_pentium3_probe, intel_pentium3_msrs }, |
| 49 | { "intel_core1", "Intel Core Duo, Intel Core Solo processors", intel_core1_probe, intel_core1_msrs }, |
| 50 | { "intel_core2_early", "Intel Xeon Processor 3000, 3200, 5100, 5300, 7300 series, Intel Core 2 Quad processor 6000 series, Intel Core 2 Extreme 6000 series, Intel Core 2 Duo 4000, 5000, 6000, 7000 series processors, Intel Pentium dual-core processors", intel_core2_early_probe, intel_core2_early_msrs }, |
| 51 | { "intel_core2_later", "Intel Xeon Processor 5200, 5400 series, Intel Core 2 Quad processors 8000, 9000 series", intel_core2_later_probe, intel_core2_later_msrs }, |
| 52 | { "intel_pentium4_early", "Intel Xeon Processor, Intel Xeon Processor MP, Intel Pentium 4 processors", intel_pentium4_early_probe, intel_pentium4_early_msrs }, |
| 53 | { "intel_pentium4_later", "Intel Xeon Processor, Intel Xeon Processor MP, Intel Pentium 4, Pentium D processors", intel_pentium4_later_probe, intel_pentium4_later_msrs }, |
Anton Kochkov | 54c07a6 | 2012-07-04 07:35:45 +0400 | [diff] [blame] | 54 | { "intel_nehalem", "Intel Core i5, i7 Processors, Intel Xeon Processor 3400, 3500, 5500, based on Nehalem architecture", intel_nehalem_probe, intel_nehalem_msrs }, |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 55 | { TARGET_EOT } |
| 56 | }; |
| 57 | |
| 58 | static struct sysdef allsystems[] = { |
| 59 | { "linux", "Linux with /dev/cpu/*/msr", linux_probe, linux_open, linux_close, linux_rdmsr }, |
Stefan Reinauer | 9018b6e | 2011-03-14 09:08:27 +0000 | [diff] [blame] | 60 | { "darwin", "Mac OS X with DirectHW", darwin_probe, darwin_open, darwin_close, darwin_rdmsr }, |
Andriy Gapon | d80e57c | 2009-11-28 05:21:42 +0000 | [diff] [blame] | 61 | { "freebsd", "FreeBSD with /dev/cpuctl*", freebsd_probe, freebsd_open, freebsd_close, freebsd_rdmsr }, |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 62 | { SYSTEM_EOT } |
| 63 | }; |
| 64 | |
| 65 | static void syntax(char *argv[]) { |
| 66 | printf("syntax: %s [-hvqrkl] [-c cpu] [-m system] [-t target ...]\n", argv[0]); |
| 67 | printf("\t [-i addr=hi[:]lo] | [-s file] | [-d [:]file] | addr...\n"); |
| 68 | printf(" -h\t show this help text\n"); |
| 69 | printf(" -v\t be verbose\n"); |
| 70 | printf(" -q\t be quiet (overrides -v)\n"); |
| 71 | printf(" -r\t include [Reserved] values\n"); |
| 72 | printf(" -k\t list all known systems and targets\n"); |
| 73 | printf(" -l\t list MSRs and bit fields for current target(s) (-kl for ALL targets!)\n"); |
| 74 | printf(" -c\t access MSRs on the specified CPU, default=%d\n", DEFAULT_CPU); |
| 75 | printf(" -m\t force a system, e.g: -m linux\n"); |
| 76 | printf(" -t\t force a target, can be used multiple times, e.g: -t geodelx -t cs5536\n"); |
| 77 | printf(" -i\t immediate mode\n"); |
| 78 | printf("\t decode hex addr=hi:lo for the target without reading hw value\n"); |
| 79 | printf("\t e.g: -i 4c00000f=f2f100ff56960004\n"); |
| 80 | printf(" -s\t stream mode\n"); |
| 81 | printf("\t read one MSR address per line and append current hw value to the line\n"); |
| 82 | printf("\t use the filename - for stdin/stdout\n"); |
| 83 | printf("\t using -l -s ignores input and will output all MSRs with values\n"); |
| 84 | printf(" -d\t diff mode\n"); |
| 85 | printf("\t read one address and value per line and compare with current hw value,\n"); |
| 86 | printf("\t printing differences to stdout. use the filename - to read from stdin\n"); |
| 87 | printf("\t use :file or :- to reverse diff, normally hw values are considered new\n"); |
| 88 | printf(" addr.. direct mode, read and decode values for the given MSR address(es)\n"); |
| 89 | } |
| 90 | |
| 91 | static void *add_target(const struct targetdef *t) { |
| 92 | void *tmp; |
| 93 | tmp = realloc(targets, (targets_found + 2) * sizeof(struct targetdef *)); |
| 94 | if (NULL == tmp) { |
| 95 | perror("realloc"); |
| 96 | return tmp; |
| 97 | } |
| 98 | targets = tmp; |
| 99 | targets[targets_found++] = t; |
| 100 | targets[targets_found] = NULL; |
| 101 | return targets; |
| 102 | } |
| 103 | |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 104 | static int found_system() { |
| 105 | if (!sys || (sys && !sys->name)) { |
| 106 | fprintf(stderr, "Unable to detect the current operating system!\n"); |
| 107 | fprintf(stderr, "On Linux, please run 'modprobe msr' and try again.\n"); |
| 108 | fprintf(stderr, "Please send a report or patch to coreboot@coreboot.org. Thanks for your help!\n"); |
| 109 | fprintf(stderr, "\n"); |
| 110 | } |
| 111 | return (sys && sys->name); |
| 112 | } |
| 113 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 114 | int do_stream(const char *streamfn, uint8_t ignoreinput) { |
| 115 | char tmpfn[20], line[256]; |
| 116 | uint8_t tn; |
| 117 | size_t start, len; |
| 118 | int ret = 1; |
| 119 | int fdout = -1; |
| 120 | FILE *fin = NULL, *fout = NULL; |
| 121 | uint32_t addr, linenum; |
| 122 | struct msr m = MSR1(0); |
| 123 | |
| 124 | if (0 == strcmp(streamfn, "-")) { |
| 125 | fin = stdin; |
| 126 | fout = stdout; |
| 127 | } else { |
| 128 | if (!ignoreinput) { |
| 129 | if (NULL == (fin = fopen(streamfn, "r"))) { |
| 130 | perror("fopen()"); |
| 131 | return 1; |
| 132 | } |
| 133 | if (snprintf(tmpfn, sizeof(tmpfn), "msrtoolXXXXXX") >= sizeof(tmpfn)) { |
| 134 | perror("snprintf"); |
| 135 | return 1; |
| 136 | } |
| 137 | if (-1 == (fdout = mkstemp(tmpfn))) { |
| 138 | perror("mkstemp"); |
| 139 | return 1; |
| 140 | } |
| 141 | if (NULL == (fout = fdopen(fdout, "w"))) { |
| 142 | perror("fdopen"); |
| 143 | return 1; |
| 144 | } |
| 145 | } else { |
| 146 | if (NULL == (fout = fopen(streamfn, "w"))) { |
| 147 | perror("fopen"); |
| 148 | return 1; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 153 | if (!found_system()) |
| 154 | goto done; |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 155 | if (!sys->open(cpu, SYS_RDONLY)) |
| 156 | goto done; |
| 157 | if (ignoreinput) { |
| 158 | for (tn = 0; tn < targets_found; tn++) |
| 159 | if (dumpmsrdefsvals(fout, targets[tn], cpu)) { |
| 160 | ret = 1; |
| 161 | break; |
| 162 | } |
| 163 | } else { |
| 164 | for (linenum = 1; NULL != fgets(line, sizeof(line), fin); ++linenum) { |
| 165 | start = (0 == strncmp("0x", line, 2)) ? 2 : 0; |
| 166 | if (1 == sscanf(line + start, "%8x", &addr)) { |
| 167 | if (!sys->rdmsr(cpu, addr, &m)) |
| 168 | goto done; |
| 169 | fprintf(fout, "0x%08x 0x%08x%08x\n", addr, m.hi, m.lo); |
| 170 | continue; |
| 171 | } |
| 172 | while (1) { |
| 173 | fprintf(fout, "%s", line); |
| 174 | len = strlen(line); |
| 175 | if (NULL != strchr("\r\n", line[len - 1])) |
| 176 | break; |
| 177 | if (NULL == fgets(line, sizeof(line), fin)) |
| 178 | goto read_done; |
| 179 | } |
| 180 | } |
| 181 | read_done: |
| 182 | if (!feof(fin)) { |
| 183 | fprintf(stderr, "%s:%d: fgets: %s\n", streamfn, linenum, strerror(errno)); |
| 184 | goto done; |
| 185 | } |
| 186 | } |
| 187 | ret = 0; |
| 188 | done: |
| 189 | sys->close(cpu); |
| 190 | if (strcmp(streamfn, "-")) { |
| 191 | if (ret) |
| 192 | unlink(tmpfn); |
| 193 | else if (!ignoreinput) |
| 194 | rename(tmpfn, streamfn); |
| 195 | } |
| 196 | if (!ignoreinput) |
| 197 | fclose(fin); |
| 198 | fclose(fout); |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | int do_diff(const char *difffn) { |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 203 | char tmpfn[20], line[512], *m1start, *m2start; |
Peter Stuge | e6cf7c0 | 2010-01-16 18:39:35 +0000 | [diff] [blame] | 204 | size_t len; |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 205 | int ret = 1, tmp, m1pos, sys_opened = 0; |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 206 | FILE *fin = NULL, *fout = stdout; |
| 207 | uint8_t rev = 0; |
| 208 | uint32_t addr, linenum; |
Peter Stuge | e6cf7c0 | 2010-01-16 18:39:35 +0000 | [diff] [blame] | 209 | struct msr m1 = MSR1(0), m2 = MSR1(0); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 210 | |
| 211 | if (':' == difffn[0]) { |
| 212 | rev = 1; |
| 213 | ++difffn; |
| 214 | } |
| 215 | if (0 == strcmp(difffn, "-")) |
| 216 | fin = stdin; |
| 217 | else if (NULL == (fin = fopen(difffn, "r"))) { |
| 218 | perror("fopen()"); |
| 219 | return 1; |
| 220 | } |
| 221 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 222 | for (linenum = 1; NULL != fgets(line, sizeof(line), fin); ++linenum) { |
Peter Stuge | e6cf7c0 | 2010-01-16 18:39:35 +0000 | [diff] [blame] | 223 | tmp = strncmp("0x", line, 2) ? 0 : 2; |
| 224 | if (sscanf(line + tmp, "%8x %n%*x", &addr, &m1pos) < 1) |
Peter Stuge | 350ca4a | 2010-01-16 17:21:17 +0000 | [diff] [blame] | 225 | continue; |
Peter Stuge | e6cf7c0 | 2010-01-16 18:39:35 +0000 | [diff] [blame] | 226 | m1start = line + tmp + m1pos; |
| 227 | for (len = strlen(m1start) - 1; NULL != strchr("\r\n", m1start[len]); --len) |
| 228 | m1start[len] = 0; |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 229 | if (!str2msr(m1start, &m1, &m2start)) { |
| 230 | fprintf(stderr, "%s:%d: invalid MSR1 value '%s'\n", difffn, linenum, m1start); |
Peter Stuge | 350ca4a | 2010-01-16 17:21:17 +0000 | [diff] [blame] | 231 | continue; |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 232 | } |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 233 | while (' ' == *m2start) |
| 234 | ++m2start; |
| 235 | if (!str2msr(m2start, &m2, NULL)) { |
| 236 | fprintf(stderr, "%s:%d: invalid MSR2 value '%s' - reading from hardware!\n", difffn, linenum, m2start); |
| 237 | if (!sys_opened) { |
| 238 | if (!found_system()) |
| 239 | goto done; |
| 240 | sys_opened = sys->open(cpu, SYS_RDONLY); |
| 241 | if (!sys_opened) |
| 242 | goto done; |
| 243 | } |
| 244 | if (!sys->rdmsr(cpu, addr, &m2)) |
| 245 | goto done; |
| 246 | } |
Peter Stuge | e6cf7c0 | 2010-01-16 18:39:35 +0000 | [diff] [blame] | 247 | if (diff_msr(fout, addr, rev ? m2 : m1, rev ? m1 : m2)) |
Peter Stuge | 350ca4a | 2010-01-16 17:21:17 +0000 | [diff] [blame] | 248 | fprintf(fout, "\n"); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 249 | } |
| 250 | if (!feof(fin)) |
| 251 | fprintf(stderr, "%s:%d: fgets: %s\n", difffn, linenum, strerror(errno)); |
| 252 | else |
| 253 | ret = 0; |
| 254 | done: |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 255 | if (sys_opened) |
| 256 | sys->close(cpu); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 257 | if (strcmp(difffn, "-")) { |
| 258 | if (ret) |
| 259 | unlink(tmpfn); |
| 260 | else |
| 261 | rename(tmpfn, difffn); |
| 262 | fclose(fin); |
| 263 | fclose(fout); |
| 264 | } |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | int main(int argc, char *argv[]) { |
| 269 | char c; |
| 270 | int ret = 1; |
| 271 | const struct sysdef *s; |
| 272 | const struct targetdef *t; |
Anton Kochkov | 59b36f1 | 2012-07-21 07:29:48 +0400 | [diff] [blame^] | 273 | const struct cpuid_t *id = cpuid(); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 274 | uint8_t tn, listmsrs = 0, listknown = 0, input = 0; |
| 275 | uint32_t addr = 0; |
| 276 | const char *streamfn = NULL, *difffn = NULL; |
| 277 | struct msr msrval = MSR2(-1, -1); |
| 278 | while ((c = getopt(argc, argv, "hqvrklc:m:t:a:i:s:d:")) != -1) |
| 279 | switch (c) { |
| 280 | case 'h': |
| 281 | syntax(argv); |
| 282 | return 0; |
| 283 | case 'q': |
| 284 | quiet = 1; |
| 285 | break; |
| 286 | case 'v': |
| 287 | ++verbose; |
| 288 | break; |
| 289 | case 'r': |
| 290 | reserved = 1; |
| 291 | break; |
| 292 | case 'k': |
| 293 | listknown = 1; |
| 294 | break; |
| 295 | case 'l': |
| 296 | listmsrs = 1; |
| 297 | break; |
| 298 | case 'c': |
| 299 | cpu = atoi(optarg); |
| 300 | break; |
| 301 | case 'm': |
| 302 | for (s = allsystems; !SYSTEM_ISEOT(*s); s++) |
| 303 | if (!strcmp(s->name, optarg)) { |
| 304 | sys = s; |
| 305 | break; |
| 306 | } |
| 307 | break; |
| 308 | case 't': |
| 309 | for (t = alltargets; !TARGET_ISEOT(*t); t++) |
| 310 | if (!strcmp(t->name, optarg)) { |
| 311 | add_target(t); |
| 312 | break; |
| 313 | } |
| 314 | break; |
| 315 | case 'i': |
| 316 | input = 1; |
Peter Stuge | 3108a12 | 2009-01-26 17:18:31 +0000 | [diff] [blame] | 317 | addr = msraddrbyname(optarg); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 318 | optarg = strchr(optarg, '='); |
| 319 | if (NULL == optarg) { |
| 320 | fprintf(stderr, "missing value in -i argument!\n"); |
| 321 | break; |
| 322 | } |
Peter Stuge | 34f2907 | 2010-01-17 18:33:53 +0000 | [diff] [blame] | 323 | if (!str2msr(++optarg, &msrval, NULL)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 324 | fprintf(stderr, "invalid value in -i argument!\n"); |
| 325 | break; |
| 326 | case 's': |
| 327 | streamfn = optarg; |
| 328 | break; |
| 329 | case 'd': |
| 330 | difffn = optarg; |
| 331 | break; |
| 332 | default: |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | printf_quiet("msrtool %s\n", VERSION); |
| 337 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 338 | pacc = pci_alloc(); |
| 339 | if (NULL == pacc) { |
| 340 | fprintf(stderr, "Could not initialize PCI library! pci_alloc() failed.\n"); |
| 341 | return 1; |
| 342 | } |
| 343 | pci_init(pacc); |
| 344 | pci_scan_bus(pacc); |
| 345 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 346 | if (!sys && !input && !listknown) |
| 347 | for (sys = allsystems; !SYSTEM_ISEOT(*sys); sys++) { |
| 348 | printf_verbose("Probing for system %s: %s\n", sys->name, sys->prettyname); |
| 349 | if (!sys->probe(sys)) |
| 350 | continue; |
| 351 | printf_quiet("Detected system %s: %s\n", sys->name, sys->prettyname); |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | if (targets) |
| 356 | for (tn = 0; tn < targets_found; tn++) |
| 357 | printf_quiet("Forced target %s: %s\n", targets[tn]->name, targets[tn]->prettyname); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 358 | else |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 359 | for (t = alltargets; !TARGET_ISEOT(*t); t++) { |
| 360 | printf_verbose("Probing for target %s: %s\n", t->name, t->prettyname); |
Anton Kochkov | 59b36f1 | 2012-07-21 07:29:48 +0400 | [diff] [blame^] | 361 | if (!t->probe(t, id)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 362 | continue; |
| 363 | printf_quiet("Detected target %s: %s\n", t->name, t->prettyname); |
| 364 | add_target(t); |
| 365 | } |
| 366 | |
| 367 | printf_quiet("\n"); |
| 368 | fflush(stdout); |
| 369 | |
| 370 | if (listknown) { |
| 371 | printf("Known systems:\n"); |
| 372 | for (s = allsystems; s->name; s++) |
| 373 | printf("%s: %s\n", s->name, s->prettyname); |
| 374 | printf("\nKnown targets:\n"); |
| 375 | for (t = alltargets; t->name; t++) { |
| 376 | if (listmsrs && alltargets != t) |
| 377 | printf("\n"); |
| 378 | printf("%s: %s\n", t->name, t->prettyname); |
| 379 | if (listmsrs) |
| 380 | dumpmsrdefs(t); |
| 381 | } |
| 382 | printf("\n"); |
| 383 | return 0; |
| 384 | } |
| 385 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 386 | if (!targets_found || !targets) { |
| 387 | fprintf(stderr, "Unable to detect a known target; can not decode any MSRs! (Use -t to force)\n"); |
| 388 | fprintf(stderr, "Please send a report or patch to coreboot@coreboot.org. Thanks for your help!\n"); |
| 389 | fprintf(stderr, "\n"); |
| 390 | return 1; |
| 391 | } |
| 392 | |
| 393 | if (input) { |
| 394 | decodemsr(cpu, addr, msrval); |
| 395 | return 0; |
| 396 | } |
| 397 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 398 | if (listmsrs) { |
| 399 | if (streamfn) |
| 400 | return do_stream(streamfn, 1); |
| 401 | for (tn = 0; tn < targets_found; tn++) { |
| 402 | if (tn) |
| 403 | printf("\n"); |
| 404 | dumpmsrdefs(targets[tn]); |
| 405 | } |
| 406 | printf("\n"); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | if (streamfn) |
| 411 | return do_stream(streamfn, 0); |
| 412 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 413 | if (difffn) { |
| 414 | ret = do_diff(difffn); |
| 415 | goto done; |
| 416 | } |
| 417 | |
| 418 | if (optind == argc) { |
| 419 | syntax(argv); |
| 420 | printf("\nNo mode or address(es) specified!\n"); |
| 421 | goto done; |
| 422 | } |
| 423 | |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 424 | if (!found_system()) |
| 425 | return 1; |
| 426 | if (!sys->open(cpu, SYS_RDONLY)) |
| 427 | return 1; |
| 428 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 429 | for (; optind < argc; optind++) { |
Peter Stuge | 3108a12 | 2009-01-26 17:18:31 +0000 | [diff] [blame] | 430 | addr = msraddrbyname(argv[optind]); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 431 | if (!sys->rdmsr(cpu, addr, &msrval)) |
| 432 | break; |
| 433 | decodemsr(cpu, addr, msrval); |
| 434 | } |
| 435 | ret = 0; |
| 436 | done: |
| 437 | sys->close(cpu); |
| 438 | return ret; |
| 439 | } |