-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
142 lines (91 loc) · 2.62 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include "cpuid.h"
#include "cpuiddata.h"
static void showflags (REG32 reg, const struct _BIT_FLAGS *flag);
static unsigned int showcpubrand (const char *str);
int main (void)
{
REG reg;
EAX1_EAX eax1_eax;
#ifndef __x86_64__
if(!testcpuid())
{
fprintf(stderr,"CPU is not support CPUID instruction\n");
return 1;
}
#endif
puts ("****************** CPU ******************");
{
CPUSTR str;
printf ("CPU string:%s\n", getcpustr (str));
}
reg.eax = 0x80000000;
reg = cpuid (®);
if (reg.eax >= 0x80000004)
{
CPUBANDSTR bstr;
printf ("CPU Brand string:%s\n",&bstr[showcpubrand (getcpubrandstr (bstr))]);
}
reg.eax = 1;
reg = cpuid (®);
eax1_eax.eax = reg.eax;
printf ("step:%X\n", eax1_eax.cpu.step);
printf ("model:%X\n", eax1_eax.cpu.model);
printf ("family:%X\n", eax1_eax.cpu.family);
printf ("type:%X\n", eax1_eax.cpu.type);
if (eax1_eax.cpu.family == 0xF)
{
printf ("ext.model:%X\n",(eax1_eax.cpu.extmodel << 4) + eax1_eax.cpu.model);
printf ("ext.family:%X\n", eax1_eax.cpu.extfamily + eax1_eax.cpu.family);
}
else if (eax1_eax.cpu.family == 0x6)
{
printf ("ext.model:%X\n",(eax1_eax.cpu.extmodel << 4) + eax1_eax.cpu.model);
printf ("ext.family:%X\n", eax1_eax.cpu.family);
}
putchar ('\n');
puts ("****************** EAX=1,EDX ******************");
showflags (reg.edx, eax1_edx);
putchar ('\n');
puts ("****************** EAX=1,ECX ******************");
showflags (reg.ecx, eax1_ecx);
putchar ('\n');
reg.eax = 7;
reg.ecx = 0;
reg = cpuid (®);
puts ("****************** EAX=7,ECX=0,EBX ******************");
showflags (reg.ebx, eax7ecx0_ebx);
putchar ('\n');
puts ("****************** EAX=7,ECX=0,ECX ******************");
showflags (reg.ecx, eax7ecx0_ecx);
putchar ('\n');
reg.eax = 0x80000000;
reg = cpuid (®);
if (reg.eax > 0x80000000)
{
reg.eax = 0x80000001;
reg = cpuid (®);
puts ("****************** EAX=80000001h,EDX ******************");
showflags (reg.edx, eax80000001h_edx);
putchar ('\n');
puts ("****************** EAX=80000001h,ECX ******************");
showflags (reg.ecx, eax80000001h_ecx);
putchar ('\n');
}
return 0;
}
static void showflags (REG32 reg, const struct _BIT_FLAGS *flag)
{
unsigned int i;
for (i = 0; i < sizeof(REG32)*8; i++)
{
if (reg & (1 << i) && flag[i].name)
printf ("bit %u:%s [%s]\n", i, flag[i].name, flag[i].feature);
}
}
static unsigned int showcpubrand (const char *str)
{
unsigned int i;
for (i = 0; str[i] == 0x20 && str[i] != '\0'; i++);
return i;
}