]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a program for printing out cpuid info.
authorJulian Seward <jseward@acm.org>
Wed, 28 Jul 2010 19:26:59 +0000 (19:26 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 28 Jul 2010 19:26:59 +0000 (19:26 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@1990

VEX/useful/cpuid.c [new file with mode: 0644]

diff --git a/VEX/useful/cpuid.c b/VEX/useful/cpuid.c
new file mode 100644 (file)
index 0000000..e4f3e91
--- /dev/null
@@ -0,0 +1,47 @@
+
+#include <stdio.h>
+
+typedef  unsigned int            UInt;
+typedef  unsigned long long int  ULong;
+
+void cpuid ( UInt* eax, UInt* ebx, UInt* ecx, UInt* edx, 
+             UInt index, UInt ecx_in )
+{
+   UInt a,b,c,d;
+   asm volatile ("cpuid"
+                 : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
+                 : "0" (index), "2"(ecx_in) );
+   *eax = a; *ebx = b; *ecx = c; *edx = d;
+   printf("%08x %08x -> %08x %08x %08x %08x\n",
+          index,ecx_in, a,b,c,d );
+}
+
+int main ( void )
+{
+  UInt eax, ebx, ecx, edx;
+  UInt maxidx, maxextidx, i,ecx_in;
+
+  cpuid(&eax,&ebx,&ecx,&edx, 0,0);
+  maxidx = eax;
+  for (i = 1; i <= maxidx; i++) {
+    cpuid(&eax,&ebx,&ecx,&edx, i,0);
+    if (i == 4) {
+      for (ecx_in = 1; ecx_in < 10; ecx_in++) {
+         cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
+      }
+    }
+  }
+
+  cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0);
+  maxextidx = eax;
+  for (i = 0x80000001; i <= maxextidx; i++) {
+     cpuid(&eax,&ebx,&ecx,&edx, i,0);
+  }
+
+  printf("invalid\n");
+  cpuid(&eax,&ebx,&ecx,&edx, 1234,0);
+  cpuid(&eax,&ebx,&ecx,&edx, 0x800004d3,0);
+
+
+  return 0;
+}