sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | typedef unsigned int UInt; |
| 5 | typedef unsigned long long int ULong; |
| 6 | |
| 7 | void 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 | |
| 19 | int main ( void ) |
| 20 | { |
| 21 | UInt eax, ebx, ecx, edx; |
| 22 | UInt maxidx, maxextidx, i,ecx_in; |
| 23 | |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 24 | printf("\n"); |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 25 | cpuid(&eax,&ebx,&ecx,&edx, 0,0); |
| 26 | maxidx = eax; |
sewardj | fe0c5e7 | 2012-06-15 15:48:07 +0000 | [diff] [blame] | 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"); |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 37 | |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 38 | cpuid(&eax,&ebx,&ecx,&edx, i,0); |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 39 | |
sewardj | fe0c5e7 | 2012-06-15 15:48:07 +0000 | [diff] [blame] | 40 | for (ecx_in = 1; ecx_in < subleaf; ecx_in++) { |
| 41 | cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in); |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 42 | } |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 43 | |
sewardj | fe0c5e7 | 2012-06-15 15:48:07 +0000 | [diff] [blame] | 44 | if (subleaf > 0) printf("\n"); |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 45 | |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 46 | } |
| 47 | |
sewardj | 3d73810 | 2010-08-06 07:55:29 +0000 | [diff] [blame] | 48 | printf("\n"); |
| 49 | |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 50 | cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0); |
| 51 | maxextidx = eax; |
sewardj | fe0c5e7 | 2012-06-15 15:48:07 +0000 | [diff] [blame] | 52 | for (i = 0x80000001; i <= maxextidx +5; i++) { |
sewardj | 95aa910 | 2010-07-28 19:26:59 +0000 | [diff] [blame] | 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 | } |