Add a cpuid helper program
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 7 Oct 2017 18:58:57 +0000 (14:58 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 17 Oct 2017 18:12:05 +0000 (14:12 -0400)
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tests/cpuid.c [new file with mode: 0644]

diff --git a/tests/cpuid.c b/tests/cpuid.c
new file mode 100644 (file)
index 0000000..aa34d2c
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <parlib/arch/arch.h>
+
+int main(int argc, char *argv[])
+{
+       uint32_t eax, ebx, ecx, edx;
+       uint32_t info1, info2 = 0;
+
+       if (argc < 2) {
+               printf("%s: eax_leaf [ecx_leaf]\n", argv[0]);
+               exit(-1);
+       }
+       errno = 0;
+       info1 = strtoul(argv[1], 0, 16);
+       if (errno) {
+               perror("info1");
+               exit(-1);
+       }
+       if (argc > 2) {
+               errno = 0;
+               info2 = strtoul(argv[2], 0, 16);
+               if (errno) {
+                       perror("info2");
+                       exit(-1);
+               }
+       }
+       eax = ebx = ecx = edx = 0xffffffff;
+       parlib_cpuid(info1, info2, &eax, &ebx, &ecx, &edx);
+       printf("CPUID for Leaf 0x%08x, Sublevel 0x%08x:\n", info1, info2);
+       printf("\teax: %08x\n\tebx: %08x\n\tecx: %08x\n\tedx: %08x\n", eax, ebx,
+              ecx, edx);
+       return 0;
+}