aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2010-03-30 15:05:17 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2010-03-30 15:05:17 -0700
commitd71b34b80fbee1df019129971d1cec2568705213 (patch)
tree79bdd4eb94a2ae40c1f497be004a4da2e4ca02fd
parentec127e4bce415e103da3ba02d0e7adee2bcc1344 (diff)
downloadcontrib-d71b34b80fbee1df019129971d1cec2568705213.tar.gz
contrib-d71b34b80fbee1df019129971d1cec2568705213.tar.xz
contrib-d71b34b80fbee1df019129971d1cec2568705213.zip
cpuid.c32: very simple low-level CPUID info CLI routine
Add a very simple com32 program to dump a single CPUID leaf. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--com32/modules/Makefile3
-rw-r--r--com32/modules/cpuid.c60
2 files changed, 62 insertions, 1 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 35906587..44bc1dfb 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -21,7 +21,8 @@ include ../MCONFIG
MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \
disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
- kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32 ifcpu.c32
+ kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32 ifcpu.c32 \
+ cpuid.c32
TESTFILES =
diff --git a/com32/modules/cpuid.c b/com32/modules/cpuid.c
new file mode 100644
index 00000000..4758fbad
--- /dev/null
+++ b/com32/modules/cpuid.c
@@ -0,0 +1,60 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2010 Intel Corporation; author: H. Peter Anvin
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/cpu.h>
+#include <console.h>
+#include <com32.h>
+
+static void dump_reg(const char *name, uint32_t val)
+{
+ int i;
+
+ printf("%-3s : %10d 0x%08x ", name, val, val);
+
+ for (i = 3; i >= 0; i--) {
+ uint8_t c = val >> (i*8);
+ putchar((c >= ' ' && c <= '~') ? c : '.');
+ }
+ putchar('\n');
+}
+
+int main(int argc, char *argv[])
+{
+ uint32_t leaf, counter;
+ uint32_t eax, ebx, ecx, edx;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc < 2 || argc > 4) {
+ printf("Usage: %s leaf [counter]\n", argv[0]);
+ exit(1);
+ }
+
+ leaf = strtoul(argv[1], NULL, 0);
+ counter = (argv > 2) ? strtoul(argv[2], NULL, 0) : 0;
+
+ if (!cpu_has_eflag(EFLAGS_ID)) {
+ printf("The CPUID instruction is not supported\n");
+ exit(1);
+ }
+
+ cpuid_count(leaf, counter, &eax, &ebx, &ecx, &edx);
+
+ dump_reg("eax", eax);
+ dump_reg("eax", ebx);
+ dump_reg("eax", ecx);
+ dump_reg("eax", edx);
+
+ return 0;
+}