From 72d62f747c40811ef164a0deff10a9bf1a39a8e3 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Wed, 28 Jul 2010 19:26:59 +0000 Subject: [PATCH] Add a program for printing out cpuid info. git-svn-id: svn://svn.valgrind.org/vex/trunk@1990 --- VEX/useful/cpuid.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 VEX/useful/cpuid.c diff --git a/VEX/useful/cpuid.c b/VEX/useful/cpuid.c new file mode 100644 index 0000000000..e4f3e9172a --- /dev/null +++ b/VEX/useful/cpuid.c @@ -0,0 +1,47 @@ + +#include + +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; +} -- 2.47.3