Home | History | Annotate | Download | only in useful
      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 
     24   printf("\n");
     25   cpuid(&eax,&ebx,&ecx,&edx, 0,0);
     26   maxidx = eax;
     27   for (i = 1; i <= maxidx +2; i++) {
     28 
     29     cpuid(&eax,&ebx,&ecx,&edx, i,0);
     30 
     31     if (i == 4) {
     32       printf("\n");
     33       for (ecx_in = 1; ecx_in < 10; ecx_in++) {
     34          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
     35       }
     36       printf("\n");
     37     }
     38 
     39     if (i == 0xb) {
     40       printf("\n");
     41       for (ecx_in = 1; ecx_in < 10; ecx_in++) {
     42          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
     43       }
     44       printf("\n");
     45     }
     46 
     47     if (i == 0xd) {
     48       printf("\n");
     49       for (ecx_in = 1; ecx_in < 5; ecx_in++) {
     50          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
     51       }
     52       printf("\n");
     53     }
     54 
     55 
     56   }
     57 
     58   printf("\n");
     59 
     60   cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0);
     61   maxextidx = eax;
     62   for (i = 0x80000001; i <= maxextidx +2; i++) {
     63      cpuid(&eax,&ebx,&ecx,&edx, i,0);
     64   }
     65 
     66   printf("invalid\n");
     67   cpuid(&eax,&ebx,&ecx,&edx, 1234,0);
     68   cpuid(&eax,&ebx,&ecx,&edx, 0x800004d3,0);
     69 
     70 
     71   return 0;
     72 }
     73 
     74 #include <stdio.h>
     75 
     76 typedef  unsigned int            UInt;
     77 typedef  unsigned long long int  ULong;
     78 
     79 void cpuid ( UInt* eax, UInt* ebx, UInt* ecx, UInt* edx,
     80              UInt index, UInt ecx_in )
     81 {
     82    UInt a,b,c,d;
     83    asm volatile ("cpuid"
     84                  : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
     85                  : "0" (index), "2"(ecx_in) );
     86    *eax = a; *ebx = b; *ecx = c; *edx = d;
     87    printf("%08x %08x -> %08x %08x %08x %08x\n",
     88           index,ecx_in, a,b,c,d );
     89 }
     90 
     91 int main ( void )
     92 {
     93   UInt eax, ebx, ecx, edx;
     94   UInt maxidx, maxextidx, i,ecx_in;
     95 
     96   printf("\n");
     97   cpuid(&eax,&ebx,&ecx,&edx, 0,0);
     98   maxidx = eax;
     99   for (i = 1; i <= maxidx +2; i++) {
    100 
    101     cpuid(&eax,&ebx,&ecx,&edx, i,0);
    102 
    103     if (i == 4) {
    104       printf("\n");
    105       for (ecx_in = 1; ecx_in < 10; ecx_in++) {
    106          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
    107       }
    108       printf("\n");
    109     }
    110 
    111     if (i == 0xb) {
    112       printf("\n");
    113       for (ecx_in = 1; ecx_in < 10; ecx_in++) {
    114          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
    115       }
    116       printf("\n");
    117     }
    118 
    119     if (i == 0xd) {
    120       printf("\n");
    121       for (ecx_in = 1; ecx_in < 5; ecx_in++) {
    122          cpuid(&eax,&ebx,&ecx,&edx, i,ecx_in);
    123       }
    124       printf("\n");
    125     }
    126 
    127 
    128   }
    129 
    130   printf("\n");
    131 
    132   cpuid(&eax,&ebx,&ecx,&edx, 0x80000000,0);
    133   maxextidx = eax;
    134   for (i = 0x80000001; i <= maxextidx +2; i++) {
    135      cpuid(&eax,&ebx,&ecx,&edx, i,0);
    136   }
    137 
    138   printf("invalid\n");
    139   cpuid(&eax,&ebx,&ecx,&edx, 1234,0);
    140   cpuid(&eax,&ebx,&ecx,&edx, 0x800004d3,0);
    141 
    142 
    143   return 0;
    144 }
    145