2 * i386 CPUID helper functions
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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/>.
25 #include "sysemu/kvm.h"
26 #include "sysemu/cpus.h"
30 #include "qemu/option.h"
31 #include "qemu/config-file.h"
32 #include "qapi/qmp/qerror.h"
34 #include "qapi-types.h"
35 #include "qapi-visit.h"
36 #include "qapi/visitor.h"
37 #include "sysemu/arch_init.h"
40 #if defined(CONFIG_KVM)
41 #include <linux/kvm_para.h>
44 #include "sysemu/sysemu.h"
45 #include "hw/qdev-properties.h"
46 #include "hw/cpu/icc_bus.h"
47 #ifndef CONFIG_USER_ONLY
48 #include "hw/xen/xen.h"
49 #include "hw/i386/apic_internal.h"
53 /* Cache topology CPUID constants: */
55 /* CPUID Leaf 2 Descriptors */
57 #define CPUID_2_L1D_32KB_8WAY_64B 0x2c
58 #define CPUID_2_L1I_32KB_8WAY_64B 0x30
59 #define CPUID_2_L2_2MB_8WAY_64B 0x7d
62 /* CPUID Leaf 4 constants: */
65 #define CPUID_4_TYPE_DCACHE 1
66 #define CPUID_4_TYPE_ICACHE 2
67 #define CPUID_4_TYPE_UNIFIED 3
69 #define CPUID_4_LEVEL(l) ((l) << 5)
71 #define CPUID_4_SELF_INIT_LEVEL (1 << 8)
72 #define CPUID_4_FULLY_ASSOC (1 << 9)
75 #define CPUID_4_NO_INVD_SHARING (1 << 0)
76 #define CPUID_4_INCLUSIVE (1 << 1)
77 #define CPUID_4_COMPLEX_IDX (1 << 2)
79 #define ASSOC_FULL 0xFF
81 /* AMD associativity encoding used on CPUID Leaf 0x80000006: */
82 #define AMD_ENC_ASSOC(a) (a <= 1 ? a : \
92 a == ASSOC_FULL ? 0xF : \
93 0 /* invalid value */)
96 /* Definitions of the hardcoded cache entries we expose: */
99 #define L1D_LINE_SIZE 64
100 #define L1D_ASSOCIATIVITY 8
102 #define L1D_PARTITIONS 1
103 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
104 #define L1D_DESCRIPTOR CPUID_2_L1D_32KB_8WAY_64B
105 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
106 #define L1D_LINES_PER_TAG 1
107 #define L1D_SIZE_KB_AMD 64
108 #define L1D_ASSOCIATIVITY_AMD 2
110 /* L1 instruction cache: */
111 #define L1I_LINE_SIZE 64
112 #define L1I_ASSOCIATIVITY 8
114 #define L1I_PARTITIONS 1
115 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
116 #define L1I_DESCRIPTOR CPUID_2_L1I_32KB_8WAY_64B
117 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
118 #define L1I_LINES_PER_TAG 1
119 #define L1I_SIZE_KB_AMD 64
120 #define L1I_ASSOCIATIVITY_AMD 2
122 /* Level 2 unified cache: */
123 #define L2_LINE_SIZE 64
124 #define L2_ASSOCIATIVITY 16
126 #define L2_PARTITIONS 1
127 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 4MiB */
128 /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */
129 #define L2_DESCRIPTOR CPUID_2_L2_2MB_8WAY_64B
130 /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */
131 #define L2_LINES_PER_TAG 1
132 #define L2_SIZE_KB_AMD 512
135 #define L3_SIZE_KB 0 /* disabled */
136 #define L3_ASSOCIATIVITY 0 /* disabled */
137 #define L3_LINES_PER_TAG 0 /* disabled */
138 #define L3_LINE_SIZE 0 /* disabled */
140 /* TLB definitions: */
142 #define L1_DTLB_2M_ASSOC 1
143 #define L1_DTLB_2M_ENTRIES 255
144 #define L1_DTLB_4K_ASSOC 1
145 #define L1_DTLB_4K_ENTRIES 255
147 #define L1_ITLB_2M_ASSOC 1
148 #define L1_ITLB_2M_ENTRIES 255
149 #define L1_ITLB_4K_ASSOC 1
150 #define L1_ITLB_4K_ENTRIES 255
152 #define L2_DTLB_2M_ASSOC 0 /* disabled */
153 #define L2_DTLB_2M_ENTRIES 0 /* disabled */
154 #define L2_DTLB_4K_ASSOC 4
155 #define L2_DTLB_4K_ENTRIES 512
157 #define L2_ITLB_2M_ASSOC 0 /* disabled */
158 #define L2_ITLB_2M_ENTRIES 0 /* disabled */
159 #define L2_ITLB_4K_ASSOC 4
160 #define L2_ITLB_4K_ENTRIES 512
164 static void x86_cpu_vendor_words2str(char *dst
, uint32_t vendor1
,
165 uint32_t vendor2
, uint32_t vendor3
)
168 for (i
= 0; i
< 4; i
++) {
169 dst
[i
] = vendor1
>> (8 * i
);
170 dst
[i
+ 4] = vendor2
>> (8 * i
);
171 dst
[i
+ 8] = vendor3
>> (8 * i
);
173 dst
[CPUID_VENDOR_SZ
] = '\0';
176 /* feature flags taken from "Intel Processor Identification and the CPUID
177 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
178 * between feature naming conventions, aliases may be added.
180 static const char *feature_name
[] = {
181 "fpu", "vme", "de", "pse",
182 "tsc", "msr", "pae", "mce",
183 "cx8", "apic", NULL
, "sep",
184 "mtrr", "pge", "mca", "cmov",
185 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
186 NULL
, "ds" /* Intel dts */, "acpi", "mmx",
187 "fxsr", "sse", "sse2", "ss",
188 "ht" /* Intel htt */, "tm", "ia64", "pbe",
190 static const char *ext_feature_name
[] = {
191 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
192 "ds_cpl", "vmx", "smx", "est",
193 "tm2", "ssse3", "cid", NULL
,
194 "fma", "cx16", "xtpr", "pdcm",
195 NULL
, "pcid", "dca", "sse4.1|sse4_1",
196 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
197 "tsc-deadline", "aes", "xsave", "osxsave",
198 "avx", "f16c", "rdrand", "hypervisor",
200 /* Feature names that are already defined on feature_name[] but are set on
201 * CPUID[8000_0001].EDX on AMD CPUs don't have their names on
202 * ext2_feature_name[]. They are copied automatically to cpuid_ext2_features
203 * if and only if CPU vendor is AMD.
205 static const char *ext2_feature_name
[] = {
206 NULL
/* fpu */, NULL
/* vme */, NULL
/* de */, NULL
/* pse */,
207 NULL
/* tsc */, NULL
/* msr */, NULL
/* pae */, NULL
/* mce */,
208 NULL
/* cx8 */ /* AMD CMPXCHG8B */, NULL
/* apic */, NULL
, "syscall",
209 NULL
/* mtrr */, NULL
/* pge */, NULL
/* mca */, NULL
/* cmov */,
210 NULL
/* pat */, NULL
/* pse36 */, NULL
, NULL
/* Linux mp */,
211 "nx|xd", NULL
, "mmxext", NULL
/* mmx */,
212 NULL
/* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
213 NULL
, "lm|i64", "3dnowext", "3dnow",
215 static const char *ext3_feature_name
[] = {
216 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
217 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
218 "3dnowprefetch", "osvw", "ibs", "xop",
219 "skinit", "wdt", NULL
, "lwp",
220 "fma4", "tce", NULL
, "nodeid_msr",
221 NULL
, "tbm", "topoext", "perfctr_core",
222 "perfctr_nb", NULL
, NULL
, NULL
,
223 NULL
, NULL
, NULL
, NULL
,
226 static const char *ext4_feature_name
[] = {
227 NULL
, NULL
, "xstore", "xstore-en",
228 NULL
, NULL
, "xcrypt", "xcrypt-en",
229 "ace2", "ace2-en", "phe", "phe-en",
230 "pmm", "pmm-en", NULL
, NULL
,
231 NULL
, NULL
, NULL
, NULL
,
232 NULL
, NULL
, NULL
, NULL
,
233 NULL
, NULL
, NULL
, NULL
,
234 NULL
, NULL
, NULL
, NULL
,
237 static const char *kvm_feature_name
[] = {
238 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
239 "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", "kvm_pv_unhalt",
240 NULL
, NULL
, NULL
, NULL
,
241 NULL
, NULL
, NULL
, NULL
,
242 NULL
, NULL
, NULL
, NULL
,
243 NULL
, NULL
, NULL
, NULL
,
244 "kvmclock-stable-bit", NULL
, NULL
, NULL
,
245 NULL
, NULL
, NULL
, NULL
,
248 static const char *svm_feature_name
[] = {
249 "npt", "lbrv", "svm_lock", "nrip_save",
250 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
251 NULL
, NULL
, "pause_filter", NULL
,
252 "pfthreshold", NULL
, NULL
, NULL
,
253 NULL
, NULL
, NULL
, NULL
,
254 NULL
, NULL
, NULL
, NULL
,
255 NULL
, NULL
, NULL
, NULL
,
256 NULL
, NULL
, NULL
, NULL
,
259 static const char *cpuid_7_0_ebx_feature_name
[] = {
260 "fsgsbase", "tsc_adjust", NULL
, "bmi1", "hle", "avx2", NULL
, "smep",
261 "bmi2", "erms", "invpcid", "rtm", NULL
, NULL
, "mpx", NULL
,
262 "avx512f", NULL
, "rdseed", "adx", "smap", NULL
, NULL
, NULL
,
263 NULL
, NULL
, "avx512pf", "avx512er", "avx512cd", NULL
, NULL
, NULL
,
266 static const char *cpuid_apm_edx_feature_name
[] = {
267 NULL
, NULL
, NULL
, NULL
,
268 NULL
, NULL
, NULL
, NULL
,
269 "invtsc", NULL
, NULL
, NULL
,
270 NULL
, NULL
, NULL
, NULL
,
271 NULL
, NULL
, NULL
, NULL
,
272 NULL
, NULL
, NULL
, NULL
,
273 NULL
, NULL
, NULL
, NULL
,
274 NULL
, NULL
, NULL
, NULL
,
277 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
278 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
279 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
280 #define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
281 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
282 CPUID_PSE36 | CPUID_FXSR)
283 #define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
284 #define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
285 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
286 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
287 CPUID_PAE | CPUID_SEP | CPUID_APIC)
289 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
290 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
291 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
292 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
293 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
294 /* partly implemented:
295 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) */
297 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
298 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \
299 CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \
300 CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \
301 CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR)
303 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX,
304 CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA,
305 CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA,
306 CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE,
307 CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C,
311 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM)
313 #define TCG_EXT2_X86_64_FEATURES 0
316 #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \
317 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
318 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \
319 TCG_EXT2_X86_64_FEATURES)
320 #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
321 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
322 #define TCG_EXT4_FEATURES 0
323 #define TCG_SVM_FEATURES 0
324 #define TCG_KVM_FEATURES 0
325 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \
326 CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)
328 CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
329 CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
330 CPUID_7_0_EBX_RDSEED */
331 #define TCG_APM_FEATURES 0
334 typedef struct FeatureWordInfo
{
335 const char **feat_names
;
336 uint32_t cpuid_eax
; /* Input EAX for CPUID */
337 bool cpuid_needs_ecx
; /* CPUID instruction uses ECX as input */
338 uint32_t cpuid_ecx
; /* Input ECX value for CPUID */
339 int cpuid_reg
; /* output register (R_* constant) */
340 uint32_t tcg_features
; /* Feature flags supported by TCG */
341 uint32_t unmigratable_flags
; /* Feature flags known to be unmigratable */
344 static FeatureWordInfo feature_word_info
[FEATURE_WORDS
] = {
346 .feat_names
= feature_name
,
347 .cpuid_eax
= 1, .cpuid_reg
= R_EDX
,
348 .tcg_features
= TCG_FEATURES
,
351 .feat_names
= ext_feature_name
,
352 .cpuid_eax
= 1, .cpuid_reg
= R_ECX
,
353 .tcg_features
= TCG_EXT_FEATURES
,
355 [FEAT_8000_0001_EDX
] = {
356 .feat_names
= ext2_feature_name
,
357 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_EDX
,
358 .tcg_features
= TCG_EXT2_FEATURES
,
360 [FEAT_8000_0001_ECX
] = {
361 .feat_names
= ext3_feature_name
,
362 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_ECX
,
363 .tcg_features
= TCG_EXT3_FEATURES
,
365 [FEAT_C000_0001_EDX
] = {
366 .feat_names
= ext4_feature_name
,
367 .cpuid_eax
= 0xC0000001, .cpuid_reg
= R_EDX
,
368 .tcg_features
= TCG_EXT4_FEATURES
,
371 .feat_names
= kvm_feature_name
,
372 .cpuid_eax
= KVM_CPUID_FEATURES
, .cpuid_reg
= R_EAX
,
373 .tcg_features
= TCG_KVM_FEATURES
,
376 .feat_names
= svm_feature_name
,
377 .cpuid_eax
= 0x8000000A, .cpuid_reg
= R_EDX
,
378 .tcg_features
= TCG_SVM_FEATURES
,
381 .feat_names
= cpuid_7_0_ebx_feature_name
,
383 .cpuid_needs_ecx
= true, .cpuid_ecx
= 0,
385 .tcg_features
= TCG_7_0_EBX_FEATURES
,
387 [FEAT_8000_0007_EDX
] = {
388 .feat_names
= cpuid_apm_edx_feature_name
,
389 .cpuid_eax
= 0x80000007,
391 .tcg_features
= TCG_APM_FEATURES
,
392 .unmigratable_flags
= CPUID_APM_INVTSC
,
396 typedef struct X86RegisterInfo32
{
397 /* Name of register */
399 /* QAPI enum value register */
400 X86CPURegister32 qapi_enum
;
403 #define REGISTER(reg) \
404 [R_##reg] = { .name = #reg, .qapi_enum = X86_CPU_REGISTER32_##reg }
405 static const X86RegisterInfo32 x86_reg_info_32
[CPU_NB_REGS32
] = {
417 typedef struct ExtSaveArea
{
418 uint32_t feature
, bits
;
419 uint32_t offset
, size
;
422 static const ExtSaveArea ext_save_areas
[] = {
423 [2] = { .feature
= FEAT_1_ECX
, .bits
= CPUID_EXT_AVX
,
424 .offset
= 0x240, .size
= 0x100 },
425 [3] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_MPX
,
426 .offset
= 0x3c0, .size
= 0x40 },
427 [4] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_MPX
,
428 .offset
= 0x400, .size
= 0x40 },
429 [5] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
430 .offset
= 0x440, .size
= 0x40 },
431 [6] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
432 .offset
= 0x480, .size
= 0x200 },
433 [7] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
434 .offset
= 0x680, .size
= 0x400 },
437 const char *get_register_name_32(unsigned int reg
)
439 if (reg
>= CPU_NB_REGS32
) {
442 return x86_reg_info_32
[reg
].name
;
445 /* collects per-function cpuid data
447 typedef struct model_features_t
{
448 uint32_t *guest_feat
;
450 FeatureWord feat_word
;
453 /* KVM-specific features that are automatically added to all CPU models
454 * when KVM is enabled.
456 static uint32_t kvm_default_features
[FEATURE_WORDS
] = {
457 [FEAT_KVM
] = (1 << KVM_FEATURE_CLOCKSOURCE
) |
458 (1 << KVM_FEATURE_NOP_IO_DELAY
) |
459 (1 << KVM_FEATURE_CLOCKSOURCE2
) |
460 (1 << KVM_FEATURE_ASYNC_PF
) |
461 (1 << KVM_FEATURE_STEAL_TIME
) |
462 (1 << KVM_FEATURE_PV_EOI
) |
463 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT
),
464 [FEAT_1_ECX
] = CPUID_EXT_X2APIC
,
467 /* Features that are not added by default to any CPU model when KVM is enabled.
469 static uint32_t kvm_default_unset_features
[FEATURE_WORDS
] = {
470 [FEAT_1_ECX
] = CPUID_EXT_MONITOR
,
473 void x86_cpu_compat_disable_kvm_features(FeatureWord w
, uint32_t features
)
475 kvm_default_features
[w
] &= ~features
;
479 * Returns the set of feature flags that are supported and migratable by
480 * QEMU, for a given FeatureWord.
482 static uint32_t x86_cpu_get_migratable_flags(FeatureWord w
)
484 FeatureWordInfo
*wi
= &feature_word_info
[w
];
488 for (i
= 0; i
< 32; i
++) {
489 uint32_t f
= 1U << i
;
490 /* If the feature name is unknown, it is not supported by QEMU yet */
491 if (!wi
->feat_names
[i
]) {
494 /* Skip features known to QEMU, but explicitly marked as unmigratable */
495 if (wi
->unmigratable_flags
& f
) {
503 void host_cpuid(uint32_t function
, uint32_t count
,
504 uint32_t *eax
, uint32_t *ebx
, uint32_t *ecx
, uint32_t *edx
)
510 : "=a"(vec
[0]), "=b"(vec
[1]),
511 "=c"(vec
[2]), "=d"(vec
[3])
512 : "0"(function
), "c"(count
) : "cc");
513 #elif defined(__i386__)
514 asm volatile("pusha \n\t"
516 "mov %%eax, 0(%2) \n\t"
517 "mov %%ebx, 4(%2) \n\t"
518 "mov %%ecx, 8(%2) \n\t"
519 "mov %%edx, 12(%2) \n\t"
521 : : "a"(function
), "c"(count
), "S"(vec
)
537 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
539 /* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
540 * a substring. ex if !NULL points to the first char after a substring,
541 * otherwise the string is assumed to sized by a terminating nul.
542 * Return lexical ordering of *s1:*s2.
544 static int sstrcmp(const char *s1
, const char *e1
, const char *s2
,
548 if (!*s1
|| !*s2
|| *s1
!= *s2
)
551 if (s1
== e1
&& s2
== e2
)
560 /* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
561 * '|' delimited (possibly empty) strings in which case search for a match
562 * within the alternatives proceeds left to right. Return 0 for success,
563 * non-zero otherwise.
565 static int altcmp(const char *s
, const char *e
, const char *altstr
)
569 for (q
= p
= altstr
; ; ) {
570 while (*p
&& *p
!= '|')
572 if ((q
== p
&& !*s
) || (q
!= p
&& !sstrcmp(s
, e
, q
, p
)))
581 /* search featureset for flag *[s..e), if found set corresponding bit in
582 * *pval and return true, otherwise return false
584 static bool lookup_feature(uint32_t *pval
, const char *s
, const char *e
,
585 const char **featureset
)
591 for (mask
= 1, ppc
= featureset
; mask
; mask
<<= 1, ++ppc
) {
592 if (*ppc
&& !altcmp(s
, e
, *ppc
)) {
600 static void add_flagname_to_bitmaps(const char *flagname
,
601 FeatureWordArray words
,
605 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
606 FeatureWordInfo
*wi
= &feature_word_info
[w
];
607 if (wi
->feat_names
&&
608 lookup_feature(&words
[w
], flagname
, NULL
, wi
->feat_names
)) {
612 if (w
== FEATURE_WORDS
) {
613 error_setg(errp
, "CPU feature %s not found", flagname
);
617 /* CPU class name definitions: */
619 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
620 #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
622 /* Return type name for a given CPU model name
623 * Caller is responsible for freeing the returned string.
625 static char *x86_cpu_type_name(const char *model_name
)
627 return g_strdup_printf(X86_CPU_TYPE_NAME("%s"), model_name
);
630 static ObjectClass
*x86_cpu_class_by_name(const char *cpu_model
)
635 if (cpu_model
== NULL
) {
639 typename
= x86_cpu_type_name(cpu_model
);
640 oc
= object_class_by_name(typename
);
645 struct X86CPUDefinition
{
650 /* vendor is zero-terminated, 12 character ASCII string */
651 char vendor
[CPUID_VENDOR_SZ
+ 1];
655 FeatureWordArray features
;
657 bool cache_info_passthrough
;
660 static X86CPUDefinition builtin_x86_defs
[] = {
664 .vendor
= CPUID_VENDOR_AMD
,
668 .features
[FEAT_1_EDX
] =
670 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
672 .features
[FEAT_1_ECX
] =
673 CPUID_EXT_SSE3
| CPUID_EXT_CX16
| CPUID_EXT_POPCNT
,
674 .features
[FEAT_8000_0001_EDX
] =
675 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
676 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
677 .features
[FEAT_8000_0001_ECX
] =
678 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
679 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
680 .xlevel
= 0x8000000A,
685 .vendor
= CPUID_VENDOR_AMD
,
689 .features
[FEAT_1_EDX
] =
691 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
692 CPUID_PSE36
| CPUID_VME
| CPUID_HT
,
693 .features
[FEAT_1_ECX
] =
694 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_CX16
|
696 .features
[FEAT_8000_0001_EDX
] =
697 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
698 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
|
699 CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
| CPUID_EXT2_MMXEXT
|
700 CPUID_EXT2_FFXSR
| CPUID_EXT2_PDPE1GB
| CPUID_EXT2_RDTSCP
,
701 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
703 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
704 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
705 .features
[FEAT_8000_0001_ECX
] =
706 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
707 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
708 .features
[FEAT_SVM
] =
709 CPUID_SVM_NPT
| CPUID_SVM_LBRV
,
710 .xlevel
= 0x8000001A,
711 .model_id
= "AMD Phenom(tm) 9550 Quad-Core Processor"
716 .vendor
= CPUID_VENDOR_INTEL
,
720 .features
[FEAT_1_EDX
] =
722 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
723 CPUID_PSE36
| CPUID_VME
| CPUID_DTS
| CPUID_ACPI
| CPUID_SS
|
724 CPUID_HT
| CPUID_TM
| CPUID_PBE
,
725 .features
[FEAT_1_ECX
] =
726 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
727 CPUID_EXT_DTES64
| CPUID_EXT_DSCPL
| CPUID_EXT_VMX
| CPUID_EXT_EST
|
728 CPUID_EXT_TM2
| CPUID_EXT_CX16
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
729 .features
[FEAT_8000_0001_EDX
] =
730 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
731 .features
[FEAT_8000_0001_ECX
] =
733 .xlevel
= 0x80000008,
734 .model_id
= "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
739 .vendor
= CPUID_VENDOR_INTEL
,
743 /* Missing: CPUID_VME, CPUID_HT */
744 .features
[FEAT_1_EDX
] =
746 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
748 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
749 .features
[FEAT_1_ECX
] =
750 CPUID_EXT_SSE3
| CPUID_EXT_CX16
,
751 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
752 .features
[FEAT_8000_0001_EDX
] =
753 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
754 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
755 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
756 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
757 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
758 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
759 .features
[FEAT_8000_0001_ECX
] =
761 .xlevel
= 0x80000008,
762 .model_id
= "Common KVM processor"
767 .vendor
= CPUID_VENDOR_INTEL
,
771 .features
[FEAT_1_EDX
] =
773 .features
[FEAT_1_ECX
] =
774 CPUID_EXT_SSE3
| CPUID_EXT_POPCNT
,
775 .xlevel
= 0x80000004,
780 .vendor
= CPUID_VENDOR_INTEL
,
784 .features
[FEAT_1_EDX
] =
786 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_PSE36
,
787 .features
[FEAT_1_ECX
] =
789 .features
[FEAT_8000_0001_EDX
] =
790 PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
,
791 .features
[FEAT_8000_0001_ECX
] =
793 .xlevel
= 0x80000008,
794 .model_id
= "Common 32-bit KVM processor"
799 .vendor
= CPUID_VENDOR_INTEL
,
803 .features
[FEAT_1_EDX
] =
804 PPRO_FEATURES
| CPUID_VME
|
805 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_DTS
| CPUID_ACPI
|
806 CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
807 .features
[FEAT_1_ECX
] =
808 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_VMX
|
809 CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
810 .features
[FEAT_8000_0001_EDX
] =
812 .xlevel
= 0x80000008,
813 .model_id
= "Genuine Intel(R) CPU T2600 @ 2.16GHz",
818 .vendor
= CPUID_VENDOR_INTEL
,
822 .features
[FEAT_1_EDX
] =
829 .vendor
= CPUID_VENDOR_INTEL
,
833 .features
[FEAT_1_EDX
] =
840 .vendor
= CPUID_VENDOR_INTEL
,
844 .features
[FEAT_1_EDX
] =
851 .vendor
= CPUID_VENDOR_INTEL
,
855 .features
[FEAT_1_EDX
] =
862 .vendor
= CPUID_VENDOR_AMD
,
866 .features
[FEAT_1_EDX
] =
867 PPRO_FEATURES
| CPUID_PSE36
| CPUID_VME
| CPUID_MTRR
|
869 .features
[FEAT_8000_0001_EDX
] =
870 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
871 CPUID_EXT2_MMXEXT
| CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
,
872 .xlevel
= 0x80000008,
876 /* original is on level 10 */
878 .vendor
= CPUID_VENDOR_INTEL
,
882 .features
[FEAT_1_EDX
] =
884 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_VME
| CPUID_DTS
|
885 CPUID_ACPI
| CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
886 /* Some CPUs got no CPUID_SEP */
887 .features
[FEAT_1_ECX
] =
888 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
889 CPUID_EXT_DSCPL
| CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
|
891 .features
[FEAT_8000_0001_EDX
] =
892 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
894 .features
[FEAT_8000_0001_ECX
] =
896 .xlevel
= 0x8000000A,
897 .model_id
= "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
902 .vendor
= CPUID_VENDOR_INTEL
,
906 .features
[FEAT_1_EDX
] =
907 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
908 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
909 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
910 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
911 CPUID_DE
| CPUID_FP87
,
912 .features
[FEAT_1_ECX
] =
913 CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
914 .features
[FEAT_8000_0001_EDX
] =
915 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
916 .features
[FEAT_8000_0001_ECX
] =
918 .xlevel
= 0x8000000A,
919 .model_id
= "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
924 .vendor
= CPUID_VENDOR_INTEL
,
928 .features
[FEAT_1_EDX
] =
929 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
930 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
931 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
932 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
933 CPUID_DE
| CPUID_FP87
,
934 .features
[FEAT_1_ECX
] =
935 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
937 .features
[FEAT_8000_0001_EDX
] =
938 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
939 .features
[FEAT_8000_0001_ECX
] =
941 .xlevel
= 0x8000000A,
942 .model_id
= "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
947 .vendor
= CPUID_VENDOR_INTEL
,
951 .features
[FEAT_1_EDX
] =
952 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
953 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
954 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
955 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
956 CPUID_DE
| CPUID_FP87
,
957 .features
[FEAT_1_ECX
] =
958 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
959 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
960 .features
[FEAT_8000_0001_EDX
] =
961 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
962 .features
[FEAT_8000_0001_ECX
] =
964 .xlevel
= 0x8000000A,
965 .model_id
= "Intel Core i7 9xx (Nehalem Class Core i7)",
970 .vendor
= CPUID_VENDOR_INTEL
,
974 .features
[FEAT_1_EDX
] =
975 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
976 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
977 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
978 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
979 CPUID_DE
| CPUID_FP87
,
980 .features
[FEAT_1_ECX
] =
981 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
982 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
983 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
984 .features
[FEAT_8000_0001_EDX
] =
985 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
986 .features
[FEAT_8000_0001_ECX
] =
988 .xlevel
= 0x8000000A,
989 .model_id
= "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
992 .name
= "SandyBridge",
994 .vendor
= CPUID_VENDOR_INTEL
,
998 .features
[FEAT_1_EDX
] =
999 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1000 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1001 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1002 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1003 CPUID_DE
| CPUID_FP87
,
1004 .features
[FEAT_1_ECX
] =
1005 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1006 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_POPCNT
|
1007 CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
1008 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
1010 .features
[FEAT_8000_0001_EDX
] =
1011 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1013 .features
[FEAT_8000_0001_ECX
] =
1015 .xlevel
= 0x8000000A,
1016 .model_id
= "Intel Xeon E312xx (Sandy Bridge)",
1021 .vendor
= CPUID_VENDOR_INTEL
,
1025 .features
[FEAT_1_EDX
] =
1026 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1027 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1028 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1029 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1030 CPUID_DE
| CPUID_FP87
,
1031 .features
[FEAT_1_ECX
] =
1032 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1033 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1034 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1035 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1036 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1038 .features
[FEAT_8000_0001_EDX
] =
1039 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1041 .features
[FEAT_8000_0001_ECX
] =
1043 .features
[FEAT_7_0_EBX
] =
1044 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1045 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1046 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
1048 .xlevel
= 0x8000000A,
1049 .model_id
= "Intel Core Processor (Haswell)",
1052 .name
= "Broadwell",
1054 .vendor
= CPUID_VENDOR_INTEL
,
1058 .features
[FEAT_1_EDX
] =
1059 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1060 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1061 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1062 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1063 CPUID_DE
| CPUID_FP87
,
1064 .features
[FEAT_1_ECX
] =
1065 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1066 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1067 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1068 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1069 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1071 .features
[FEAT_8000_0001_EDX
] =
1072 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1074 .features
[FEAT_8000_0001_ECX
] =
1075 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_3DNOWPREFETCH
,
1076 .features
[FEAT_7_0_EBX
] =
1077 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1078 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1079 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
1080 CPUID_7_0_EBX_RTM
| CPUID_7_0_EBX_RDSEED
| CPUID_7_0_EBX_ADX
|
1082 .xlevel
= 0x8000000A,
1083 .model_id
= "Intel Core Processor (Broadwell)",
1086 .name
= "Opteron_G1",
1088 .vendor
= CPUID_VENDOR_AMD
,
1092 .features
[FEAT_1_EDX
] =
1093 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1094 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1095 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1096 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1097 CPUID_DE
| CPUID_FP87
,
1098 .features
[FEAT_1_ECX
] =
1100 .features
[FEAT_8000_0001_EDX
] =
1101 CPUID_EXT2_LM
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1102 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1103 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1104 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1105 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1106 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1107 .xlevel
= 0x80000008,
1108 .model_id
= "AMD Opteron 240 (Gen 1 Class Opteron)",
1111 .name
= "Opteron_G2",
1113 .vendor
= CPUID_VENDOR_AMD
,
1117 .features
[FEAT_1_EDX
] =
1118 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1119 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1120 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1121 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1122 CPUID_DE
| CPUID_FP87
,
1123 .features
[FEAT_1_ECX
] =
1124 CPUID_EXT_CX16
| CPUID_EXT_SSE3
,
1125 .features
[FEAT_8000_0001_EDX
] =
1126 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
1127 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
1128 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
1129 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
1130 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
1131 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
1132 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1133 .features
[FEAT_8000_0001_ECX
] =
1134 CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
1135 .xlevel
= 0x80000008,
1136 .model_id
= "AMD Opteron 22xx (Gen 2 Class Opteron)",
1139 .name
= "Opteron_G3",
1141 .vendor
= CPUID_VENDOR_AMD
,
1145 .features
[FEAT_1_EDX
] =
1146 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1147 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1148 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1149 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1150 CPUID_DE
| CPUID_FP87
,
1151 .features
[FEAT_1_ECX
] =
1152 CPUID_EXT_POPCNT
| CPUID_EXT_CX16
| CPUID_EXT_MONITOR
|
1154 .features
[FEAT_8000_0001_EDX
] =
1155 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
1156 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
1157 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
1158 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
1159 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
1160 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
1161 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1162 .features
[FEAT_8000_0001_ECX
] =
1163 CPUID_EXT3_MISALIGNSSE
| CPUID_EXT3_SSE4A
|
1164 CPUID_EXT3_ABM
| CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
1165 .xlevel
= 0x80000008,
1166 .model_id
= "AMD Opteron 23xx (Gen 3 Class Opteron)",
1169 .name
= "Opteron_G4",
1171 .vendor
= CPUID_VENDOR_AMD
,
1175 .features
[FEAT_1_EDX
] =
1176 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1177 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1178 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1179 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1180 CPUID_DE
| CPUID_FP87
,
1181 .features
[FEAT_1_ECX
] =
1182 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1183 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
1184 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
1186 .features
[FEAT_8000_0001_EDX
] =
1187 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
1188 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1189 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1190 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1191 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1192 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1193 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1194 .features
[FEAT_8000_0001_ECX
] =
1195 CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
1196 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
1197 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
1199 .xlevel
= 0x8000001A,
1200 .model_id
= "AMD Opteron 62xx class CPU",
1203 .name
= "Opteron_G5",
1205 .vendor
= CPUID_VENDOR_AMD
,
1209 .features
[FEAT_1_EDX
] =
1210 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1211 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1212 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1213 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1214 CPUID_DE
| CPUID_FP87
,
1215 .features
[FEAT_1_ECX
] =
1216 CPUID_EXT_F16C
| CPUID_EXT_AVX
| CPUID_EXT_XSAVE
|
1217 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
1218 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_FMA
|
1219 CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
1220 .features
[FEAT_8000_0001_EDX
] =
1221 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
1222 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1223 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1224 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1225 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1226 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1227 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1228 .features
[FEAT_8000_0001_ECX
] =
1229 CPUID_EXT3_TBM
| CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
1230 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
1231 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
1233 .xlevel
= 0x8000001A,
1234 .model_id
= "AMD Opteron 63xx class CPU",
1239 * x86_cpu_compat_set_features:
1240 * @cpu_model: CPU model name to be changed. If NULL, all CPU models are changed
1241 * @w: Identifies the feature word to be changed.
1242 * @feat_add: Feature bits to be added to feature word
1243 * @feat_remove: Feature bits to be removed from feature word
1245 * Change CPU model feature bits for compatibility.
1247 * This function may be used by machine-type compatibility functions
1248 * to enable or disable feature bits on specific CPU models.
1250 void x86_cpu_compat_set_features(const char *cpu_model
, FeatureWord w
,
1251 uint32_t feat_add
, uint32_t feat_remove
)
1253 X86CPUDefinition
*def
;
1255 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1256 def
= &builtin_x86_defs
[i
];
1257 if (!cpu_model
|| !strcmp(cpu_model
, def
->name
)) {
1258 def
->features
[w
] |= feat_add
;
1259 def
->features
[w
] &= ~feat_remove
;
1264 static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w
,
1265 bool migratable_only
);
1269 static int cpu_x86_fill_model_id(char *str
)
1271 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1274 for (i
= 0; i
< 3; i
++) {
1275 host_cpuid(0x80000002 + i
, 0, &eax
, &ebx
, &ecx
, &edx
);
1276 memcpy(str
+ i
* 16 + 0, &eax
, 4);
1277 memcpy(str
+ i
* 16 + 4, &ebx
, 4);
1278 memcpy(str
+ i
* 16 + 8, &ecx
, 4);
1279 memcpy(str
+ i
* 16 + 12, &edx
, 4);
1284 static X86CPUDefinition host_cpudef
;
1286 static Property host_x86_cpu_properties
[] = {
1287 DEFINE_PROP_BOOL("migratable", X86CPU
, migratable
, true),
1288 DEFINE_PROP_END_OF_LIST()
1291 /* class_init for the "host" CPU model
1293 * This function may be called before KVM is initialized.
1295 static void host_x86_cpu_class_init(ObjectClass
*oc
, void *data
)
1297 DeviceClass
*dc
= DEVICE_CLASS(oc
);
1298 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
1299 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1301 xcc
->kvm_required
= true;
1303 host_cpuid(0x0, 0, &eax
, &ebx
, &ecx
, &edx
);
1304 x86_cpu_vendor_words2str(host_cpudef
.vendor
, ebx
, edx
, ecx
);
1306 host_cpuid(0x1, 0, &eax
, &ebx
, &ecx
, &edx
);
1307 host_cpudef
.family
= ((eax
>> 8) & 0x0F) + ((eax
>> 20) & 0xFF);
1308 host_cpudef
.model
= ((eax
>> 4) & 0x0F) | ((eax
& 0xF0000) >> 12);
1309 host_cpudef
.stepping
= eax
& 0x0F;
1311 cpu_x86_fill_model_id(host_cpudef
.model_id
);
1313 xcc
->cpu_def
= &host_cpudef
;
1314 host_cpudef
.cache_info_passthrough
= true;
1316 /* level, xlevel, xlevel2, and the feature words are initialized on
1317 * instance_init, because they require KVM to be initialized.
1320 dc
->props
= host_x86_cpu_properties
;
1323 static void host_x86_cpu_initfn(Object
*obj
)
1325 X86CPU
*cpu
= X86_CPU(obj
);
1326 CPUX86State
*env
= &cpu
->env
;
1327 KVMState
*s
= kvm_state
;
1329 assert(kvm_enabled());
1331 /* We can't fill the features array here because we don't know yet if
1332 * "migratable" is true or false.
1334 cpu
->host_features
= true;
1336 env
->cpuid_level
= kvm_arch_get_supported_cpuid(s
, 0x0, 0, R_EAX
);
1337 env
->cpuid_xlevel
= kvm_arch_get_supported_cpuid(s
, 0x80000000, 0, R_EAX
);
1338 env
->cpuid_xlevel2
= kvm_arch_get_supported_cpuid(s
, 0xC0000000, 0, R_EAX
);
1340 object_property_set_bool(OBJECT(cpu
), true, "pmu", &error_abort
);
1343 static const TypeInfo host_x86_cpu_type_info
= {
1344 .name
= X86_CPU_TYPE_NAME("host"),
1345 .parent
= TYPE_X86_CPU
,
1346 .instance_init
= host_x86_cpu_initfn
,
1347 .class_init
= host_x86_cpu_class_init
,
1352 static void report_unavailable_features(FeatureWord w
, uint32_t mask
)
1354 FeatureWordInfo
*f
= &feature_word_info
[w
];
1357 for (i
= 0; i
< 32; ++i
) {
1358 if (1 << i
& mask
) {
1359 const char *reg
= get_register_name_32(f
->cpuid_reg
);
1361 fprintf(stderr
, "warning: %s doesn't support requested feature: "
1362 "CPUID.%02XH:%s%s%s [bit %d]\n",
1363 kvm_enabled() ? "host" : "TCG",
1365 f
->feat_names
[i
] ? "." : "",
1366 f
->feat_names
[i
] ? f
->feat_names
[i
] : "", i
);
1371 static void x86_cpuid_version_get_family(Object
*obj
, Visitor
*v
, void *opaque
,
1372 const char *name
, Error
**errp
)
1374 X86CPU
*cpu
= X86_CPU(obj
);
1375 CPUX86State
*env
= &cpu
->env
;
1378 value
= (env
->cpuid_version
>> 8) & 0xf;
1380 value
+= (env
->cpuid_version
>> 20) & 0xff;
1382 visit_type_int(v
, &value
, name
, errp
);
1385 static void x86_cpuid_version_set_family(Object
*obj
, Visitor
*v
, void *opaque
,
1386 const char *name
, Error
**errp
)
1388 X86CPU
*cpu
= X86_CPU(obj
);
1389 CPUX86State
*env
= &cpu
->env
;
1390 const int64_t min
= 0;
1391 const int64_t max
= 0xff + 0xf;
1392 Error
*local_err
= NULL
;
1395 visit_type_int(v
, &value
, name
, &local_err
);
1397 error_propagate(errp
, local_err
);
1400 if (value
< min
|| value
> max
) {
1401 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1402 name
? name
: "null", value
, min
, max
);
1406 env
->cpuid_version
&= ~0xff00f00;
1408 env
->cpuid_version
|= 0xf00 | ((value
- 0x0f) << 20);
1410 env
->cpuid_version
|= value
<< 8;
1414 static void x86_cpuid_version_get_model(Object
*obj
, Visitor
*v
, void *opaque
,
1415 const char *name
, Error
**errp
)
1417 X86CPU
*cpu
= X86_CPU(obj
);
1418 CPUX86State
*env
= &cpu
->env
;
1421 value
= (env
->cpuid_version
>> 4) & 0xf;
1422 value
|= ((env
->cpuid_version
>> 16) & 0xf) << 4;
1423 visit_type_int(v
, &value
, name
, errp
);
1426 static void x86_cpuid_version_set_model(Object
*obj
, Visitor
*v
, void *opaque
,
1427 const char *name
, Error
**errp
)
1429 X86CPU
*cpu
= X86_CPU(obj
);
1430 CPUX86State
*env
= &cpu
->env
;
1431 const int64_t min
= 0;
1432 const int64_t max
= 0xff;
1433 Error
*local_err
= NULL
;
1436 visit_type_int(v
, &value
, name
, &local_err
);
1438 error_propagate(errp
, local_err
);
1441 if (value
< min
|| value
> max
) {
1442 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1443 name
? name
: "null", value
, min
, max
);
1447 env
->cpuid_version
&= ~0xf00f0;
1448 env
->cpuid_version
|= ((value
& 0xf) << 4) | ((value
>> 4) << 16);
1451 static void x86_cpuid_version_get_stepping(Object
*obj
, Visitor
*v
,
1452 void *opaque
, const char *name
,
1455 X86CPU
*cpu
= X86_CPU(obj
);
1456 CPUX86State
*env
= &cpu
->env
;
1459 value
= env
->cpuid_version
& 0xf;
1460 visit_type_int(v
, &value
, name
, errp
);
1463 static void x86_cpuid_version_set_stepping(Object
*obj
, Visitor
*v
,
1464 void *opaque
, const char *name
,
1467 X86CPU
*cpu
= X86_CPU(obj
);
1468 CPUX86State
*env
= &cpu
->env
;
1469 const int64_t min
= 0;
1470 const int64_t max
= 0xf;
1471 Error
*local_err
= NULL
;
1474 visit_type_int(v
, &value
, name
, &local_err
);
1476 error_propagate(errp
, local_err
);
1479 if (value
< min
|| value
> max
) {
1480 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1481 name
? name
: "null", value
, min
, max
);
1485 env
->cpuid_version
&= ~0xf;
1486 env
->cpuid_version
|= value
& 0xf;
1489 static void x86_cpuid_get_level(Object
*obj
, Visitor
*v
, void *opaque
,
1490 const char *name
, Error
**errp
)
1492 X86CPU
*cpu
= X86_CPU(obj
);
1494 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1497 static void x86_cpuid_set_level(Object
*obj
, Visitor
*v
, void *opaque
,
1498 const char *name
, Error
**errp
)
1500 X86CPU
*cpu
= X86_CPU(obj
);
1502 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1505 static void x86_cpuid_get_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1506 const char *name
, Error
**errp
)
1508 X86CPU
*cpu
= X86_CPU(obj
);
1510 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1513 static void x86_cpuid_set_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1514 const char *name
, Error
**errp
)
1516 X86CPU
*cpu
= X86_CPU(obj
);
1518 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1521 static char *x86_cpuid_get_vendor(Object
*obj
, Error
**errp
)
1523 X86CPU
*cpu
= X86_CPU(obj
);
1524 CPUX86State
*env
= &cpu
->env
;
1527 value
= (char *)g_malloc(CPUID_VENDOR_SZ
+ 1);
1528 x86_cpu_vendor_words2str(value
, env
->cpuid_vendor1
, env
->cpuid_vendor2
,
1529 env
->cpuid_vendor3
);
1533 static void x86_cpuid_set_vendor(Object
*obj
, const char *value
,
1536 X86CPU
*cpu
= X86_CPU(obj
);
1537 CPUX86State
*env
= &cpu
->env
;
1540 if (strlen(value
) != CPUID_VENDOR_SZ
) {
1541 error_set(errp
, QERR_PROPERTY_VALUE_BAD
, "",
1546 env
->cpuid_vendor1
= 0;
1547 env
->cpuid_vendor2
= 0;
1548 env
->cpuid_vendor3
= 0;
1549 for (i
= 0; i
< 4; i
++) {
1550 env
->cpuid_vendor1
|= ((uint8_t)value
[i
]) << (8 * i
);
1551 env
->cpuid_vendor2
|= ((uint8_t)value
[i
+ 4]) << (8 * i
);
1552 env
->cpuid_vendor3
|= ((uint8_t)value
[i
+ 8]) << (8 * i
);
1556 static char *x86_cpuid_get_model_id(Object
*obj
, Error
**errp
)
1558 X86CPU
*cpu
= X86_CPU(obj
);
1559 CPUX86State
*env
= &cpu
->env
;
1563 value
= g_malloc(48 + 1);
1564 for (i
= 0; i
< 48; i
++) {
1565 value
[i
] = env
->cpuid_model
[i
>> 2] >> (8 * (i
& 3));
1571 static void x86_cpuid_set_model_id(Object
*obj
, const char *model_id
,
1574 X86CPU
*cpu
= X86_CPU(obj
);
1575 CPUX86State
*env
= &cpu
->env
;
1578 if (model_id
== NULL
) {
1581 len
= strlen(model_id
);
1582 memset(env
->cpuid_model
, 0, 48);
1583 for (i
= 0; i
< 48; i
++) {
1587 c
= (uint8_t)model_id
[i
];
1589 env
->cpuid_model
[i
>> 2] |= c
<< (8 * (i
& 3));
1593 static void x86_cpuid_get_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1594 const char *name
, Error
**errp
)
1596 X86CPU
*cpu
= X86_CPU(obj
);
1599 value
= cpu
->env
.tsc_khz
* 1000;
1600 visit_type_int(v
, &value
, name
, errp
);
1603 static void x86_cpuid_set_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1604 const char *name
, Error
**errp
)
1606 X86CPU
*cpu
= X86_CPU(obj
);
1607 const int64_t min
= 0;
1608 const int64_t max
= INT64_MAX
;
1609 Error
*local_err
= NULL
;
1612 visit_type_int(v
, &value
, name
, &local_err
);
1614 error_propagate(errp
, local_err
);
1617 if (value
< min
|| value
> max
) {
1618 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1619 name
? name
: "null", value
, min
, max
);
1623 cpu
->env
.tsc_khz
= value
/ 1000;
1626 static void x86_cpuid_get_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1627 const char *name
, Error
**errp
)
1629 X86CPU
*cpu
= X86_CPU(obj
);
1630 int64_t value
= cpu
->env
.cpuid_apic_id
;
1632 visit_type_int(v
, &value
, name
, errp
);
1635 static void x86_cpuid_set_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1636 const char *name
, Error
**errp
)
1638 X86CPU
*cpu
= X86_CPU(obj
);
1639 DeviceState
*dev
= DEVICE(obj
);
1640 const int64_t min
= 0;
1641 const int64_t max
= UINT32_MAX
;
1642 Error
*error
= NULL
;
1645 if (dev
->realized
) {
1646 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
1647 "it was realized", name
, object_get_typename(obj
));
1651 visit_type_int(v
, &value
, name
, &error
);
1653 error_propagate(errp
, error
);
1656 if (value
< min
|| value
> max
) {
1657 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
1658 " (minimum: %" PRId64
", maximum: %" PRId64
")" ,
1659 object_get_typename(obj
), name
, value
, min
, max
);
1663 if ((value
!= cpu
->env
.cpuid_apic_id
) && cpu_exists(value
)) {
1664 error_setg(errp
, "CPU with APIC ID %" PRIi64
" exists", value
);
1667 cpu
->env
.cpuid_apic_id
= value
;
1670 /* Generic getter for "feature-words" and "filtered-features" properties */
1671 static void x86_cpu_get_feature_words(Object
*obj
, Visitor
*v
, void *opaque
,
1672 const char *name
, Error
**errp
)
1674 uint32_t *array
= (uint32_t *)opaque
;
1677 X86CPUFeatureWordInfo word_infos
[FEATURE_WORDS
] = { };
1678 X86CPUFeatureWordInfoList list_entries
[FEATURE_WORDS
] = { };
1679 X86CPUFeatureWordInfoList
*list
= NULL
;
1681 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1682 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1683 X86CPUFeatureWordInfo
*qwi
= &word_infos
[w
];
1684 qwi
->cpuid_input_eax
= wi
->cpuid_eax
;
1685 qwi
->has_cpuid_input_ecx
= wi
->cpuid_needs_ecx
;
1686 qwi
->cpuid_input_ecx
= wi
->cpuid_ecx
;
1687 qwi
->cpuid_register
= x86_reg_info_32
[wi
->cpuid_reg
].qapi_enum
;
1688 qwi
->features
= array
[w
];
1690 /* List will be in reverse order, but order shouldn't matter */
1691 list_entries
[w
].next
= list
;
1692 list_entries
[w
].value
= &word_infos
[w
];
1693 list
= &list_entries
[w
];
1696 visit_type_X86CPUFeatureWordInfoList(v
, &list
, "feature-words", &err
);
1697 error_propagate(errp
, err
);
1700 static void x86_get_hv_spinlocks(Object
*obj
, Visitor
*v
, void *opaque
,
1701 const char *name
, Error
**errp
)
1703 X86CPU
*cpu
= X86_CPU(obj
);
1704 int64_t value
= cpu
->hyperv_spinlock_attempts
;
1706 visit_type_int(v
, &value
, name
, errp
);
1709 static void x86_set_hv_spinlocks(Object
*obj
, Visitor
*v
, void *opaque
,
1710 const char *name
, Error
**errp
)
1712 const int64_t min
= 0xFFF;
1713 const int64_t max
= UINT_MAX
;
1714 X86CPU
*cpu
= X86_CPU(obj
);
1718 visit_type_int(v
, &value
, name
, &err
);
1720 error_propagate(errp
, err
);
1724 if (value
< min
|| value
> max
) {
1725 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
1726 " (minimum: %" PRId64
", maximum: %" PRId64
")",
1727 object_get_typename(obj
), name
? name
: "null",
1731 cpu
->hyperv_spinlock_attempts
= value
;
1734 static PropertyInfo qdev_prop_spinlocks
= {
1736 .get
= x86_get_hv_spinlocks
,
1737 .set
= x86_set_hv_spinlocks
,
1740 /* Convert all '_' in a feature string option name to '-', to make feature
1741 * name conform to QOM property naming rule, which uses '-' instead of '_'.
1743 static inline void feat2prop(char *s
)
1745 while ((s
= strchr(s
, '_'))) {
1750 /* Parse "+feature,-feature,feature=foo" CPU feature string
1752 static void x86_cpu_parse_featurestr(CPUState
*cs
, char *features
,
1755 X86CPU
*cpu
= X86_CPU(cs
);
1756 char *featurestr
; /* Single 'key=value" string being parsed */
1758 /* Features to be added */
1759 FeatureWordArray plus_features
= { 0 };
1760 /* Features to be removed */
1761 FeatureWordArray minus_features
= { 0 };
1763 CPUX86State
*env
= &cpu
->env
;
1764 Error
*local_err
= NULL
;
1766 featurestr
= features
? strtok(features
, ",") : NULL
;
1768 while (featurestr
) {
1770 if (featurestr
[0] == '+') {
1771 add_flagname_to_bitmaps(featurestr
+ 1, plus_features
, &local_err
);
1772 } else if (featurestr
[0] == '-') {
1773 add_flagname_to_bitmaps(featurestr
+ 1, minus_features
, &local_err
);
1774 } else if ((val
= strchr(featurestr
, '='))) {
1776 feat2prop(featurestr
);
1777 if (!strcmp(featurestr
, "xlevel")) {
1781 numvalue
= strtoul(val
, &err
, 0);
1782 if (!*val
|| *err
) {
1783 error_setg(errp
, "bad numerical value %s", val
);
1786 if (numvalue
< 0x80000000) {
1787 error_report("xlevel value shall always be >= 0x80000000"
1788 ", fixup will be removed in future versions");
1789 numvalue
+= 0x80000000;
1791 snprintf(num
, sizeof(num
), "%" PRIu32
, numvalue
);
1792 object_property_parse(OBJECT(cpu
), num
, featurestr
, &local_err
);
1793 } else if (!strcmp(featurestr
, "tsc-freq")) {
1798 tsc_freq
= strtosz_suffix_unit(val
, &err
,
1799 STRTOSZ_DEFSUFFIX_B
, 1000);
1800 if (tsc_freq
< 0 || *err
) {
1801 error_setg(errp
, "bad numerical value %s", val
);
1804 snprintf(num
, sizeof(num
), "%" PRId64
, tsc_freq
);
1805 object_property_parse(OBJECT(cpu
), num
, "tsc-frequency",
1807 } else if (!strcmp(featurestr
, "hv-spinlocks")) {
1809 const int min
= 0xFFF;
1811 numvalue
= strtoul(val
, &err
, 0);
1812 if (!*val
|| *err
) {
1813 error_setg(errp
, "bad numerical value %s", val
);
1816 if (numvalue
< min
) {
1817 error_report("hv-spinlocks value shall always be >= 0x%x"
1818 ", fixup will be removed in future versions",
1822 snprintf(num
, sizeof(num
), "%" PRId32
, numvalue
);
1823 object_property_parse(OBJECT(cpu
), num
, featurestr
, &local_err
);
1825 object_property_parse(OBJECT(cpu
), val
, featurestr
, &local_err
);
1828 feat2prop(featurestr
);
1829 object_property_parse(OBJECT(cpu
), "on", featurestr
, &local_err
);
1832 error_propagate(errp
, local_err
);
1835 featurestr
= strtok(NULL
, ",");
1838 if (cpu
->host_features
) {
1839 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1841 x86_cpu_get_supported_feature_word(w
, cpu
->migratable
);
1845 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1846 env
->features
[w
] |= plus_features
[w
];
1847 env
->features
[w
] &= ~minus_features
[w
];
1851 /* generate a composite string into buf of all cpuid names in featureset
1852 * selected by fbits. indicate truncation at bufsize in the event of overflow.
1853 * if flags, suppress names undefined in featureset.
1855 static void listflags(char *buf
, int bufsize
, uint32_t fbits
,
1856 const char **featureset
, uint32_t flags
)
1858 const char **p
= &featureset
[31];
1862 b
= 4 <= bufsize
? buf
+ (bufsize
-= 3) - 1 : NULL
;
1864 for (q
= buf
, bit
= 31; fbits
&& bufsize
; --p
, fbits
&= ~(1 << bit
), --bit
)
1865 if (fbits
& 1 << bit
&& (*p
|| !flags
)) {
1867 nc
= snprintf(q
, bufsize
, "%s%s", q
== buf
? "" : " ", *p
);
1869 nc
= snprintf(q
, bufsize
, "%s[%d]", q
== buf
? "" : " ", bit
);
1870 if (bufsize
<= nc
) {
1872 memcpy(b
, "...", sizeof("..."));
1881 /* generate CPU information. */
1882 void x86_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
1884 X86CPUDefinition
*def
;
1888 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1889 def
= &builtin_x86_defs
[i
];
1890 snprintf(buf
, sizeof(buf
), "%s", def
->name
);
1891 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", buf
, def
->model_id
);
1894 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", "host",
1895 "KVM processor with all supported host features "
1896 "(only available in KVM mode)");
1899 (*cpu_fprintf
)(f
, "\nRecognized CPUID flags:\n");
1900 for (i
= 0; i
< ARRAY_SIZE(feature_word_info
); i
++) {
1901 FeatureWordInfo
*fw
= &feature_word_info
[i
];
1903 listflags(buf
, sizeof(buf
), (uint32_t)~0, fw
->feat_names
, 1);
1904 (*cpu_fprintf
)(f
, " %s\n", buf
);
1908 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
1910 CpuDefinitionInfoList
*cpu_list
= NULL
;
1911 X86CPUDefinition
*def
;
1914 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1915 CpuDefinitionInfoList
*entry
;
1916 CpuDefinitionInfo
*info
;
1918 def
= &builtin_x86_defs
[i
];
1919 info
= g_malloc0(sizeof(*info
));
1920 info
->name
= g_strdup(def
->name
);
1922 entry
= g_malloc0(sizeof(*entry
));
1923 entry
->value
= info
;
1924 entry
->next
= cpu_list
;
1931 static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w
,
1932 bool migratable_only
)
1934 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1937 if (kvm_enabled()) {
1938 r
= kvm_arch_get_supported_cpuid(kvm_state
, wi
->cpuid_eax
,
1941 } else if (tcg_enabled()) {
1942 r
= wi
->tcg_features
;
1946 if (migratable_only
) {
1947 r
&= x86_cpu_get_migratable_flags(w
);
1953 * Filters CPU feature words based on host availability of each feature.
1955 * Returns: 0 if all flags are supported by the host, non-zero otherwise.
1957 static int x86_cpu_filter_features(X86CPU
*cpu
)
1959 CPUX86State
*env
= &cpu
->env
;
1963 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1964 uint32_t host_feat
=
1965 x86_cpu_get_supported_feature_word(w
, cpu
->migratable
);
1966 uint32_t requested_features
= env
->features
[w
];
1967 env
->features
[w
] &= host_feat
;
1968 cpu
->filtered_features
[w
] = requested_features
& ~env
->features
[w
];
1969 if (cpu
->filtered_features
[w
]) {
1970 if (cpu
->check_cpuid
|| cpu
->enforce_cpuid
) {
1971 report_unavailable_features(w
, cpu
->filtered_features
[w
]);
1980 /* Load data from X86CPUDefinition
1982 static void x86_cpu_load_def(X86CPU
*cpu
, X86CPUDefinition
*def
, Error
**errp
)
1984 CPUX86State
*env
= &cpu
->env
;
1986 char host_vendor
[CPUID_VENDOR_SZ
+ 1];
1989 object_property_set_int(OBJECT(cpu
), def
->level
, "level", errp
);
1990 object_property_set_int(OBJECT(cpu
), def
->family
, "family", errp
);
1991 object_property_set_int(OBJECT(cpu
), def
->model
, "model", errp
);
1992 object_property_set_int(OBJECT(cpu
), def
->stepping
, "stepping", errp
);
1993 object_property_set_int(OBJECT(cpu
), def
->xlevel
, "xlevel", errp
);
1994 env
->cpuid_xlevel2
= def
->xlevel2
;
1995 cpu
->cache_info_passthrough
= def
->cache_info_passthrough
;
1996 object_property_set_str(OBJECT(cpu
), def
->model_id
, "model-id", errp
);
1997 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1998 env
->features
[w
] = def
->features
[w
];
2001 /* Special cases not set in the X86CPUDefinition structs: */
2002 if (kvm_enabled()) {
2004 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
2005 env
->features
[w
] |= kvm_default_features
[w
];
2006 env
->features
[w
] &= ~kvm_default_unset_features
[w
];
2010 env
->features
[FEAT_1_ECX
] |= CPUID_EXT_HYPERVISOR
;
2012 /* sysenter isn't supported in compatibility mode on AMD,
2013 * syscall isn't supported in compatibility mode on Intel.
2014 * Normally we advertise the actual CPU vendor, but you can
2015 * override this using the 'vendor' property if you want to use
2016 * KVM's sysenter/syscall emulation in compatibility mode and
2017 * when doing cross vendor migration
2019 vendor
= def
->vendor
;
2020 if (kvm_enabled()) {
2021 uint32_t ebx
= 0, ecx
= 0, edx
= 0;
2022 host_cpuid(0, 0, NULL
, &ebx
, &ecx
, &edx
);
2023 x86_cpu_vendor_words2str(host_vendor
, ebx
, edx
, ecx
);
2024 vendor
= host_vendor
;
2027 object_property_set_str(OBJECT(cpu
), vendor
, "vendor", errp
);
2031 X86CPU
*cpu_x86_create(const char *cpu_model
, DeviceState
*icc_bridge
,
2037 gchar
**model_pieces
;
2038 char *name
, *features
;
2039 Error
*error
= NULL
;
2041 model_pieces
= g_strsplit(cpu_model
, ",", 2);
2042 if (!model_pieces
[0]) {
2043 error_setg(&error
, "Invalid/empty CPU model name");
2046 name
= model_pieces
[0];
2047 features
= model_pieces
[1];
2049 oc
= x86_cpu_class_by_name(name
);
2051 error_setg(&error
, "Unable to find CPU definition: %s", name
);
2054 xcc
= X86_CPU_CLASS(oc
);
2056 if (xcc
->kvm_required
&& !kvm_enabled()) {
2057 error_setg(&error
, "CPU model '%s' requires KVM", name
);
2061 cpu
= X86_CPU(object_new(object_class_get_name(oc
)));
2063 #ifndef CONFIG_USER_ONLY
2064 if (icc_bridge
== NULL
) {
2065 error_setg(&error
, "Invalid icc-bridge value");
2068 qdev_set_parent_bus(DEVICE(cpu
), qdev_get_child_bus(icc_bridge
, "icc"));
2069 object_unref(OBJECT(cpu
));
2072 x86_cpu_parse_featurestr(CPU(cpu
), features
, &error
);
2078 if (error
!= NULL
) {
2079 error_propagate(errp
, error
);
2081 object_unref(OBJECT(cpu
));
2085 g_strfreev(model_pieces
);
2089 X86CPU
*cpu_x86_init(const char *cpu_model
)
2091 Error
*error
= NULL
;
2094 cpu
= cpu_x86_create(cpu_model
, NULL
, &error
);
2099 object_property_set_bool(OBJECT(cpu
), true, "realized", &error
);
2103 error_report("%s", error_get_pretty(error
));
2106 object_unref(OBJECT(cpu
));
2113 static void x86_cpu_cpudef_class_init(ObjectClass
*oc
, void *data
)
2115 X86CPUDefinition
*cpudef
= data
;
2116 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
2118 xcc
->cpu_def
= cpudef
;
2121 static void x86_register_cpudef_type(X86CPUDefinition
*def
)
2123 char *typename
= x86_cpu_type_name(def
->name
);
2126 .parent
= TYPE_X86_CPU
,
2127 .class_init
= x86_cpu_cpudef_class_init
,
2135 #if !defined(CONFIG_USER_ONLY)
2137 void cpu_clear_apic_feature(CPUX86State
*env
)
2139 env
->features
[FEAT_1_EDX
] &= ~CPUID_APIC
;
2142 #endif /* !CONFIG_USER_ONLY */
2144 /* Initialize list of CPU models, filling some non-static fields if necessary
2146 void x86_cpudef_setup(void)
2149 static const char *model_with_versions
[] = { "qemu32", "qemu64", "athlon" };
2151 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); ++i
) {
2152 X86CPUDefinition
*def
= &builtin_x86_defs
[i
];
2154 /* Look for specific "cpudef" models that */
2155 /* have the QEMU version in .model_id */
2156 for (j
= 0; j
< ARRAY_SIZE(model_with_versions
); j
++) {
2157 if (strcmp(model_with_versions
[j
], def
->name
) == 0) {
2158 pstrcpy(def
->model_id
, sizeof(def
->model_id
),
2159 "QEMU Virtual CPU version ");
2160 pstrcat(def
->model_id
, sizeof(def
->model_id
),
2161 qemu_get_version());
2168 static void get_cpuid_vendor(CPUX86State
*env
, uint32_t *ebx
,
2169 uint32_t *ecx
, uint32_t *edx
)
2171 *ebx
= env
->cpuid_vendor1
;
2172 *edx
= env
->cpuid_vendor2
;
2173 *ecx
= env
->cpuid_vendor3
;
2176 void cpu_x86_cpuid(CPUX86State
*env
, uint32_t index
, uint32_t count
,
2177 uint32_t *eax
, uint32_t *ebx
,
2178 uint32_t *ecx
, uint32_t *edx
)
2180 X86CPU
*cpu
= x86_env_get_cpu(env
);
2181 CPUState
*cs
= CPU(cpu
);
2183 /* test if maximum index reached */
2184 if (index
& 0x80000000) {
2185 if (index
> env
->cpuid_xlevel
) {
2186 if (env
->cpuid_xlevel2
> 0) {
2187 /* Handle the Centaur's CPUID instruction. */
2188 if (index
> env
->cpuid_xlevel2
) {
2189 index
= env
->cpuid_xlevel2
;
2190 } else if (index
< 0xC0000000) {
2191 index
= env
->cpuid_xlevel
;
2194 /* Intel documentation states that invalid EAX input will
2195 * return the same information as EAX=cpuid_level
2196 * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
2198 index
= env
->cpuid_level
;
2202 if (index
> env
->cpuid_level
)
2203 index
= env
->cpuid_level
;
2208 *eax
= env
->cpuid_level
;
2209 get_cpuid_vendor(env
, ebx
, ecx
, edx
);
2212 *eax
= env
->cpuid_version
;
2213 *ebx
= (env
->cpuid_apic_id
<< 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
2214 *ecx
= env
->features
[FEAT_1_ECX
];
2215 *edx
= env
->features
[FEAT_1_EDX
];
2216 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2217 *ebx
|= (cs
->nr_cores
* cs
->nr_threads
) << 16;
2218 *edx
|= 1 << 28; /* HTT bit */
2222 /* cache info: needed for Pentium Pro compatibility */
2223 if (cpu
->cache_info_passthrough
) {
2224 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2227 *eax
= 1; /* Number of CPUID[EAX=2] calls required */
2230 *edx
= (L1D_DESCRIPTOR
<< 16) | \
2231 (L1I_DESCRIPTOR
<< 8) | \
2235 /* cache info: needed for Core compatibility */
2236 if (cpu
->cache_info_passthrough
) {
2237 host_cpuid(index
, count
, eax
, ebx
, ecx
, edx
);
2238 *eax
&= ~0xFC000000;
2242 case 0: /* L1 dcache info */
2243 *eax
|= CPUID_4_TYPE_DCACHE
| \
2244 CPUID_4_LEVEL(1) | \
2245 CPUID_4_SELF_INIT_LEVEL
;
2246 *ebx
= (L1D_LINE_SIZE
- 1) | \
2247 ((L1D_PARTITIONS
- 1) << 12) | \
2248 ((L1D_ASSOCIATIVITY
- 1) << 22);
2249 *ecx
= L1D_SETS
- 1;
2250 *edx
= CPUID_4_NO_INVD_SHARING
;
2252 case 1: /* L1 icache info */
2253 *eax
|= CPUID_4_TYPE_ICACHE
| \
2254 CPUID_4_LEVEL(1) | \
2255 CPUID_4_SELF_INIT_LEVEL
;
2256 *ebx
= (L1I_LINE_SIZE
- 1) | \
2257 ((L1I_PARTITIONS
- 1) << 12) | \
2258 ((L1I_ASSOCIATIVITY
- 1) << 22);
2259 *ecx
= L1I_SETS
- 1;
2260 *edx
= CPUID_4_NO_INVD_SHARING
;
2262 case 2: /* L2 cache info */
2263 *eax
|= CPUID_4_TYPE_UNIFIED
| \
2264 CPUID_4_LEVEL(2) | \
2265 CPUID_4_SELF_INIT_LEVEL
;
2266 if (cs
->nr_threads
> 1) {
2267 *eax
|= (cs
->nr_threads
- 1) << 14;
2269 *ebx
= (L2_LINE_SIZE
- 1) | \
2270 ((L2_PARTITIONS
- 1) << 12) | \
2271 ((L2_ASSOCIATIVITY
- 1) << 22);
2273 *edx
= CPUID_4_NO_INVD_SHARING
;
2275 default: /* end of info */
2284 /* QEMU gives out its own APIC IDs, never pass down bits 31..26. */
2285 if ((*eax
& 31) && cs
->nr_cores
> 1) {
2286 *eax
|= (cs
->nr_cores
- 1) << 26;
2290 /* mwait info: needed for Core compatibility */
2291 *eax
= 0; /* Smallest monitor-line size in bytes */
2292 *ebx
= 0; /* Largest monitor-line size in bytes */
2293 *ecx
= CPUID_MWAIT_EMX
| CPUID_MWAIT_IBE
;
2297 /* Thermal and Power Leaf */
2304 /* Structured Extended Feature Flags Enumeration Leaf */
2306 *eax
= 0; /* Maximum ECX value for sub-leaves */
2307 *ebx
= env
->features
[FEAT_7_0_EBX
]; /* Feature flags */
2308 *ecx
= 0; /* Reserved */
2309 *edx
= 0; /* Reserved */
2318 /* Direct Cache Access Information Leaf */
2319 *eax
= 0; /* Bits 0-31 in DCA_CAP MSR */
2325 /* Architectural Performance Monitoring Leaf */
2326 if (kvm_enabled() && cpu
->enable_pmu
) {
2327 KVMState
*s
= cs
->kvm_state
;
2329 *eax
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EAX
);
2330 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EBX
);
2331 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_ECX
);
2332 *edx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EDX
);
2341 KVMState
*s
= cs
->kvm_state
;
2345 /* Processor Extended State */
2350 if (!(env
->features
[FEAT_1_ECX
] & CPUID_EXT_XSAVE
) || !kvm_enabled()) {
2354 kvm_arch_get_supported_cpuid(s
, 0xd, 0, R_EAX
) |
2355 ((uint64_t)kvm_arch_get_supported_cpuid(s
, 0xd, 0, R_EDX
) << 32);
2359 for (i
= 2; i
< ARRAY_SIZE(ext_save_areas
); i
++) {
2360 const ExtSaveArea
*esa
= &ext_save_areas
[i
];
2361 if ((env
->features
[esa
->feature
] & esa
->bits
) == esa
->bits
&&
2362 (kvm_mask
& (1 << i
)) != 0) {
2366 *edx
|= 1 << (i
- 32);
2368 *ecx
= MAX(*ecx
, esa
->offset
+ esa
->size
);
2371 *eax
|= kvm_mask
& (XSTATE_FP
| XSTATE_SSE
);
2373 } else if (count
== 1) {
2374 *eax
= kvm_arch_get_supported_cpuid(s
, 0xd, 1, R_EAX
);
2375 } else if (count
< ARRAY_SIZE(ext_save_areas
)) {
2376 const ExtSaveArea
*esa
= &ext_save_areas
[count
];
2377 if ((env
->features
[esa
->feature
] & esa
->bits
) == esa
->bits
&&
2378 (kvm_mask
& (1 << count
)) != 0) {
2386 *eax
= env
->cpuid_xlevel
;
2387 *ebx
= env
->cpuid_vendor1
;
2388 *edx
= env
->cpuid_vendor2
;
2389 *ecx
= env
->cpuid_vendor3
;
2392 *eax
= env
->cpuid_version
;
2394 *ecx
= env
->features
[FEAT_8000_0001_ECX
];
2395 *edx
= env
->features
[FEAT_8000_0001_EDX
];
2397 /* The Linux kernel checks for the CMPLegacy bit and
2398 * discards multiple thread information if it is set.
2399 * So dont set it here for Intel to make Linux guests happy.
2401 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2402 uint32_t tebx
, tecx
, tedx
;
2403 get_cpuid_vendor(env
, &tebx
, &tecx
, &tedx
);
2404 if (tebx
!= CPUID_VENDOR_INTEL_1
||
2405 tedx
!= CPUID_VENDOR_INTEL_2
||
2406 tecx
!= CPUID_VENDOR_INTEL_3
) {
2407 *ecx
|= 1 << 1; /* CmpLegacy bit */
2414 *eax
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 0];
2415 *ebx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 1];
2416 *ecx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 2];
2417 *edx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 3];
2420 /* cache info (L1 cache) */
2421 if (cpu
->cache_info_passthrough
) {
2422 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2425 *eax
= (L1_DTLB_2M_ASSOC
<< 24) | (L1_DTLB_2M_ENTRIES
<< 16) | \
2426 (L1_ITLB_2M_ASSOC
<< 8) | (L1_ITLB_2M_ENTRIES
);
2427 *ebx
= (L1_DTLB_4K_ASSOC
<< 24) | (L1_DTLB_4K_ENTRIES
<< 16) | \
2428 (L1_ITLB_4K_ASSOC
<< 8) | (L1_ITLB_4K_ENTRIES
);
2429 *ecx
= (L1D_SIZE_KB_AMD
<< 24) | (L1D_ASSOCIATIVITY_AMD
<< 16) | \
2430 (L1D_LINES_PER_TAG
<< 8) | (L1D_LINE_SIZE
);
2431 *edx
= (L1I_SIZE_KB_AMD
<< 24) | (L1I_ASSOCIATIVITY_AMD
<< 16) | \
2432 (L1I_LINES_PER_TAG
<< 8) | (L1I_LINE_SIZE
);
2435 /* cache info (L2 cache) */
2436 if (cpu
->cache_info_passthrough
) {
2437 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2440 *eax
= (AMD_ENC_ASSOC(L2_DTLB_2M_ASSOC
) << 28) | \
2441 (L2_DTLB_2M_ENTRIES
<< 16) | \
2442 (AMD_ENC_ASSOC(L2_ITLB_2M_ASSOC
) << 12) | \
2443 (L2_ITLB_2M_ENTRIES
);
2444 *ebx
= (AMD_ENC_ASSOC(L2_DTLB_4K_ASSOC
) << 28) | \
2445 (L2_DTLB_4K_ENTRIES
<< 16) | \
2446 (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC
) << 12) | \
2447 (L2_ITLB_4K_ENTRIES
);
2448 *ecx
= (L2_SIZE_KB_AMD
<< 16) | \
2449 (AMD_ENC_ASSOC(L2_ASSOCIATIVITY
) << 12) | \
2450 (L2_LINES_PER_TAG
<< 8) | (L2_LINE_SIZE
);
2451 *edx
= ((L3_SIZE_KB
/512) << 18) | \
2452 (AMD_ENC_ASSOC(L3_ASSOCIATIVITY
) << 12) | \
2453 (L3_LINES_PER_TAG
<< 8) | (L3_LINE_SIZE
);
2459 *edx
= env
->features
[FEAT_8000_0007_EDX
];
2462 /* virtual & phys address size in low 2 bytes. */
2463 /* XXX: This value must match the one used in the MMU code. */
2464 if (env
->features
[FEAT_8000_0001_EDX
] & CPUID_EXT2_LM
) {
2465 /* 64 bit processor */
2466 /* XXX: The physical address space is limited to 42 bits in exec.c. */
2467 *eax
= 0x00003028; /* 48 bits virtual, 40 bits physical */
2469 if (env
->features
[FEAT_1_EDX
] & CPUID_PSE36
) {
2470 *eax
= 0x00000024; /* 36 bits physical */
2472 *eax
= 0x00000020; /* 32 bits physical */
2478 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2479 *ecx
|= (cs
->nr_cores
* cs
->nr_threads
) - 1;
2483 if (env
->features
[FEAT_8000_0001_ECX
] & CPUID_EXT3_SVM
) {
2484 *eax
= 0x00000001; /* SVM Revision */
2485 *ebx
= 0x00000010; /* nr of ASIDs */
2487 *edx
= env
->features
[FEAT_SVM
]; /* optional features */
2496 *eax
= env
->cpuid_xlevel2
;
2502 /* Support for VIA CPU's CPUID instruction */
2503 *eax
= env
->cpuid_version
;
2506 *edx
= env
->features
[FEAT_C000_0001_EDX
];
2511 /* Reserved for the future, and now filled with zero */
2518 /* reserved values: zero */
2527 /* CPUClass::reset() */
2528 static void x86_cpu_reset(CPUState
*s
)
2530 X86CPU
*cpu
= X86_CPU(s
);
2531 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(cpu
);
2532 CPUX86State
*env
= &cpu
->env
;
2535 xcc
->parent_reset(s
);
2537 memset(env
, 0, offsetof(CPUX86State
, cpuid_level
));
2541 env
->old_exception
= -1;
2543 /* init to reset state */
2545 #ifdef CONFIG_SOFTMMU
2546 env
->hflags
|= HF_SOFTMMU_MASK
;
2548 env
->hflags2
|= HF2_GIF_MASK
;
2550 cpu_x86_update_cr0(env
, 0x60000010);
2551 env
->a20_mask
= ~0x0;
2552 env
->smbase
= 0x30000;
2554 env
->idt
.limit
= 0xffff;
2555 env
->gdt
.limit
= 0xffff;
2556 env
->ldt
.limit
= 0xffff;
2557 env
->ldt
.flags
= DESC_P_MASK
| (2 << DESC_TYPE_SHIFT
);
2558 env
->tr
.limit
= 0xffff;
2559 env
->tr
.flags
= DESC_P_MASK
| (11 << DESC_TYPE_SHIFT
);
2561 cpu_x86_load_seg_cache(env
, R_CS
, 0xf000, 0xffff0000, 0xffff,
2562 DESC_P_MASK
| DESC_S_MASK
| DESC_CS_MASK
|
2563 DESC_R_MASK
| DESC_A_MASK
);
2564 cpu_x86_load_seg_cache(env
, R_DS
, 0, 0, 0xffff,
2565 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2567 cpu_x86_load_seg_cache(env
, R_ES
, 0, 0, 0xffff,
2568 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2570 cpu_x86_load_seg_cache(env
, R_SS
, 0, 0, 0xffff,
2571 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2573 cpu_x86_load_seg_cache(env
, R_FS
, 0, 0, 0xffff,
2574 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2576 cpu_x86_load_seg_cache(env
, R_GS
, 0, 0, 0xffff,
2577 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2581 env
->regs
[R_EDX
] = env
->cpuid_version
;
2586 for (i
= 0; i
< 8; i
++) {
2589 cpu_set_fpuc(env
, 0x37f);
2591 env
->mxcsr
= 0x1f80;
2592 env
->xstate_bv
= XSTATE_FP
| XSTATE_SSE
;
2594 env
->pat
= 0x0007040600070406ULL
;
2595 env
->msr_ia32_misc_enable
= MSR_IA32_MISC_ENABLE_DEFAULT
;
2597 memset(env
->dr
, 0, sizeof(env
->dr
));
2598 env
->dr
[6] = DR6_FIXED_1
;
2599 env
->dr
[7] = DR7_FIXED_1
;
2600 cpu_breakpoint_remove_all(s
, BP_CPU
);
2601 cpu_watchpoint_remove_all(s
, BP_CPU
);
2606 * SDM 11.11.5 requires:
2607 * - IA32_MTRR_DEF_TYPE MSR.E = 0
2608 * - IA32_MTRR_PHYSMASKn.V = 0
2609 * All other bits are undefined. For simplification, zero it all.
2611 env
->mtrr_deftype
= 0;
2612 memset(env
->mtrr_var
, 0, sizeof(env
->mtrr_var
));
2613 memset(env
->mtrr_fixed
, 0, sizeof(env
->mtrr_fixed
));
2615 #if !defined(CONFIG_USER_ONLY)
2616 /* We hard-wire the BSP to the first CPU. */
2617 if (s
->cpu_index
== 0) {
2618 apic_designate_bsp(cpu
->apic_state
);
2621 s
->halted
= !cpu_is_bsp(cpu
);
2623 if (kvm_enabled()) {
2624 kvm_arch_reset_vcpu(cpu
);
2629 #ifndef CONFIG_USER_ONLY
2630 bool cpu_is_bsp(X86CPU
*cpu
)
2632 return cpu_get_apic_base(cpu
->apic_state
) & MSR_IA32_APICBASE_BSP
;
2635 /* TODO: remove me, when reset over QOM tree is implemented */
2636 static void x86_cpu_machine_reset_cb(void *opaque
)
2638 X86CPU
*cpu
= opaque
;
2639 cpu_reset(CPU(cpu
));
2643 static void mce_init(X86CPU
*cpu
)
2645 CPUX86State
*cenv
= &cpu
->env
;
2648 if (((cenv
->cpuid_version
>> 8) & 0xf) >= 6
2649 && (cenv
->features
[FEAT_1_EDX
] & (CPUID_MCE
| CPUID_MCA
)) ==
2650 (CPUID_MCE
| CPUID_MCA
)) {
2651 cenv
->mcg_cap
= MCE_CAP_DEF
| MCE_BANKS_DEF
;
2652 cenv
->mcg_ctl
= ~(uint64_t)0;
2653 for (bank
= 0; bank
< MCE_BANKS_DEF
; bank
++) {
2654 cenv
->mce_banks
[bank
* 4] = ~(uint64_t)0;
2659 #ifndef CONFIG_USER_ONLY
2660 static void x86_cpu_apic_create(X86CPU
*cpu
, Error
**errp
)
2662 CPUX86State
*env
= &cpu
->env
;
2663 DeviceState
*dev
= DEVICE(cpu
);
2664 APICCommonState
*apic
;
2665 const char *apic_type
= "apic";
2667 if (kvm_irqchip_in_kernel()) {
2668 apic_type
= "kvm-apic";
2669 } else if (xen_enabled()) {
2670 apic_type
= "xen-apic";
2673 cpu
->apic_state
= qdev_try_create(qdev_get_parent_bus(dev
), apic_type
);
2674 if (cpu
->apic_state
== NULL
) {
2675 error_setg(errp
, "APIC device '%s' could not be created", apic_type
);
2679 object_property_add_child(OBJECT(cpu
), "apic",
2680 OBJECT(cpu
->apic_state
), NULL
);
2681 qdev_prop_set_uint8(cpu
->apic_state
, "id", env
->cpuid_apic_id
);
2682 /* TODO: convert to link<> */
2683 apic
= APIC_COMMON(cpu
->apic_state
);
2687 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2689 if (cpu
->apic_state
== NULL
) {
2693 if (qdev_init(cpu
->apic_state
)) {
2694 error_setg(errp
, "APIC device '%s' could not be initialized",
2695 object_get_typename(OBJECT(cpu
->apic_state
)));
2700 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2706 #define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
2707 (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
2708 (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
2709 #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
2710 (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
2711 (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
2712 static void x86_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
2714 CPUState
*cs
= CPU(dev
);
2715 X86CPU
*cpu
= X86_CPU(dev
);
2716 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(dev
);
2717 CPUX86State
*env
= &cpu
->env
;
2718 Error
*local_err
= NULL
;
2719 static bool ht_warned
;
2721 if (env
->features
[FEAT_7_0_EBX
] && env
->cpuid_level
< 7) {
2722 env
->cpuid_level
= 7;
2725 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
2728 if (IS_AMD_CPU(env
)) {
2729 env
->features
[FEAT_8000_0001_EDX
] &= ~CPUID_EXT2_AMD_ALIASES
;
2730 env
->features
[FEAT_8000_0001_EDX
] |= (env
->features
[FEAT_1_EDX
]
2731 & CPUID_EXT2_AMD_ALIASES
);
2735 if (x86_cpu_filter_features(cpu
) && cpu
->enforce_cpuid
) {
2736 error_setg(&local_err
,
2738 "Host doesn't support requested features" :
2739 "TCG doesn't support requested features");
2743 #ifndef CONFIG_USER_ONLY
2744 qemu_register_reset(x86_cpu_machine_reset_cb
, cpu
);
2746 if (cpu
->env
.features
[FEAT_1_EDX
] & CPUID_APIC
|| smp_cpus
> 1) {
2747 x86_cpu_apic_create(cpu
, &local_err
);
2748 if (local_err
!= NULL
) {
2757 /* Only Intel CPUs support hyperthreading. Even though QEMU fixes this
2758 * issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
2759 * based on inputs (sockets,cores,threads), it is still better to gives
2762 * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
2763 * cs->nr_threads hasn't be populated yet and the checking is incorrect.
2765 if (!IS_INTEL_CPU(env
) && cs
->nr_threads
> 1 && !ht_warned
) {
2766 error_report("AMD CPU doesn't support hyperthreading. Please configure"
2767 " -smp options properly.");
2771 x86_cpu_apic_realize(cpu
, &local_err
);
2772 if (local_err
!= NULL
) {
2777 xcc
->parent_realize(dev
, &local_err
);
2779 if (local_err
!= NULL
) {
2780 error_propagate(errp
, local_err
);
2785 /* Enables contiguous-apic-ID mode, for compatibility */
2786 static bool compat_apic_id_mode
;
2788 void enable_compat_apic_id_mode(void)
2790 compat_apic_id_mode
= true;
2793 /* Calculates initial APIC ID for a specific CPU index
2795 * Currently we need to be able to calculate the APIC ID from the CPU index
2796 * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
2797 * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
2798 * all CPUs up to max_cpus.
2800 uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index
)
2802 uint32_t correct_id
;
2805 correct_id
= x86_apicid_from_cpu_idx(smp_cores
, smp_threads
, cpu_index
);
2806 if (compat_apic_id_mode
) {
2807 if (cpu_index
!= correct_id
&& !warned
) {
2808 error_report("APIC IDs set in compatibility mode, "
2809 "CPU topology won't match the configuration");
2818 static void x86_cpu_initfn(Object
*obj
)
2820 CPUState
*cs
= CPU(obj
);
2821 X86CPU
*cpu
= X86_CPU(obj
);
2822 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(obj
);
2823 CPUX86State
*env
= &cpu
->env
;
2829 object_property_add(obj
, "family", "int",
2830 x86_cpuid_version_get_family
,
2831 x86_cpuid_version_set_family
, NULL
, NULL
, NULL
);
2832 object_property_add(obj
, "model", "int",
2833 x86_cpuid_version_get_model
,
2834 x86_cpuid_version_set_model
, NULL
, NULL
, NULL
);
2835 object_property_add(obj
, "stepping", "int",
2836 x86_cpuid_version_get_stepping
,
2837 x86_cpuid_version_set_stepping
, NULL
, NULL
, NULL
);
2838 object_property_add(obj
, "level", "int",
2839 x86_cpuid_get_level
,
2840 x86_cpuid_set_level
, NULL
, NULL
, NULL
);
2841 object_property_add(obj
, "xlevel", "int",
2842 x86_cpuid_get_xlevel
,
2843 x86_cpuid_set_xlevel
, NULL
, NULL
, NULL
);
2844 object_property_add_str(obj
, "vendor",
2845 x86_cpuid_get_vendor
,
2846 x86_cpuid_set_vendor
, NULL
);
2847 object_property_add_str(obj
, "model-id",
2848 x86_cpuid_get_model_id
,
2849 x86_cpuid_set_model_id
, NULL
);
2850 object_property_add(obj
, "tsc-frequency", "int",
2851 x86_cpuid_get_tsc_freq
,
2852 x86_cpuid_set_tsc_freq
, NULL
, NULL
, NULL
);
2853 object_property_add(obj
, "apic-id", "int",
2854 x86_cpuid_get_apic_id
,
2855 x86_cpuid_set_apic_id
, NULL
, NULL
, NULL
);
2856 object_property_add(obj
, "feature-words", "X86CPUFeatureWordInfo",
2857 x86_cpu_get_feature_words
,
2858 NULL
, NULL
, (void *)env
->features
, NULL
);
2859 object_property_add(obj
, "filtered-features", "X86CPUFeatureWordInfo",
2860 x86_cpu_get_feature_words
,
2861 NULL
, NULL
, (void *)cpu
->filtered_features
, NULL
);
2863 cpu
->hyperv_spinlock_attempts
= HYPERV_SPINLOCK_NEVER_RETRY
;
2864 env
->cpuid_apic_id
= x86_cpu_apic_id_from_index(cs
->cpu_index
);
2866 x86_cpu_load_def(cpu
, xcc
->cpu_def
, &error_abort
);
2868 /* init various static tables used in TCG mode */
2869 if (tcg_enabled() && !inited
) {
2871 optimize_flags_init();
2875 static int64_t x86_cpu_get_arch_id(CPUState
*cs
)
2877 X86CPU
*cpu
= X86_CPU(cs
);
2878 CPUX86State
*env
= &cpu
->env
;
2880 return env
->cpuid_apic_id
;
2883 static bool x86_cpu_get_paging_enabled(const CPUState
*cs
)
2885 X86CPU
*cpu
= X86_CPU(cs
);
2887 return cpu
->env
.cr
[0] & CR0_PG_MASK
;
2890 static void x86_cpu_set_pc(CPUState
*cs
, vaddr value
)
2892 X86CPU
*cpu
= X86_CPU(cs
);
2894 cpu
->env
.eip
= value
;
2897 static void x86_cpu_synchronize_from_tb(CPUState
*cs
, TranslationBlock
*tb
)
2899 X86CPU
*cpu
= X86_CPU(cs
);
2901 cpu
->env
.eip
= tb
->pc
- tb
->cs_base
;
2904 static bool x86_cpu_has_work(CPUState
*cs
)
2906 X86CPU
*cpu
= X86_CPU(cs
);
2907 CPUX86State
*env
= &cpu
->env
;
2909 return ((cs
->interrupt_request
& (CPU_INTERRUPT_HARD
|
2910 CPU_INTERRUPT_POLL
)) &&
2911 (env
->eflags
& IF_MASK
)) ||
2912 (cs
->interrupt_request
& (CPU_INTERRUPT_NMI
|
2913 CPU_INTERRUPT_INIT
|
2914 CPU_INTERRUPT_SIPI
|
2915 CPU_INTERRUPT_MCE
));
2918 static Property x86_cpu_properties
[] = {
2919 DEFINE_PROP_BOOL("pmu", X86CPU
, enable_pmu
, false),
2920 { .name
= "hv-spinlocks", .info
= &qdev_prop_spinlocks
},
2921 DEFINE_PROP_BOOL("hv-relaxed", X86CPU
, hyperv_relaxed_timing
, false),
2922 DEFINE_PROP_BOOL("hv-vapic", X86CPU
, hyperv_vapic
, false),
2923 DEFINE_PROP_BOOL("hv-time", X86CPU
, hyperv_time
, false),
2924 DEFINE_PROP_BOOL("check", X86CPU
, check_cpuid
, false),
2925 DEFINE_PROP_BOOL("enforce", X86CPU
, enforce_cpuid
, false),
2926 DEFINE_PROP_BOOL("kvm", X86CPU
, expose_kvm
, true),
2927 DEFINE_PROP_END_OF_LIST()
2930 static void x86_cpu_common_class_init(ObjectClass
*oc
, void *data
)
2932 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
2933 CPUClass
*cc
= CPU_CLASS(oc
);
2934 DeviceClass
*dc
= DEVICE_CLASS(oc
);
2936 xcc
->parent_realize
= dc
->realize
;
2937 dc
->realize
= x86_cpu_realizefn
;
2938 dc
->bus_type
= TYPE_ICC_BUS
;
2939 dc
->props
= x86_cpu_properties
;
2941 xcc
->parent_reset
= cc
->reset
;
2942 cc
->reset
= x86_cpu_reset
;
2943 cc
->reset_dump_flags
= CPU_DUMP_FPU
| CPU_DUMP_CCOP
;
2945 cc
->class_by_name
= x86_cpu_class_by_name
;
2946 cc
->parse_features
= x86_cpu_parse_featurestr
;
2947 cc
->has_work
= x86_cpu_has_work
;
2948 cc
->do_interrupt
= x86_cpu_do_interrupt
;
2949 cc
->cpu_exec_interrupt
= x86_cpu_exec_interrupt
;
2950 cc
->dump_state
= x86_cpu_dump_state
;
2951 cc
->set_pc
= x86_cpu_set_pc
;
2952 cc
->synchronize_from_tb
= x86_cpu_synchronize_from_tb
;
2953 cc
->gdb_read_register
= x86_cpu_gdb_read_register
;
2954 cc
->gdb_write_register
= x86_cpu_gdb_write_register
;
2955 cc
->get_arch_id
= x86_cpu_get_arch_id
;
2956 cc
->get_paging_enabled
= x86_cpu_get_paging_enabled
;
2957 #ifdef CONFIG_USER_ONLY
2958 cc
->handle_mmu_fault
= x86_cpu_handle_mmu_fault
;
2960 cc
->get_memory_mapping
= x86_cpu_get_memory_mapping
;
2961 cc
->get_phys_page_debug
= x86_cpu_get_phys_page_debug
;
2962 cc
->write_elf64_note
= x86_cpu_write_elf64_note
;
2963 cc
->write_elf64_qemunote
= x86_cpu_write_elf64_qemunote
;
2964 cc
->write_elf32_note
= x86_cpu_write_elf32_note
;
2965 cc
->write_elf32_qemunote
= x86_cpu_write_elf32_qemunote
;
2966 cc
->vmsd
= &vmstate_x86_cpu
;
2968 cc
->gdb_num_core_regs
= CPU_NB_REGS
* 2 + 25;
2969 #ifndef CONFIG_USER_ONLY
2970 cc
->debug_excp_handler
= breakpoint_handler
;
2972 cc
->cpu_exec_enter
= x86_cpu_exec_enter
;
2973 cc
->cpu_exec_exit
= x86_cpu_exec_exit
;
2976 static const TypeInfo x86_cpu_type_info
= {
2977 .name
= TYPE_X86_CPU
,
2979 .instance_size
= sizeof(X86CPU
),
2980 .instance_init
= x86_cpu_initfn
,
2982 .class_size
= sizeof(X86CPUClass
),
2983 .class_init
= x86_cpu_common_class_init
,
2986 static void x86_cpu_register_types(void)
2990 type_register_static(&x86_cpu_type_info
);
2991 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
2992 x86_register_cpudef_type(&builtin_x86_defs
[i
]);
2995 type_register_static(&host_x86_cpu_type_info
);
2999 type_init(x86_cpu_register_types
)