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; |
| 273 | uint8_t tn, listmsrs = 0, listknown = 0, input = 0; |
| 274 | uint32_t addr = 0; |
| 275 | const char *streamfn = NULL, *difffn = NULL; |
| 276 | struct msr msrval = MSR2(-1, -1); |
| 277 | while ((c = getopt(argc, argv, "hqvrklc:m:t:a:i:s:d:")) != -1) |
| 278 | switch (c) { |
| 279 | case 'h': |
| 280 | syntax(argv); |
| 281 | return 0; |
| 282 | case 'q': |
| 283 | quiet = 1; |
| 284 | break; |
| 285 | case 'v': |
| 286 | ++verbose; |
| 287 | break; |
| 288 | case 'r': |
| 289 | reserved = 1; |
| 290 | break; |
| 291 | case 'k': |
| 292 | listknown = 1; |
| 293 | break; |
| 294 | case 'l': |
| 295 | listmsrs = 1; |
| 296 | break; |
| 297 | case 'c': |
| 298 | cpu = atoi(optarg); |
| 299 | break; |
| 300 | case 'm': |
| 301 | for (s = allsystems; !SYSTEM_ISEOT(*s); s++) |
| 302 | if (!strcmp(s->name, optarg)) { |
| 303 | sys = s; |
| 304 | break; |
| 305 | } |
| 306 | break; |
| 307 | case 't': |
| 308 | for (t = alltargets; !TARGET_ISEOT(*t); t++) |
| 309 | if (!strcmp(t->name, optarg)) { |
| 310 | add_target(t); |
| 311 | break; |
| 312 | } |
| 313 | break; |
| 314 | case 'i': |
| 315 | input = 1; |
Peter Stuge | 3108a12 | 2009-01-26 17:18:31 +0000 | [diff] [blame] | 316 | addr = msraddrbyname(optarg); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 317 | optarg = strchr(optarg, '='); |
| 318 | if (NULL == optarg) { |
| 319 | fprintf(stderr, "missing value in -i argument!\n"); |
| 320 | break; |
| 321 | } |
Peter Stuge | 34f2907 | 2010-01-17 18:33:53 +0000 | [diff] [blame] | 322 | if (!str2msr(++optarg, &msrval, NULL)) |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 323 | fprintf(stderr, "invalid value in -i argument!\n"); |
| 324 | break; |
| 325 | case 's': |
| 326 | streamfn = optarg; |
| 327 | break; |
| 328 | case 'd': |
| 329 | difffn = optarg; |
| 330 | break; |
| 331 | default: |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | printf_quiet("msrtool %s\n", VERSION); |
| 336 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 337 | pacc = pci_alloc(); |
| 338 | if (NULL == pacc) { |
| 339 | fprintf(stderr, "Could not initialize PCI library! pci_alloc() failed.\n"); |
| 340 | return 1; |
| 341 | } |
| 342 | pci_init(pacc); |
| 343 | pci_scan_bus(pacc); |
| 344 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 345 | if (!sys && !input && !listknown) |
| 346 | for (sys = allsystems; !SYSTEM_ISEOT(*sys); sys++) { |
| 347 | printf_verbose("Probing for system %s: %s\n", sys->name, sys->prettyname); |
| 348 | if (!sys->probe(sys)) |
| 349 | continue; |
| 350 | printf_quiet("Detected system %s: %s\n", sys->name, sys->prettyname); |
| 351 | break; |
| 352 | } |
| 353 | |
| 354 | if (targets) |
| 355 | for (tn = 0; tn < targets_found; tn++) |
| 356 | 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] | 357 | else |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 358 | for (t = alltargets; !TARGET_ISEOT(*t); t++) { |
| 359 | printf_verbose("Probing for target %s: %s\n", t->name, t->prettyname); |
| 360 | if (!t->probe(t)) |
| 361 | continue; |
| 362 | printf_quiet("Detected target %s: %s\n", t->name, t->prettyname); |
| 363 | add_target(t); |
| 364 | } |
| 365 | |
| 366 | printf_quiet("\n"); |
| 367 | fflush(stdout); |
| 368 | |
| 369 | if (listknown) { |
| 370 | printf("Known systems:\n"); |
| 371 | for (s = allsystems; s->name; s++) |
| 372 | printf("%s: %s\n", s->name, s->prettyname); |
| 373 | printf("\nKnown targets:\n"); |
| 374 | for (t = alltargets; t->name; t++) { |
| 375 | if (listmsrs && alltargets != t) |
| 376 | printf("\n"); |
| 377 | printf("%s: %s\n", t->name, t->prettyname); |
| 378 | if (listmsrs) |
| 379 | dumpmsrdefs(t); |
| 380 | } |
| 381 | printf("\n"); |
| 382 | return 0; |
| 383 | } |
| 384 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 385 | if (!targets_found || !targets) { |
| 386 | fprintf(stderr, "Unable to detect a known target; can not decode any MSRs! (Use -t to force)\n"); |
| 387 | fprintf(stderr, "Please send a report or patch to coreboot@coreboot.org. Thanks for your help!\n"); |
| 388 | fprintf(stderr, "\n"); |
| 389 | return 1; |
| 390 | } |
| 391 | |
| 392 | if (input) { |
| 393 | decodemsr(cpu, addr, msrval); |
| 394 | return 0; |
| 395 | } |
| 396 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 397 | if (listmsrs) { |
| 398 | if (streamfn) |
| 399 | return do_stream(streamfn, 1); |
| 400 | for (tn = 0; tn < targets_found; tn++) { |
| 401 | if (tn) |
| 402 | printf("\n"); |
| 403 | dumpmsrdefs(targets[tn]); |
| 404 | } |
| 405 | printf("\n"); |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | if (streamfn) |
| 410 | return do_stream(streamfn, 0); |
| 411 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 412 | if (difffn) { |
| 413 | ret = do_diff(difffn); |
| 414 | goto done; |
| 415 | } |
| 416 | |
| 417 | if (optind == argc) { |
| 418 | syntax(argv); |
| 419 | printf("\nNo mode or address(es) specified!\n"); |
| 420 | goto done; |
| 421 | } |
| 422 | |
Peter Stuge | cba6169 | 2010-01-17 18:34:00 +0000 | [diff] [blame] | 423 | if (!found_system()) |
| 424 | return 1; |
| 425 | if (!sys->open(cpu, SYS_RDONLY)) |
| 426 | return 1; |
| 427 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 428 | for (; optind < argc; optind++) { |
Peter Stuge | 3108a12 | 2009-01-26 17:18:31 +0000 | [diff] [blame] | 429 | addr = msraddrbyname(argv[optind]); |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 430 | if (!sys->rdmsr(cpu, addr, &msrval)) |
| 431 | break; |
| 432 | decodemsr(cpu, addr, msrval); |
| 433 | } |
| 434 | ret = 0; |
| 435 | done: |
| 436 | sys->close(cpu); |
| 437 | return ret; |
| 438 | } |