]> git.proxmox.com Git - mirror_qemu.git/blame - target-i386/cpu.c
target-i386: Add property getter for CPU model
[mirror_qemu.git] / target-i386 / cpu.c
CommitLineData
c6dc6f63
AP
1/*
2 * i386 CPUID helper functions
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22#include <inttypes.h>
23
24#include "cpu.h"
25#include "kvm.h"
26
27#include "qemu-option.h"
28#include "qemu-config.h"
29
71ad61d3
AF
30#include "qapi/qapi-visit-core.h"
31
28f52cc0
VR
32#include "hyperv.h"
33
c6dc6f63
AP
34/* feature flags taken from "Intel Processor Identification and the CPUID
35 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
36 * between feature naming conventions, aliases may be added.
37 */
38static const char *feature_name[] = {
39 "fpu", "vme", "de", "pse",
40 "tsc", "msr", "pae", "mce",
41 "cx8", "apic", NULL, "sep",
42 "mtrr", "pge", "mca", "cmov",
43 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
44 NULL, "ds" /* Intel dts */, "acpi", "mmx",
45 "fxsr", "sse", "sse2", "ss",
46 "ht" /* Intel htt */, "tm", "ia64", "pbe",
47};
48static const char *ext_feature_name[] = {
f370be3c 49 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
e117f772 50 "ds_cpl", "vmx", "smx", "est",
c6dc6f63 51 "tm2", "ssse3", "cid", NULL,
e117f772 52 "fma", "cx16", "xtpr", "pdcm",
c6dc6f63 53 NULL, NULL, "dca", "sse4.1|sse4_1",
e117f772 54 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
eaf3f097 55 "tsc-deadline", "aes", "xsave", "osxsave",
e117f772 56 "avx", NULL, NULL, "hypervisor",
c6dc6f63
AP
57};
58static const char *ext2_feature_name[] = {
59 "fpu", "vme", "de", "pse",
60 "tsc", "msr", "pae", "mce",
61 "cx8" /* AMD CMPXCHG8B */, "apic", NULL, "syscall",
62 "mtrr", "pge", "mca", "cmov",
63 "pat", "pse36", NULL, NULL /* Linux mp */,
3ac8ebfe 64 "nx|xd", NULL, "mmxext", "mmx",
f370be3c 65 "fxsr", "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
3ac8ebfe 66 NULL, "lm|i64", "3dnowext", "3dnow",
c6dc6f63
AP
67};
68static const char *ext3_feature_name[] = {
69 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
70 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
e117f772 71 "3dnowprefetch", "osvw", "ibs", "xop",
c6dc6f63 72 "skinit", "wdt", NULL, NULL,
e117f772 73 "fma4", NULL, "cvt16", "nodeid_msr",
c6dc6f63
AP
74 NULL, NULL, NULL, NULL,
75 NULL, NULL, NULL, NULL,
76 NULL, NULL, NULL, NULL,
77};
78
79static const char *kvm_feature_name[] = {
642258c6 80 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock", "kvm_asyncpf", NULL, NULL, NULL,
c6dc6f63
AP
81 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
82 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
83 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
84};
85
296acb64
JR
86static const char *svm_feature_name[] = {
87 "npt", "lbrv", "svm_lock", "nrip_save",
88 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
89 NULL, NULL, "pause_filter", NULL,
90 "pfthreshold", NULL, NULL, NULL,
91 NULL, NULL, NULL, NULL,
92 NULL, NULL, NULL, NULL,
93 NULL, NULL, NULL, NULL,
94 NULL, NULL, NULL, NULL,
95};
96
c6dc6f63
AP
97/* collects per-function cpuid data
98 */
99typedef struct model_features_t {
100 uint32_t *guest_feat;
101 uint32_t *host_feat;
102 uint32_t check_feat;
103 const char **flag_names;
104 uint32_t cpuid;
105 } model_features_t;
106
107int check_cpuid = 0;
108int enforce_cpuid = 0;
109
bb44e0d1
JK
110void host_cpuid(uint32_t function, uint32_t count,
111 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
bdde476a
AP
112{
113#if defined(CONFIG_KVM)
a1fd24af
AL
114 uint32_t vec[4];
115
116#ifdef __x86_64__
117 asm volatile("cpuid"
118 : "=a"(vec[0]), "=b"(vec[1]),
119 "=c"(vec[2]), "=d"(vec[3])
120 : "0"(function), "c"(count) : "cc");
121#else
122 asm volatile("pusha \n\t"
123 "cpuid \n\t"
124 "mov %%eax, 0(%2) \n\t"
125 "mov %%ebx, 4(%2) \n\t"
126 "mov %%ecx, 8(%2) \n\t"
127 "mov %%edx, 12(%2) \n\t"
128 "popa"
129 : : "a"(function), "c"(count), "S"(vec)
130 : "memory", "cc");
131#endif
132
bdde476a 133 if (eax)
a1fd24af 134 *eax = vec[0];
bdde476a 135 if (ebx)
a1fd24af 136 *ebx = vec[1];
bdde476a 137 if (ecx)
a1fd24af 138 *ecx = vec[2];
bdde476a 139 if (edx)
a1fd24af 140 *edx = vec[3];
bdde476a
AP
141#endif
142}
c6dc6f63
AP
143
144#define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
145
146/* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
147 * a substring. ex if !NULL points to the first char after a substring,
148 * otherwise the string is assumed to sized by a terminating nul.
149 * Return lexical ordering of *s1:*s2.
150 */
151static int sstrcmp(const char *s1, const char *e1, const char *s2,
152 const char *e2)
153{
154 for (;;) {
155 if (!*s1 || !*s2 || *s1 != *s2)
156 return (*s1 - *s2);
157 ++s1, ++s2;
158 if (s1 == e1 && s2 == e2)
159 return (0);
160 else if (s1 == e1)
161 return (*s2);
162 else if (s2 == e2)
163 return (*s1);
164 }
165}
166
167/* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
168 * '|' delimited (possibly empty) strings in which case search for a match
169 * within the alternatives proceeds left to right. Return 0 for success,
170 * non-zero otherwise.
171 */
172static int altcmp(const char *s, const char *e, const char *altstr)
173{
174 const char *p, *q;
175
176 for (q = p = altstr; ; ) {
177 while (*p && *p != '|')
178 ++p;
179 if ((q == p && !*s) || (q != p && !sstrcmp(s, e, q, p)))
180 return (0);
181 if (!*p)
182 return (1);
183 else
184 q = ++p;
185 }
186}
187
188/* search featureset for flag *[s..e), if found set corresponding bit in
e41e0fc6 189 * *pval and return true, otherwise return false
c6dc6f63 190 */
e41e0fc6
JK
191static bool lookup_feature(uint32_t *pval, const char *s, const char *e,
192 const char **featureset)
c6dc6f63
AP
193{
194 uint32_t mask;
195 const char **ppc;
e41e0fc6 196 bool found = false;
c6dc6f63 197
e41e0fc6 198 for (mask = 1, ppc = featureset; mask; mask <<= 1, ++ppc) {
c6dc6f63
AP
199 if (*ppc && !altcmp(s, e, *ppc)) {
200 *pval |= mask;
e41e0fc6 201 found = true;
c6dc6f63 202 }
e41e0fc6
JK
203 }
204 return found;
c6dc6f63
AP
205}
206
207static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features,
208 uint32_t *ext_features,
209 uint32_t *ext2_features,
210 uint32_t *ext3_features,
296acb64
JR
211 uint32_t *kvm_features,
212 uint32_t *svm_features)
c6dc6f63
AP
213{
214 if (!lookup_feature(features, flagname, NULL, feature_name) &&
215 !lookup_feature(ext_features, flagname, NULL, ext_feature_name) &&
216 !lookup_feature(ext2_features, flagname, NULL, ext2_feature_name) &&
217 !lookup_feature(ext3_features, flagname, NULL, ext3_feature_name) &&
296acb64
JR
218 !lookup_feature(kvm_features, flagname, NULL, kvm_feature_name) &&
219 !lookup_feature(svm_features, flagname, NULL, svm_feature_name))
c6dc6f63
AP
220 fprintf(stderr, "CPU feature %s not found\n", flagname);
221}
222
223typedef struct x86_def_t {
224 struct x86_def_t *next;
225 const char *name;
226 uint32_t level;
227 uint32_t vendor1, vendor2, vendor3;
228 int family;
229 int model;
230 int stepping;
b862d1fe 231 int tsc_khz;
296acb64
JR
232 uint32_t features, ext_features, ext2_features, ext3_features;
233 uint32_t kvm_features, svm_features;
c6dc6f63
AP
234 uint32_t xlevel;
235 char model_id[48];
236 int vendor_override;
237 uint32_t flags;
b3baa152
BW
238 /* Store the results of Centaur's CPUID instructions */
239 uint32_t ext4_features;
240 uint32_t xlevel2;
c6dc6f63
AP
241} x86_def_t;
242
243#define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
244#define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
245 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
246#define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
247 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
248 CPUID_PSE36 | CPUID_FXSR)
249#define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
250#define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
251 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
252 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
253 CPUID_PAE | CPUID_SEP | CPUID_APIC)
42673936 254#define EXT2_FEATURE_MASK 0x0183F3FF
c6dc6f63 255
551a2dec
AP
256#define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
257 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
258 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
259 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
260 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
8560efed
AJ
261 /* partly implemented:
262 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64)
263 CPUID_PSE36 (needed for Solaris) */
264 /* missing:
265 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
551a2dec 266#define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | \
8713f8ff 267 CPUID_EXT_CX16 | CPUID_EXT_POPCNT | \
551a2dec 268 CPUID_EXT_HYPERVISOR)
8560efed
AJ
269 /* missing:
270 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_EST,
8713f8ff 271 CPUID_EXT_TM2, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_XSAVE */
551a2dec
AP
272#define TCG_EXT2_FEATURES ((TCG_FEATURES & EXT2_FEATURE_MASK) | \
273 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
274 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT)
8560efed
AJ
275 /* missing:
276 CPUID_EXT2_PDPE1GB */
551a2dec
AP
277#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
278 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
296acb64 279#define TCG_SVM_FEATURES 0
551a2dec 280
c6dc6f63
AP
281/* maintains list of cpu model definitions
282 */
283static x86_def_t *x86_defs = {NULL};
284
285/* built-in cpu model definitions (deprecated)
286 */
287static x86_def_t builtin_x86_defs[] = {
c6dc6f63
AP
288 {
289 .name = "qemu64",
290 .level = 4,
291 .vendor1 = CPUID_VENDOR_AMD_1,
292 .vendor2 = CPUID_VENDOR_AMD_2,
293 .vendor3 = CPUID_VENDOR_AMD_3,
294 .family = 6,
295 .model = 2,
296 .stepping = 3,
297 .features = PPRO_FEATURES |
c6dc6f63 298 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
c6dc6f63
AP
299 CPUID_PSE36,
300 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT,
42673936 301 .ext2_features = (PPRO_FEATURES & EXT2_FEATURE_MASK) |
c6dc6f63
AP
302 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
303 .ext3_features = CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
304 CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
305 .xlevel = 0x8000000A,
306 .model_id = "QEMU Virtual CPU version " QEMU_VERSION,
307 },
308 {
309 .name = "phenom",
310 .level = 5,
311 .vendor1 = CPUID_VENDOR_AMD_1,
312 .vendor2 = CPUID_VENDOR_AMD_2,
313 .vendor3 = CPUID_VENDOR_AMD_3,
314 .family = 16,
315 .model = 2,
316 .stepping = 3,
c6dc6f63
AP
317 .features = PPRO_FEATURES |
318 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
8560efed 319 CPUID_PSE36 | CPUID_VME | CPUID_HT,
c6dc6f63
AP
320 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_CX16 |
321 CPUID_EXT_POPCNT,
42673936 322 .ext2_features = (PPRO_FEATURES & EXT2_FEATURE_MASK) |
c6dc6f63
AP
323 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX |
324 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_MMXEXT |
8560efed 325 CPUID_EXT2_FFXSR | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP,
c6dc6f63
AP
326 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
327 CPUID_EXT3_CR8LEG,
328 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
329 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
330 .ext3_features = CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
331 CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
296acb64 332 .svm_features = CPUID_SVM_NPT | CPUID_SVM_LBRV,
c6dc6f63
AP
333 .xlevel = 0x8000001A,
334 .model_id = "AMD Phenom(tm) 9550 Quad-Core Processor"
335 },
336 {
337 .name = "core2duo",
338 .level = 10,
339 .family = 6,
340 .model = 15,
341 .stepping = 11,
c6dc6f63
AP
342 .features = PPRO_FEATURES |
343 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
8560efed
AJ
344 CPUID_PSE36 | CPUID_VME | CPUID_DTS | CPUID_ACPI | CPUID_SS |
345 CPUID_HT | CPUID_TM | CPUID_PBE,
346 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
347 CPUID_EXT_DTES64 | CPUID_EXT_DSCPL | CPUID_EXT_VMX | CPUID_EXT_EST |
348 CPUID_EXT_TM2 | CPUID_EXT_CX16 | CPUID_EXT_XTPR | CPUID_EXT_PDCM,
c6dc6f63
AP
349 .ext2_features = CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
350 .ext3_features = CPUID_EXT3_LAHF_LM,
351 .xlevel = 0x80000008,
352 .model_id = "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
353 },
354 {
355 .name = "kvm64",
356 .level = 5,
357 .vendor1 = CPUID_VENDOR_INTEL_1,
358 .vendor2 = CPUID_VENDOR_INTEL_2,
359 .vendor3 = CPUID_VENDOR_INTEL_3,
360 .family = 15,
361 .model = 6,
362 .stepping = 1,
363 /* Missing: CPUID_VME, CPUID_HT */
364 .features = PPRO_FEATURES |
365 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
366 CPUID_PSE36,
367 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
368 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_CX16,
369 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
42673936 370 .ext2_features = (PPRO_FEATURES & EXT2_FEATURE_MASK) |
c6dc6f63
AP
371 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
372 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
373 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
374 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
375 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
376 .ext3_features = 0,
377 .xlevel = 0x80000008,
378 .model_id = "Common KVM processor"
379 },
c6dc6f63
AP
380 {
381 .name = "qemu32",
382 .level = 4,
383 .family = 6,
384 .model = 3,
385 .stepping = 3,
386 .features = PPRO_FEATURES,
387 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_POPCNT,
58012d66 388 .xlevel = 0x80000004,
c6dc6f63
AP
389 .model_id = "QEMU Virtual CPU version " QEMU_VERSION,
390 },
eafaf1e5
AP
391 {
392 .name = "kvm32",
393 .level = 5,
394 .family = 15,
395 .model = 6,
396 .stepping = 1,
397 .features = PPRO_FEATURES |
398 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_PSE36,
399 .ext_features = CPUID_EXT_SSE3,
400 .ext2_features = PPRO_FEATURES & EXT2_FEATURE_MASK,
401 .ext3_features = 0,
402 .xlevel = 0x80000008,
403 .model_id = "Common 32-bit KVM processor"
404 },
c6dc6f63
AP
405 {
406 .name = "coreduo",
407 .level = 10,
408 .family = 6,
409 .model = 14,
410 .stepping = 8,
c6dc6f63 411 .features = PPRO_FEATURES | CPUID_VME |
8560efed
AJ
412 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_DTS | CPUID_ACPI |
413 CPUID_SS | CPUID_HT | CPUID_TM | CPUID_PBE,
414 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_VMX |
415 CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR | CPUID_EXT_PDCM,
c6dc6f63
AP
416 .ext2_features = CPUID_EXT2_NX,
417 .xlevel = 0x80000008,
418 .model_id = "Genuine Intel(R) CPU T2600 @ 2.16GHz",
419 },
420 {
421 .name = "486",
58012d66 422 .level = 1,
c6dc6f63
AP
423 .family = 4,
424 .model = 0,
425 .stepping = 0,
426 .features = I486_FEATURES,
427 .xlevel = 0,
428 },
429 {
430 .name = "pentium",
431 .level = 1,
432 .family = 5,
433 .model = 4,
434 .stepping = 3,
435 .features = PENTIUM_FEATURES,
436 .xlevel = 0,
437 },
438 {
439 .name = "pentium2",
440 .level = 2,
441 .family = 6,
442 .model = 5,
443 .stepping = 2,
444 .features = PENTIUM2_FEATURES,
445 .xlevel = 0,
446 },
447 {
448 .name = "pentium3",
449 .level = 2,
450 .family = 6,
451 .model = 7,
452 .stepping = 3,
453 .features = PENTIUM3_FEATURES,
454 .xlevel = 0,
455 },
456 {
457 .name = "athlon",
458 .level = 2,
459 .vendor1 = CPUID_VENDOR_AMD_1,
460 .vendor2 = CPUID_VENDOR_AMD_2,
461 .vendor3 = CPUID_VENDOR_AMD_3,
462 .family = 6,
463 .model = 2,
464 .stepping = 3,
465 .features = PPRO_FEATURES | CPUID_PSE36 | CPUID_VME | CPUID_MTRR | CPUID_MCA,
42673936 466 .ext2_features = (PPRO_FEATURES & EXT2_FEATURE_MASK) | CPUID_EXT2_MMXEXT | CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT,
c6dc6f63
AP
467 .xlevel = 0x80000008,
468 /* XXX: put another string ? */
469 .model_id = "QEMU Virtual CPU version " QEMU_VERSION,
470 },
471 {
472 .name = "n270",
473 /* original is on level 10 */
474 .level = 5,
475 .family = 6,
476 .model = 28,
477 .stepping = 2,
478 .features = PPRO_FEATURES |
8560efed
AJ
479 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_VME | CPUID_DTS |
480 CPUID_ACPI | CPUID_SS | CPUID_HT | CPUID_TM | CPUID_PBE,
c6dc6f63 481 /* Some CPUs got no CPUID_SEP */
8560efed
AJ
482 .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
483 CPUID_EXT_DSCPL | CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR,
42673936 484 .ext2_features = (PPRO_FEATURES & EXT2_FEATURE_MASK) | CPUID_EXT2_NX,
8560efed 485 .ext3_features = CPUID_EXT3_LAHF_LM,
c6dc6f63
AP
486 .xlevel = 0x8000000A,
487 .model_id = "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
488 },
489};
490
491static int cpu_x86_fill_model_id(char *str)
492{
493 uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
494 int i;
495
496 for (i = 0; i < 3; i++) {
497 host_cpuid(0x80000002 + i, 0, &eax, &ebx, &ecx, &edx);
498 memcpy(str + i * 16 + 0, &eax, 4);
499 memcpy(str + i * 16 + 4, &ebx, 4);
500 memcpy(str + i * 16 + 8, &ecx, 4);
501 memcpy(str + i * 16 + 12, &edx, 4);
502 }
503 return 0;
504}
505
506static int cpu_x86_fill_host(x86_def_t *x86_cpu_def)
507{
508 uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
509
510 x86_cpu_def->name = "host";
511 host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx);
512 x86_cpu_def->level = eax;
513 x86_cpu_def->vendor1 = ebx;
514 x86_cpu_def->vendor2 = edx;
515 x86_cpu_def->vendor3 = ecx;
516
517 host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx);
518 x86_cpu_def->family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF);
519 x86_cpu_def->model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12);
520 x86_cpu_def->stepping = eax & 0x0F;
521 x86_cpu_def->ext_features = ecx;
522 x86_cpu_def->features = edx;
523
524 host_cpuid(0x80000000, 0, &eax, &ebx, &ecx, &edx);
525 x86_cpu_def->xlevel = eax;
526
527 host_cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx);
528 x86_cpu_def->ext2_features = edx;
529 x86_cpu_def->ext3_features = ecx;
530 cpu_x86_fill_model_id(x86_cpu_def->model_id);
531 x86_cpu_def->vendor_override = 0;
532
b3baa152
BW
533 /* Call Centaur's CPUID instruction. */
534 if (x86_cpu_def->vendor1 == CPUID_VENDOR_VIA_1 &&
535 x86_cpu_def->vendor2 == CPUID_VENDOR_VIA_2 &&
536 x86_cpu_def->vendor3 == CPUID_VENDOR_VIA_3) {
537 host_cpuid(0xC0000000, 0, &eax, &ebx, &ecx, &edx);
538 if (eax >= 0xC0000001) {
539 /* Support VIA max extended level */
540 x86_cpu_def->xlevel2 = eax;
541 host_cpuid(0xC0000001, 0, &eax, &ebx, &ecx, &edx);
542 x86_cpu_def->ext4_features = edx;
543 }
544 }
296acb64
JR
545
546 /*
547 * Every SVM feature requires emulation support in KVM - so we can't just
548 * read the host features here. KVM might even support SVM features not
549 * available on the host hardware. Just set all bits and mask out the
550 * unsupported ones later.
551 */
552 x86_cpu_def->svm_features = -1;
553
c6dc6f63
AP
554 return 0;
555}
556
557static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)
558{
559 int i;
560
561 for (i = 0; i < 32; ++i)
562 if (1 << i & mask) {
563 fprintf(stderr, "warning: host cpuid %04x_%04x lacks requested"
564 " flag '%s' [0x%08x]\n",
565 f->cpuid >> 16, f->cpuid & 0xffff,
566 f->flag_names[i] ? f->flag_names[i] : "[reserved]", mask);
567 break;
568 }
569 return 0;
570}
571
572/* best effort attempt to inform user requested cpu flags aren't making
573 * their way to the guest. Note: ft[].check_feat ideally should be
574 * specified via a guest_def field to suppress report of extraneous flags.
575 */
576static int check_features_against_host(x86_def_t *guest_def)
577{
578 x86_def_t host_def;
579 uint32_t mask;
580 int rv, i;
581 struct model_features_t ft[] = {
582 {&guest_def->features, &host_def.features,
583 ~0, feature_name, 0x00000000},
584 {&guest_def->ext_features, &host_def.ext_features,
585 ~CPUID_EXT_HYPERVISOR, ext_feature_name, 0x00000001},
586 {&guest_def->ext2_features, &host_def.ext2_features,
587 ~PPRO_FEATURES, ext2_feature_name, 0x80000000},
588 {&guest_def->ext3_features, &host_def.ext3_features,
589 ~CPUID_EXT3_SVM, ext3_feature_name, 0x80000001}};
590
591 cpu_x86_fill_host(&host_def);
66fe09ee 592 for (rv = 0, i = 0; i < ARRAY_SIZE(ft); ++i)
c6dc6f63
AP
593 for (mask = 1; mask; mask <<= 1)
594 if (ft[i].check_feat & mask && *ft[i].guest_feat & mask &&
595 !(*ft[i].host_feat & mask)) {
596 unavailable_host_feature(&ft[i], mask);
597 rv = 1;
598 }
599 return rv;
600}
601
95b8519d
AF
602static void x86_cpuid_version_get_family(Object *obj, Visitor *v, void *opaque,
603 const char *name, Error **errp)
604{
605 X86CPU *cpu = X86_CPU(obj);
606 CPUX86State *env = &cpu->env;
607 int64_t value;
608
609 value = (env->cpuid_version >> 8) & 0xf;
610 if (value == 0xf) {
611 value += (env->cpuid_version >> 20) & 0xff;
612 }
613 visit_type_int(v, &value, name, errp);
614}
615
71ad61d3
AF
616static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
617 const char *name, Error **errp)
ed5e1ec3 618{
71ad61d3
AF
619 X86CPU *cpu = X86_CPU(obj);
620 CPUX86State *env = &cpu->env;
621 const int64_t min = 0;
622 const int64_t max = 0xff + 0xf;
623 int64_t value;
624
625 visit_type_int(v, &value, name, errp);
626 if (error_is_set(errp)) {
627 return;
628 }
629 if (value < min || value > max) {
630 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
631 name ? name : "null", value, min, max);
632 return;
633 }
634
ed5e1ec3 635 env->cpuid_version &= ~0xff00f00;
71ad61d3
AF
636 if (value > 0x0f) {
637 env->cpuid_version |= 0xf00 | ((value - 0x0f) << 20);
ed5e1ec3 638 } else {
71ad61d3 639 env->cpuid_version |= value << 8;
ed5e1ec3
AF
640 }
641}
642
67e30c83
AF
643static void x86_cpuid_version_get_model(Object *obj, Visitor *v, void *opaque,
644 const char *name, Error **errp)
645{
646 X86CPU *cpu = X86_CPU(obj);
647 CPUX86State *env = &cpu->env;
648 int64_t value;
649
650 value = (env->cpuid_version >> 4) & 0xf;
651 value |= ((env->cpuid_version >> 16) & 0xf) << 4;
652 visit_type_int(v, &value, name, errp);
653}
654
c5291a4f
AF
655static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque,
656 const char *name, Error **errp)
b0704cbd 657{
c5291a4f
AF
658 X86CPU *cpu = X86_CPU(obj);
659 CPUX86State *env = &cpu->env;
660 const int64_t min = 0;
661 const int64_t max = 0xff;
662 int64_t value;
663
664 visit_type_int(v, &value, name, errp);
665 if (error_is_set(errp)) {
666 return;
667 }
668 if (value < min || value > max) {
669 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
670 name ? name : "null", value, min, max);
671 return;
672 }
673
b0704cbd 674 env->cpuid_version &= ~0xf00f0;
c5291a4f 675 env->cpuid_version |= ((value & 0xf) << 4) | ((value >> 4) << 16);
b0704cbd
AF
676}
677
036e2222
AF
678static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v,
679 void *opaque, const char *name,
680 Error **errp)
38c3dc46 681{
036e2222
AF
682 X86CPU *cpu = X86_CPU(obj);
683 CPUX86State *env = &cpu->env;
684 const int64_t min = 0;
685 const int64_t max = 0xf;
686 int64_t value;
687
688 visit_type_int(v, &value, name, errp);
689 if (error_is_set(errp)) {
690 return;
691 }
692 if (value < min || value > max) {
693 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
694 name ? name : "null", value, min, max);
695 return;
696 }
697
38c3dc46 698 env->cpuid_version &= ~0xf;
036e2222 699 env->cpuid_version |= value & 0xf;
38c3dc46
AF
700}
701
938d4c25
AF
702static void x86_cpuid_set_model_id(Object *obj, const char *model_id,
703 Error **errp)
dcce6675 704{
938d4c25
AF
705 X86CPU *cpu = X86_CPU(obj);
706 CPUX86State *env = &cpu->env;
dcce6675
AF
707 int c, len, i;
708
709 if (model_id == NULL) {
710 model_id = "";
711 }
712 len = strlen(model_id);
d0a6acf4 713 memset(env->cpuid_model, 0, 48);
dcce6675
AF
714 for (i = 0; i < 48; i++) {
715 if (i >= len) {
716 c = '\0';
717 } else {
718 c = (uint8_t)model_id[i];
719 }
720 env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
721 }
722}
723
c6dc6f63
AP
724static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
725{
726 unsigned int i;
727 x86_def_t *def;
728
d3c481b3 729 char *s = g_strdup(cpu_model);
c6dc6f63 730 char *featurestr, *name = strtok(s, ",");
296acb64
JR
731 /* Features to be added*/
732 uint32_t plus_features = 0, plus_ext_features = 0;
733 uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
734 uint32_t plus_kvm_features = 0, plus_svm_features = 0;
735 /* Features to be removed */
736 uint32_t minus_features = 0, minus_ext_features = 0;
737 uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
738 uint32_t minus_kvm_features = 0, minus_svm_features = 0;
c6dc6f63
AP
739 uint32_t numvalue;
740
741 for (def = x86_defs; def; def = def->next)
04c5b17a 742 if (name && !strcmp(name, def->name))
c6dc6f63 743 break;
04c5b17a 744 if (kvm_enabled() && name && strcmp(name, "host") == 0) {
c6dc6f63
AP
745 cpu_x86_fill_host(x86_cpu_def);
746 } else if (!def) {
747 goto error;
748 } else {
749 memcpy(x86_cpu_def, def, sizeof(*def));
750 }
751
752 plus_kvm_features = ~0; /* not supported bits will be filtered out later */
753
754 add_flagname_to_bitmaps("hypervisor", &plus_features,
755 &plus_ext_features, &plus_ext2_features, &plus_ext3_features,
296acb64 756 &plus_kvm_features, &plus_svm_features);
c6dc6f63
AP
757
758 featurestr = strtok(NULL, ",");
759
760 while (featurestr) {
761 char *val;
762 if (featurestr[0] == '+') {
296acb64
JR
763 add_flagname_to_bitmaps(featurestr + 1, &plus_features,
764 &plus_ext_features, &plus_ext2_features,
765 &plus_ext3_features, &plus_kvm_features,
766 &plus_svm_features);
c6dc6f63 767 } else if (featurestr[0] == '-') {
296acb64
JR
768 add_flagname_to_bitmaps(featurestr + 1, &minus_features,
769 &minus_ext_features, &minus_ext2_features,
770 &minus_ext3_features, &minus_kvm_features,
771 &minus_svm_features);
c6dc6f63
AP
772 } else if ((val = strchr(featurestr, '='))) {
773 *val = 0; val++;
774 if (!strcmp(featurestr, "family")) {
775 char *err;
776 numvalue = strtoul(val, &err, 0);
a88a677f 777 if (!*val || *err || numvalue > 0xff + 0xf) {
c6dc6f63
AP
778 fprintf(stderr, "bad numerical value %s\n", val);
779 goto error;
780 }
781 x86_cpu_def->family = numvalue;
782 } else if (!strcmp(featurestr, "model")) {
783 char *err;
784 numvalue = strtoul(val, &err, 0);
785 if (!*val || *err || numvalue > 0xff) {
786 fprintf(stderr, "bad numerical value %s\n", val);
787 goto error;
788 }
789 x86_cpu_def->model = numvalue;
790 } else if (!strcmp(featurestr, "stepping")) {
791 char *err;
792 numvalue = strtoul(val, &err, 0);
793 if (!*val || *err || numvalue > 0xf) {
794 fprintf(stderr, "bad numerical value %s\n", val);
795 goto error;
796 }
797 x86_cpu_def->stepping = numvalue ;
798 } else if (!strcmp(featurestr, "level")) {
799 char *err;
800 numvalue = strtoul(val, &err, 0);
801 if (!*val || *err) {
802 fprintf(stderr, "bad numerical value %s\n", val);
803 goto error;
804 }
805 x86_cpu_def->level = numvalue;
806 } else if (!strcmp(featurestr, "xlevel")) {
807 char *err;
808 numvalue = strtoul(val, &err, 0);
809 if (!*val || *err) {
810 fprintf(stderr, "bad numerical value %s\n", val);
811 goto error;
812 }
813 if (numvalue < 0x80000000) {
2f7a21c4 814 numvalue += 0x80000000;
c6dc6f63
AP
815 }
816 x86_cpu_def->xlevel = numvalue;
817 } else if (!strcmp(featurestr, "vendor")) {
818 if (strlen(val) != 12) {
819 fprintf(stderr, "vendor string must be 12 chars long\n");
820 goto error;
821 }
822 x86_cpu_def->vendor1 = 0;
823 x86_cpu_def->vendor2 = 0;
824 x86_cpu_def->vendor3 = 0;
825 for(i = 0; i < 4; i++) {
826 x86_cpu_def->vendor1 |= ((uint8_t)val[i ]) << (8 * i);
827 x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i);
828 x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i);
829 }
830 x86_cpu_def->vendor_override = 1;
831 } else if (!strcmp(featurestr, "model_id")) {
832 pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),
833 val);
b862d1fe
JR
834 } else if (!strcmp(featurestr, "tsc_freq")) {
835 int64_t tsc_freq;
836 char *err;
837
838 tsc_freq = strtosz_suffix_unit(val, &err,
839 STRTOSZ_DEFSUFFIX_B, 1000);
45009a30 840 if (tsc_freq < 0 || *err) {
b862d1fe
JR
841 fprintf(stderr, "bad numerical value %s\n", val);
842 goto error;
843 }
844 x86_cpu_def->tsc_khz = tsc_freq / 1000;
28f52cc0
VR
845 } else if (!strcmp(featurestr, "hv_spinlocks")) {
846 char *err;
847 numvalue = strtoul(val, &err, 0);
848 if (!*val || *err) {
849 fprintf(stderr, "bad numerical value %s\n", val);
850 goto error;
851 }
852 hyperv_set_spinlock_retries(numvalue);
c6dc6f63
AP
853 } else {
854 fprintf(stderr, "unrecognized feature %s\n", featurestr);
855 goto error;
856 }
857 } else if (!strcmp(featurestr, "check")) {
858 check_cpuid = 1;
859 } else if (!strcmp(featurestr, "enforce")) {
860 check_cpuid = enforce_cpuid = 1;
28f52cc0
VR
861 } else if (!strcmp(featurestr, "hv_relaxed")) {
862 hyperv_enable_relaxed_timing(true);
863 } else if (!strcmp(featurestr, "hv_vapic")) {
864 hyperv_enable_vapic_recommended(true);
c6dc6f63
AP
865 } else {
866 fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
867 goto error;
868 }
869 featurestr = strtok(NULL, ",");
870 }
871 x86_cpu_def->features |= plus_features;
872 x86_cpu_def->ext_features |= plus_ext_features;
873 x86_cpu_def->ext2_features |= plus_ext2_features;
874 x86_cpu_def->ext3_features |= plus_ext3_features;
875 x86_cpu_def->kvm_features |= plus_kvm_features;
296acb64 876 x86_cpu_def->svm_features |= plus_svm_features;
c6dc6f63
AP
877 x86_cpu_def->features &= ~minus_features;
878 x86_cpu_def->ext_features &= ~minus_ext_features;
879 x86_cpu_def->ext2_features &= ~minus_ext2_features;
880 x86_cpu_def->ext3_features &= ~minus_ext3_features;
881 x86_cpu_def->kvm_features &= ~minus_kvm_features;
296acb64 882 x86_cpu_def->svm_features &= ~minus_svm_features;
c6dc6f63
AP
883 if (check_cpuid) {
884 if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
885 goto error;
886 }
d3c481b3 887 g_free(s);
c6dc6f63
AP
888 return 0;
889
890error:
d3c481b3 891 g_free(s);
c6dc6f63
AP
892 return -1;
893}
894
895/* generate a composite string into buf of all cpuid names in featureset
896 * selected by fbits. indicate truncation at bufsize in the event of overflow.
897 * if flags, suppress names undefined in featureset.
898 */
899static void listflags(char *buf, int bufsize, uint32_t fbits,
900 const char **featureset, uint32_t flags)
901{
902 const char **p = &featureset[31];
903 char *q, *b, bit;
904 int nc;
905
906 b = 4 <= bufsize ? buf + (bufsize -= 3) - 1 : NULL;
907 *buf = '\0';
908 for (q = buf, bit = 31; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit)
909 if (fbits & 1 << bit && (*p || !flags)) {
910 if (*p)
911 nc = snprintf(q, bufsize, "%s%s", q == buf ? "" : " ", *p);
912 else
913 nc = snprintf(q, bufsize, "%s[%d]", q == buf ? "" : " ", bit);
914 if (bufsize <= nc) {
915 if (b) {
916 memcpy(b, "...", sizeof("..."));
917 }
918 return;
919 }
920 q += nc;
921 bufsize -= nc;
922 }
923}
924
925/* generate CPU information:
926 * -? list model names
927 * -?model list model names/IDs
928 * -?dump output all model (x86_def_t) data
929 * -?cpuid list all recognized cpuid flag names
930 */
9a78eead 931void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
c6dc6f63
AP
932{
933 unsigned char model = !strcmp("?model", optarg);
934 unsigned char dump = !strcmp("?dump", optarg);
935 unsigned char cpuid = !strcmp("?cpuid", optarg);
936 x86_def_t *def;
937 char buf[256];
938
939 if (cpuid) {
940 (*cpu_fprintf)(f, "Recognized CPUID flags:\n");
941 listflags(buf, sizeof (buf), (uint32_t)~0, feature_name, 1);
942 (*cpu_fprintf)(f, " f_edx: %s\n", buf);
943 listflags(buf, sizeof (buf), (uint32_t)~0, ext_feature_name, 1);
944 (*cpu_fprintf)(f, " f_ecx: %s\n", buf);
945 listflags(buf, sizeof (buf), (uint32_t)~0, ext2_feature_name, 1);
946 (*cpu_fprintf)(f, " extf_edx: %s\n", buf);
947 listflags(buf, sizeof (buf), (uint32_t)~0, ext3_feature_name, 1);
948 (*cpu_fprintf)(f, " extf_ecx: %s\n", buf);
949 return;
950 }
951 for (def = x86_defs; def; def = def->next) {
952 snprintf(buf, sizeof (buf), def->flags ? "[%s]": "%s", def->name);
953 if (model || dump) {
954 (*cpu_fprintf)(f, "x86 %16s %-48s\n", buf, def->model_id);
955 } else {
956 (*cpu_fprintf)(f, "x86 %16s\n", buf);
957 }
958 if (dump) {
959 memcpy(buf, &def->vendor1, sizeof (def->vendor1));
960 memcpy(buf + 4, &def->vendor2, sizeof (def->vendor2));
961 memcpy(buf + 8, &def->vendor3, sizeof (def->vendor3));
962 buf[12] = '\0';
963 (*cpu_fprintf)(f,
964 " family %d model %d stepping %d level %d xlevel 0x%x"
965 " vendor \"%s\"\n",
966 def->family, def->model, def->stepping, def->level,
967 def->xlevel, buf);
968 listflags(buf, sizeof (buf), def->features, feature_name, 0);
969 (*cpu_fprintf)(f, " feature_edx %08x (%s)\n", def->features,
970 buf);
971 listflags(buf, sizeof (buf), def->ext_features, ext_feature_name,
972 0);
973 (*cpu_fprintf)(f, " feature_ecx %08x (%s)\n", def->ext_features,
974 buf);
975 listflags(buf, sizeof (buf), def->ext2_features, ext2_feature_name,
976 0);
977 (*cpu_fprintf)(f, " extfeature_edx %08x (%s)\n",
978 def->ext2_features, buf);
979 listflags(buf, sizeof (buf), def->ext3_features, ext3_feature_name,
980 0);
981 (*cpu_fprintf)(f, " extfeature_ecx %08x (%s)\n",
982 def->ext3_features, buf);
983 (*cpu_fprintf)(f, "\n");
984 }
985 }
ed2c54d4
AP
986 if (kvm_enabled()) {
987 (*cpu_fprintf)(f, "x86 %16s\n", "[host]");
988 }
c6dc6f63
AP
989}
990
61dcd775 991int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
c6dc6f63 992{
61dcd775 993 CPUX86State *env = &cpu->env;
c6dc6f63 994 x86_def_t def1, *def = &def1;
71ad61d3 995 Error *error = NULL;
c6dc6f63 996
db0ad1ba
JR
997 memset(def, 0, sizeof(*def));
998
c6dc6f63
AP
999 if (cpu_x86_find_by_name(def, cpu_model) < 0)
1000 return -1;
1001 if (def->vendor1) {
1002 env->cpuid_vendor1 = def->vendor1;
1003 env->cpuid_vendor2 = def->vendor2;
1004 env->cpuid_vendor3 = def->vendor3;
1005 } else {
1006 env->cpuid_vendor1 = CPUID_VENDOR_INTEL_1;
1007 env->cpuid_vendor2 = CPUID_VENDOR_INTEL_2;
1008 env->cpuid_vendor3 = CPUID_VENDOR_INTEL_3;
1009 }
1010 env->cpuid_vendor_override = def->vendor_override;
1011 env->cpuid_level = def->level;
71ad61d3 1012 object_property_set_int(OBJECT(cpu), def->family, "family", &error);
c5291a4f 1013 object_property_set_int(OBJECT(cpu), def->model, "model", &error);
036e2222 1014 object_property_set_int(OBJECT(cpu), def->stepping, "stepping", &error);
c6dc6f63 1015 env->cpuid_features = def->features;
c6dc6f63
AP
1016 env->cpuid_ext_features = def->ext_features;
1017 env->cpuid_ext2_features = def->ext2_features;
4d067ed7 1018 env->cpuid_ext3_features = def->ext3_features;
c6dc6f63
AP
1019 env->cpuid_xlevel = def->xlevel;
1020 env->cpuid_kvm_features = def->kvm_features;
296acb64 1021 env->cpuid_svm_features = def->svm_features;
b3baa152
BW
1022 env->cpuid_ext4_features = def->ext4_features;
1023 env->cpuid_xlevel2 = def->xlevel2;
b862d1fe 1024 env->tsc_khz = def->tsc_khz;
551a2dec
AP
1025 if (!kvm_enabled()) {
1026 env->cpuid_features &= TCG_FEATURES;
1027 env->cpuid_ext_features &= TCG_EXT_FEATURES;
1028 env->cpuid_ext2_features &= (TCG_EXT2_FEATURES
1029#ifdef TARGET_X86_64
1030 | CPUID_EXT2_SYSCALL | CPUID_EXT2_LM
1031#endif
1032 );
1033 env->cpuid_ext3_features &= TCG_EXT3_FEATURES;
296acb64 1034 env->cpuid_svm_features &= TCG_SVM_FEATURES;
551a2dec 1035 }
938d4c25 1036 object_property_set_str(OBJECT(cpu), def->model_id, "model-id", &error);
71ad61d3
AF
1037 if (error_is_set(&error)) {
1038 error_free(error);
1039 return -1;
1040 }
c6dc6f63
AP
1041 return 0;
1042}
1043
1044#if !defined(CONFIG_USER_ONLY)
1045/* copy vendor id string to 32 bit register, nul pad as needed
1046 */
1047static void cpyid(const char *s, uint32_t *id)
1048{
1049 char *d = (char *)id;
1050 char i;
1051
1052 for (i = sizeof (*id); i--; )
1053 *d++ = *s ? *s++ : '\0';
1054}
1055
1056/* interpret radix and convert from string to arbitrary scalar,
1057 * otherwise flag failure
1058 */
1059#define setscalar(pval, str, perr) \
1060{ \
1061 char *pend; \
1062 unsigned long ul; \
1063 \
1064 ul = strtoul(str, &pend, 0); \
1065 *str && !*pend ? (*pval = ul) : (*perr = 1); \
1066}
1067
1068/* map cpuid options to feature bits, otherwise return failure
1069 * (option tags in *str are delimited by whitespace)
1070 */
1071static void setfeatures(uint32_t *pval, const char *str,
1072 const char **featureset, int *perr)
1073{
1074 const char *p, *q;
1075
1076 for (q = p = str; *p || *q; q = p) {
1077 while (iswhite(*p))
1078 q = ++p;
1079 while (*p && !iswhite(*p))
1080 ++p;
1081 if (!*q && !*p)
1082 return;
1083 if (!lookup_feature(pval, q, p, featureset)) {
1084 fprintf(stderr, "error: feature \"%.*s\" not available in set\n",
1085 (int)(p - q), q);
1086 *perr = 1;
1087 return;
1088 }
1089 }
1090}
1091
1092/* map config file options to x86_def_t form
1093 */
1094static int cpudef_setfield(const char *name, const char *str, void *opaque)
1095{
1096 x86_def_t *def = opaque;
1097 int err = 0;
1098
1099 if (!strcmp(name, "name")) {
99e1dec0 1100 g_free((void *)def->name);
d3c481b3 1101 def->name = g_strdup(str);
c6dc6f63
AP
1102 } else if (!strcmp(name, "model_id")) {
1103 strncpy(def->model_id, str, sizeof (def->model_id));
1104 } else if (!strcmp(name, "level")) {
1105 setscalar(&def->level, str, &err)
1106 } else if (!strcmp(name, "vendor")) {
1107 cpyid(&str[0], &def->vendor1);
1108 cpyid(&str[4], &def->vendor2);
1109 cpyid(&str[8], &def->vendor3);
1110 } else if (!strcmp(name, "family")) {
1111 setscalar(&def->family, str, &err)
1112 } else if (!strcmp(name, "model")) {
1113 setscalar(&def->model, str, &err)
1114 } else if (!strcmp(name, "stepping")) {
1115 setscalar(&def->stepping, str, &err)
1116 } else if (!strcmp(name, "feature_edx")) {
1117 setfeatures(&def->features, str, feature_name, &err);
1118 } else if (!strcmp(name, "feature_ecx")) {
1119 setfeatures(&def->ext_features, str, ext_feature_name, &err);
1120 } else if (!strcmp(name, "extfeature_edx")) {
1121 setfeatures(&def->ext2_features, str, ext2_feature_name, &err);
1122 } else if (!strcmp(name, "extfeature_ecx")) {
1123 setfeatures(&def->ext3_features, str, ext3_feature_name, &err);
1124 } else if (!strcmp(name, "xlevel")) {
1125 setscalar(&def->xlevel, str, &err)
1126 } else {
1127 fprintf(stderr, "error: unknown option [%s = %s]\n", name, str);
1128 return (1);
1129 }
1130 if (err) {
1131 fprintf(stderr, "error: bad option value [%s = %s]\n", name, str);
1132 return (1);
1133 }
1134 return (0);
1135}
1136
1137/* register config file entry as x86_def_t
1138 */
1139static int cpudef_register(QemuOpts *opts, void *opaque)
1140{
7267c094 1141 x86_def_t *def = g_malloc0(sizeof (x86_def_t));
c6dc6f63
AP
1142
1143 qemu_opt_foreach(opts, cpudef_setfield, def, 1);
1144 def->next = x86_defs;
1145 x86_defs = def;
1146 return (0);
1147}
0e26b7b8
BS
1148
1149void cpu_clear_apic_feature(CPUX86State *env)
1150{
1151 env->cpuid_features &= ~CPUID_APIC;
1152}
1153
c6dc6f63
AP
1154#endif /* !CONFIG_USER_ONLY */
1155
1156/* register "cpudef" models defined in configuration file. Here we first
1157 * preload any built-in definitions
1158 */
1159void x86_cpudef_setup(void)
1160{
1161 int i;
1162
1163 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) {
1164 builtin_x86_defs[i].next = x86_defs;
1165 builtin_x86_defs[i].flags = 1;
1166 x86_defs = &builtin_x86_defs[i];
1167 }
1168#if !defined(CONFIG_USER_ONLY)
3329f07b 1169 qemu_opts_foreach(qemu_find_opts("cpudef"), cpudef_register, NULL, 0);
c6dc6f63
AP
1170#endif
1171}
1172
c6dc6f63
AP
1173static void get_cpuid_vendor(CPUX86State *env, uint32_t *ebx,
1174 uint32_t *ecx, uint32_t *edx)
1175{
1176 *ebx = env->cpuid_vendor1;
1177 *edx = env->cpuid_vendor2;
1178 *ecx = env->cpuid_vendor3;
1179
1180 /* sysenter isn't supported on compatibility mode on AMD, syscall
1181 * isn't supported in compatibility mode on Intel.
1182 * Normally we advertise the actual cpu vendor, but you can override
1183 * this if you want to use KVM's sysenter/syscall emulation
1184 * in compatibility mode and when doing cross vendor migration
1185 */
89354998 1186 if (kvm_enabled() && ! env->cpuid_vendor_override) {
c6dc6f63
AP
1187 host_cpuid(0, 0, NULL, ebx, ecx, edx);
1188 }
1189}
1190
1191void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
1192 uint32_t *eax, uint32_t *ebx,
1193 uint32_t *ecx, uint32_t *edx)
1194{
1195 /* test if maximum index reached */
1196 if (index & 0x80000000) {
b3baa152
BW
1197 if (index > env->cpuid_xlevel) {
1198 if (env->cpuid_xlevel2 > 0) {
1199 /* Handle the Centaur's CPUID instruction. */
1200 if (index > env->cpuid_xlevel2) {
1201 index = env->cpuid_xlevel2;
1202 } else if (index < 0xC0000000) {
1203 index = env->cpuid_xlevel;
1204 }
1205 } else {
1206 index = env->cpuid_xlevel;
1207 }
1208 }
c6dc6f63
AP
1209 } else {
1210 if (index > env->cpuid_level)
1211 index = env->cpuid_level;
1212 }
1213
1214 switch(index) {
1215 case 0:
1216 *eax = env->cpuid_level;
1217 get_cpuid_vendor(env, ebx, ecx, edx);
1218 break;
1219 case 1:
1220 *eax = env->cpuid_version;
1221 *ebx = (env->cpuid_apic_id << 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
1222 *ecx = env->cpuid_ext_features;
1223 *edx = env->cpuid_features;
1224 if (env->nr_cores * env->nr_threads > 1) {
1225 *ebx |= (env->nr_cores * env->nr_threads) << 16;
1226 *edx |= 1 << 28; /* HTT bit */
1227 }
1228 break;
1229 case 2:
1230 /* cache info: needed for Pentium Pro compatibility */
1231 *eax = 1;
1232 *ebx = 0;
1233 *ecx = 0;
1234 *edx = 0x2c307d;
1235 break;
1236 case 4:
1237 /* cache info: needed for Core compatibility */
1238 if (env->nr_cores > 1) {
2f7a21c4 1239 *eax = (env->nr_cores - 1) << 26;
c6dc6f63 1240 } else {
2f7a21c4 1241 *eax = 0;
c6dc6f63
AP
1242 }
1243 switch (count) {
1244 case 0: /* L1 dcache info */
1245 *eax |= 0x0000121;
1246 *ebx = 0x1c0003f;
1247 *ecx = 0x000003f;
1248 *edx = 0x0000001;
1249 break;
1250 case 1: /* L1 icache info */
1251 *eax |= 0x0000122;
1252 *ebx = 0x1c0003f;
1253 *ecx = 0x000003f;
1254 *edx = 0x0000001;
1255 break;
1256 case 2: /* L2 cache info */
1257 *eax |= 0x0000143;
1258 if (env->nr_threads > 1) {
1259 *eax |= (env->nr_threads - 1) << 14;
1260 }
1261 *ebx = 0x3c0003f;
1262 *ecx = 0x0000fff;
1263 *edx = 0x0000001;
1264 break;
1265 default: /* end of info */
1266 *eax = 0;
1267 *ebx = 0;
1268 *ecx = 0;
1269 *edx = 0;
1270 break;
1271 }
1272 break;
1273 case 5:
1274 /* mwait info: needed for Core compatibility */
1275 *eax = 0; /* Smallest monitor-line size in bytes */
1276 *ebx = 0; /* Largest monitor-line size in bytes */
1277 *ecx = CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
1278 *edx = 0;
1279 break;
1280 case 6:
1281 /* Thermal and Power Leaf */
1282 *eax = 0;
1283 *ebx = 0;
1284 *ecx = 0;
1285 *edx = 0;
1286 break;
f7911686
YW
1287 case 7:
1288 if (kvm_enabled()) {
ba9bc59e
JK
1289 KVMState *s = env->kvm_state;
1290
1291 *eax = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EAX);
1292 *ebx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EBX);
1293 *ecx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_ECX);
1294 *edx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EDX);
f7911686
YW
1295 } else {
1296 *eax = 0;
1297 *ebx = 0;
1298 *ecx = 0;
1299 *edx = 0;
1300 }
1301 break;
c6dc6f63
AP
1302 case 9:
1303 /* Direct Cache Access Information Leaf */
1304 *eax = 0; /* Bits 0-31 in DCA_CAP MSR */
1305 *ebx = 0;
1306 *ecx = 0;
1307 *edx = 0;
1308 break;
1309 case 0xA:
1310 /* Architectural Performance Monitoring Leaf */
a0fa8208
GN
1311 if (kvm_enabled()) {
1312 KVMState *s = env->kvm_state;
1313
1314 *eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX);
1315 *ebx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX);
1316 *ecx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_ECX);
1317 *edx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EDX);
1318 } else {
1319 *eax = 0;
1320 *ebx = 0;
1321 *ecx = 0;
1322 *edx = 0;
1323 }
c6dc6f63 1324 break;
51e49430
SY
1325 case 0xD:
1326 /* Processor Extended State */
1327 if (!(env->cpuid_ext_features & CPUID_EXT_XSAVE)) {
1328 *eax = 0;
1329 *ebx = 0;
1330 *ecx = 0;
1331 *edx = 0;
1332 break;
1333 }
1334 if (kvm_enabled()) {
ba9bc59e
JK
1335 KVMState *s = env->kvm_state;
1336
1337 *eax = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EAX);
1338 *ebx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EBX);
1339 *ecx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_ECX);
1340 *edx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EDX);
51e49430
SY
1341 } else {
1342 *eax = 0;
1343 *ebx = 0;
1344 *ecx = 0;
1345 *edx = 0;
1346 }
1347 break;
c6dc6f63
AP
1348 case 0x80000000:
1349 *eax = env->cpuid_xlevel;
1350 *ebx = env->cpuid_vendor1;
1351 *edx = env->cpuid_vendor2;
1352 *ecx = env->cpuid_vendor3;
1353 break;
1354 case 0x80000001:
1355 *eax = env->cpuid_version;
1356 *ebx = 0;
1357 *ecx = env->cpuid_ext3_features;
1358 *edx = env->cpuid_ext2_features;
1359
1360 /* The Linux kernel checks for the CMPLegacy bit and
1361 * discards multiple thread information if it is set.
1362 * So dont set it here for Intel to make Linux guests happy.
1363 */
1364 if (env->nr_cores * env->nr_threads > 1) {
1365 uint32_t tebx, tecx, tedx;
1366 get_cpuid_vendor(env, &tebx, &tecx, &tedx);
1367 if (tebx != CPUID_VENDOR_INTEL_1 ||
1368 tedx != CPUID_VENDOR_INTEL_2 ||
1369 tecx != CPUID_VENDOR_INTEL_3) {
1370 *ecx |= 1 << 1; /* CmpLegacy bit */
1371 }
1372 }
c6dc6f63
AP
1373 break;
1374 case 0x80000002:
1375 case 0x80000003:
1376 case 0x80000004:
1377 *eax = env->cpuid_model[(index - 0x80000002) * 4 + 0];
1378 *ebx = env->cpuid_model[(index - 0x80000002) * 4 + 1];
1379 *ecx = env->cpuid_model[(index - 0x80000002) * 4 + 2];
1380 *edx = env->cpuid_model[(index - 0x80000002) * 4 + 3];
1381 break;
1382 case 0x80000005:
1383 /* cache info (L1 cache) */
1384 *eax = 0x01ff01ff;
1385 *ebx = 0x01ff01ff;
1386 *ecx = 0x40020140;
1387 *edx = 0x40020140;
1388 break;
1389 case 0x80000006:
1390 /* cache info (L2 cache) */
1391 *eax = 0;
1392 *ebx = 0x42004200;
1393 *ecx = 0x02008140;
1394 *edx = 0;
1395 break;
1396 case 0x80000008:
1397 /* virtual & phys address size in low 2 bytes. */
1398/* XXX: This value must match the one used in the MMU code. */
1399 if (env->cpuid_ext2_features & CPUID_EXT2_LM) {
1400 /* 64 bit processor */
1401/* XXX: The physical address space is limited to 42 bits in exec.c. */
1402 *eax = 0x00003028; /* 48 bits virtual, 40 bits physical */
1403 } else {
1404 if (env->cpuid_features & CPUID_PSE36)
1405 *eax = 0x00000024; /* 36 bits physical */
1406 else
1407 *eax = 0x00000020; /* 32 bits physical */
1408 }
1409 *ebx = 0;
1410 *ecx = 0;
1411 *edx = 0;
1412 if (env->nr_cores * env->nr_threads > 1) {
1413 *ecx |= (env->nr_cores * env->nr_threads) - 1;
1414 }
1415 break;
1416 case 0x8000000A:
296acb64
JR
1417 if (env->cpuid_ext3_features & CPUID_EXT3_SVM) {
1418 *eax = 0x00000001; /* SVM Revision */
1419 *ebx = 0x00000010; /* nr of ASIDs */
1420 *ecx = 0;
1421 *edx = env->cpuid_svm_features; /* optional features */
1422 } else {
1423 *eax = 0;
1424 *ebx = 0;
1425 *ecx = 0;
1426 *edx = 0;
1427 }
c6dc6f63 1428 break;
b3baa152
BW
1429 case 0xC0000000:
1430 *eax = env->cpuid_xlevel2;
1431 *ebx = 0;
1432 *ecx = 0;
1433 *edx = 0;
1434 break;
1435 case 0xC0000001:
1436 /* Support for VIA CPU's CPUID instruction */
1437 *eax = env->cpuid_version;
1438 *ebx = 0;
1439 *ecx = 0;
1440 *edx = env->cpuid_ext4_features;
1441 break;
1442 case 0xC0000002:
1443 case 0xC0000003:
1444 case 0xC0000004:
1445 /* Reserved for the future, and now filled with zero */
1446 *eax = 0;
1447 *ebx = 0;
1448 *ecx = 0;
1449 *edx = 0;
1450 break;
c6dc6f63
AP
1451 default:
1452 /* reserved values: zero */
1453 *eax = 0;
1454 *ebx = 0;
1455 *ecx = 0;
1456 *edx = 0;
1457 break;
1458 }
1459}
5fd2087a
AF
1460
1461/* CPUClass::reset() */
1462static void x86_cpu_reset(CPUState *s)
1463{
1464 X86CPU *cpu = X86_CPU(s);
1465 X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
1466 CPUX86State *env = &cpu->env;
c1958aea
AF
1467 int i;
1468
1469 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
1470 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
1471 log_cpu_state(env, X86_DUMP_FPU | X86_DUMP_CCOP);
1472 }
5fd2087a
AF
1473
1474 xcc->parent_reset(s);
1475
c1958aea
AF
1476
1477 memset(env, 0, offsetof(CPUX86State, breakpoints));
1478
1479 tlb_flush(env, 1);
1480
1481 env->old_exception = -1;
1482
1483 /* init to reset state */
1484
1485#ifdef CONFIG_SOFTMMU
1486 env->hflags |= HF_SOFTMMU_MASK;
1487#endif
1488 env->hflags2 |= HF2_GIF_MASK;
1489
1490 cpu_x86_update_cr0(env, 0x60000010);
1491 env->a20_mask = ~0x0;
1492 env->smbase = 0x30000;
1493
1494 env->idt.limit = 0xffff;
1495 env->gdt.limit = 0xffff;
1496 env->ldt.limit = 0xffff;
1497 env->ldt.flags = DESC_P_MASK | (2 << DESC_TYPE_SHIFT);
1498 env->tr.limit = 0xffff;
1499 env->tr.flags = DESC_P_MASK | (11 << DESC_TYPE_SHIFT);
1500
1501 cpu_x86_load_seg_cache(env, R_CS, 0xf000, 0xffff0000, 0xffff,
1502 DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK |
1503 DESC_R_MASK | DESC_A_MASK);
1504 cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff,
1505 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
1506 DESC_A_MASK);
1507 cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff,
1508 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
1509 DESC_A_MASK);
1510 cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff,
1511 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
1512 DESC_A_MASK);
1513 cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffff,
1514 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
1515 DESC_A_MASK);
1516 cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffff,
1517 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
1518 DESC_A_MASK);
1519
1520 env->eip = 0xfff0;
1521 env->regs[R_EDX] = env->cpuid_version;
1522
1523 env->eflags = 0x2;
1524
1525 /* FPU init */
1526 for (i = 0; i < 8; i++) {
1527 env->fptags[i] = 1;
1528 }
1529 env->fpuc = 0x37f;
1530
1531 env->mxcsr = 0x1f80;
1532
1533 env->pat = 0x0007040600070406ULL;
1534 env->msr_ia32_misc_enable = MSR_IA32_MISC_ENABLE_DEFAULT;
1535
1536 memset(env->dr, 0, sizeof(env->dr));
1537 env->dr[6] = DR6_FIXED_1;
1538 env->dr[7] = DR7_FIXED_1;
1539 cpu_breakpoint_remove_all(env, BP_CPU);
1540 cpu_watchpoint_remove_all(env, BP_CPU);
5fd2087a
AF
1541}
1542
de024815
AF
1543static void mce_init(X86CPU *cpu)
1544{
1545 CPUX86State *cenv = &cpu->env;
1546 unsigned int bank;
1547
1548 if (((cenv->cpuid_version >> 8) & 0xf) >= 6
1549 && (cenv->cpuid_features & (CPUID_MCE | CPUID_MCA)) ==
1550 (CPUID_MCE | CPUID_MCA)) {
1551 cenv->mcg_cap = MCE_CAP_DEF | MCE_BANKS_DEF;
1552 cenv->mcg_ctl = ~(uint64_t)0;
1553 for (bank = 0; bank < MCE_BANKS_DEF; bank++) {
1554 cenv->mce_banks[bank * 4] = ~(uint64_t)0;
1555 }
1556 }
1557}
1558
1559static void x86_cpu_initfn(Object *obj)
1560{
1561 X86CPU *cpu = X86_CPU(obj);
1562 CPUX86State *env = &cpu->env;
1563
1564 cpu_exec_init(env);
71ad61d3
AF
1565
1566 object_property_add(obj, "family", "int",
95b8519d 1567 x86_cpuid_version_get_family,
71ad61d3 1568 x86_cpuid_version_set_family, NULL, NULL, NULL);
c5291a4f 1569 object_property_add(obj, "model", "int",
67e30c83 1570 x86_cpuid_version_get_model,
c5291a4f 1571 x86_cpuid_version_set_model, NULL, NULL, NULL);
036e2222
AF
1572 object_property_add(obj, "stepping", "int",
1573 NULL,
1574 x86_cpuid_version_set_stepping, NULL, NULL, NULL);
938d4c25
AF
1575 object_property_add_str(obj, "model-id",
1576 NULL,
1577 x86_cpuid_set_model_id, NULL);
71ad61d3 1578
de024815
AF
1579 env->cpuid_apic_id = env->cpu_index;
1580 mce_init(cpu);
1581}
1582
5fd2087a
AF
1583static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
1584{
1585 X86CPUClass *xcc = X86_CPU_CLASS(oc);
1586 CPUClass *cc = CPU_CLASS(oc);
1587
1588 xcc->parent_reset = cc->reset;
1589 cc->reset = x86_cpu_reset;
1590}
1591
1592static const TypeInfo x86_cpu_type_info = {
1593 .name = TYPE_X86_CPU,
1594 .parent = TYPE_CPU,
1595 .instance_size = sizeof(X86CPU),
de024815 1596 .instance_init = x86_cpu_initfn,
5fd2087a
AF
1597 .abstract = false,
1598 .class_size = sizeof(X86CPUClass),
1599 .class_init = x86_cpu_common_class_init,
1600};
1601
1602static void x86_cpu_register_types(void)
1603{
1604 type_register_static(&x86_cpu_type_info);
1605}
1606
1607type_init(x86_cpu_register_types)