[e16e8f2] | 1 | /* ----------------------------------------------------------------------- * |
---|
| 2 | * |
---|
| 3 | * Copyright 2010 Intel Corporation; author: H. Peter Anvin |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
---|
| 8 | * Boston MA 02110-1301, USA; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version; incorporated herein by reference. |
---|
| 10 | * |
---|
| 11 | * ----------------------------------------------------------------------- */ |
---|
| 12 | |
---|
| 13 | #include <stdio.h> |
---|
| 14 | #include <stdlib.h> |
---|
| 15 | #include <sys/cpu.h> |
---|
| 16 | #include <console.h> |
---|
| 17 | #include <com32.h> |
---|
| 18 | |
---|
| 19 | static void dump_reg(const char *name, uint32_t val) |
---|
| 20 | { |
---|
| 21 | int i; |
---|
| 22 | |
---|
| 23 | printf("%-3s : %10u 0x%08x ", name, val, val); |
---|
| 24 | |
---|
| 25 | for (i = 3; i >= 0; i--) { |
---|
| 26 | uint8_t c = val >> (i*8); |
---|
| 27 | putchar((c >= ' ' && c <= '~') ? c : '.'); |
---|
| 28 | } |
---|
| 29 | putchar('\n'); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | int main(int argc, char *argv[]) |
---|
| 33 | { |
---|
| 34 | uint32_t leaf, counter; |
---|
| 35 | uint32_t eax, ebx, ecx, edx; |
---|
| 36 | |
---|
| 37 | if (argc < 2 || argc > 4) { |
---|
| 38 | printf("Usage: %s leaf [counter]\n", argv[0]); |
---|
| 39 | exit(1); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | leaf = strtoul(argv[1], NULL, 0); |
---|
| 43 | counter = (argc > 2) ? strtoul(argv[2], NULL, 0) : 0; |
---|
| 44 | |
---|
| 45 | if (!cpu_has_eflag(EFLAGS_ID)) { |
---|
| 46 | printf("The CPUID instruction is not supported\n"); |
---|
| 47 | exit(1); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | cpuid_count(leaf, counter, &eax, &ebx, &ecx, &edx); |
---|
| 51 | |
---|
| 52 | dump_reg("eax", eax); |
---|
| 53 | dump_reg("ebx", ebx); |
---|
| 54 | dump_reg("ecx", ecx); |
---|
| 55 | dump_reg("edx", edx); |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|