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