-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
75 lines (65 loc) · 2.59 KB
/
test.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
#ifdef _WIN32
#include <windows.h>
#endif
#include "cpuid.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef DUMMYSTRUCTNAME
#define DUMMYSTRUCTNAME
#endif
#ifndef DUMMYUNIONNAME
#define DUMMYUNIONNAME
#endif
const char * PRINTF_MASK = " Leaf=%02x -->> [ EAX=%08x, EBX=%08x, ECX=%08x, EDX=%08x ]\n";
int main(int argc, char* argv[]) {
int avail = is_cpuid_available();
printf("Is CPUID available = %s\n", avail ? "yes" : "no");
if (!avail) return 1;
CPU_INFO * info = cpu_info();
CPUID_REGS r;
puts("\nBasic CPUID raw data:");
int i = 0;
for (; i <= info->max_values.basic; i++) {
cpuid(i, r.Raw);
if (r.EAX > 0 || r.EBX > 0 || r.ECX > 0 || r.EDX > 0)
printf(PRINTF_MASK, i, r.EAX, r.EBX, r.ECX, r.EDX);
}
puts("\nExtended CPUID raw data:");
i = 0x80000000;
for (; i <= info->max_values.extended; i++) {
cpuid(i, r.Raw);
if (r.EAX > 0 || r.EBX > 0 || r.ECX > 0 || r.EDX > 0)
printf(PRINTF_MASK, i, r.EAX, r.EBX, r.ECX, r.EDX);
}
puts("\nHypervisor CPUID raw data:");
if(info->features.Regs.ECX.HYPERVISOR) {
i = 0x40000000;
cpuid(i, r.Raw);
int hv = r.EAX;
for (; i <= hv; i++) {
cpuid(i, r.Raw);
if (r.EAX > 0 || r.EBX > 0 || r.ECX > 0 || r.EDX > 0)
printf(PRINTF_MASK, i, r.EAX, r.EBX, r.ECX, r.EDX);
}
} else {
printf(" -- Hypervisor is not present!\n");
}
puts("\nCPUID information:");
if (info) {
printf(" Vendor : %s\n", info->vendor.name);
printf(" Brand name : %s\n", info->brand);
if (info->arch) printf(" Codename : %s\n", info->arch);
printf(" Core : %s\n", info->core);
printf(" Lythography : %d nm\n", info->process);
printf(" Signature : %x\n", info->features.Signature);
printf(" Family : %02xh (%d)\n", info->family, info->family);
printf(" Model : %02xh (%d)\n", info->model, info->model);
printf(" Stepping : %02xh (%d)\n", info->stepping, info->stepping);
printf(" Max CPUID : basic = 0x%02X, extended = 0x%08X\n", info->max_values.basic, info->max_values.extended);
printf(" Hypervisor : %s\n", info->features.Regs.ECX.HYPERVISOR ? "present" : "not present");
printf(" CPU sockets : %d\n", cpu_count());
printf(" Physical cores : %d\n", (info->features.Regs.EDX.HTT)?info->features.Regs.EBX.LogicalProcessors/2:info->features.Regs.EBX.LogicalProcessors);
printf(" Logical cores : %d\n", info->features.Regs.EBX.LogicalProcessors);
printf(" Hyper Threading : %s\n", info->features.Regs.EDX.HTT ? "enabled" : "disabled");
}
}