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/>.
20 #include "qemu-common.h"
22 #include "sysemu/kvm.h"
23 #include "sysemu/cpus.h"
26 #include "qemu/error-report.h"
27 #include "qemu/option.h"
28 #include "qemu/config-file.h"
29 #include "qapi/qmp/qerror.h"
31 #include "qapi-types.h"
32 #include "qapi-visit.h"
33 #include "qapi/visitor.h"
34 #include "sysemu/arch_init.h"
37 #if defined(CONFIG_KVM)
38 #include <linux/kvm_para.h>
41 #include "sysemu/sysemu.h"
42 #include "hw/qdev-properties.h"
43 #include "hw/cpu/icc_bus.h"
44 #ifndef CONFIG_USER_ONLY
45 #include "exec/address-spaces.h"
46 #include "hw/xen/xen.h"
47 #include "hw/i386/apic_internal.h"
51 /* Cache topology CPUID constants: */
53 /* CPUID Leaf 2 Descriptors */
55 #define CPUID_2_L1D_32KB_8WAY_64B 0x2c
56 #define CPUID_2_L1I_32KB_8WAY_64B 0x30
57 #define CPUID_2_L2_2MB_8WAY_64B 0x7d
60 /* CPUID Leaf 4 constants: */
63 #define CPUID_4_TYPE_DCACHE 1
64 #define CPUID_4_TYPE_ICACHE 2
65 #define CPUID_4_TYPE_UNIFIED 3
67 #define CPUID_4_LEVEL(l) ((l) << 5)
69 #define CPUID_4_SELF_INIT_LEVEL (1 << 8)
70 #define CPUID_4_FULLY_ASSOC (1 << 9)
73 #define CPUID_4_NO_INVD_SHARING (1 << 0)
74 #define CPUID_4_INCLUSIVE (1 << 1)
75 #define CPUID_4_COMPLEX_IDX (1 << 2)
77 #define ASSOC_FULL 0xFF
79 /* AMD associativity encoding used on CPUID Leaf 0x80000006: */
80 #define AMD_ENC_ASSOC(a) (a <= 1 ? a : \
90 a == ASSOC_FULL ? 0xF : \
91 0 /* invalid value */)
94 /* Definitions of the hardcoded cache entries we expose: */
97 #define L1D_LINE_SIZE 64
98 #define L1D_ASSOCIATIVITY 8
100 #define L1D_PARTITIONS 1
101 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
102 #define L1D_DESCRIPTOR CPUID_2_L1D_32KB_8WAY_64B
103 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
104 #define L1D_LINES_PER_TAG 1
105 #define L1D_SIZE_KB_AMD 64
106 #define L1D_ASSOCIATIVITY_AMD 2
108 /* L1 instruction cache: */
109 #define L1I_LINE_SIZE 64
110 #define L1I_ASSOCIATIVITY 8
112 #define L1I_PARTITIONS 1
113 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
114 #define L1I_DESCRIPTOR CPUID_2_L1I_32KB_8WAY_64B
115 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
116 #define L1I_LINES_PER_TAG 1
117 #define L1I_SIZE_KB_AMD 64
118 #define L1I_ASSOCIATIVITY_AMD 2
120 /* Level 2 unified cache: */
121 #define L2_LINE_SIZE 64
122 #define L2_ASSOCIATIVITY 16
124 #define L2_PARTITIONS 1
125 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 4MiB */
126 /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */
127 #define L2_DESCRIPTOR CPUID_2_L2_2MB_8WAY_64B
128 /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */
129 #define L2_LINES_PER_TAG 1
130 #define L2_SIZE_KB_AMD 512
133 #define L3_SIZE_KB 0 /* disabled */
134 #define L3_ASSOCIATIVITY 0 /* disabled */
135 #define L3_LINES_PER_TAG 0 /* disabled */
136 #define L3_LINE_SIZE 0 /* disabled */
138 /* TLB definitions: */
140 #define L1_DTLB_2M_ASSOC 1
141 #define L1_DTLB_2M_ENTRIES 255
142 #define L1_DTLB_4K_ASSOC 1
143 #define L1_DTLB_4K_ENTRIES 255
145 #define L1_ITLB_2M_ASSOC 1
146 #define L1_ITLB_2M_ENTRIES 255
147 #define L1_ITLB_4K_ASSOC 1
148 #define L1_ITLB_4K_ENTRIES 255
150 #define L2_DTLB_2M_ASSOC 0 /* disabled */
151 #define L2_DTLB_2M_ENTRIES 0 /* disabled */
152 #define L2_DTLB_4K_ASSOC 4
153 #define L2_DTLB_4K_ENTRIES 512
155 #define L2_ITLB_2M_ASSOC 0 /* disabled */
156 #define L2_ITLB_2M_ENTRIES 0 /* disabled */
157 #define L2_ITLB_4K_ASSOC 4
158 #define L2_ITLB_4K_ENTRIES 512
162 static void x86_cpu_vendor_words2str(char *dst
, uint32_t vendor1
,
163 uint32_t vendor2
, uint32_t vendor3
)
166 for (i
= 0; i
< 4; i
++) {
167 dst
[i
] = vendor1
>> (8 * i
);
168 dst
[i
+ 4] = vendor2
>> (8 * i
);
169 dst
[i
+ 8] = vendor3
>> (8 * i
);
171 dst
[CPUID_VENDOR_SZ
] = '\0';
174 /* feature flags taken from "Intel Processor Identification and the CPUID
175 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
176 * between feature naming conventions, aliases may be added.
178 static const char *feature_name
[] = {
179 "fpu", "vme", "de", "pse",
180 "tsc", "msr", "pae", "mce",
181 "cx8", "apic", NULL
, "sep",
182 "mtrr", "pge", "mca", "cmov",
183 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
184 NULL
, "ds" /* Intel dts */, "acpi", "mmx",
185 "fxsr", "sse", "sse2", "ss",
186 "ht" /* Intel htt */, "tm", "ia64", "pbe",
188 static const char *ext_feature_name
[] = {
189 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
190 "ds_cpl", "vmx", "smx", "est",
191 "tm2", "ssse3", "cid", NULL
,
192 "fma", "cx16", "xtpr", "pdcm",
193 NULL
, "pcid", "dca", "sse4.1|sse4_1",
194 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
195 "tsc-deadline", "aes", "xsave", "osxsave",
196 "avx", "f16c", "rdrand", "hypervisor",
198 /* Feature names that are already defined on feature_name[] but are set on
199 * CPUID[8000_0001].EDX on AMD CPUs don't have their names on
200 * ext2_feature_name[]. They are copied automatically to cpuid_ext2_features
201 * if and only if CPU vendor is AMD.
203 static const char *ext2_feature_name
[] = {
204 NULL
/* fpu */, NULL
/* vme */, NULL
/* de */, NULL
/* pse */,
205 NULL
/* tsc */, NULL
/* msr */, NULL
/* pae */, NULL
/* mce */,
206 NULL
/* cx8 */ /* AMD CMPXCHG8B */, NULL
/* apic */, NULL
, "syscall",
207 NULL
/* mtrr */, NULL
/* pge */, NULL
/* mca */, NULL
/* cmov */,
208 NULL
/* pat */, NULL
/* pse36 */, NULL
, NULL
/* Linux mp */,
209 "nx|xd", NULL
, "mmxext", NULL
/* mmx */,
210 NULL
/* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
211 NULL
, "lm|i64", "3dnowext", "3dnow",
213 static const char *ext3_feature_name
[] = {
214 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
215 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
216 "3dnowprefetch", "osvw", "ibs", "xop",
217 "skinit", "wdt", NULL
, "lwp",
218 "fma4", "tce", NULL
, "nodeid_msr",
219 NULL
, "tbm", "topoext", "perfctr_core",
220 "perfctr_nb", NULL
, NULL
, NULL
,
221 NULL
, NULL
, NULL
, NULL
,
224 static const char *ext4_feature_name
[] = {
225 NULL
, NULL
, "xstore", "xstore-en",
226 NULL
, NULL
, "xcrypt", "xcrypt-en",
227 "ace2", "ace2-en", "phe", "phe-en",
228 "pmm", "pmm-en", NULL
, NULL
,
229 NULL
, NULL
, NULL
, NULL
,
230 NULL
, NULL
, NULL
, NULL
,
231 NULL
, NULL
, NULL
, NULL
,
232 NULL
, NULL
, NULL
, NULL
,
235 static const char *kvm_feature_name
[] = {
236 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
237 "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", "kvm_pv_unhalt",
238 NULL
, NULL
, NULL
, NULL
,
239 NULL
, NULL
, NULL
, NULL
,
240 NULL
, NULL
, NULL
, NULL
,
241 NULL
, NULL
, NULL
, NULL
,
242 "kvmclock-stable-bit", NULL
, NULL
, NULL
,
243 NULL
, NULL
, NULL
, NULL
,
246 static const char *svm_feature_name
[] = {
247 "npt", "lbrv", "svm_lock", "nrip_save",
248 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
249 NULL
, NULL
, "pause_filter", NULL
,
250 "pfthreshold", NULL
, NULL
, NULL
,
251 NULL
, NULL
, NULL
, NULL
,
252 NULL
, NULL
, NULL
, NULL
,
253 NULL
, NULL
, NULL
, NULL
,
254 NULL
, NULL
, NULL
, NULL
,
257 static const char *cpuid_7_0_ebx_feature_name
[] = {
258 "fsgsbase", "tsc_adjust", NULL
, "bmi1", "hle", "avx2", NULL
, "smep",
259 "bmi2", "erms", "invpcid", "rtm", NULL
, NULL
, "mpx", NULL
,
260 "avx512f", NULL
, "rdseed", "adx", "smap", NULL
, NULL
, NULL
,
261 NULL
, NULL
, "avx512pf", "avx512er", "avx512cd", NULL
, NULL
, NULL
,
264 static const char *cpuid_apm_edx_feature_name
[] = {
265 NULL
, NULL
, NULL
, NULL
,
266 NULL
, NULL
, NULL
, NULL
,
267 "invtsc", NULL
, NULL
, NULL
,
268 NULL
, NULL
, NULL
, NULL
,
269 NULL
, NULL
, NULL
, NULL
,
270 NULL
, NULL
, NULL
, NULL
,
271 NULL
, NULL
, NULL
, NULL
,
272 NULL
, NULL
, NULL
, NULL
,
275 static const char *cpuid_xsave_feature_name
[] = {
276 "xsaveopt", "xsavec", "xgetbv1", "xsaves",
277 NULL
, NULL
, NULL
, NULL
,
278 NULL
, NULL
, NULL
, NULL
,
279 NULL
, NULL
, NULL
, NULL
,
280 NULL
, NULL
, NULL
, NULL
,
281 NULL
, NULL
, NULL
, NULL
,
282 NULL
, NULL
, NULL
, NULL
,
283 NULL
, NULL
, NULL
, NULL
,
286 static const char *cpuid_6_feature_name
[] = {
287 NULL
, NULL
, "arat", NULL
,
288 NULL
, NULL
, NULL
, NULL
,
289 NULL
, NULL
, NULL
, NULL
,
290 NULL
, NULL
, NULL
, NULL
,
291 NULL
, NULL
, NULL
, NULL
,
292 NULL
, NULL
, NULL
, NULL
,
293 NULL
, NULL
, NULL
, NULL
,
294 NULL
, NULL
, NULL
, NULL
,
297 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
298 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
299 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
300 #define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
301 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
302 CPUID_PSE36 | CPUID_FXSR)
303 #define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
304 #define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
305 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
306 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
307 CPUID_PAE | CPUID_SEP | CPUID_APIC)
309 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
310 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
311 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
312 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
313 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
314 /* partly implemented:
315 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) */
317 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
318 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \
319 CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \
320 CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \
321 CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR)
323 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX,
324 CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA,
325 CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA,
326 CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE,
327 CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C,
331 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM)
333 #define TCG_EXT2_X86_64_FEATURES 0
336 #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \
337 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
338 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \
339 TCG_EXT2_X86_64_FEATURES)
340 #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
341 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
342 #define TCG_EXT4_FEATURES 0
343 #define TCG_SVM_FEATURES 0
344 #define TCG_KVM_FEATURES 0
345 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \
346 CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)
348 CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
349 CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
350 CPUID_7_0_EBX_RDSEED */
351 #define TCG_APM_FEATURES 0
352 #define TCG_6_EAX_FEATURES CPUID_6_EAX_ARAT
355 typedef struct FeatureWordInfo
{
356 const char **feat_names
;
357 uint32_t cpuid_eax
; /* Input EAX for CPUID */
358 bool cpuid_needs_ecx
; /* CPUID instruction uses ECX as input */
359 uint32_t cpuid_ecx
; /* Input ECX value for CPUID */
360 int cpuid_reg
; /* output register (R_* constant) */
361 uint32_t tcg_features
; /* Feature flags supported by TCG */
362 uint32_t unmigratable_flags
; /* Feature flags known to be unmigratable */
365 static FeatureWordInfo feature_word_info
[FEATURE_WORDS
] = {
367 .feat_names
= feature_name
,
368 .cpuid_eax
= 1, .cpuid_reg
= R_EDX
,
369 .tcg_features
= TCG_FEATURES
,
372 .feat_names
= ext_feature_name
,
373 .cpuid_eax
= 1, .cpuid_reg
= R_ECX
,
374 .tcg_features
= TCG_EXT_FEATURES
,
376 [FEAT_8000_0001_EDX
] = {
377 .feat_names
= ext2_feature_name
,
378 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_EDX
,
379 .tcg_features
= TCG_EXT2_FEATURES
,
381 [FEAT_8000_0001_ECX
] = {
382 .feat_names
= ext3_feature_name
,
383 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_ECX
,
384 .tcg_features
= TCG_EXT3_FEATURES
,
386 [FEAT_C000_0001_EDX
] = {
387 .feat_names
= ext4_feature_name
,
388 .cpuid_eax
= 0xC0000001, .cpuid_reg
= R_EDX
,
389 .tcg_features
= TCG_EXT4_FEATURES
,
392 .feat_names
= kvm_feature_name
,
393 .cpuid_eax
= KVM_CPUID_FEATURES
, .cpuid_reg
= R_EAX
,
394 .tcg_features
= TCG_KVM_FEATURES
,
397 .feat_names
= svm_feature_name
,
398 .cpuid_eax
= 0x8000000A, .cpuid_reg
= R_EDX
,
399 .tcg_features
= TCG_SVM_FEATURES
,
402 .feat_names
= cpuid_7_0_ebx_feature_name
,
404 .cpuid_needs_ecx
= true, .cpuid_ecx
= 0,
406 .tcg_features
= TCG_7_0_EBX_FEATURES
,
408 [FEAT_8000_0007_EDX
] = {
409 .feat_names
= cpuid_apm_edx_feature_name
,
410 .cpuid_eax
= 0x80000007,
412 .tcg_features
= TCG_APM_FEATURES
,
413 .unmigratable_flags
= CPUID_APM_INVTSC
,
416 .feat_names
= cpuid_xsave_feature_name
,
418 .cpuid_needs_ecx
= true, .cpuid_ecx
= 1,
423 .feat_names
= cpuid_6_feature_name
,
424 .cpuid_eax
= 6, .cpuid_reg
= R_EAX
,
425 .tcg_features
= TCG_6_EAX_FEATURES
,
429 typedef struct X86RegisterInfo32
{
430 /* Name of register */
432 /* QAPI enum value register */
433 X86CPURegister32 qapi_enum
;
436 #define REGISTER(reg) \
437 [R_##reg] = { .name = #reg, .qapi_enum = X86_CPU_REGISTER32_##reg }
438 static const X86RegisterInfo32 x86_reg_info_32
[CPU_NB_REGS32
] = {
450 typedef struct ExtSaveArea
{
451 uint32_t feature
, bits
;
452 uint32_t offset
, size
;
455 static const ExtSaveArea ext_save_areas
[] = {
456 [2] = { .feature
= FEAT_1_ECX
, .bits
= CPUID_EXT_AVX
,
457 .offset
= 0x240, .size
= 0x100 },
458 [3] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_MPX
,
459 .offset
= 0x3c0, .size
= 0x40 },
460 [4] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_MPX
,
461 .offset
= 0x400, .size
= 0x40 },
462 [5] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
463 .offset
= 0x440, .size
= 0x40 },
464 [6] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
465 .offset
= 0x480, .size
= 0x200 },
466 [7] = { .feature
= FEAT_7_0_EBX
, .bits
= CPUID_7_0_EBX_AVX512F
,
467 .offset
= 0x680, .size
= 0x400 },
470 const char *get_register_name_32(unsigned int reg
)
472 if (reg
>= CPU_NB_REGS32
) {
475 return x86_reg_info_32
[reg
].name
;
478 /* KVM-specific features that are automatically added to all CPU models
479 * when KVM is enabled.
481 static uint32_t kvm_default_features
[FEATURE_WORDS
] = {
482 [FEAT_KVM
] = (1 << KVM_FEATURE_CLOCKSOURCE
) |
483 (1 << KVM_FEATURE_NOP_IO_DELAY
) |
484 (1 << KVM_FEATURE_CLOCKSOURCE2
) |
485 (1 << KVM_FEATURE_ASYNC_PF
) |
486 (1 << KVM_FEATURE_STEAL_TIME
) |
487 (1 << KVM_FEATURE_PV_EOI
) |
488 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT
),
489 [FEAT_1_ECX
] = CPUID_EXT_X2APIC
,
492 /* Features that are not added by default to any CPU model when KVM is enabled.
494 static uint32_t kvm_default_unset_features
[FEATURE_WORDS
] = {
495 [FEAT_1_EDX
] = CPUID_ACPI
,
496 [FEAT_1_ECX
] = CPUID_EXT_MONITOR
,
497 [FEAT_8000_0001_ECX
] = CPUID_EXT3_SVM
,
500 void x86_cpu_compat_kvm_no_autoenable(FeatureWord w
, uint32_t features
)
502 kvm_default_features
[w
] &= ~features
;
505 void x86_cpu_compat_kvm_no_autodisable(FeatureWord w
, uint32_t features
)
507 kvm_default_unset_features
[w
] &= ~features
;
511 * Returns the set of feature flags that are supported and migratable by
512 * QEMU, for a given FeatureWord.
514 static uint32_t x86_cpu_get_migratable_flags(FeatureWord w
)
516 FeatureWordInfo
*wi
= &feature_word_info
[w
];
520 for (i
= 0; i
< 32; i
++) {
521 uint32_t f
= 1U << i
;
522 /* If the feature name is unknown, it is not supported by QEMU yet */
523 if (!wi
->feat_names
[i
]) {
526 /* Skip features known to QEMU, but explicitly marked as unmigratable */
527 if (wi
->unmigratable_flags
& f
) {
535 void host_cpuid(uint32_t function
, uint32_t count
,
536 uint32_t *eax
, uint32_t *ebx
, uint32_t *ecx
, uint32_t *edx
)
542 : "=a"(vec
[0]), "=b"(vec
[1]),
543 "=c"(vec
[2]), "=d"(vec
[3])
544 : "0"(function
), "c"(count
) : "cc");
545 #elif defined(__i386__)
546 asm volatile("pusha \n\t"
548 "mov %%eax, 0(%2) \n\t"
549 "mov %%ebx, 4(%2) \n\t"
550 "mov %%ecx, 8(%2) \n\t"
551 "mov %%edx, 12(%2) \n\t"
553 : : "a"(function
), "c"(count
), "S"(vec
)
569 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
571 /* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
572 * a substring. ex if !NULL points to the first char after a substring,
573 * otherwise the string is assumed to sized by a terminating nul.
574 * Return lexical ordering of *s1:*s2.
576 static int sstrcmp(const char *s1
, const char *e1
,
577 const char *s2
, const char *e2
)
580 if (!*s1
|| !*s2
|| *s1
!= *s2
)
583 if (s1
== e1
&& s2
== e2
)
592 /* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
593 * '|' delimited (possibly empty) strings in which case search for a match
594 * within the alternatives proceeds left to right. Return 0 for success,
595 * non-zero otherwise.
597 static int altcmp(const char *s
, const char *e
, const char *altstr
)
601 for (q
= p
= altstr
; ; ) {
602 while (*p
&& *p
!= '|')
604 if ((q
== p
&& !*s
) || (q
!= p
&& !sstrcmp(s
, e
, q
, p
)))
613 /* search featureset for flag *[s..e), if found set corresponding bit in
614 * *pval and return true, otherwise return false
616 static bool lookup_feature(uint32_t *pval
, const char *s
, const char *e
,
617 const char **featureset
)
623 for (mask
= 1, ppc
= featureset
; mask
; mask
<<= 1, ++ppc
) {
624 if (*ppc
&& !altcmp(s
, e
, *ppc
)) {
632 static void add_flagname_to_bitmaps(const char *flagname
,
633 FeatureWordArray words
,
637 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
638 FeatureWordInfo
*wi
= &feature_word_info
[w
];
639 if (wi
->feat_names
&&
640 lookup_feature(&words
[w
], flagname
, NULL
, wi
->feat_names
)) {
644 if (w
== FEATURE_WORDS
) {
645 error_setg(errp
, "CPU feature %s not found", flagname
);
649 /* CPU class name definitions: */
651 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
652 #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
654 /* Return type name for a given CPU model name
655 * Caller is responsible for freeing the returned string.
657 static char *x86_cpu_type_name(const char *model_name
)
659 return g_strdup_printf(X86_CPU_TYPE_NAME("%s"), model_name
);
662 static ObjectClass
*x86_cpu_class_by_name(const char *cpu_model
)
667 if (cpu_model
== NULL
) {
671 typename
= x86_cpu_type_name(cpu_model
);
672 oc
= object_class_by_name(typename
);
677 struct X86CPUDefinition
{
682 /* vendor is zero-terminated, 12 character ASCII string */
683 char vendor
[CPUID_VENDOR_SZ
+ 1];
687 FeatureWordArray features
;
689 bool cache_info_passthrough
;
692 static X86CPUDefinition builtin_x86_defs
[] = {
696 .vendor
= CPUID_VENDOR_AMD
,
700 .features
[FEAT_1_EDX
] =
702 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
704 .features
[FEAT_1_ECX
] =
705 CPUID_EXT_SSE3
| CPUID_EXT_CX16
| CPUID_EXT_POPCNT
,
706 .features
[FEAT_8000_0001_EDX
] =
707 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
708 .features
[FEAT_8000_0001_ECX
] =
709 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
710 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
711 .xlevel
= 0x8000000A,
716 .vendor
= CPUID_VENDOR_AMD
,
720 /* Missing: CPUID_HT */
721 .features
[FEAT_1_EDX
] =
723 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
724 CPUID_PSE36
| CPUID_VME
,
725 .features
[FEAT_1_ECX
] =
726 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_CX16
|
728 .features
[FEAT_8000_0001_EDX
] =
729 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
|
730 CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
| CPUID_EXT2_MMXEXT
|
731 CPUID_EXT2_FFXSR
| CPUID_EXT2_PDPE1GB
| CPUID_EXT2_RDTSCP
,
732 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
734 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
735 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
736 .features
[FEAT_8000_0001_ECX
] =
737 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
738 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
739 /* Missing: CPUID_SVM_LBRV */
740 .features
[FEAT_SVM
] =
742 .xlevel
= 0x8000001A,
743 .model_id
= "AMD Phenom(tm) 9550 Quad-Core Processor"
748 .vendor
= CPUID_VENDOR_INTEL
,
752 /* Missing: CPUID_DTS, CPUID_HT, CPUID_TM, CPUID_PBE */
753 .features
[FEAT_1_EDX
] =
755 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
756 CPUID_PSE36
| CPUID_VME
| CPUID_ACPI
| CPUID_SS
,
757 /* Missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_EST,
758 * CPUID_EXT_TM2, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_VMX */
759 .features
[FEAT_1_ECX
] =
760 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
762 .features
[FEAT_8000_0001_EDX
] =
763 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
764 .features
[FEAT_8000_0001_ECX
] =
766 .xlevel
= 0x80000008,
767 .model_id
= "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
772 .vendor
= CPUID_VENDOR_INTEL
,
776 /* Missing: CPUID_HT */
777 .features
[FEAT_1_EDX
] =
778 PPRO_FEATURES
| CPUID_VME
|
779 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
781 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
782 .features
[FEAT_1_ECX
] =
783 CPUID_EXT_SSE3
| CPUID_EXT_CX16
,
784 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
785 .features
[FEAT_8000_0001_EDX
] =
786 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
787 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
788 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
789 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
790 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
791 .features
[FEAT_8000_0001_ECX
] =
793 .xlevel
= 0x80000008,
794 .model_id
= "Common KVM processor"
799 .vendor
= CPUID_VENDOR_INTEL
,
803 .features
[FEAT_1_EDX
] =
805 .features
[FEAT_1_ECX
] =
806 CPUID_EXT_SSE3
| CPUID_EXT_POPCNT
,
807 .xlevel
= 0x80000004,
812 .vendor
= CPUID_VENDOR_INTEL
,
816 .features
[FEAT_1_EDX
] =
817 PPRO_FEATURES
| CPUID_VME
|
818 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_PSE36
,
819 .features
[FEAT_1_ECX
] =
821 .features
[FEAT_8000_0001_ECX
] =
823 .xlevel
= 0x80000008,
824 .model_id
= "Common 32-bit KVM processor"
829 .vendor
= CPUID_VENDOR_INTEL
,
833 /* Missing: CPUID_DTS, CPUID_HT, CPUID_TM, CPUID_PBE */
834 .features
[FEAT_1_EDX
] =
835 PPRO_FEATURES
| CPUID_VME
|
836 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_ACPI
|
838 /* Missing: CPUID_EXT_EST, CPUID_EXT_TM2 , CPUID_EXT_XTPR,
839 * CPUID_EXT_PDCM, CPUID_EXT_VMX */
840 .features
[FEAT_1_ECX
] =
841 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
,
842 .features
[FEAT_8000_0001_EDX
] =
844 .xlevel
= 0x80000008,
845 .model_id
= "Genuine Intel(R) CPU T2600 @ 2.16GHz",
850 .vendor
= CPUID_VENDOR_INTEL
,
854 .features
[FEAT_1_EDX
] =
861 .vendor
= CPUID_VENDOR_INTEL
,
865 .features
[FEAT_1_EDX
] =
872 .vendor
= CPUID_VENDOR_INTEL
,
876 .features
[FEAT_1_EDX
] =
883 .vendor
= CPUID_VENDOR_INTEL
,
887 .features
[FEAT_1_EDX
] =
894 .vendor
= CPUID_VENDOR_AMD
,
898 .features
[FEAT_1_EDX
] =
899 PPRO_FEATURES
| CPUID_PSE36
| CPUID_VME
| CPUID_MTRR
|
901 .features
[FEAT_8000_0001_EDX
] =
902 CPUID_EXT2_MMXEXT
| CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
,
903 .xlevel
= 0x80000008,
908 .vendor
= CPUID_VENDOR_INTEL
,
912 /* Missing: CPUID_DTS, CPUID_HT, CPUID_TM, CPUID_PBE */
913 .features
[FEAT_1_EDX
] =
915 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_VME
|
916 CPUID_ACPI
| CPUID_SS
,
917 /* Some CPUs got no CPUID_SEP */
918 /* Missing: CPUID_EXT_DSCPL, CPUID_EXT_EST, CPUID_EXT_TM2,
920 .features
[FEAT_1_ECX
] =
921 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
923 .features
[FEAT_8000_0001_EDX
] =
925 .features
[FEAT_8000_0001_ECX
] =
927 .xlevel
= 0x80000008,
928 .model_id
= "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
933 .vendor
= CPUID_VENDOR_INTEL
,
937 .features
[FEAT_1_EDX
] =
938 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
939 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
940 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
941 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
942 CPUID_DE
| CPUID_FP87
,
943 .features
[FEAT_1_ECX
] =
944 CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
945 .features
[FEAT_8000_0001_EDX
] =
946 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
947 .features
[FEAT_8000_0001_ECX
] =
949 .xlevel
= 0x80000008,
950 .model_id
= "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
955 .vendor
= CPUID_VENDOR_INTEL
,
959 .features
[FEAT_1_EDX
] =
960 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
961 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
962 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
963 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
964 CPUID_DE
| CPUID_FP87
,
965 .features
[FEAT_1_ECX
] =
966 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
968 .features
[FEAT_8000_0001_EDX
] =
969 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
970 .features
[FEAT_8000_0001_ECX
] =
972 .xlevel
= 0x80000008,
973 .model_id
= "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
978 .vendor
= CPUID_VENDOR_INTEL
,
982 .features
[FEAT_1_EDX
] =
983 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
984 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
985 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
986 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
987 CPUID_DE
| CPUID_FP87
,
988 .features
[FEAT_1_ECX
] =
989 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
990 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
991 .features
[FEAT_8000_0001_EDX
] =
992 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
993 .features
[FEAT_8000_0001_ECX
] =
995 .xlevel
= 0x80000008,
996 .model_id
= "Intel Core i7 9xx (Nehalem Class Core i7)",
1001 .vendor
= CPUID_VENDOR_INTEL
,
1005 .features
[FEAT_1_EDX
] =
1006 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1007 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1008 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1009 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1010 CPUID_DE
| CPUID_FP87
,
1011 .features
[FEAT_1_ECX
] =
1012 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
1013 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1014 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
1015 .features
[FEAT_8000_0001_EDX
] =
1016 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
1017 .features
[FEAT_8000_0001_ECX
] =
1019 .features
[FEAT_6_EAX
] =
1021 .xlevel
= 0x80000008,
1022 .model_id
= "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
1025 .name
= "SandyBridge",
1027 .vendor
= CPUID_VENDOR_INTEL
,
1031 .features
[FEAT_1_EDX
] =
1032 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1033 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1034 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1035 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1036 CPUID_DE
| CPUID_FP87
,
1037 .features
[FEAT_1_ECX
] =
1038 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1039 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_POPCNT
|
1040 CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
1041 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
1043 .features
[FEAT_8000_0001_EDX
] =
1044 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1046 .features
[FEAT_8000_0001_ECX
] =
1048 .features
[FEAT_XSAVE
] =
1049 CPUID_XSAVE_XSAVEOPT
,
1050 .features
[FEAT_6_EAX
] =
1052 .xlevel
= 0x80000008,
1053 .model_id
= "Intel Xeon E312xx (Sandy Bridge)",
1056 .name
= "IvyBridge",
1058 .vendor
= CPUID_VENDOR_INTEL
,
1062 .features
[FEAT_1_EDX
] =
1063 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1064 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1065 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1066 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1067 CPUID_DE
| CPUID_FP87
,
1068 .features
[FEAT_1_ECX
] =
1069 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1070 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_POPCNT
|
1071 CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
1072 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
1073 CPUID_EXT_SSE3
| CPUID_EXT_F16C
| CPUID_EXT_RDRAND
,
1074 .features
[FEAT_7_0_EBX
] =
1075 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_SMEP
|
1077 .features
[FEAT_8000_0001_EDX
] =
1078 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1080 .features
[FEAT_8000_0001_ECX
] =
1082 .features
[FEAT_XSAVE
] =
1083 CPUID_XSAVE_XSAVEOPT
,
1084 .features
[FEAT_6_EAX
] =
1086 .xlevel
= 0x80000008,
1087 .model_id
= "Intel Xeon E3-12xx v2 (Ivy Bridge)",
1090 .name
= "Haswell-noTSX",
1092 .vendor
= CPUID_VENDOR_INTEL
,
1096 .features
[FEAT_1_EDX
] =
1097 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1098 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1099 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1100 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1101 CPUID_DE
| CPUID_FP87
,
1102 .features
[FEAT_1_ECX
] =
1103 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1104 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1105 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1106 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1107 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1108 CPUID_EXT_PCID
| CPUID_EXT_F16C
| CPUID_EXT_RDRAND
,
1109 .features
[FEAT_8000_0001_EDX
] =
1110 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1112 .features
[FEAT_8000_0001_ECX
] =
1114 .features
[FEAT_7_0_EBX
] =
1115 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1116 CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1117 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
,
1118 .features
[FEAT_XSAVE
] =
1119 CPUID_XSAVE_XSAVEOPT
,
1120 .features
[FEAT_6_EAX
] =
1122 .xlevel
= 0x80000008,
1123 .model_id
= "Intel Core Processor (Haswell, no TSX)",
1127 .vendor
= CPUID_VENDOR_INTEL
,
1131 .features
[FEAT_1_EDX
] =
1132 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1133 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1134 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1135 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1136 CPUID_DE
| CPUID_FP87
,
1137 .features
[FEAT_1_ECX
] =
1138 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1139 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1140 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1141 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1142 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1143 CPUID_EXT_PCID
| CPUID_EXT_F16C
| CPUID_EXT_RDRAND
,
1144 .features
[FEAT_8000_0001_EDX
] =
1145 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1147 .features
[FEAT_8000_0001_ECX
] =
1149 .features
[FEAT_7_0_EBX
] =
1150 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1151 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1152 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
1154 .features
[FEAT_XSAVE
] =
1155 CPUID_XSAVE_XSAVEOPT
,
1156 .features
[FEAT_6_EAX
] =
1158 .xlevel
= 0x80000008,
1159 .model_id
= "Intel Core Processor (Haswell)",
1162 .name
= "Broadwell-noTSX",
1164 .vendor
= CPUID_VENDOR_INTEL
,
1168 .features
[FEAT_1_EDX
] =
1169 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1170 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1171 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1172 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1173 CPUID_DE
| CPUID_FP87
,
1174 .features
[FEAT_1_ECX
] =
1175 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1176 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1177 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1178 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1179 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1180 CPUID_EXT_PCID
| CPUID_EXT_F16C
| CPUID_EXT_RDRAND
,
1181 .features
[FEAT_8000_0001_EDX
] =
1182 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1184 .features
[FEAT_8000_0001_ECX
] =
1185 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_3DNOWPREFETCH
,
1186 .features
[FEAT_7_0_EBX
] =
1187 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1188 CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1189 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
1190 CPUID_7_0_EBX_RDSEED
| CPUID_7_0_EBX_ADX
|
1192 .features
[FEAT_XSAVE
] =
1193 CPUID_XSAVE_XSAVEOPT
,
1194 .features
[FEAT_6_EAX
] =
1196 .xlevel
= 0x80000008,
1197 .model_id
= "Intel Core Processor (Broadwell, no TSX)",
1200 .name
= "Broadwell",
1202 .vendor
= CPUID_VENDOR_INTEL
,
1206 .features
[FEAT_1_EDX
] =
1207 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1208 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1209 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1210 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1211 CPUID_DE
| CPUID_FP87
,
1212 .features
[FEAT_1_ECX
] =
1213 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1214 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
1215 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
1216 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
1217 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
1218 CPUID_EXT_PCID
| CPUID_EXT_F16C
| CPUID_EXT_RDRAND
,
1219 .features
[FEAT_8000_0001_EDX
] =
1220 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
1222 .features
[FEAT_8000_0001_ECX
] =
1223 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_3DNOWPREFETCH
,
1224 .features
[FEAT_7_0_EBX
] =
1225 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
1226 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
1227 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
1228 CPUID_7_0_EBX_RTM
| CPUID_7_0_EBX_RDSEED
| CPUID_7_0_EBX_ADX
|
1230 .features
[FEAT_XSAVE
] =
1231 CPUID_XSAVE_XSAVEOPT
,
1232 .features
[FEAT_6_EAX
] =
1234 .xlevel
= 0x80000008,
1235 .model_id
= "Intel Core Processor (Broadwell)",
1238 .name
= "Opteron_G1",
1240 .vendor
= CPUID_VENDOR_AMD
,
1244 .features
[FEAT_1_EDX
] =
1245 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1246 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1247 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1248 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1249 CPUID_DE
| CPUID_FP87
,
1250 .features
[FEAT_1_ECX
] =
1252 .features
[FEAT_8000_0001_EDX
] =
1253 CPUID_EXT2_LM
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1254 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1255 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1256 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1257 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1258 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1259 .xlevel
= 0x80000008,
1260 .model_id
= "AMD Opteron 240 (Gen 1 Class Opteron)",
1263 .name
= "Opteron_G2",
1265 .vendor
= CPUID_VENDOR_AMD
,
1269 .features
[FEAT_1_EDX
] =
1270 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1271 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1272 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1273 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1274 CPUID_DE
| CPUID_FP87
,
1275 .features
[FEAT_1_ECX
] =
1276 CPUID_EXT_CX16
| CPUID_EXT_SSE3
,
1277 .features
[FEAT_8000_0001_EDX
] =
1278 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
1279 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
1280 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
1281 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
1282 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
1283 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
1284 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1285 .features
[FEAT_8000_0001_ECX
] =
1286 CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
1287 .xlevel
= 0x80000008,
1288 .model_id
= "AMD Opteron 22xx (Gen 2 Class Opteron)",
1291 .name
= "Opteron_G3",
1293 .vendor
= CPUID_VENDOR_AMD
,
1297 .features
[FEAT_1_EDX
] =
1298 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1299 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1300 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1301 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1302 CPUID_DE
| CPUID_FP87
,
1303 .features
[FEAT_1_ECX
] =
1304 CPUID_EXT_POPCNT
| CPUID_EXT_CX16
| CPUID_EXT_MONITOR
|
1306 .features
[FEAT_8000_0001_EDX
] =
1307 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
1308 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
1309 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
1310 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
1311 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
1312 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
1313 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1314 .features
[FEAT_8000_0001_ECX
] =
1315 CPUID_EXT3_MISALIGNSSE
| CPUID_EXT3_SSE4A
|
1316 CPUID_EXT3_ABM
| CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
1317 .xlevel
= 0x80000008,
1318 .model_id
= "AMD Opteron 23xx (Gen 3 Class Opteron)",
1321 .name
= "Opteron_G4",
1323 .vendor
= CPUID_VENDOR_AMD
,
1327 .features
[FEAT_1_EDX
] =
1328 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1329 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1330 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1331 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1332 CPUID_DE
| CPUID_FP87
,
1333 .features
[FEAT_1_ECX
] =
1334 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
1335 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
1336 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
1338 .features
[FEAT_8000_0001_EDX
] =
1339 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
1340 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1341 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1342 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1343 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1344 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1345 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1346 .features
[FEAT_8000_0001_ECX
] =
1347 CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
1348 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
1349 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
1352 .xlevel
= 0x8000001A,
1353 .model_id
= "AMD Opteron 62xx class CPU",
1356 .name
= "Opteron_G5",
1358 .vendor
= CPUID_VENDOR_AMD
,
1362 .features
[FEAT_1_EDX
] =
1363 CPUID_VME
| CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
1364 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
1365 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
1366 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
1367 CPUID_DE
| CPUID_FP87
,
1368 .features
[FEAT_1_ECX
] =
1369 CPUID_EXT_F16C
| CPUID_EXT_AVX
| CPUID_EXT_XSAVE
|
1370 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
1371 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_FMA
|
1372 CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
1373 .features
[FEAT_8000_0001_EDX
] =
1374 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
1375 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
1376 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
1377 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
1378 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
1379 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
1380 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
1381 .features
[FEAT_8000_0001_ECX
] =
1382 CPUID_EXT3_TBM
| CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
1383 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
1384 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
1387 .xlevel
= 0x8000001A,
1388 .model_id
= "AMD Opteron 63xx class CPU",
1393 * x86_cpu_compat_set_features:
1394 * @cpu_model: CPU model name to be changed. If NULL, all CPU models are changed
1395 * @w: Identifies the feature word to be changed.
1396 * @feat_add: Feature bits to be added to feature word
1397 * @feat_remove: Feature bits to be removed from feature word
1399 * Change CPU model feature bits for compatibility.
1401 * This function may be used by machine-type compatibility functions
1402 * to enable or disable feature bits on specific CPU models.
1404 void x86_cpu_compat_set_features(const char *cpu_model
, FeatureWord w
,
1405 uint32_t feat_add
, uint32_t feat_remove
)
1407 X86CPUDefinition
*def
;
1409 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1410 def
= &builtin_x86_defs
[i
];
1411 if (!cpu_model
|| !strcmp(cpu_model
, def
->name
)) {
1412 def
->features
[w
] |= feat_add
;
1413 def
->features
[w
] &= ~feat_remove
;
1418 static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w
,
1419 bool migratable_only
);
1423 static int cpu_x86_fill_model_id(char *str
)
1425 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1428 for (i
= 0; i
< 3; i
++) {
1429 host_cpuid(0x80000002 + i
, 0, &eax
, &ebx
, &ecx
, &edx
);
1430 memcpy(str
+ i
* 16 + 0, &eax
, 4);
1431 memcpy(str
+ i
* 16 + 4, &ebx
, 4);
1432 memcpy(str
+ i
* 16 + 8, &ecx
, 4);
1433 memcpy(str
+ i
* 16 + 12, &edx
, 4);
1438 static X86CPUDefinition host_cpudef
;
1440 static Property host_x86_cpu_properties
[] = {
1441 DEFINE_PROP_BOOL("migratable", X86CPU
, migratable
, true),
1442 DEFINE_PROP_END_OF_LIST()
1445 /* class_init for the "host" CPU model
1447 * This function may be called before KVM is initialized.
1449 static void host_x86_cpu_class_init(ObjectClass
*oc
, void *data
)
1451 DeviceClass
*dc
= DEVICE_CLASS(oc
);
1452 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
1453 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1455 xcc
->kvm_required
= true;
1457 host_cpuid(0x0, 0, &eax
, &ebx
, &ecx
, &edx
);
1458 x86_cpu_vendor_words2str(host_cpudef
.vendor
, ebx
, edx
, ecx
);
1460 host_cpuid(0x1, 0, &eax
, &ebx
, &ecx
, &edx
);
1461 host_cpudef
.family
= ((eax
>> 8) & 0x0F) + ((eax
>> 20) & 0xFF);
1462 host_cpudef
.model
= ((eax
>> 4) & 0x0F) | ((eax
& 0xF0000) >> 12);
1463 host_cpudef
.stepping
= eax
& 0x0F;
1465 cpu_x86_fill_model_id(host_cpudef
.model_id
);
1467 xcc
->cpu_def
= &host_cpudef
;
1468 host_cpudef
.cache_info_passthrough
= true;
1470 /* level, xlevel, xlevel2, and the feature words are initialized on
1471 * instance_init, because they require KVM to be initialized.
1474 dc
->props
= host_x86_cpu_properties
;
1477 static void host_x86_cpu_initfn(Object
*obj
)
1479 X86CPU
*cpu
= X86_CPU(obj
);
1480 CPUX86State
*env
= &cpu
->env
;
1481 KVMState
*s
= kvm_state
;
1483 assert(kvm_enabled());
1485 /* We can't fill the features array here because we don't know yet if
1486 * "migratable" is true or false.
1488 cpu
->host_features
= true;
1490 env
->cpuid_level
= kvm_arch_get_supported_cpuid(s
, 0x0, 0, R_EAX
);
1491 env
->cpuid_xlevel
= kvm_arch_get_supported_cpuid(s
, 0x80000000, 0, R_EAX
);
1492 env
->cpuid_xlevel2
= kvm_arch_get_supported_cpuid(s
, 0xC0000000, 0, R_EAX
);
1494 object_property_set_bool(OBJECT(cpu
), true, "pmu", &error_abort
);
1497 static const TypeInfo host_x86_cpu_type_info
= {
1498 .name
= X86_CPU_TYPE_NAME("host"),
1499 .parent
= TYPE_X86_CPU
,
1500 .instance_init
= host_x86_cpu_initfn
,
1501 .class_init
= host_x86_cpu_class_init
,
1506 static void report_unavailable_features(FeatureWord w
, uint32_t mask
)
1508 FeatureWordInfo
*f
= &feature_word_info
[w
];
1511 for (i
= 0; i
< 32; ++i
) {
1512 if (1 << i
& mask
) {
1513 const char *reg
= get_register_name_32(f
->cpuid_reg
);
1515 fprintf(stderr
, "warning: %s doesn't support requested feature: "
1516 "CPUID.%02XH:%s%s%s [bit %d]\n",
1517 kvm_enabled() ? "host" : "TCG",
1519 f
->feat_names
[i
] ? "." : "",
1520 f
->feat_names
[i
] ? f
->feat_names
[i
] : "", i
);
1525 static void x86_cpuid_version_get_family(Object
*obj
, Visitor
*v
, void *opaque
,
1526 const char *name
, Error
**errp
)
1528 X86CPU
*cpu
= X86_CPU(obj
);
1529 CPUX86State
*env
= &cpu
->env
;
1532 value
= (env
->cpuid_version
>> 8) & 0xf;
1534 value
+= (env
->cpuid_version
>> 20) & 0xff;
1536 visit_type_int(v
, &value
, name
, errp
);
1539 static void x86_cpuid_version_set_family(Object
*obj
, Visitor
*v
, void *opaque
,
1540 const char *name
, Error
**errp
)
1542 X86CPU
*cpu
= X86_CPU(obj
);
1543 CPUX86State
*env
= &cpu
->env
;
1544 const int64_t min
= 0;
1545 const int64_t max
= 0xff + 0xf;
1546 Error
*local_err
= NULL
;
1549 visit_type_int(v
, &value
, name
, &local_err
);
1551 error_propagate(errp
, local_err
);
1554 if (value
< min
|| value
> max
) {
1555 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1556 name
? name
: "null", value
, min
, max
);
1560 env
->cpuid_version
&= ~0xff00f00;
1562 env
->cpuid_version
|= 0xf00 | ((value
- 0x0f) << 20);
1564 env
->cpuid_version
|= value
<< 8;
1568 static void x86_cpuid_version_get_model(Object
*obj
, Visitor
*v
, void *opaque
,
1569 const char *name
, Error
**errp
)
1571 X86CPU
*cpu
= X86_CPU(obj
);
1572 CPUX86State
*env
= &cpu
->env
;
1575 value
= (env
->cpuid_version
>> 4) & 0xf;
1576 value
|= ((env
->cpuid_version
>> 16) & 0xf) << 4;
1577 visit_type_int(v
, &value
, name
, errp
);
1580 static void x86_cpuid_version_set_model(Object
*obj
, Visitor
*v
, void *opaque
,
1581 const char *name
, Error
**errp
)
1583 X86CPU
*cpu
= X86_CPU(obj
);
1584 CPUX86State
*env
= &cpu
->env
;
1585 const int64_t min
= 0;
1586 const int64_t max
= 0xff;
1587 Error
*local_err
= NULL
;
1590 visit_type_int(v
, &value
, name
, &local_err
);
1592 error_propagate(errp
, local_err
);
1595 if (value
< min
|| value
> max
) {
1596 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1597 name
? name
: "null", value
, min
, max
);
1601 env
->cpuid_version
&= ~0xf00f0;
1602 env
->cpuid_version
|= ((value
& 0xf) << 4) | ((value
>> 4) << 16);
1605 static void x86_cpuid_version_get_stepping(Object
*obj
, Visitor
*v
,
1606 void *opaque
, const char *name
,
1609 X86CPU
*cpu
= X86_CPU(obj
);
1610 CPUX86State
*env
= &cpu
->env
;
1613 value
= env
->cpuid_version
& 0xf;
1614 visit_type_int(v
, &value
, name
, errp
);
1617 static void x86_cpuid_version_set_stepping(Object
*obj
, Visitor
*v
,
1618 void *opaque
, const char *name
,
1621 X86CPU
*cpu
= X86_CPU(obj
);
1622 CPUX86State
*env
= &cpu
->env
;
1623 const int64_t min
= 0;
1624 const int64_t max
= 0xf;
1625 Error
*local_err
= NULL
;
1628 visit_type_int(v
, &value
, name
, &local_err
);
1630 error_propagate(errp
, local_err
);
1633 if (value
< min
|| value
> max
) {
1634 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1635 name
? name
: "null", value
, min
, max
);
1639 env
->cpuid_version
&= ~0xf;
1640 env
->cpuid_version
|= value
& 0xf;
1643 static char *x86_cpuid_get_vendor(Object
*obj
, Error
**errp
)
1645 X86CPU
*cpu
= X86_CPU(obj
);
1646 CPUX86State
*env
= &cpu
->env
;
1649 value
= g_malloc(CPUID_VENDOR_SZ
+ 1);
1650 x86_cpu_vendor_words2str(value
, env
->cpuid_vendor1
, env
->cpuid_vendor2
,
1651 env
->cpuid_vendor3
);
1655 static void x86_cpuid_set_vendor(Object
*obj
, const char *value
,
1658 X86CPU
*cpu
= X86_CPU(obj
);
1659 CPUX86State
*env
= &cpu
->env
;
1662 if (strlen(value
) != CPUID_VENDOR_SZ
) {
1663 error_setg(errp
, QERR_PROPERTY_VALUE_BAD
, "", "vendor", value
);
1667 env
->cpuid_vendor1
= 0;
1668 env
->cpuid_vendor2
= 0;
1669 env
->cpuid_vendor3
= 0;
1670 for (i
= 0; i
< 4; i
++) {
1671 env
->cpuid_vendor1
|= ((uint8_t)value
[i
]) << (8 * i
);
1672 env
->cpuid_vendor2
|= ((uint8_t)value
[i
+ 4]) << (8 * i
);
1673 env
->cpuid_vendor3
|= ((uint8_t)value
[i
+ 8]) << (8 * i
);
1677 static char *x86_cpuid_get_model_id(Object
*obj
, Error
**errp
)
1679 X86CPU
*cpu
= X86_CPU(obj
);
1680 CPUX86State
*env
= &cpu
->env
;
1684 value
= g_malloc(48 + 1);
1685 for (i
= 0; i
< 48; i
++) {
1686 value
[i
] = env
->cpuid_model
[i
>> 2] >> (8 * (i
& 3));
1692 static void x86_cpuid_set_model_id(Object
*obj
, const char *model_id
,
1695 X86CPU
*cpu
= X86_CPU(obj
);
1696 CPUX86State
*env
= &cpu
->env
;
1699 if (model_id
== NULL
) {
1702 len
= strlen(model_id
);
1703 memset(env
->cpuid_model
, 0, 48);
1704 for (i
= 0; i
< 48; i
++) {
1708 c
= (uint8_t)model_id
[i
];
1710 env
->cpuid_model
[i
>> 2] |= c
<< (8 * (i
& 3));
1714 static void x86_cpuid_get_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1715 const char *name
, Error
**errp
)
1717 X86CPU
*cpu
= X86_CPU(obj
);
1720 value
= cpu
->env
.tsc_khz
* 1000;
1721 visit_type_int(v
, &value
, name
, errp
);
1724 static void x86_cpuid_set_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1725 const char *name
, Error
**errp
)
1727 X86CPU
*cpu
= X86_CPU(obj
);
1728 const int64_t min
= 0;
1729 const int64_t max
= INT64_MAX
;
1730 Error
*local_err
= NULL
;
1733 visit_type_int(v
, &value
, name
, &local_err
);
1735 error_propagate(errp
, local_err
);
1738 if (value
< min
|| value
> max
) {
1739 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1740 name
? name
: "null", value
, min
, max
);
1744 cpu
->env
.tsc_khz
= value
/ 1000;
1747 static void x86_cpuid_get_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1748 const char *name
, Error
**errp
)
1750 X86CPU
*cpu
= X86_CPU(obj
);
1751 int64_t value
= cpu
->apic_id
;
1753 visit_type_int(v
, &value
, name
, errp
);
1756 static void x86_cpuid_set_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1757 const char *name
, Error
**errp
)
1759 X86CPU
*cpu
= X86_CPU(obj
);
1760 DeviceState
*dev
= DEVICE(obj
);
1761 const int64_t min
= 0;
1762 const int64_t max
= UINT32_MAX
;
1763 Error
*error
= NULL
;
1766 if (dev
->realized
) {
1767 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
1768 "it was realized", name
, object_get_typename(obj
));
1772 visit_type_int(v
, &value
, name
, &error
);
1774 error_propagate(errp
, error
);
1777 if (value
< min
|| value
> max
) {
1778 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
1779 " (minimum: %" PRId64
", maximum: %" PRId64
")" ,
1780 object_get_typename(obj
), name
, value
, min
, max
);
1784 if ((value
!= cpu
->apic_id
) && cpu_exists(value
)) {
1785 error_setg(errp
, "CPU with APIC ID %" PRIi64
" exists", value
);
1788 cpu
->apic_id
= value
;
1791 /* Generic getter for "feature-words" and "filtered-features" properties */
1792 static void x86_cpu_get_feature_words(Object
*obj
, Visitor
*v
, void *opaque
,
1793 const char *name
, Error
**errp
)
1795 uint32_t *array
= (uint32_t *)opaque
;
1798 X86CPUFeatureWordInfo word_infos
[FEATURE_WORDS
] = { };
1799 X86CPUFeatureWordInfoList list_entries
[FEATURE_WORDS
] = { };
1800 X86CPUFeatureWordInfoList
*list
= NULL
;
1802 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1803 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1804 X86CPUFeatureWordInfo
*qwi
= &word_infos
[w
];
1805 qwi
->cpuid_input_eax
= wi
->cpuid_eax
;
1806 qwi
->has_cpuid_input_ecx
= wi
->cpuid_needs_ecx
;
1807 qwi
->cpuid_input_ecx
= wi
->cpuid_ecx
;
1808 qwi
->cpuid_register
= x86_reg_info_32
[wi
->cpuid_reg
].qapi_enum
;
1809 qwi
->features
= array
[w
];
1811 /* List will be in reverse order, but order shouldn't matter */
1812 list_entries
[w
].next
= list
;
1813 list_entries
[w
].value
= &word_infos
[w
];
1814 list
= &list_entries
[w
];
1817 visit_type_X86CPUFeatureWordInfoList(v
, &list
, "feature-words", &err
);
1818 error_propagate(errp
, err
);
1821 static void x86_get_hv_spinlocks(Object
*obj
, Visitor
*v
, void *opaque
,
1822 const char *name
, Error
**errp
)
1824 X86CPU
*cpu
= X86_CPU(obj
);
1825 int64_t value
= cpu
->hyperv_spinlock_attempts
;
1827 visit_type_int(v
, &value
, name
, errp
);
1830 static void x86_set_hv_spinlocks(Object
*obj
, Visitor
*v
, void *opaque
,
1831 const char *name
, Error
**errp
)
1833 const int64_t min
= 0xFFF;
1834 const int64_t max
= UINT_MAX
;
1835 X86CPU
*cpu
= X86_CPU(obj
);
1839 visit_type_int(v
, &value
, name
, &err
);
1841 error_propagate(errp
, err
);
1845 if (value
< min
|| value
> max
) {
1846 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
1847 " (minimum: %" PRId64
", maximum: %" PRId64
")",
1848 object_get_typename(obj
), name
? name
: "null",
1852 cpu
->hyperv_spinlock_attempts
= value
;
1855 static PropertyInfo qdev_prop_spinlocks
= {
1857 .get
= x86_get_hv_spinlocks
,
1858 .set
= x86_set_hv_spinlocks
,
1861 /* Convert all '_' in a feature string option name to '-', to make feature
1862 * name conform to QOM property naming rule, which uses '-' instead of '_'.
1864 static inline void feat2prop(char *s
)
1866 while ((s
= strchr(s
, '_'))) {
1871 /* Parse "+feature,-feature,feature=foo" CPU feature string
1873 static void x86_cpu_parse_featurestr(CPUState
*cs
, char *features
,
1876 X86CPU
*cpu
= X86_CPU(cs
);
1877 char *featurestr
; /* Single 'key=value" string being parsed */
1879 /* Features to be added */
1880 FeatureWordArray plus_features
= { 0 };
1881 /* Features to be removed */
1882 FeatureWordArray minus_features
= { 0 };
1884 CPUX86State
*env
= &cpu
->env
;
1885 Error
*local_err
= NULL
;
1887 featurestr
= features
? strtok(features
, ",") : NULL
;
1889 while (featurestr
) {
1891 if (featurestr
[0] == '+') {
1892 add_flagname_to_bitmaps(featurestr
+ 1, plus_features
, &local_err
);
1893 } else if (featurestr
[0] == '-') {
1894 add_flagname_to_bitmaps(featurestr
+ 1, minus_features
, &local_err
);
1895 } else if ((val
= strchr(featurestr
, '='))) {
1897 feat2prop(featurestr
);
1898 if (!strcmp(featurestr
, "xlevel")) {
1902 numvalue
= strtoul(val
, &err
, 0);
1903 if (!*val
|| *err
) {
1904 error_setg(errp
, "bad numerical value %s", val
);
1907 if (numvalue
< 0x80000000) {
1908 error_report("xlevel value shall always be >= 0x80000000"
1909 ", fixup will be removed in future versions");
1910 numvalue
+= 0x80000000;
1912 snprintf(num
, sizeof(num
), "%" PRIu32
, numvalue
);
1913 object_property_parse(OBJECT(cpu
), num
, featurestr
, &local_err
);
1914 } else if (!strcmp(featurestr
, "tsc-freq")) {
1919 tsc_freq
= strtosz_suffix_unit(val
, &err
,
1920 STRTOSZ_DEFSUFFIX_B
, 1000);
1921 if (tsc_freq
< 0 || *err
) {
1922 error_setg(errp
, "bad numerical value %s", val
);
1925 snprintf(num
, sizeof(num
), "%" PRId64
, tsc_freq
);
1926 object_property_parse(OBJECT(cpu
), num
, "tsc-frequency",
1928 } else if (!strcmp(featurestr
, "hv-spinlocks")) {
1930 const int min
= 0xFFF;
1932 numvalue
= strtoul(val
, &err
, 0);
1933 if (!*val
|| *err
) {
1934 error_setg(errp
, "bad numerical value %s", val
);
1937 if (numvalue
< min
) {
1938 error_report("hv-spinlocks value shall always be >= 0x%x"
1939 ", fixup will be removed in future versions",
1943 snprintf(num
, sizeof(num
), "%" PRId32
, numvalue
);
1944 object_property_parse(OBJECT(cpu
), num
, featurestr
, &local_err
);
1946 object_property_parse(OBJECT(cpu
), val
, featurestr
, &local_err
);
1949 feat2prop(featurestr
);
1950 object_property_parse(OBJECT(cpu
), "on", featurestr
, &local_err
);
1953 error_propagate(errp
, local_err
);
1956 featurestr
= strtok(NULL
, ",");
1959 if (cpu
->host_features
) {
1960 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1962 x86_cpu_get_supported_feature_word(w
, cpu
->migratable
);
1966 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1967 env
->features
[w
] |= plus_features
[w
];
1968 env
->features
[w
] &= ~minus_features
[w
];
1972 /* Print all cpuid feature names in featureset
1974 static void listflags(FILE *f
, fprintf_function print
, const char **featureset
)
1979 for (bit
= 0; bit
< 32; bit
++) {
1980 if (featureset
[bit
]) {
1981 print(f
, "%s%s", first
? "" : " ", featureset
[bit
]);
1987 /* generate CPU information. */
1988 void x86_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
1990 X86CPUDefinition
*def
;
1994 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1995 def
= &builtin_x86_defs
[i
];
1996 snprintf(buf
, sizeof(buf
), "%s", def
->name
);
1997 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", buf
, def
->model_id
);
2000 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", "host",
2001 "KVM processor with all supported host features "
2002 "(only available in KVM mode)");
2005 (*cpu_fprintf
)(f
, "\nRecognized CPUID flags:\n");
2006 for (i
= 0; i
< ARRAY_SIZE(feature_word_info
); i
++) {
2007 FeatureWordInfo
*fw
= &feature_word_info
[i
];
2009 (*cpu_fprintf
)(f
, " ");
2010 listflags(f
, cpu_fprintf
, fw
->feat_names
);
2011 (*cpu_fprintf
)(f
, "\n");
2015 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
2017 CpuDefinitionInfoList
*cpu_list
= NULL
;
2018 X86CPUDefinition
*def
;
2021 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
2022 CpuDefinitionInfoList
*entry
;
2023 CpuDefinitionInfo
*info
;
2025 def
= &builtin_x86_defs
[i
];
2026 info
= g_malloc0(sizeof(*info
));
2027 info
->name
= g_strdup(def
->name
);
2029 entry
= g_malloc0(sizeof(*entry
));
2030 entry
->value
= info
;
2031 entry
->next
= cpu_list
;
2038 static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w
,
2039 bool migratable_only
)
2041 FeatureWordInfo
*wi
= &feature_word_info
[w
];
2044 if (kvm_enabled()) {
2045 r
= kvm_arch_get_supported_cpuid(kvm_state
, wi
->cpuid_eax
,
2048 } else if (tcg_enabled()) {
2049 r
= wi
->tcg_features
;
2053 if (migratable_only
) {
2054 r
&= x86_cpu_get_migratable_flags(w
);
2060 * Filters CPU feature words based on host availability of each feature.
2062 * Returns: 0 if all flags are supported by the host, non-zero otherwise.
2064 static int x86_cpu_filter_features(X86CPU
*cpu
)
2066 CPUX86State
*env
= &cpu
->env
;
2070 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
2071 uint32_t host_feat
=
2072 x86_cpu_get_supported_feature_word(w
, cpu
->migratable
);
2073 uint32_t requested_features
= env
->features
[w
];
2074 env
->features
[w
] &= host_feat
;
2075 cpu
->filtered_features
[w
] = requested_features
& ~env
->features
[w
];
2076 if (cpu
->filtered_features
[w
]) {
2077 if (cpu
->check_cpuid
|| cpu
->enforce_cpuid
) {
2078 report_unavailable_features(w
, cpu
->filtered_features
[w
]);
2087 /* Load data from X86CPUDefinition
2089 static void x86_cpu_load_def(X86CPU
*cpu
, X86CPUDefinition
*def
, Error
**errp
)
2091 CPUX86State
*env
= &cpu
->env
;
2093 char host_vendor
[CPUID_VENDOR_SZ
+ 1];
2096 object_property_set_int(OBJECT(cpu
), def
->level
, "level", errp
);
2097 object_property_set_int(OBJECT(cpu
), def
->family
, "family", errp
);
2098 object_property_set_int(OBJECT(cpu
), def
->model
, "model", errp
);
2099 object_property_set_int(OBJECT(cpu
), def
->stepping
, "stepping", errp
);
2100 object_property_set_int(OBJECT(cpu
), def
->xlevel
, "xlevel", errp
);
2101 object_property_set_int(OBJECT(cpu
), def
->xlevel2
, "xlevel2", errp
);
2102 cpu
->cache_info_passthrough
= def
->cache_info_passthrough
;
2103 object_property_set_str(OBJECT(cpu
), def
->model_id
, "model-id", errp
);
2104 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
2105 env
->features
[w
] = def
->features
[w
];
2108 /* Special cases not set in the X86CPUDefinition structs: */
2109 if (kvm_enabled()) {
2111 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
2112 env
->features
[w
] |= kvm_default_features
[w
];
2113 env
->features
[w
] &= ~kvm_default_unset_features
[w
];
2117 env
->features
[FEAT_1_ECX
] |= CPUID_EXT_HYPERVISOR
;
2119 /* sysenter isn't supported in compatibility mode on AMD,
2120 * syscall isn't supported in compatibility mode on Intel.
2121 * Normally we advertise the actual CPU vendor, but you can
2122 * override this using the 'vendor' property if you want to use
2123 * KVM's sysenter/syscall emulation in compatibility mode and
2124 * when doing cross vendor migration
2126 vendor
= def
->vendor
;
2127 if (kvm_enabled()) {
2128 uint32_t ebx
= 0, ecx
= 0, edx
= 0;
2129 host_cpuid(0, 0, NULL
, &ebx
, &ecx
, &edx
);
2130 x86_cpu_vendor_words2str(host_vendor
, ebx
, edx
, ecx
);
2131 vendor
= host_vendor
;
2134 object_property_set_str(OBJECT(cpu
), vendor
, "vendor", errp
);
2138 X86CPU
*cpu_x86_create(const char *cpu_model
, Error
**errp
)
2143 gchar
**model_pieces
;
2144 char *name
, *features
;
2145 Error
*error
= NULL
;
2147 model_pieces
= g_strsplit(cpu_model
, ",", 2);
2148 if (!model_pieces
[0]) {
2149 error_setg(&error
, "Invalid/empty CPU model name");
2152 name
= model_pieces
[0];
2153 features
= model_pieces
[1];
2155 oc
= x86_cpu_class_by_name(name
);
2157 error_setg(&error
, "Unable to find CPU definition: %s", name
);
2160 xcc
= X86_CPU_CLASS(oc
);
2162 if (xcc
->kvm_required
&& !kvm_enabled()) {
2163 error_setg(&error
, "CPU model '%s' requires KVM", name
);
2167 cpu
= X86_CPU(object_new(object_class_get_name(oc
)));
2169 x86_cpu_parse_featurestr(CPU(cpu
), features
, &error
);
2175 if (error
!= NULL
) {
2176 error_propagate(errp
, error
);
2178 object_unref(OBJECT(cpu
));
2182 g_strfreev(model_pieces
);
2186 X86CPU
*cpu_x86_init(const char *cpu_model
)
2188 Error
*error
= NULL
;
2191 cpu
= cpu_x86_create(cpu_model
, &error
);
2196 object_property_set_bool(OBJECT(cpu
), true, "realized", &error
);
2200 error_report_err(error
);
2202 object_unref(OBJECT(cpu
));
2209 static void x86_cpu_cpudef_class_init(ObjectClass
*oc
, void *data
)
2211 X86CPUDefinition
*cpudef
= data
;
2212 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
2214 xcc
->cpu_def
= cpudef
;
2217 static void x86_register_cpudef_type(X86CPUDefinition
*def
)
2219 char *typename
= x86_cpu_type_name(def
->name
);
2222 .parent
= TYPE_X86_CPU
,
2223 .class_init
= x86_cpu_cpudef_class_init
,
2231 #if !defined(CONFIG_USER_ONLY)
2233 void cpu_clear_apic_feature(CPUX86State
*env
)
2235 env
->features
[FEAT_1_EDX
] &= ~CPUID_APIC
;
2238 #endif /* !CONFIG_USER_ONLY */
2240 /* Initialize list of CPU models, filling some non-static fields if necessary
2242 void x86_cpudef_setup(void)
2245 static const char *model_with_versions
[] = { "qemu32", "qemu64", "athlon" };
2247 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); ++i
) {
2248 X86CPUDefinition
*def
= &builtin_x86_defs
[i
];
2250 /* Look for specific "cpudef" models that */
2251 /* have the QEMU version in .model_id */
2252 for (j
= 0; j
< ARRAY_SIZE(model_with_versions
); j
++) {
2253 if (strcmp(model_with_versions
[j
], def
->name
) == 0) {
2254 pstrcpy(def
->model_id
, sizeof(def
->model_id
),
2255 "QEMU Virtual CPU version ");
2256 pstrcat(def
->model_id
, sizeof(def
->model_id
),
2257 qemu_get_version());
2264 void cpu_x86_cpuid(CPUX86State
*env
, uint32_t index
, uint32_t count
,
2265 uint32_t *eax
, uint32_t *ebx
,
2266 uint32_t *ecx
, uint32_t *edx
)
2268 X86CPU
*cpu
= x86_env_get_cpu(env
);
2269 CPUState
*cs
= CPU(cpu
);
2271 /* test if maximum index reached */
2272 if (index
& 0x80000000) {
2273 if (index
> env
->cpuid_xlevel
) {
2274 if (env
->cpuid_xlevel2
> 0) {
2275 /* Handle the Centaur's CPUID instruction. */
2276 if (index
> env
->cpuid_xlevel2
) {
2277 index
= env
->cpuid_xlevel2
;
2278 } else if (index
< 0xC0000000) {
2279 index
= env
->cpuid_xlevel
;
2282 /* Intel documentation states that invalid EAX input will
2283 * return the same information as EAX=cpuid_level
2284 * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
2286 index
= env
->cpuid_level
;
2290 if (index
> env
->cpuid_level
)
2291 index
= env
->cpuid_level
;
2296 *eax
= env
->cpuid_level
;
2297 *ebx
= env
->cpuid_vendor1
;
2298 *edx
= env
->cpuid_vendor2
;
2299 *ecx
= env
->cpuid_vendor3
;
2302 *eax
= env
->cpuid_version
;
2303 *ebx
= (cpu
->apic_id
<< 24) |
2304 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
2305 *ecx
= env
->features
[FEAT_1_ECX
];
2306 *edx
= env
->features
[FEAT_1_EDX
];
2307 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2308 *ebx
|= (cs
->nr_cores
* cs
->nr_threads
) << 16;
2309 *edx
|= 1 << 28; /* HTT bit */
2313 /* cache info: needed for Pentium Pro compatibility */
2314 if (cpu
->cache_info_passthrough
) {
2315 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2318 *eax
= 1; /* Number of CPUID[EAX=2] calls required */
2321 *edx
= (L1D_DESCRIPTOR
<< 16) | \
2322 (L1I_DESCRIPTOR
<< 8) | \
2326 /* cache info: needed for Core compatibility */
2327 if (cpu
->cache_info_passthrough
) {
2328 host_cpuid(index
, count
, eax
, ebx
, ecx
, edx
);
2329 *eax
&= ~0xFC000000;
2333 case 0: /* L1 dcache info */
2334 *eax
|= CPUID_4_TYPE_DCACHE
| \
2335 CPUID_4_LEVEL(1) | \
2336 CPUID_4_SELF_INIT_LEVEL
;
2337 *ebx
= (L1D_LINE_SIZE
- 1) | \
2338 ((L1D_PARTITIONS
- 1) << 12) | \
2339 ((L1D_ASSOCIATIVITY
- 1) << 22);
2340 *ecx
= L1D_SETS
- 1;
2341 *edx
= CPUID_4_NO_INVD_SHARING
;
2343 case 1: /* L1 icache info */
2344 *eax
|= CPUID_4_TYPE_ICACHE
| \
2345 CPUID_4_LEVEL(1) | \
2346 CPUID_4_SELF_INIT_LEVEL
;
2347 *ebx
= (L1I_LINE_SIZE
- 1) | \
2348 ((L1I_PARTITIONS
- 1) << 12) | \
2349 ((L1I_ASSOCIATIVITY
- 1) << 22);
2350 *ecx
= L1I_SETS
- 1;
2351 *edx
= CPUID_4_NO_INVD_SHARING
;
2353 case 2: /* L2 cache info */
2354 *eax
|= CPUID_4_TYPE_UNIFIED
| \
2355 CPUID_4_LEVEL(2) | \
2356 CPUID_4_SELF_INIT_LEVEL
;
2357 if (cs
->nr_threads
> 1) {
2358 *eax
|= (cs
->nr_threads
- 1) << 14;
2360 *ebx
= (L2_LINE_SIZE
- 1) | \
2361 ((L2_PARTITIONS
- 1) << 12) | \
2362 ((L2_ASSOCIATIVITY
- 1) << 22);
2364 *edx
= CPUID_4_NO_INVD_SHARING
;
2366 default: /* end of info */
2375 /* QEMU gives out its own APIC IDs, never pass down bits 31..26. */
2376 if ((*eax
& 31) && cs
->nr_cores
> 1) {
2377 *eax
|= (cs
->nr_cores
- 1) << 26;
2381 /* mwait info: needed for Core compatibility */
2382 *eax
= 0; /* Smallest monitor-line size in bytes */
2383 *ebx
= 0; /* Largest monitor-line size in bytes */
2384 *ecx
= CPUID_MWAIT_EMX
| CPUID_MWAIT_IBE
;
2388 /* Thermal and Power Leaf */
2389 *eax
= env
->features
[FEAT_6_EAX
];
2395 /* Structured Extended Feature Flags Enumeration Leaf */
2397 *eax
= 0; /* Maximum ECX value for sub-leaves */
2398 *ebx
= env
->features
[FEAT_7_0_EBX
]; /* Feature flags */
2399 *ecx
= 0; /* Reserved */
2400 *edx
= 0; /* Reserved */
2409 /* Direct Cache Access Information Leaf */
2410 *eax
= 0; /* Bits 0-31 in DCA_CAP MSR */
2416 /* Architectural Performance Monitoring Leaf */
2417 if (kvm_enabled() && cpu
->enable_pmu
) {
2418 KVMState
*s
= cs
->kvm_state
;
2420 *eax
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EAX
);
2421 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EBX
);
2422 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_ECX
);
2423 *edx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EDX
);
2432 KVMState
*s
= cs
->kvm_state
;
2436 /* Processor Extended State */
2441 if (!(env
->features
[FEAT_1_ECX
] & CPUID_EXT_XSAVE
) || !kvm_enabled()) {
2445 kvm_arch_get_supported_cpuid(s
, 0xd, 0, R_EAX
) |
2446 ((uint64_t)kvm_arch_get_supported_cpuid(s
, 0xd, 0, R_EDX
) << 32);
2450 for (i
= 2; i
< ARRAY_SIZE(ext_save_areas
); i
++) {
2451 const ExtSaveArea
*esa
= &ext_save_areas
[i
];
2452 if ((env
->features
[esa
->feature
] & esa
->bits
) == esa
->bits
&&
2453 (kvm_mask
& (1 << i
)) != 0) {
2457 *edx
|= 1 << (i
- 32);
2459 *ecx
= MAX(*ecx
, esa
->offset
+ esa
->size
);
2462 *eax
|= kvm_mask
& (XSTATE_FP
| XSTATE_SSE
);
2464 } else if (count
== 1) {
2465 *eax
= env
->features
[FEAT_XSAVE
];
2466 } else if (count
< ARRAY_SIZE(ext_save_areas
)) {
2467 const ExtSaveArea
*esa
= &ext_save_areas
[count
];
2468 if ((env
->features
[esa
->feature
] & esa
->bits
) == esa
->bits
&&
2469 (kvm_mask
& (1 << count
)) != 0) {
2477 *eax
= env
->cpuid_xlevel
;
2478 *ebx
= env
->cpuid_vendor1
;
2479 *edx
= env
->cpuid_vendor2
;
2480 *ecx
= env
->cpuid_vendor3
;
2483 *eax
= env
->cpuid_version
;
2485 *ecx
= env
->features
[FEAT_8000_0001_ECX
];
2486 *edx
= env
->features
[FEAT_8000_0001_EDX
];
2488 /* The Linux kernel checks for the CMPLegacy bit and
2489 * discards multiple thread information if it is set.
2490 * So dont set it here for Intel to make Linux guests happy.
2492 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2493 if (env
->cpuid_vendor1
!= CPUID_VENDOR_INTEL_1
||
2494 env
->cpuid_vendor2
!= CPUID_VENDOR_INTEL_2
||
2495 env
->cpuid_vendor3
!= CPUID_VENDOR_INTEL_3
) {
2496 *ecx
|= 1 << 1; /* CmpLegacy bit */
2503 *eax
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 0];
2504 *ebx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 1];
2505 *ecx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 2];
2506 *edx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 3];
2509 /* cache info (L1 cache) */
2510 if (cpu
->cache_info_passthrough
) {
2511 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2514 *eax
= (L1_DTLB_2M_ASSOC
<< 24) | (L1_DTLB_2M_ENTRIES
<< 16) | \
2515 (L1_ITLB_2M_ASSOC
<< 8) | (L1_ITLB_2M_ENTRIES
);
2516 *ebx
= (L1_DTLB_4K_ASSOC
<< 24) | (L1_DTLB_4K_ENTRIES
<< 16) | \
2517 (L1_ITLB_4K_ASSOC
<< 8) | (L1_ITLB_4K_ENTRIES
);
2518 *ecx
= (L1D_SIZE_KB_AMD
<< 24) | (L1D_ASSOCIATIVITY_AMD
<< 16) | \
2519 (L1D_LINES_PER_TAG
<< 8) | (L1D_LINE_SIZE
);
2520 *edx
= (L1I_SIZE_KB_AMD
<< 24) | (L1I_ASSOCIATIVITY_AMD
<< 16) | \
2521 (L1I_LINES_PER_TAG
<< 8) | (L1I_LINE_SIZE
);
2524 /* cache info (L2 cache) */
2525 if (cpu
->cache_info_passthrough
) {
2526 host_cpuid(index
, 0, eax
, ebx
, ecx
, edx
);
2529 *eax
= (AMD_ENC_ASSOC(L2_DTLB_2M_ASSOC
) << 28) | \
2530 (L2_DTLB_2M_ENTRIES
<< 16) | \
2531 (AMD_ENC_ASSOC(L2_ITLB_2M_ASSOC
) << 12) | \
2532 (L2_ITLB_2M_ENTRIES
);
2533 *ebx
= (AMD_ENC_ASSOC(L2_DTLB_4K_ASSOC
) << 28) | \
2534 (L2_DTLB_4K_ENTRIES
<< 16) | \
2535 (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC
) << 12) | \
2536 (L2_ITLB_4K_ENTRIES
);
2537 *ecx
= (L2_SIZE_KB_AMD
<< 16) | \
2538 (AMD_ENC_ASSOC(L2_ASSOCIATIVITY
) << 12) | \
2539 (L2_LINES_PER_TAG
<< 8) | (L2_LINE_SIZE
);
2540 *edx
= ((L3_SIZE_KB
/512) << 18) | \
2541 (AMD_ENC_ASSOC(L3_ASSOCIATIVITY
) << 12) | \
2542 (L3_LINES_PER_TAG
<< 8) | (L3_LINE_SIZE
);
2548 *edx
= env
->features
[FEAT_8000_0007_EDX
];
2551 /* virtual & phys address size in low 2 bytes. */
2552 /* XXX: This value must match the one used in the MMU code. */
2553 if (env
->features
[FEAT_8000_0001_EDX
] & CPUID_EXT2_LM
) {
2554 /* 64 bit processor */
2555 /* XXX: The physical address space is limited to 42 bits in exec.c. */
2556 *eax
= 0x00003028; /* 48 bits virtual, 40 bits physical */
2558 if (env
->features
[FEAT_1_EDX
] & CPUID_PSE36
) {
2559 *eax
= 0x00000024; /* 36 bits physical */
2561 *eax
= 0x00000020; /* 32 bits physical */
2567 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2568 *ecx
|= (cs
->nr_cores
* cs
->nr_threads
) - 1;
2572 if (env
->features
[FEAT_8000_0001_ECX
] & CPUID_EXT3_SVM
) {
2573 *eax
= 0x00000001; /* SVM Revision */
2574 *ebx
= 0x00000010; /* nr of ASIDs */
2576 *edx
= env
->features
[FEAT_SVM
]; /* optional features */
2585 *eax
= env
->cpuid_xlevel2
;
2591 /* Support for VIA CPU's CPUID instruction */
2592 *eax
= env
->cpuid_version
;
2595 *edx
= env
->features
[FEAT_C000_0001_EDX
];
2600 /* Reserved for the future, and now filled with zero */
2607 /* reserved values: zero */
2616 /* CPUClass::reset() */
2617 static void x86_cpu_reset(CPUState
*s
)
2619 X86CPU
*cpu
= X86_CPU(s
);
2620 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(cpu
);
2621 CPUX86State
*env
= &cpu
->env
;
2624 xcc
->parent_reset(s
);
2626 memset(env
, 0, offsetof(CPUX86State
, cpuid_level
));
2630 env
->old_exception
= -1;
2632 /* init to reset state */
2634 #ifdef CONFIG_SOFTMMU
2635 env
->hflags
|= HF_SOFTMMU_MASK
;
2637 env
->hflags2
|= HF2_GIF_MASK
;
2639 cpu_x86_update_cr0(env
, 0x60000010);
2640 env
->a20_mask
= ~0x0;
2641 env
->smbase
= 0x30000;
2643 env
->idt
.limit
= 0xffff;
2644 env
->gdt
.limit
= 0xffff;
2645 env
->ldt
.limit
= 0xffff;
2646 env
->ldt
.flags
= DESC_P_MASK
| (2 << DESC_TYPE_SHIFT
);
2647 env
->tr
.limit
= 0xffff;
2648 env
->tr
.flags
= DESC_P_MASK
| (11 << DESC_TYPE_SHIFT
);
2650 cpu_x86_load_seg_cache(env
, R_CS
, 0xf000, 0xffff0000, 0xffff,
2651 DESC_P_MASK
| DESC_S_MASK
| DESC_CS_MASK
|
2652 DESC_R_MASK
| DESC_A_MASK
);
2653 cpu_x86_load_seg_cache(env
, R_DS
, 0, 0, 0xffff,
2654 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2656 cpu_x86_load_seg_cache(env
, R_ES
, 0, 0, 0xffff,
2657 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2659 cpu_x86_load_seg_cache(env
, R_SS
, 0, 0, 0xffff,
2660 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2662 cpu_x86_load_seg_cache(env
, R_FS
, 0, 0, 0xffff,
2663 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2665 cpu_x86_load_seg_cache(env
, R_GS
, 0, 0, 0xffff,
2666 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2670 env
->regs
[R_EDX
] = env
->cpuid_version
;
2675 for (i
= 0; i
< 8; i
++) {
2678 cpu_set_fpuc(env
, 0x37f);
2680 env
->mxcsr
= 0x1f80;
2681 env
->xstate_bv
= XSTATE_FP
| XSTATE_SSE
;
2683 env
->pat
= 0x0007040600070406ULL
;
2684 env
->msr_ia32_misc_enable
= MSR_IA32_MISC_ENABLE_DEFAULT
;
2686 memset(env
->dr
, 0, sizeof(env
->dr
));
2687 env
->dr
[6] = DR6_FIXED_1
;
2688 env
->dr
[7] = DR7_FIXED_1
;
2689 cpu_breakpoint_remove_all(s
, BP_CPU
);
2690 cpu_watchpoint_remove_all(s
, BP_CPU
);
2695 * SDM 11.11.5 requires:
2696 * - IA32_MTRR_DEF_TYPE MSR.E = 0
2697 * - IA32_MTRR_PHYSMASKn.V = 0
2698 * All other bits are undefined. For simplification, zero it all.
2700 env
->mtrr_deftype
= 0;
2701 memset(env
->mtrr_var
, 0, sizeof(env
->mtrr_var
));
2702 memset(env
->mtrr_fixed
, 0, sizeof(env
->mtrr_fixed
));
2704 #if !defined(CONFIG_USER_ONLY)
2705 /* We hard-wire the BSP to the first CPU. */
2706 apic_designate_bsp(cpu
->apic_state
, s
->cpu_index
== 0);
2708 s
->halted
= !cpu_is_bsp(cpu
);
2710 if (kvm_enabled()) {
2711 kvm_arch_reset_vcpu(cpu
);
2716 #ifndef CONFIG_USER_ONLY
2717 bool cpu_is_bsp(X86CPU
*cpu
)
2719 return cpu_get_apic_base(cpu
->apic_state
) & MSR_IA32_APICBASE_BSP
;
2722 /* TODO: remove me, when reset over QOM tree is implemented */
2723 static void x86_cpu_machine_reset_cb(void *opaque
)
2725 X86CPU
*cpu
= opaque
;
2726 cpu_reset(CPU(cpu
));
2730 static void mce_init(X86CPU
*cpu
)
2732 CPUX86State
*cenv
= &cpu
->env
;
2735 if (((cenv
->cpuid_version
>> 8) & 0xf) >= 6
2736 && (cenv
->features
[FEAT_1_EDX
] & (CPUID_MCE
| CPUID_MCA
)) ==
2737 (CPUID_MCE
| CPUID_MCA
)) {
2738 cenv
->mcg_cap
= MCE_CAP_DEF
| MCE_BANKS_DEF
;
2739 cenv
->mcg_ctl
= ~(uint64_t)0;
2740 for (bank
= 0; bank
< MCE_BANKS_DEF
; bank
++) {
2741 cenv
->mce_banks
[bank
* 4] = ~(uint64_t)0;
2746 #ifndef CONFIG_USER_ONLY
2747 static void x86_cpu_apic_create(X86CPU
*cpu
, Error
**errp
)
2749 DeviceState
*dev
= DEVICE(cpu
);
2750 APICCommonState
*apic
;
2751 const char *apic_type
= "apic";
2753 if (kvm_irqchip_in_kernel()) {
2754 apic_type
= "kvm-apic";
2755 } else if (xen_enabled()) {
2756 apic_type
= "xen-apic";
2759 cpu
->apic_state
= qdev_try_create(qdev_get_parent_bus(dev
), apic_type
);
2760 if (cpu
->apic_state
== NULL
) {
2761 error_setg(errp
, "APIC device '%s' could not be created", apic_type
);
2765 object_property_add_child(OBJECT(cpu
), "apic",
2766 OBJECT(cpu
->apic_state
), NULL
);
2767 qdev_prop_set_uint8(cpu
->apic_state
, "id", cpu
->apic_id
);
2768 /* TODO: convert to link<> */
2769 apic
= APIC_COMMON(cpu
->apic_state
);
2773 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2775 if (cpu
->apic_state
== NULL
) {
2778 object_property_set_bool(OBJECT(cpu
->apic_state
), true, "realized",
2782 static void x86_cpu_machine_done(Notifier
*n
, void *unused
)
2784 X86CPU
*cpu
= container_of(n
, X86CPU
, machine_done
);
2785 MemoryRegion
*smram
=
2786 (MemoryRegion
*) object_resolve_path("/machine/smram", NULL
);
2789 cpu
->smram
= g_new(MemoryRegion
, 1);
2790 memory_region_init_alias(cpu
->smram
, OBJECT(cpu
), "smram",
2791 smram
, 0, 1ull << 32);
2792 memory_region_set_enabled(cpu
->smram
, false);
2793 memory_region_add_subregion_overlap(cpu
->cpu_as_root
, 0, cpu
->smram
, 1);
2797 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2803 #define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
2804 (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
2805 (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
2806 #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
2807 (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
2808 (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
2809 static void x86_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
2811 CPUState
*cs
= CPU(dev
);
2812 X86CPU
*cpu
= X86_CPU(dev
);
2813 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(dev
);
2814 CPUX86State
*env
= &cpu
->env
;
2815 Error
*local_err
= NULL
;
2816 static bool ht_warned
;
2818 if (cpu
->apic_id
< 0) {
2819 error_setg(errp
, "apic-id property was not initialized properly");
2823 if (env
->features
[FEAT_7_0_EBX
] && env
->cpuid_level
< 7) {
2824 env
->cpuid_level
= 7;
2827 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
2830 if (IS_AMD_CPU(env
)) {
2831 env
->features
[FEAT_8000_0001_EDX
] &= ~CPUID_EXT2_AMD_ALIASES
;
2832 env
->features
[FEAT_8000_0001_EDX
] |= (env
->features
[FEAT_1_EDX
]
2833 & CPUID_EXT2_AMD_ALIASES
);
2837 if (x86_cpu_filter_features(cpu
) && cpu
->enforce_cpuid
) {
2838 error_setg(&local_err
,
2840 "Host doesn't support requested features" :
2841 "TCG doesn't support requested features");
2845 #ifndef CONFIG_USER_ONLY
2846 qemu_register_reset(x86_cpu_machine_reset_cb
, cpu
);
2848 if (cpu
->env
.features
[FEAT_1_EDX
] & CPUID_APIC
|| smp_cpus
> 1) {
2849 x86_cpu_apic_create(cpu
, &local_err
);
2850 if (local_err
!= NULL
) {
2858 #ifndef CONFIG_USER_ONLY
2859 if (tcg_enabled()) {
2860 cpu
->cpu_as_mem
= g_new(MemoryRegion
, 1);
2861 cpu
->cpu_as_root
= g_new(MemoryRegion
, 1);
2862 cs
->as
= g_new(AddressSpace
, 1);
2864 /* Outer container... */
2865 memory_region_init(cpu
->cpu_as_root
, OBJECT(cpu
), "memory", ~0ull);
2866 memory_region_set_enabled(cpu
->cpu_as_root
, true);
2868 /* ... with two regions inside: normal system memory with low
2871 memory_region_init_alias(cpu
->cpu_as_mem
, OBJECT(cpu
), "memory",
2872 get_system_memory(), 0, ~0ull);
2873 memory_region_add_subregion_overlap(cpu
->cpu_as_root
, 0, cpu
->cpu_as_mem
, 0);
2874 memory_region_set_enabled(cpu
->cpu_as_mem
, true);
2875 address_space_init(cs
->as
, cpu
->cpu_as_root
, "CPU");
2877 /* ... SMRAM with higher priority, linked from /machine/smram. */
2878 cpu
->machine_done
.notify
= x86_cpu_machine_done
;
2879 qemu_add_machine_init_done_notifier(&cpu
->machine_done
);
2885 /* Only Intel CPUs support hyperthreading. Even though QEMU fixes this
2886 * issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
2887 * based on inputs (sockets,cores,threads), it is still better to gives
2890 * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise
2891 * cs->nr_threads hasn't be populated yet and the checking is incorrect.
2893 if (!IS_INTEL_CPU(env
) && cs
->nr_threads
> 1 && !ht_warned
) {
2894 error_report("AMD CPU doesn't support hyperthreading. Please configure"
2895 " -smp options properly.");
2899 x86_cpu_apic_realize(cpu
, &local_err
);
2900 if (local_err
!= NULL
) {
2905 xcc
->parent_realize(dev
, &local_err
);
2908 if (local_err
!= NULL
) {
2909 error_propagate(errp
, local_err
);
2914 typedef struct BitProperty
{
2919 static void x86_cpu_get_bit_prop(Object
*obj
,
2925 BitProperty
*fp
= opaque
;
2926 bool value
= (*fp
->ptr
& fp
->mask
) == fp
->mask
;
2927 visit_type_bool(v
, &value
, name
, errp
);
2930 static void x86_cpu_set_bit_prop(Object
*obj
,
2936 DeviceState
*dev
= DEVICE(obj
);
2937 BitProperty
*fp
= opaque
;
2938 Error
*local_err
= NULL
;
2941 if (dev
->realized
) {
2942 qdev_prop_set_after_realize(dev
, name
, errp
);
2946 visit_type_bool(v
, &value
, name
, &local_err
);
2948 error_propagate(errp
, local_err
);
2953 *fp
->ptr
|= fp
->mask
;
2955 *fp
->ptr
&= ~fp
->mask
;
2959 static void x86_cpu_release_bit_prop(Object
*obj
, const char *name
,
2962 BitProperty
*prop
= opaque
;
2966 /* Register a boolean property to get/set a single bit in a uint32_t field.
2968 * The same property name can be registered multiple times to make it affect
2969 * multiple bits in the same FeatureWord. In that case, the getter will return
2970 * true only if all bits are set.
2972 static void x86_cpu_register_bit_prop(X86CPU
*cpu
,
2973 const char *prop_name
,
2979 uint32_t mask
= (1UL << bitnr
);
2981 op
= object_property_find(OBJECT(cpu
), prop_name
, NULL
);
2984 assert(fp
->ptr
== field
);
2987 fp
= g_new0(BitProperty
, 1);
2990 object_property_add(OBJECT(cpu
), prop_name
, "bool",
2991 x86_cpu_get_bit_prop
,
2992 x86_cpu_set_bit_prop
,
2993 x86_cpu_release_bit_prop
, fp
, &error_abort
);
2997 static void x86_cpu_register_feature_bit_props(X86CPU
*cpu
,
3001 Object
*obj
= OBJECT(cpu
);
3004 FeatureWordInfo
*fi
= &feature_word_info
[w
];
3006 if (!fi
->feat_names
) {
3009 if (!fi
->feat_names
[bitnr
]) {
3013 names
= g_strsplit(fi
->feat_names
[bitnr
], "|", 0);
3015 feat2prop(names
[0]);
3016 x86_cpu_register_bit_prop(cpu
, names
[0], &cpu
->env
.features
[w
], bitnr
);
3018 for (i
= 1; names
[i
]; i
++) {
3019 feat2prop(names
[i
]);
3020 object_property_add_alias(obj
, names
[i
], obj
, names
[0],
3027 static void x86_cpu_initfn(Object
*obj
)
3029 CPUState
*cs
= CPU(obj
);
3030 X86CPU
*cpu
= X86_CPU(obj
);
3031 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(obj
);
3032 CPUX86State
*env
= &cpu
->env
;
3037 cpu_exec_init(cs
, &error_abort
);
3039 object_property_add(obj
, "family", "int",
3040 x86_cpuid_version_get_family
,
3041 x86_cpuid_version_set_family
, NULL
, NULL
, NULL
);
3042 object_property_add(obj
, "model", "int",
3043 x86_cpuid_version_get_model
,
3044 x86_cpuid_version_set_model
, NULL
, NULL
, NULL
);
3045 object_property_add(obj
, "stepping", "int",
3046 x86_cpuid_version_get_stepping
,
3047 x86_cpuid_version_set_stepping
, NULL
, NULL
, NULL
);
3048 object_property_add_str(obj
, "vendor",
3049 x86_cpuid_get_vendor
,
3050 x86_cpuid_set_vendor
, NULL
);
3051 object_property_add_str(obj
, "model-id",
3052 x86_cpuid_get_model_id
,
3053 x86_cpuid_set_model_id
, NULL
);
3054 object_property_add(obj
, "tsc-frequency", "int",
3055 x86_cpuid_get_tsc_freq
,
3056 x86_cpuid_set_tsc_freq
, NULL
, NULL
, NULL
);
3057 object_property_add(obj
, "apic-id", "int",
3058 x86_cpuid_get_apic_id
,
3059 x86_cpuid_set_apic_id
, NULL
, NULL
, NULL
);
3060 object_property_add(obj
, "feature-words", "X86CPUFeatureWordInfo",
3061 x86_cpu_get_feature_words
,
3062 NULL
, NULL
, (void *)env
->features
, NULL
);
3063 object_property_add(obj
, "filtered-features", "X86CPUFeatureWordInfo",
3064 x86_cpu_get_feature_words
,
3065 NULL
, NULL
, (void *)cpu
->filtered_features
, NULL
);
3067 cpu
->hyperv_spinlock_attempts
= HYPERV_SPINLOCK_NEVER_RETRY
;
3069 #ifndef CONFIG_USER_ONLY
3070 /* Any code creating new X86CPU objects have to set apic-id explicitly */
3074 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
3077 for (bitnr
= 0; bitnr
< 32; bitnr
++) {
3078 x86_cpu_register_feature_bit_props(cpu
, w
, bitnr
);
3082 x86_cpu_load_def(cpu
, xcc
->cpu_def
, &error_abort
);
3084 /* init various static tables used in TCG mode */
3085 if (tcg_enabled() && !inited
) {
3087 optimize_flags_init();
3091 static int64_t x86_cpu_get_arch_id(CPUState
*cs
)
3093 X86CPU
*cpu
= X86_CPU(cs
);
3095 return cpu
->apic_id
;
3098 static bool x86_cpu_get_paging_enabled(const CPUState
*cs
)
3100 X86CPU
*cpu
= X86_CPU(cs
);
3102 return cpu
->env
.cr
[0] & CR0_PG_MASK
;
3105 static void x86_cpu_set_pc(CPUState
*cs
, vaddr value
)
3107 X86CPU
*cpu
= X86_CPU(cs
);
3109 cpu
->env
.eip
= value
;
3112 static void x86_cpu_synchronize_from_tb(CPUState
*cs
, TranslationBlock
*tb
)
3114 X86CPU
*cpu
= X86_CPU(cs
);
3116 cpu
->env
.eip
= tb
->pc
- tb
->cs_base
;
3119 static bool x86_cpu_has_work(CPUState
*cs
)
3121 X86CPU
*cpu
= X86_CPU(cs
);
3122 CPUX86State
*env
= &cpu
->env
;
3124 #if !defined(CONFIG_USER_ONLY)
3125 if (cs
->interrupt_request
& CPU_INTERRUPT_POLL
) {
3126 apic_poll_irq(cpu
->apic_state
);
3127 cpu_reset_interrupt(cs
, CPU_INTERRUPT_POLL
);
3131 return ((cs
->interrupt_request
& CPU_INTERRUPT_HARD
) &&
3132 (env
->eflags
& IF_MASK
)) ||
3133 (cs
->interrupt_request
& (CPU_INTERRUPT_NMI
|
3134 CPU_INTERRUPT_INIT
|
3135 CPU_INTERRUPT_SIPI
|
3136 CPU_INTERRUPT_MCE
)) ||
3137 ((cs
->interrupt_request
& CPU_INTERRUPT_SMI
) &&
3138 !(env
->hflags
& HF_SMM_MASK
));
3141 static Property x86_cpu_properties
[] = {
3142 DEFINE_PROP_BOOL("pmu", X86CPU
, enable_pmu
, false),
3143 { .name
= "hv-spinlocks", .info
= &qdev_prop_spinlocks
},
3144 DEFINE_PROP_BOOL("hv-relaxed", X86CPU
, hyperv_relaxed_timing
, false),
3145 DEFINE_PROP_BOOL("hv-vapic", X86CPU
, hyperv_vapic
, false),
3146 DEFINE_PROP_BOOL("hv-time", X86CPU
, hyperv_time
, false),
3147 DEFINE_PROP_BOOL("check", X86CPU
, check_cpuid
, false),
3148 DEFINE_PROP_BOOL("enforce", X86CPU
, enforce_cpuid
, false),
3149 DEFINE_PROP_BOOL("kvm", X86CPU
, expose_kvm
, true),
3150 DEFINE_PROP_UINT32("level", X86CPU
, env
.cpuid_level
, 0),
3151 DEFINE_PROP_UINT32("xlevel", X86CPU
, env
.cpuid_xlevel
, 0),
3152 DEFINE_PROP_UINT32("xlevel2", X86CPU
, env
.cpuid_xlevel2
, 0),
3153 DEFINE_PROP_END_OF_LIST()
3156 static void x86_cpu_common_class_init(ObjectClass
*oc
, void *data
)
3158 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
3159 CPUClass
*cc
= CPU_CLASS(oc
);
3160 DeviceClass
*dc
= DEVICE_CLASS(oc
);
3162 xcc
->parent_realize
= dc
->realize
;
3163 dc
->realize
= x86_cpu_realizefn
;
3164 dc
->bus_type
= TYPE_ICC_BUS
;
3165 dc
->props
= x86_cpu_properties
;
3167 xcc
->parent_reset
= cc
->reset
;
3168 cc
->reset
= x86_cpu_reset
;
3169 cc
->reset_dump_flags
= CPU_DUMP_FPU
| CPU_DUMP_CCOP
;
3171 cc
->class_by_name
= x86_cpu_class_by_name
;
3172 cc
->parse_features
= x86_cpu_parse_featurestr
;
3173 cc
->has_work
= x86_cpu_has_work
;
3174 cc
->do_interrupt
= x86_cpu_do_interrupt
;
3175 cc
->cpu_exec_interrupt
= x86_cpu_exec_interrupt
;
3176 cc
->dump_state
= x86_cpu_dump_state
;
3177 cc
->set_pc
= x86_cpu_set_pc
;
3178 cc
->synchronize_from_tb
= x86_cpu_synchronize_from_tb
;
3179 cc
->gdb_read_register
= x86_cpu_gdb_read_register
;
3180 cc
->gdb_write_register
= x86_cpu_gdb_write_register
;
3181 cc
->get_arch_id
= x86_cpu_get_arch_id
;
3182 cc
->get_paging_enabled
= x86_cpu_get_paging_enabled
;
3183 #ifdef CONFIG_USER_ONLY
3184 cc
->handle_mmu_fault
= x86_cpu_handle_mmu_fault
;
3186 cc
->get_memory_mapping
= x86_cpu_get_memory_mapping
;
3187 cc
->get_phys_page_debug
= x86_cpu_get_phys_page_debug
;
3188 cc
->write_elf64_note
= x86_cpu_write_elf64_note
;
3189 cc
->write_elf64_qemunote
= x86_cpu_write_elf64_qemunote
;
3190 cc
->write_elf32_note
= x86_cpu_write_elf32_note
;
3191 cc
->write_elf32_qemunote
= x86_cpu_write_elf32_qemunote
;
3192 cc
->vmsd
= &vmstate_x86_cpu
;
3194 cc
->gdb_num_core_regs
= CPU_NB_REGS
* 2 + 25;
3195 #ifndef CONFIG_USER_ONLY
3196 cc
->debug_excp_handler
= breakpoint_handler
;
3198 cc
->cpu_exec_enter
= x86_cpu_exec_enter
;
3199 cc
->cpu_exec_exit
= x86_cpu_exec_exit
;
3202 static const TypeInfo x86_cpu_type_info
= {
3203 .name
= TYPE_X86_CPU
,
3205 .instance_size
= sizeof(X86CPU
),
3206 .instance_init
= x86_cpu_initfn
,
3208 .class_size
= sizeof(X86CPUClass
),
3209 .class_init
= x86_cpu_common_class_init
,
3212 static void x86_cpu_register_types(void)
3216 type_register_static(&x86_cpu_type_info
);
3217 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
3218 x86_register_cpudef_type(&builtin_x86_defs
[i
]);
3221 type_register_static(&host_x86_cpu_type_info
);
3225 type_init(x86_cpu_register_types
)