blob: a6ded547e9e91ecfa548b06aee2a3a68dc6c6b24 [file] [log] [blame]
sewardj95aa9102010-07-28 19:26:59 +00001
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
sewardj3d738102010-08-06 07:55:29 +000024 printf("\n");
sewardj95aa9102010-07-28 19:26:59 +000025 cpuid(&eax,&ebx,&ecx,&edx, 0,0);
26 maxidx = eax;
sewardjfe0c5e72012-06-15 15:48:07 +000027 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");
sewardj3d738102010-08-06 07:55:29 +000037
sewardj95aa9102010-07-28 19:26:59 +000038 cpuid(&eax,&ebx,&ecx,&edx, i,0);
sewardj3d738102010-08-06 07:55:29 +000039
sewardjfe0c5e72012-06-15 15:48:07 +000040 for (ecx_in = 1; ecx_in < subleaf; ecx_in++) {
41 cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
sewardj95aa9102010-07-28 19:26:59 +000042 }
sewardj3d738102010-08-06 07:55:29 +000043
sewardjfe0c5e72012-06-15 15:48:07 +000044 if (subleaf > 0) printf("\n");
sewardj3d738102010-08-06 07:55:29 +000045
sewardj95aa9102010-07-28 19:26:59 +000046 }
47
sewardj3d738102010-08-06 07:55:29 +000048 printf("\n");
49
sewardj95aa9102010-07-28 19:26:59 +000050 cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0);
51 maxextidx = eax;
sewardjfe0c5e72012-06-15 15:48:07 +000052 for (i = 0x80000001; i <= maxextidx +5; i++) {
sewardj95aa9102010-07-28 19:26:59 +000053 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}