1
2#include <stdio.h>
3
4typedef  unsigned int            UInt;
5typedef  unsigned long long int  ULong;
6
7void cpuid ( UInt* eax, UInt* ebx, UInt* ecx, UInt* edx,
8             UInt index, UInt ecx_in )
9{
10   UInt a,b,c,d;
11   asm volatile ("cpuid"
12                 : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
13                 : "0" (index), "2"(ecx_in) );
14   *eax = a; *ebx = b; *ecx = c; *edx = d;
15   printf("%08x %08x -> %08x %08x %08x %08x\n",
16          index,ecx_in, a,b,c,d );
17}
18
19int main ( void )
20{
21  UInt eax, ebx, ecx, edx;
22  UInt maxidx, maxextidx, i,ecx_in;
23
24  printf("\n");
25  cpuid(&eax,&ebx,&ecx,&edx, 0,0);
26  maxidx = eax;
27  for (i = 1; i <= maxidx +5; i++) {
28
29    UInt subleaf = 0;
30
31    if (i == 4) subleaf = 10;
32    if (i == 7) subleaf = 10;
33    if (i == 0xB) subleaf = 10;
34    if (i == 0xD) subleaf = 10;
35
36    if (subleaf > 0) printf("\n");
37
38    cpuid(&eax,&ebx,&ecx,&edx, i,0);
39
40    for (ecx_in = 1; ecx_in < subleaf; ecx_in++) {
41       cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
42    }
43
44    if (subleaf > 0) printf("\n");
45
46  }
47
48  printf("\n");
49
50  cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0);
51  maxextidx = eax;
52  for (i = 0x80000001; i <= maxextidx +5; i++) {
53     cpuid(&eax,&ebx,&ecx,&edx, i,0);
54  }
55
56  printf("invalid\n");
57  cpuid(&eax,&ebx,&ecx,&edx, 1234,0);
58  cpuid(&eax,&ebx,&ecx,&edx, 0x800004d3,0);
59
60
61  return 0;
62}
63