add relative mouse handling in mouse.asm
[retroray] / src / cpuid.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "cpuid.h"
4
5 static const char *cpuname(struct cpuid_info *cpu);
6 static const char *cpuvendor(struct cpuid_info *cpu);
7
8 struct cpuid_info cpuid;
9
10 void print_cpuid(struct cpuid_info *cpu)
11 {
12         int i, col, len;
13         static const char *featstr[32] = {
14                 "fpu", "vme", "dbgext", "pse", "tsc", "msr", "pae", "mce",
15                 "cx8", "apic", "?", "sep", "mtrr", "pge", "mca", "cmov",
16                 "pat", "pse36", "psn", "clf", "?", "dtes", "acpi", "mmx",
17                 "fxsr", "sse", "sse2", "ss", "htt", "tm1", "ia64", "pbe"};
18         static const char *feat2str[32] = {
19                 "sse3", "pclmul", "dtes64", "monitor", "ds-cpl", "vmx", "smx", "est",
20                 "tm2", "ssse3", "cid", "sdbg", "fma", "cx16", "etprd", "pdcm",
21                 "?", "pcid", "dca", "sse41", "sse42", "x2apic", "movbe", "popcnt",
22                 "?", "aes", "xsave", "osxsave", "avx", "f16c", "rdrand", "?"};
23
24         printf("CPU: %s - %s\n", cpuvendor(cpu), cpuname(cpu));
25         printf("features:\n   ");
26         col = 3;
27         for(i=0; i<32; i++) {
28                 if(cpu->feat & (1 << i)) {
29                         len = strlen(featstr[i]) + 1;
30                         if(col + len >= 80) {
31                                 fputs("\n   ", stdout);
32                                 col = 3;
33                         }
34                         col += printf(" %s", featstr[i]);
35                 }
36         }
37         for(i=0; i<32; i++) {
38                 if(cpu->feat2 & (1 << i)) {
39                         len = strlen(feat2str[i]) + 1;
40                         if(col + len >= 80) {
41                                 fputs("\n   ", stdout);
42                                 col = 3;
43                         }
44                         col += printf(" %s", feat2str[i]);
45                 }
46         }
47         putchar('\n');
48 }
49
50 static const char *fam4_models[16] = {
51         "486 DX 25/33", "486 DX 50", "486 SX", "486 DX/2", "486 SL", "486 SX/2",
52         0, "486 DX/2-WB", "486 DX/4", "486 DX/4-WB"
53 };
54 static const char *fam5_models[16] = {
55         "Pentium 60/66", "Pentium 60/66", "Pentium 75-200", "OverDrive", "Pentium MMX",
56         0, 0, "Mobile Pentium 75-200", "Mobile Pentium MMX", "Quark"
57 };
58 static const char *fam6_models[16] = {
59         "Pentium Pro", "Pentium Pro", 0, "Pentium 2", "Pentium 2", "Pentium 2",
60         "Mobile Pentium 2", "Pentium 3", "Pentium 3", 0, "Pentium 3", "Pentium 3"
61 };
62
63
64 static const char *cpuname(struct cpuid_info *cpu)
65 {
66         int model, family;
67         char *rd, *wr;
68
69         if(*cpu->brandstr) {
70                 /* unwank the string */
71                 rd = wr = cpu->brandstr;
72                 while(*rd) {
73                         if(rd[0] == '(' && rd[1] == 'T' && rd[2] == 'M' && rd[3] == ')')
74                                 rd += 4;
75                         else if(rd[0] == '(' && rd[1] == 'R' && rd[2] == ')')
76                                 rd += 3;
77                         if(rd != wr) *wr = *rd;
78                         wr++;
79                         rd++;
80                 }
81                 *wr = 0;
82                 return cpu->brandstr;
83         }
84
85         if(CPUID_EXTMODEL(cpu->id)) {
86                 /* processors new enough to have an extended model, should also provide
87                  * a brand string. If we end up here, we don't know what it is
88                  */
89                 return "unknown";
90         }
91
92         model = CPUID_MODEL(cpu->id);
93         family = CPUID_FAMILY(cpu->id) | (CPUID_EXTFAMILY(cpu->id) << 4);
94
95         switch(family) {
96         case 3: return "386";
97         case 4: return fam4_models[model] ? fam4_models[model] : "486";
98         case 5: return fam5_models[model] ? fam5_models[model] : "Pentium";
99         case 6: return fam6_models[model] ? fam6_models[model] : "unknown";
100         case 15: return "Pentium 4";
101         default:
102                 break;
103         }
104         return "unknown";
105 }
106
107 static const char *cpuvendor(struct cpuid_info *cpu)
108 {
109         static char other[16];
110         static const struct { const char *wank, *vendor; } unwanktab[] = {
111                 {"GenuineIntel", "intel"},
112                 {"AuthenticAMD", "AMD"},
113                 {"AMDisbetter!", "AMD"},
114                 {"CentaurHauls", "IDT"},
115                 {"CyrixInstead", "Cyrix"},
116                 {"TransmetaCPU", "Transmeta"},
117                 {"GenuineTMx86", "Transmeta"},
118                 {"Geode by NSC", "NatSemi"},
119                 {"NexGenDriven", "NexGen"},
120                 {"RiseRiseRise", "Rise"},
121                 {"SiS SiS SiS ", "SiS"},
122                 {"UMC UMC UMC ", "UMC"},
123                 {"VIA VIA VIA ", "VIA"},
124                 {"Vortex86 SoC", "DM&P"},
125                 {"  Shanghai  ", "Zhaoxin"},
126                 {"HygonGenuine", "Hygon"},
127                 {"E2K MACHINE", "MCST Elbrus"},
128                 {"MiSTer A0486", "ao486"},
129                 {"bhyve bhyve ", "bhyve"},
130                 {" KVMKVMKVM  ", "KVM"},
131                 {"TCGTCGTCGTCG", "qemu"},
132                 {"Microsoft Hv", "MS Hyper-V"},
133                 {" lrpepyh  vr", "Parallels"},
134                 {"VMwareVMware", "VMware"},
135                 {"XenVMMXenVMM", "Xen"},
136                 {"ACRNACRNACRN", "ACRN"},
137                 {" QNXQVMBSQG ", "QNX Hypervisor"},
138                 {0, 0}
139         };
140
141         int i;
142         for(i=0; unwanktab[i].wank; i++) {
143                 if(memcmp(cpu->vendor, unwanktab[i].wank, 12) == 0) {
144                         return unwanktab[i].vendor;
145                 }
146         }
147
148         memcpy(other, cpu->vendor, 12);
149         other[12] = 0;
150         return other;
151 }