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"
29 #include "qemu/option.h"
30 #include "qemu/config-file.h"
31 #include "qapi/qmp/qerror.h"
33 #include "qapi-types.h"
34 #include "qapi-visit.h"
35 #include "qapi/visitor.h"
36 #include "sysemu/arch_init.h"
39 #if defined(CONFIG_KVM)
40 #include <linux/kvm_para.h>
43 #include "sysemu/sysemu.h"
44 #include "hw/qdev-properties.h"
45 #include "hw/cpu/icc_bus.h"
46 #ifndef CONFIG_USER_ONLY
47 #include "hw/xen/xen.h"
48 #include "hw/i386/apic_internal.h"
51 static void x86_cpu_vendor_words2str(char *dst
, uint32_t vendor1
,
52 uint32_t vendor2
, uint32_t vendor3
)
55 for (i
= 0; i
< 4; i
++) {
56 dst
[i
] = vendor1
>> (8 * i
);
57 dst
[i
+ 4] = vendor2
>> (8 * i
);
58 dst
[i
+ 8] = vendor3
>> (8 * i
);
60 dst
[CPUID_VENDOR_SZ
] = '\0';
63 /* feature flags taken from "Intel Processor Identification and the CPUID
64 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
65 * between feature naming conventions, aliases may be added.
67 static const char *feature_name
[] = {
68 "fpu", "vme", "de", "pse",
69 "tsc", "msr", "pae", "mce",
70 "cx8", "apic", NULL
, "sep",
71 "mtrr", "pge", "mca", "cmov",
72 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
73 NULL
, "ds" /* Intel dts */, "acpi", "mmx",
74 "fxsr", "sse", "sse2", "ss",
75 "ht" /* Intel htt */, "tm", "ia64", "pbe",
77 static const char *ext_feature_name
[] = {
78 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
79 "ds_cpl", "vmx", "smx", "est",
80 "tm2", "ssse3", "cid", NULL
,
81 "fma", "cx16", "xtpr", "pdcm",
82 NULL
, "pcid", "dca", "sse4.1|sse4_1",
83 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
84 "tsc-deadline", "aes", "xsave", "osxsave",
85 "avx", "f16c", "rdrand", "hypervisor",
87 /* Feature names that are already defined on feature_name[] but are set on
88 * CPUID[8000_0001].EDX on AMD CPUs don't have their names on
89 * ext2_feature_name[]. They are copied automatically to cpuid_ext2_features
90 * if and only if CPU vendor is AMD.
92 static const char *ext2_feature_name
[] = {
93 NULL
/* fpu */, NULL
/* vme */, NULL
/* de */, NULL
/* pse */,
94 NULL
/* tsc */, NULL
/* msr */, NULL
/* pae */, NULL
/* mce */,
95 NULL
/* cx8 */ /* AMD CMPXCHG8B */, NULL
/* apic */, NULL
, "syscall",
96 NULL
/* mtrr */, NULL
/* pge */, NULL
/* mca */, NULL
/* cmov */,
97 NULL
/* pat */, NULL
/* pse36 */, NULL
, NULL
/* Linux mp */,
98 "nx|xd", NULL
, "mmxext", NULL
/* mmx */,
99 NULL
/* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
100 NULL
, "lm|i64", "3dnowext", "3dnow",
102 static const char *ext3_feature_name
[] = {
103 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
104 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
105 "3dnowprefetch", "osvw", "ibs", "xop",
106 "skinit", "wdt", NULL
, "lwp",
107 "fma4", "tce", NULL
, "nodeid_msr",
108 NULL
, "tbm", "topoext", "perfctr_core",
109 "perfctr_nb", NULL
, NULL
, NULL
,
110 NULL
, NULL
, NULL
, NULL
,
113 static const char *ext4_feature_name
[] = {
114 NULL
, NULL
, "xstore", "xstore-en",
115 NULL
, NULL
, "xcrypt", "xcrypt-en",
116 "ace2", "ace2-en", "phe", "phe-en",
117 "pmm", "pmm-en", NULL
, NULL
,
118 NULL
, NULL
, NULL
, NULL
,
119 NULL
, NULL
, NULL
, NULL
,
120 NULL
, NULL
, NULL
, NULL
,
121 NULL
, NULL
, NULL
, NULL
,
124 static const char *kvm_feature_name
[] = {
125 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
126 "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", NULL
,
127 NULL
, NULL
, NULL
, NULL
,
128 NULL
, NULL
, NULL
, NULL
,
129 NULL
, NULL
, NULL
, NULL
,
130 NULL
, NULL
, NULL
, NULL
,
131 NULL
, NULL
, NULL
, NULL
,
132 NULL
, NULL
, NULL
, NULL
,
135 static const char *svm_feature_name
[] = {
136 "npt", "lbrv", "svm_lock", "nrip_save",
137 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
138 NULL
, NULL
, "pause_filter", NULL
,
139 "pfthreshold", NULL
, NULL
, NULL
,
140 NULL
, NULL
, NULL
, NULL
,
141 NULL
, NULL
, NULL
, NULL
,
142 NULL
, NULL
, NULL
, NULL
,
143 NULL
, NULL
, NULL
, NULL
,
146 static const char *cpuid_7_0_ebx_feature_name
[] = {
147 "fsgsbase", NULL
, NULL
, "bmi1", "hle", "avx2", NULL
, "smep",
148 "bmi2", "erms", "invpcid", "rtm", NULL
, NULL
, NULL
, NULL
,
149 NULL
, NULL
, "rdseed", "adx", "smap", NULL
, NULL
, NULL
,
150 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
153 typedef struct FeatureWordInfo
{
154 const char **feat_names
;
155 uint32_t cpuid_eax
; /* Input EAX for CPUID */
156 bool cpuid_needs_ecx
; /* CPUID instruction uses ECX as input */
157 uint32_t cpuid_ecx
; /* Input ECX value for CPUID */
158 int cpuid_reg
; /* output register (R_* constant) */
161 static FeatureWordInfo feature_word_info
[FEATURE_WORDS
] = {
163 .feat_names
= feature_name
,
164 .cpuid_eax
= 1, .cpuid_reg
= R_EDX
,
167 .feat_names
= ext_feature_name
,
168 .cpuid_eax
= 1, .cpuid_reg
= R_ECX
,
170 [FEAT_8000_0001_EDX
] = {
171 .feat_names
= ext2_feature_name
,
172 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_EDX
,
174 [FEAT_8000_0001_ECX
] = {
175 .feat_names
= ext3_feature_name
,
176 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_ECX
,
178 [FEAT_C000_0001_EDX
] = {
179 .feat_names
= ext4_feature_name
,
180 .cpuid_eax
= 0xC0000001, .cpuid_reg
= R_EDX
,
183 .feat_names
= kvm_feature_name
,
184 .cpuid_eax
= KVM_CPUID_FEATURES
, .cpuid_reg
= R_EAX
,
187 .feat_names
= svm_feature_name
,
188 .cpuid_eax
= 0x8000000A, .cpuid_reg
= R_EDX
,
191 .feat_names
= cpuid_7_0_ebx_feature_name
,
193 .cpuid_needs_ecx
= true, .cpuid_ecx
= 0,
198 typedef struct X86RegisterInfo32
{
199 /* Name of register */
201 /* QAPI enum value register */
202 X86CPURegister32 qapi_enum
;
205 #define REGISTER(reg) \
206 [R_##reg] = { .name = #reg, .qapi_enum = X86_C_P_U_REGISTER32_##reg }
207 X86RegisterInfo32 x86_reg_info_32
[CPU_NB_REGS32
] = {
220 const char *get_register_name_32(unsigned int reg
)
222 if (reg
>= CPU_NB_REGS32
) {
225 return x86_reg_info_32
[reg
].name
;
228 /* collects per-function cpuid data
230 typedef struct model_features_t
{
231 uint32_t *guest_feat
;
233 FeatureWord feat_word
;
237 int enforce_cpuid
= 0;
239 static uint32_t kvm_default_features
= (1 << KVM_FEATURE_CLOCKSOURCE
) |
240 (1 << KVM_FEATURE_NOP_IO_DELAY
) |
241 (1 << KVM_FEATURE_CLOCKSOURCE2
) |
242 (1 << KVM_FEATURE_ASYNC_PF
) |
243 (1 << KVM_FEATURE_STEAL_TIME
) |
244 (1 << KVM_FEATURE_PV_EOI
) |
245 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT
);
247 void disable_kvm_pv_eoi(void)
249 kvm_default_features
&= ~(1UL << KVM_FEATURE_PV_EOI
);
252 void host_cpuid(uint32_t function
, uint32_t count
,
253 uint32_t *eax
, uint32_t *ebx
, uint32_t *ecx
, uint32_t *edx
)
255 #if defined(CONFIG_KVM)
260 : "=a"(vec
[0]), "=b"(vec
[1]),
261 "=c"(vec
[2]), "=d"(vec
[3])
262 : "0"(function
), "c"(count
) : "cc");
264 asm volatile("pusha \n\t"
266 "mov %%eax, 0(%2) \n\t"
267 "mov %%ebx, 4(%2) \n\t"
268 "mov %%ecx, 8(%2) \n\t"
269 "mov %%edx, 12(%2) \n\t"
271 : : "a"(function
), "c"(count
), "S"(vec
)
286 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
288 /* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
289 * a substring. ex if !NULL points to the first char after a substring,
290 * otherwise the string is assumed to sized by a terminating nul.
291 * Return lexical ordering of *s1:*s2.
293 static int sstrcmp(const char *s1
, const char *e1
, const char *s2
,
297 if (!*s1
|| !*s2
|| *s1
!= *s2
)
300 if (s1
== e1
&& s2
== e2
)
309 /* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
310 * '|' delimited (possibly empty) strings in which case search for a match
311 * within the alternatives proceeds left to right. Return 0 for success,
312 * non-zero otherwise.
314 static int altcmp(const char *s
, const char *e
, const char *altstr
)
318 for (q
= p
= altstr
; ; ) {
319 while (*p
&& *p
!= '|')
321 if ((q
== p
&& !*s
) || (q
!= p
&& !sstrcmp(s
, e
, q
, p
)))
330 /* search featureset for flag *[s..e), if found set corresponding bit in
331 * *pval and return true, otherwise return false
333 static bool lookup_feature(uint32_t *pval
, const char *s
, const char *e
,
334 const char **featureset
)
340 for (mask
= 1, ppc
= featureset
; mask
; mask
<<= 1, ++ppc
) {
341 if (*ppc
&& !altcmp(s
, e
, *ppc
)) {
349 static void add_flagname_to_bitmaps(const char *flagname
,
350 FeatureWordArray words
)
353 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
354 FeatureWordInfo
*wi
= &feature_word_info
[w
];
355 if (wi
->feat_names
&&
356 lookup_feature(&words
[w
], flagname
, NULL
, wi
->feat_names
)) {
360 if (w
== FEATURE_WORDS
) {
361 fprintf(stderr
, "CPU feature %s not found\n", flagname
);
365 typedef struct x86_def_t
{
370 /* vendor is zero-terminated, 12 character ASCII string */
371 char vendor
[CPUID_VENDOR_SZ
+ 1];
375 FeatureWordArray features
;
379 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
380 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
381 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
382 #define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
383 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
384 CPUID_PSE36 | CPUID_FXSR)
385 #define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
386 #define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
387 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
388 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
389 CPUID_PAE | CPUID_SEP | CPUID_APIC)
391 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
392 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
393 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
394 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
395 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
396 /* partly implemented:
397 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64)
398 CPUID_PSE36 (needed for Solaris) */
400 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
401 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \
402 CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \
403 CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \
404 CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR)
406 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX,
407 CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA,
408 CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA,
409 CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE,
410 CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C,
412 #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \
413 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
414 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT)
416 CPUID_EXT2_PDPE1GB */
417 #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
418 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
419 #define TCG_SVM_FEATURES 0
420 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP \
421 CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)
423 CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
424 CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
425 CPUID_7_0_EBX_RDSEED */
427 /* built-in CPU model definitions
429 static x86_def_t builtin_x86_defs
[] = {
433 .vendor
= CPUID_VENDOR_AMD
,
437 .features
[FEAT_1_EDX
] =
439 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
441 .features
[FEAT_1_ECX
] =
442 CPUID_EXT_SSE3
| CPUID_EXT_CX16
| CPUID_EXT_POPCNT
,
443 .features
[FEAT_8000_0001_EDX
] =
444 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
445 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
446 .features
[FEAT_8000_0001_ECX
] =
447 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
448 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
449 .xlevel
= 0x8000000A,
454 .vendor
= CPUID_VENDOR_AMD
,
458 .features
[FEAT_1_EDX
] =
460 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
461 CPUID_PSE36
| CPUID_VME
| CPUID_HT
,
462 .features
[FEAT_1_ECX
] =
463 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_CX16
|
465 .features
[FEAT_8000_0001_EDX
] =
466 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
467 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
|
468 CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
| CPUID_EXT2_MMXEXT
|
469 CPUID_EXT2_FFXSR
| CPUID_EXT2_PDPE1GB
| CPUID_EXT2_RDTSCP
,
470 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
472 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
473 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
474 .features
[FEAT_8000_0001_ECX
] =
475 CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
476 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
477 .features
[FEAT_SVM
] =
478 CPUID_SVM_NPT
| CPUID_SVM_LBRV
,
479 .xlevel
= 0x8000001A,
480 .model_id
= "AMD Phenom(tm) 9550 Quad-Core Processor"
485 .vendor
= CPUID_VENDOR_INTEL
,
489 .features
[FEAT_1_EDX
] =
491 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
492 CPUID_PSE36
| CPUID_VME
| CPUID_DTS
| CPUID_ACPI
| CPUID_SS
|
493 CPUID_HT
| CPUID_TM
| CPUID_PBE
,
494 .features
[FEAT_1_ECX
] =
495 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
496 CPUID_EXT_DTES64
| CPUID_EXT_DSCPL
| CPUID_EXT_VMX
| CPUID_EXT_EST
|
497 CPUID_EXT_TM2
| CPUID_EXT_CX16
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
498 .features
[FEAT_8000_0001_EDX
] =
499 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
500 .features
[FEAT_8000_0001_ECX
] =
502 .xlevel
= 0x80000008,
503 .model_id
= "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
508 .vendor
= CPUID_VENDOR_INTEL
,
512 /* Missing: CPUID_VME, CPUID_HT */
513 .features
[FEAT_1_EDX
] =
515 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
517 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
518 .features
[FEAT_1_ECX
] =
519 CPUID_EXT_SSE3
| CPUID_EXT_CX16
,
520 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
521 .features
[FEAT_8000_0001_EDX
] =
522 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
523 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
524 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
525 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
526 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
527 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
528 .features
[FEAT_8000_0001_ECX
] =
530 .xlevel
= 0x80000008,
531 .model_id
= "Common KVM processor"
536 .vendor
= CPUID_VENDOR_INTEL
,
540 .features
[FEAT_1_EDX
] =
542 .features
[FEAT_1_ECX
] =
543 CPUID_EXT_SSE3
| CPUID_EXT_POPCNT
,
544 .xlevel
= 0x80000004,
549 .vendor
= CPUID_VENDOR_INTEL
,
553 .features
[FEAT_1_EDX
] =
555 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_PSE36
,
556 .features
[FEAT_1_ECX
] =
558 .features
[FEAT_8000_0001_EDX
] =
559 PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
,
560 .features
[FEAT_8000_0001_ECX
] =
562 .xlevel
= 0x80000008,
563 .model_id
= "Common 32-bit KVM processor"
568 .vendor
= CPUID_VENDOR_INTEL
,
572 .features
[FEAT_1_EDX
] =
573 PPRO_FEATURES
| CPUID_VME
|
574 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_DTS
| CPUID_ACPI
|
575 CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
576 .features
[FEAT_1_ECX
] =
577 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_VMX
|
578 CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
579 .features
[FEAT_8000_0001_EDX
] =
581 .xlevel
= 0x80000008,
582 .model_id
= "Genuine Intel(R) CPU T2600 @ 2.16GHz",
587 .vendor
= CPUID_VENDOR_INTEL
,
591 .features
[FEAT_1_EDX
] =
598 .vendor
= CPUID_VENDOR_INTEL
,
602 .features
[FEAT_1_EDX
] =
609 .vendor
= CPUID_VENDOR_INTEL
,
613 .features
[FEAT_1_EDX
] =
620 .vendor
= CPUID_VENDOR_INTEL
,
624 .features
[FEAT_1_EDX
] =
631 .vendor
= CPUID_VENDOR_AMD
,
635 .features
[FEAT_1_EDX
] =
636 PPRO_FEATURES
| CPUID_PSE36
| CPUID_VME
| CPUID_MTRR
|
638 .features
[FEAT_8000_0001_EDX
] =
639 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
640 CPUID_EXT2_MMXEXT
| CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
,
641 .xlevel
= 0x80000008,
645 /* original is on level 10 */
647 .vendor
= CPUID_VENDOR_INTEL
,
651 .features
[FEAT_1_EDX
] =
653 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_VME
| CPUID_DTS
|
654 CPUID_ACPI
| CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
655 /* Some CPUs got no CPUID_SEP */
656 .features
[FEAT_1_ECX
] =
657 CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
658 CPUID_EXT_DSCPL
| CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
|
660 .features
[FEAT_8000_0001_EDX
] =
661 (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
663 .features
[FEAT_8000_0001_ECX
] =
665 .xlevel
= 0x8000000A,
666 .model_id
= "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
671 .vendor
= CPUID_VENDOR_INTEL
,
675 .features
[FEAT_1_EDX
] =
676 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
677 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
678 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
679 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
680 CPUID_DE
| CPUID_FP87
,
681 .features
[FEAT_1_ECX
] =
682 CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
683 .features
[FEAT_8000_0001_EDX
] =
684 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
685 .features
[FEAT_8000_0001_ECX
] =
687 .xlevel
= 0x8000000A,
688 .model_id
= "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
693 .vendor
= CPUID_VENDOR_INTEL
,
697 .features
[FEAT_1_EDX
] =
698 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
699 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
700 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
701 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
702 CPUID_DE
| CPUID_FP87
,
703 .features
[FEAT_1_ECX
] =
704 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
706 .features
[FEAT_8000_0001_EDX
] =
707 CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
708 .features
[FEAT_8000_0001_ECX
] =
710 .xlevel
= 0x8000000A,
711 .model_id
= "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
716 .vendor
= CPUID_VENDOR_INTEL
,
720 .features
[FEAT_1_EDX
] =
721 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
722 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
723 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
724 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
725 CPUID_DE
| CPUID_FP87
,
726 .features
[FEAT_1_ECX
] =
727 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
728 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
729 .features
[FEAT_8000_0001_EDX
] =
730 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
731 .features
[FEAT_8000_0001_ECX
] =
733 .xlevel
= 0x8000000A,
734 .model_id
= "Intel Core i7 9xx (Nehalem Class Core i7)",
739 .vendor
= CPUID_VENDOR_INTEL
,
743 .features
[FEAT_1_EDX
] =
744 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
745 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
746 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
747 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
748 CPUID_DE
| CPUID_FP87
,
749 .features
[FEAT_1_ECX
] =
750 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
751 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
752 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
753 .features
[FEAT_8000_0001_EDX
] =
754 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
755 .features
[FEAT_8000_0001_ECX
] =
757 .xlevel
= 0x8000000A,
758 .model_id
= "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
761 .name
= "SandyBridge",
763 .vendor
= CPUID_VENDOR_INTEL
,
767 .features
[FEAT_1_EDX
] =
768 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
769 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
770 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
771 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
772 CPUID_DE
| CPUID_FP87
,
773 .features
[FEAT_1_ECX
] =
774 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
775 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_POPCNT
|
776 CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
777 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
779 .features
[FEAT_8000_0001_EDX
] =
780 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
782 .features
[FEAT_8000_0001_ECX
] =
784 .xlevel
= 0x8000000A,
785 .model_id
= "Intel Xeon E312xx (Sandy Bridge)",
790 .vendor
= CPUID_VENDOR_INTEL
,
794 .features
[FEAT_1_EDX
] =
795 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
796 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
797 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
798 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
799 CPUID_DE
| CPUID_FP87
,
800 .features
[FEAT_1_ECX
] =
801 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
802 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
803 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
804 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
805 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
807 .features
[FEAT_8000_0001_EDX
] =
808 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
810 .features
[FEAT_8000_0001_ECX
] =
812 .features
[FEAT_7_0_EBX
] =
813 CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
814 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
815 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
817 .xlevel
= 0x8000000A,
818 .model_id
= "Intel Core Processor (Haswell)",
821 .name
= "Opteron_G1",
823 .vendor
= CPUID_VENDOR_AMD
,
827 .features
[FEAT_1_EDX
] =
828 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
829 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
830 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
831 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
832 CPUID_DE
| CPUID_FP87
,
833 .features
[FEAT_1_ECX
] =
835 .features
[FEAT_8000_0001_EDX
] =
836 CPUID_EXT2_LM
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
837 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
838 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
839 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
840 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
841 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
842 .xlevel
= 0x80000008,
843 .model_id
= "AMD Opteron 240 (Gen 1 Class Opteron)",
846 .name
= "Opteron_G2",
848 .vendor
= CPUID_VENDOR_AMD
,
852 .features
[FEAT_1_EDX
] =
853 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
854 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
855 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
856 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
857 CPUID_DE
| CPUID_FP87
,
858 .features
[FEAT_1_ECX
] =
859 CPUID_EXT_CX16
| CPUID_EXT_SSE3
,
860 .features
[FEAT_8000_0001_EDX
] =
861 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
862 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
863 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
864 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
865 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
866 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
867 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
868 .features
[FEAT_8000_0001_ECX
] =
869 CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
870 .xlevel
= 0x80000008,
871 .model_id
= "AMD Opteron 22xx (Gen 2 Class Opteron)",
874 .name
= "Opteron_G3",
876 .vendor
= CPUID_VENDOR_AMD
,
880 .features
[FEAT_1_EDX
] =
881 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
882 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
883 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
884 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
885 CPUID_DE
| CPUID_FP87
,
886 .features
[FEAT_1_ECX
] =
887 CPUID_EXT_POPCNT
| CPUID_EXT_CX16
| CPUID_EXT_MONITOR
|
889 .features
[FEAT_8000_0001_EDX
] =
890 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
891 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
892 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
893 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
894 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
895 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
896 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
897 .features
[FEAT_8000_0001_ECX
] =
898 CPUID_EXT3_MISALIGNSSE
| CPUID_EXT3_SSE4A
|
899 CPUID_EXT3_ABM
| CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
900 .xlevel
= 0x80000008,
901 .model_id
= "AMD Opteron 23xx (Gen 3 Class Opteron)",
904 .name
= "Opteron_G4",
906 .vendor
= CPUID_VENDOR_AMD
,
910 .features
[FEAT_1_EDX
] =
911 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
912 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
913 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
914 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
915 CPUID_DE
| CPUID_FP87
,
916 .features
[FEAT_1_ECX
] =
917 CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
918 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
919 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
921 .features
[FEAT_8000_0001_EDX
] =
922 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
923 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
924 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
925 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
926 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
927 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
928 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
929 .features
[FEAT_8000_0001_ECX
] =
930 CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
931 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
932 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
934 .xlevel
= 0x8000001A,
935 .model_id
= "AMD Opteron 62xx class CPU",
938 .name
= "Opteron_G5",
940 .vendor
= CPUID_VENDOR_AMD
,
944 .features
[FEAT_1_EDX
] =
945 CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
946 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
947 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
948 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
949 CPUID_DE
| CPUID_FP87
,
950 .features
[FEAT_1_ECX
] =
951 CPUID_EXT_F16C
| CPUID_EXT_AVX
| CPUID_EXT_XSAVE
|
952 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
953 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_FMA
|
954 CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
955 .features
[FEAT_8000_0001_EDX
] =
956 CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
957 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
958 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
959 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
960 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
961 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
962 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
963 .features
[FEAT_8000_0001_ECX
] =
964 CPUID_EXT3_TBM
| CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
965 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
966 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
968 .xlevel
= 0x8000001A,
969 .model_id
= "AMD Opteron 63xx class CPU",
974 * x86_cpu_compat_set_features:
975 * @cpu_model: CPU model name to be changed. If NULL, all CPU models are changed
976 * @w: Identifies the feature word to be changed.
977 * @feat_add: Feature bits to be added to feature word
978 * @feat_remove: Feature bits to be removed from feature word
980 * Change CPU model feature bits for compatibility.
982 * This function may be used by machine-type compatibility functions
983 * to enable or disable feature bits on specific CPU models.
985 void x86_cpu_compat_set_features(const char *cpu_model
, FeatureWord w
,
986 uint32_t feat_add
, uint32_t feat_remove
)
990 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
991 def
= &builtin_x86_defs
[i
];
992 if (!cpu_model
|| !strcmp(cpu_model
, def
->name
)) {
993 def
->features
[w
] |= feat_add
;
994 def
->features
[w
] &= ~feat_remove
;
1000 static int cpu_x86_fill_model_id(char *str
)
1002 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1005 for (i
= 0; i
< 3; i
++) {
1006 host_cpuid(0x80000002 + i
, 0, &eax
, &ebx
, &ecx
, &edx
);
1007 memcpy(str
+ i
* 16 + 0, &eax
, 4);
1008 memcpy(str
+ i
* 16 + 4, &ebx
, 4);
1009 memcpy(str
+ i
* 16 + 8, &ecx
, 4);
1010 memcpy(str
+ i
* 16 + 12, &edx
, 4);
1016 /* Fill a x86_def_t struct with information about the host CPU, and
1017 * the CPU features supported by the host hardware + host kernel
1019 * This function may be called only if KVM is enabled.
1021 static void kvm_cpu_fill_host(x86_def_t
*x86_cpu_def
)
1024 KVMState
*s
= kvm_state
;
1025 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
1027 assert(kvm_enabled());
1029 x86_cpu_def
->name
= "host";
1030 host_cpuid(0x0, 0, &eax
, &ebx
, &ecx
, &edx
);
1031 x86_cpu_vendor_words2str(x86_cpu_def
->vendor
, ebx
, edx
, ecx
);
1033 host_cpuid(0x1, 0, &eax
, &ebx
, &ecx
, &edx
);
1034 x86_cpu_def
->family
= ((eax
>> 8) & 0x0F) + ((eax
>> 20) & 0xFF);
1035 x86_cpu_def
->model
= ((eax
>> 4) & 0x0F) | ((eax
& 0xF0000) >> 12);
1036 x86_cpu_def
->stepping
= eax
& 0x0F;
1038 x86_cpu_def
->level
= kvm_arch_get_supported_cpuid(s
, 0x0, 0, R_EAX
);
1039 x86_cpu_def
->features
[FEAT_1_EDX
] =
1040 kvm_arch_get_supported_cpuid(s
, 0x1, 0, R_EDX
);
1041 x86_cpu_def
->features
[FEAT_1_ECX
] =
1042 kvm_arch_get_supported_cpuid(s
, 0x1, 0, R_ECX
);
1044 if (x86_cpu_def
->level
>= 7) {
1045 x86_cpu_def
->features
[FEAT_7_0_EBX
] =
1046 kvm_arch_get_supported_cpuid(s
, 0x7, 0, R_EBX
);
1048 x86_cpu_def
->features
[FEAT_7_0_EBX
] = 0;
1051 x86_cpu_def
->xlevel
= kvm_arch_get_supported_cpuid(s
, 0x80000000, 0, R_EAX
);
1052 x86_cpu_def
->features
[FEAT_8000_0001_EDX
] =
1053 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_EDX
);
1054 x86_cpu_def
->features
[FEAT_8000_0001_ECX
] =
1055 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_ECX
);
1057 cpu_x86_fill_model_id(x86_cpu_def
->model_id
);
1059 /* Call Centaur's CPUID instruction. */
1060 if (!strcmp(x86_cpu_def
->vendor
, CPUID_VENDOR_VIA
)) {
1061 host_cpuid(0xC0000000, 0, &eax
, &ebx
, &ecx
, &edx
);
1062 eax
= kvm_arch_get_supported_cpuid(s
, 0xC0000000, 0, R_EAX
);
1063 if (eax
>= 0xC0000001) {
1064 /* Support VIA max extended level */
1065 x86_cpu_def
->xlevel2
= eax
;
1066 host_cpuid(0xC0000001, 0, &eax
, &ebx
, &ecx
, &edx
);
1067 x86_cpu_def
->features
[FEAT_C000_0001_EDX
] =
1068 kvm_arch_get_supported_cpuid(s
, 0xC0000001, 0, R_EDX
);
1072 /* Other KVM-specific feature fields: */
1073 x86_cpu_def
->features
[FEAT_SVM
] =
1074 kvm_arch_get_supported_cpuid(s
, 0x8000000A, 0, R_EDX
);
1075 x86_cpu_def
->features
[FEAT_KVM
] =
1076 kvm_arch_get_supported_cpuid(s
, KVM_CPUID_FEATURES
, 0, R_EAX
);
1078 #endif /* CONFIG_KVM */
1081 static int unavailable_host_feature(FeatureWordInfo
*f
, uint32_t mask
)
1085 for (i
= 0; i
< 32; ++i
)
1086 if (1 << i
& mask
) {
1087 const char *reg
= get_register_name_32(f
->cpuid_reg
);
1089 fprintf(stderr
, "warning: host doesn't support requested feature: "
1090 "CPUID.%02XH:%s%s%s [bit %d]\n",
1092 f
->feat_names
[i
] ? "." : "",
1093 f
->feat_names
[i
] ? f
->feat_names
[i
] : "", i
);
1099 /* Check if all requested cpu flags are making their way to the guest
1101 * Returns 0 if all flags are supported by the host, non-zero otherwise.
1103 * This function may be called only if KVM is enabled.
1105 static int kvm_check_features_against_host(X86CPU
*cpu
)
1107 CPUX86State
*env
= &cpu
->env
;
1111 struct model_features_t ft
[] = {
1112 {&env
->features
[FEAT_1_EDX
],
1113 &host_def
.features
[FEAT_1_EDX
],
1115 {&env
->features
[FEAT_1_ECX
],
1116 &host_def
.features
[FEAT_1_ECX
],
1118 {&env
->features
[FEAT_8000_0001_EDX
],
1119 &host_def
.features
[FEAT_8000_0001_EDX
],
1120 FEAT_8000_0001_EDX
},
1121 {&env
->features
[FEAT_8000_0001_ECX
],
1122 &host_def
.features
[FEAT_8000_0001_ECX
],
1123 FEAT_8000_0001_ECX
},
1124 {&env
->features
[FEAT_C000_0001_EDX
],
1125 &host_def
.features
[FEAT_C000_0001_EDX
],
1126 FEAT_C000_0001_EDX
},
1127 {&env
->features
[FEAT_7_0_EBX
],
1128 &host_def
.features
[FEAT_7_0_EBX
],
1130 {&env
->features
[FEAT_SVM
],
1131 &host_def
.features
[FEAT_SVM
],
1133 {&env
->features
[FEAT_KVM
],
1134 &host_def
.features
[FEAT_KVM
],
1138 assert(kvm_enabled());
1140 kvm_cpu_fill_host(&host_def
);
1141 for (rv
= 0, i
= 0; i
< ARRAY_SIZE(ft
); ++i
) {
1142 FeatureWord w
= ft
[i
].feat_word
;
1143 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1144 for (mask
= 1; mask
; mask
<<= 1) {
1145 if (*ft
[i
].guest_feat
& mask
&&
1146 !(*ft
[i
].host_feat
& mask
)) {
1147 unavailable_host_feature(wi
, mask
);
1155 static void x86_cpuid_version_get_family(Object
*obj
, Visitor
*v
, void *opaque
,
1156 const char *name
, Error
**errp
)
1158 X86CPU
*cpu
= X86_CPU(obj
);
1159 CPUX86State
*env
= &cpu
->env
;
1162 value
= (env
->cpuid_version
>> 8) & 0xf;
1164 value
+= (env
->cpuid_version
>> 20) & 0xff;
1166 visit_type_int(v
, &value
, name
, errp
);
1169 static void x86_cpuid_version_set_family(Object
*obj
, Visitor
*v
, void *opaque
,
1170 const char *name
, Error
**errp
)
1172 X86CPU
*cpu
= X86_CPU(obj
);
1173 CPUX86State
*env
= &cpu
->env
;
1174 const int64_t min
= 0;
1175 const int64_t max
= 0xff + 0xf;
1178 visit_type_int(v
, &value
, name
, errp
);
1179 if (error_is_set(errp
)) {
1182 if (value
< min
|| value
> max
) {
1183 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1184 name
? name
: "null", value
, min
, max
);
1188 env
->cpuid_version
&= ~0xff00f00;
1190 env
->cpuid_version
|= 0xf00 | ((value
- 0x0f) << 20);
1192 env
->cpuid_version
|= value
<< 8;
1196 static void x86_cpuid_version_get_model(Object
*obj
, Visitor
*v
, void *opaque
,
1197 const char *name
, Error
**errp
)
1199 X86CPU
*cpu
= X86_CPU(obj
);
1200 CPUX86State
*env
= &cpu
->env
;
1203 value
= (env
->cpuid_version
>> 4) & 0xf;
1204 value
|= ((env
->cpuid_version
>> 16) & 0xf) << 4;
1205 visit_type_int(v
, &value
, name
, errp
);
1208 static void x86_cpuid_version_set_model(Object
*obj
, Visitor
*v
, void *opaque
,
1209 const char *name
, Error
**errp
)
1211 X86CPU
*cpu
= X86_CPU(obj
);
1212 CPUX86State
*env
= &cpu
->env
;
1213 const int64_t min
= 0;
1214 const int64_t max
= 0xff;
1217 visit_type_int(v
, &value
, name
, errp
);
1218 if (error_is_set(errp
)) {
1221 if (value
< min
|| value
> max
) {
1222 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1223 name
? name
: "null", value
, min
, max
);
1227 env
->cpuid_version
&= ~0xf00f0;
1228 env
->cpuid_version
|= ((value
& 0xf) << 4) | ((value
>> 4) << 16);
1231 static void x86_cpuid_version_get_stepping(Object
*obj
, Visitor
*v
,
1232 void *opaque
, const char *name
,
1235 X86CPU
*cpu
= X86_CPU(obj
);
1236 CPUX86State
*env
= &cpu
->env
;
1239 value
= env
->cpuid_version
& 0xf;
1240 visit_type_int(v
, &value
, name
, errp
);
1243 static void x86_cpuid_version_set_stepping(Object
*obj
, Visitor
*v
,
1244 void *opaque
, const char *name
,
1247 X86CPU
*cpu
= X86_CPU(obj
);
1248 CPUX86State
*env
= &cpu
->env
;
1249 const int64_t min
= 0;
1250 const int64_t max
= 0xf;
1253 visit_type_int(v
, &value
, name
, errp
);
1254 if (error_is_set(errp
)) {
1257 if (value
< min
|| value
> max
) {
1258 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1259 name
? name
: "null", value
, min
, max
);
1263 env
->cpuid_version
&= ~0xf;
1264 env
->cpuid_version
|= value
& 0xf;
1267 static void x86_cpuid_get_level(Object
*obj
, Visitor
*v
, void *opaque
,
1268 const char *name
, Error
**errp
)
1270 X86CPU
*cpu
= X86_CPU(obj
);
1272 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1275 static void x86_cpuid_set_level(Object
*obj
, Visitor
*v
, void *opaque
,
1276 const char *name
, Error
**errp
)
1278 X86CPU
*cpu
= X86_CPU(obj
);
1280 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1283 static void x86_cpuid_get_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1284 const char *name
, Error
**errp
)
1286 X86CPU
*cpu
= X86_CPU(obj
);
1288 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1291 static void x86_cpuid_set_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1292 const char *name
, Error
**errp
)
1294 X86CPU
*cpu
= X86_CPU(obj
);
1296 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1299 static char *x86_cpuid_get_vendor(Object
*obj
, Error
**errp
)
1301 X86CPU
*cpu
= X86_CPU(obj
);
1302 CPUX86State
*env
= &cpu
->env
;
1305 value
= (char *)g_malloc(CPUID_VENDOR_SZ
+ 1);
1306 x86_cpu_vendor_words2str(value
, env
->cpuid_vendor1
, env
->cpuid_vendor2
,
1307 env
->cpuid_vendor3
);
1311 static void x86_cpuid_set_vendor(Object
*obj
, const char *value
,
1314 X86CPU
*cpu
= X86_CPU(obj
);
1315 CPUX86State
*env
= &cpu
->env
;
1318 if (strlen(value
) != CPUID_VENDOR_SZ
) {
1319 error_set(errp
, QERR_PROPERTY_VALUE_BAD
, "",
1324 env
->cpuid_vendor1
= 0;
1325 env
->cpuid_vendor2
= 0;
1326 env
->cpuid_vendor3
= 0;
1327 for (i
= 0; i
< 4; i
++) {
1328 env
->cpuid_vendor1
|= ((uint8_t)value
[i
]) << (8 * i
);
1329 env
->cpuid_vendor2
|= ((uint8_t)value
[i
+ 4]) << (8 * i
);
1330 env
->cpuid_vendor3
|= ((uint8_t)value
[i
+ 8]) << (8 * i
);
1334 static char *x86_cpuid_get_model_id(Object
*obj
, Error
**errp
)
1336 X86CPU
*cpu
= X86_CPU(obj
);
1337 CPUX86State
*env
= &cpu
->env
;
1341 value
= g_malloc(48 + 1);
1342 for (i
= 0; i
< 48; i
++) {
1343 value
[i
] = env
->cpuid_model
[i
>> 2] >> (8 * (i
& 3));
1349 static void x86_cpuid_set_model_id(Object
*obj
, const char *model_id
,
1352 X86CPU
*cpu
= X86_CPU(obj
);
1353 CPUX86State
*env
= &cpu
->env
;
1356 if (model_id
== NULL
) {
1359 len
= strlen(model_id
);
1360 memset(env
->cpuid_model
, 0, 48);
1361 for (i
= 0; i
< 48; i
++) {
1365 c
= (uint8_t)model_id
[i
];
1367 env
->cpuid_model
[i
>> 2] |= c
<< (8 * (i
& 3));
1371 static void x86_cpuid_get_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1372 const char *name
, Error
**errp
)
1374 X86CPU
*cpu
= X86_CPU(obj
);
1377 value
= cpu
->env
.tsc_khz
* 1000;
1378 visit_type_int(v
, &value
, name
, errp
);
1381 static void x86_cpuid_set_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1382 const char *name
, Error
**errp
)
1384 X86CPU
*cpu
= X86_CPU(obj
);
1385 const int64_t min
= 0;
1386 const int64_t max
= INT64_MAX
;
1389 visit_type_int(v
, &value
, name
, errp
);
1390 if (error_is_set(errp
)) {
1393 if (value
< min
|| value
> max
) {
1394 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1395 name
? name
: "null", value
, min
, max
);
1399 cpu
->env
.tsc_khz
= value
/ 1000;
1402 static void x86_cpuid_get_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1403 const char *name
, Error
**errp
)
1405 X86CPU
*cpu
= X86_CPU(obj
);
1406 int64_t value
= cpu
->env
.cpuid_apic_id
;
1408 visit_type_int(v
, &value
, name
, errp
);
1411 static void x86_cpuid_set_apic_id(Object
*obj
, Visitor
*v
, void *opaque
,
1412 const char *name
, Error
**errp
)
1414 X86CPU
*cpu
= X86_CPU(obj
);
1415 DeviceState
*dev
= DEVICE(obj
);
1416 const int64_t min
= 0;
1417 const int64_t max
= UINT32_MAX
;
1418 Error
*error
= NULL
;
1421 if (dev
->realized
) {
1422 error_setg(errp
, "Attempt to set property '%s' on '%s' after "
1423 "it was realized", name
, object_get_typename(obj
));
1427 visit_type_int(v
, &value
, name
, &error
);
1429 error_propagate(errp
, error
);
1432 if (value
< min
|| value
> max
) {
1433 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
1434 " (minimum: %" PRId64
", maximum: %" PRId64
")" ,
1435 object_get_typename(obj
), name
, value
, min
, max
);
1439 if ((value
!= cpu
->env
.cpuid_apic_id
) && cpu_exists(value
)) {
1440 error_setg(errp
, "CPU with APIC ID %" PRIi64
" exists", value
);
1443 cpu
->env
.cpuid_apic_id
= value
;
1446 /* Generic getter for "feature-words" and "filtered-features" properties */
1447 static void x86_cpu_get_feature_words(Object
*obj
, Visitor
*v
, void *opaque
,
1448 const char *name
, Error
**errp
)
1450 uint32_t *array
= (uint32_t *)opaque
;
1453 X86CPUFeatureWordInfo word_infos
[FEATURE_WORDS
] = { };
1454 X86CPUFeatureWordInfoList list_entries
[FEATURE_WORDS
] = { };
1455 X86CPUFeatureWordInfoList
*list
= NULL
;
1457 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1458 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1459 X86CPUFeatureWordInfo
*qwi
= &word_infos
[w
];
1460 qwi
->cpuid_input_eax
= wi
->cpuid_eax
;
1461 qwi
->has_cpuid_input_ecx
= wi
->cpuid_needs_ecx
;
1462 qwi
->cpuid_input_ecx
= wi
->cpuid_ecx
;
1463 qwi
->cpuid_register
= x86_reg_info_32
[wi
->cpuid_reg
].qapi_enum
;
1464 qwi
->features
= array
[w
];
1466 /* List will be in reverse order, but order shouldn't matter */
1467 list_entries
[w
].next
= list
;
1468 list_entries
[w
].value
= &word_infos
[w
];
1469 list
= &list_entries
[w
];
1472 visit_type_X86CPUFeatureWordInfoList(v
, &list
, "feature-words", &err
);
1473 error_propagate(errp
, err
);
1476 static int cpu_x86_find_by_name(X86CPU
*cpu
, x86_def_t
*x86_cpu_def
,
1486 if (kvm_enabled() && strcmp(name
, "host") == 0) {
1487 kvm_cpu_fill_host(x86_cpu_def
);
1488 object_property_set_bool(OBJECT(cpu
), true, "pmu", &err
);
1489 assert_no_error(err
);
1493 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1494 def
= &builtin_x86_defs
[i
];
1495 if (strcmp(name
, def
->name
) == 0) {
1496 memcpy(x86_cpu_def
, def
, sizeof(*def
));
1497 /* sysenter isn't supported in compatibility mode on AMD,
1498 * syscall isn't supported in compatibility mode on Intel.
1499 * Normally we advertise the actual CPU vendor, but you can
1500 * override this using the 'vendor' property if you want to use
1501 * KVM's sysenter/syscall emulation in compatibility mode and
1502 * when doing cross vendor migration
1504 if (kvm_enabled()) {
1505 uint32_t ebx
= 0, ecx
= 0, edx
= 0;
1506 host_cpuid(0, 0, NULL
, &ebx
, &ecx
, &edx
);
1507 x86_cpu_vendor_words2str(x86_cpu_def
->vendor
, ebx
, edx
, ecx
);
1516 /* Convert all '_' in a feature string option name to '-', to make feature
1517 * name conform to QOM property naming rule, which uses '-' instead of '_'.
1519 static inline void feat2prop(char *s
)
1521 while ((s
= strchr(s
, '_'))) {
1526 /* Parse "+feature,-feature,feature=foo" CPU feature string
1528 static void cpu_x86_parse_featurestr(X86CPU
*cpu
, char *features
, Error
**errp
)
1530 char *featurestr
; /* Single 'key=value" string being parsed */
1531 /* Features to be added */
1532 FeatureWordArray plus_features
= { 0 };
1533 /* Features to be removed */
1534 FeatureWordArray minus_features
= { 0 };
1536 CPUX86State
*env
= &cpu
->env
;
1538 featurestr
= features
? strtok(features
, ",") : NULL
;
1540 while (featurestr
) {
1542 if (featurestr
[0] == '+') {
1543 add_flagname_to_bitmaps(featurestr
+ 1, plus_features
);
1544 } else if (featurestr
[0] == '-') {
1545 add_flagname_to_bitmaps(featurestr
+ 1, minus_features
);
1546 } else if ((val
= strchr(featurestr
, '='))) {
1548 feat2prop(featurestr
);
1549 if (!strcmp(featurestr
, "family")) {
1550 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1551 } else if (!strcmp(featurestr
, "model")) {
1552 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1553 } else if (!strcmp(featurestr
, "stepping")) {
1554 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1555 } else if (!strcmp(featurestr
, "level")) {
1556 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1557 } else if (!strcmp(featurestr
, "xlevel")) {
1561 numvalue
= strtoul(val
, &err
, 0);
1562 if (!*val
|| *err
) {
1563 error_setg(errp
, "bad numerical value %s", val
);
1566 if (numvalue
< 0x80000000) {
1567 fprintf(stderr
, "xlevel value shall always be >= 0x80000000"
1568 ", fixup will be removed in future versions\n");
1569 numvalue
+= 0x80000000;
1571 snprintf(num
, sizeof(num
), "%" PRIu32
, numvalue
);
1572 object_property_parse(OBJECT(cpu
), num
, featurestr
, errp
);
1573 } else if (!strcmp(featurestr
, "vendor")) {
1574 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1575 } else if (!strcmp(featurestr
, "model-id")) {
1576 object_property_parse(OBJECT(cpu
), val
, featurestr
, errp
);
1577 } else if (!strcmp(featurestr
, "tsc-freq")) {
1582 tsc_freq
= strtosz_suffix_unit(val
, &err
,
1583 STRTOSZ_DEFSUFFIX_B
, 1000);
1584 if (tsc_freq
< 0 || *err
) {
1585 error_setg(errp
, "bad numerical value %s", val
);
1588 snprintf(num
, sizeof(num
), "%" PRId64
, tsc_freq
);
1589 object_property_parse(OBJECT(cpu
), num
, "tsc-frequency", errp
);
1590 } else if (!strcmp(featurestr
, "hv-spinlocks")) {
1592 const int min
= 0xFFF;
1593 numvalue
= strtoul(val
, &err
, 0);
1594 if (!*val
|| *err
) {
1595 error_setg(errp
, "bad numerical value %s", val
);
1598 if (numvalue
< min
) {
1599 fprintf(stderr
, "hv-spinlocks value shall always be >= 0x%x"
1600 ", fixup will be removed in future versions\n",
1604 cpu
->hyperv_spinlock_attempts
= numvalue
;
1606 error_setg(errp
, "unrecognized feature %s", featurestr
);
1609 } else if (!strcmp(featurestr
, "check")) {
1611 } else if (!strcmp(featurestr
, "enforce")) {
1612 check_cpuid
= enforce_cpuid
= 1;
1613 } else if (!strcmp(featurestr
, "hv_relaxed")) {
1614 cpu
->hyperv_relaxed_timing
= true;
1615 } else if (!strcmp(featurestr
, "hv_vapic")) {
1616 cpu
->hyperv_vapic
= true;
1618 error_setg(errp
, "feature string `%s' not in format (+feature|"
1619 "-feature|feature=xyz)", featurestr
);
1622 if (error_is_set(errp
)) {
1625 featurestr
= strtok(NULL
, ",");
1627 env
->features
[FEAT_1_EDX
] |= plus_features
[FEAT_1_EDX
];
1628 env
->features
[FEAT_1_ECX
] |= plus_features
[FEAT_1_ECX
];
1629 env
->features
[FEAT_8000_0001_EDX
] |= plus_features
[FEAT_8000_0001_EDX
];
1630 env
->features
[FEAT_8000_0001_ECX
] |= plus_features
[FEAT_8000_0001_ECX
];
1631 env
->features
[FEAT_C000_0001_EDX
] |= plus_features
[FEAT_C000_0001_EDX
];
1632 env
->features
[FEAT_KVM
] |= plus_features
[FEAT_KVM
];
1633 env
->features
[FEAT_SVM
] |= plus_features
[FEAT_SVM
];
1634 env
->features
[FEAT_7_0_EBX
] |= plus_features
[FEAT_7_0_EBX
];
1635 env
->features
[FEAT_1_EDX
] &= ~minus_features
[FEAT_1_EDX
];
1636 env
->features
[FEAT_1_ECX
] &= ~minus_features
[FEAT_1_ECX
];
1637 env
->features
[FEAT_8000_0001_EDX
] &= ~minus_features
[FEAT_8000_0001_EDX
];
1638 env
->features
[FEAT_8000_0001_ECX
] &= ~minus_features
[FEAT_8000_0001_ECX
];
1639 env
->features
[FEAT_C000_0001_EDX
] &= ~minus_features
[FEAT_C000_0001_EDX
];
1640 env
->features
[FEAT_KVM
] &= ~minus_features
[FEAT_KVM
];
1641 env
->features
[FEAT_SVM
] &= ~minus_features
[FEAT_SVM
];
1642 env
->features
[FEAT_7_0_EBX
] &= ~minus_features
[FEAT_7_0_EBX
];
1648 /* generate a composite string into buf of all cpuid names in featureset
1649 * selected by fbits. indicate truncation at bufsize in the event of overflow.
1650 * if flags, suppress names undefined in featureset.
1652 static void listflags(char *buf
, int bufsize
, uint32_t fbits
,
1653 const char **featureset
, uint32_t flags
)
1655 const char **p
= &featureset
[31];
1659 b
= 4 <= bufsize
? buf
+ (bufsize
-= 3) - 1 : NULL
;
1661 for (q
= buf
, bit
= 31; fbits
&& bufsize
; --p
, fbits
&= ~(1 << bit
), --bit
)
1662 if (fbits
& 1 << bit
&& (*p
|| !flags
)) {
1664 nc
= snprintf(q
, bufsize
, "%s%s", q
== buf
? "" : " ", *p
);
1666 nc
= snprintf(q
, bufsize
, "%s[%d]", q
== buf
? "" : " ", bit
);
1667 if (bufsize
<= nc
) {
1669 memcpy(b
, "...", sizeof("..."));
1678 /* generate CPU information. */
1679 void x86_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
1685 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1686 def
= &builtin_x86_defs
[i
];
1687 snprintf(buf
, sizeof(buf
), "%s", def
->name
);
1688 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", buf
, def
->model_id
);
1691 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", "host",
1692 "KVM processor with all supported host features "
1693 "(only available in KVM mode)");
1696 (*cpu_fprintf
)(f
, "\nRecognized CPUID flags:\n");
1697 for (i
= 0; i
< ARRAY_SIZE(feature_word_info
); i
++) {
1698 FeatureWordInfo
*fw
= &feature_word_info
[i
];
1700 listflags(buf
, sizeof(buf
), (uint32_t)~0, fw
->feat_names
, 1);
1701 (*cpu_fprintf
)(f
, " %s\n", buf
);
1705 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
1707 CpuDefinitionInfoList
*cpu_list
= NULL
;
1711 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); i
++) {
1712 CpuDefinitionInfoList
*entry
;
1713 CpuDefinitionInfo
*info
;
1715 def
= &builtin_x86_defs
[i
];
1716 info
= g_malloc0(sizeof(*info
));
1717 info
->name
= g_strdup(def
->name
);
1719 entry
= g_malloc0(sizeof(*entry
));
1720 entry
->value
= info
;
1721 entry
->next
= cpu_list
;
1729 static void filter_features_for_kvm(X86CPU
*cpu
)
1731 CPUX86State
*env
= &cpu
->env
;
1732 KVMState
*s
= kvm_state
;
1735 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
1736 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1737 uint32_t host_feat
= kvm_arch_get_supported_cpuid(s
, wi
->cpuid_eax
,
1740 uint32_t requested_features
= env
->features
[w
];
1741 env
->features
[w
] &= host_feat
;
1742 cpu
->filtered_features
[w
] = requested_features
& ~env
->features
[w
];
1747 static void cpu_x86_register(X86CPU
*cpu
, const char *name
, Error
**errp
)
1749 CPUX86State
*env
= &cpu
->env
;
1750 x86_def_t def1
, *def
= &def1
;
1752 memset(def
, 0, sizeof(*def
));
1754 if (cpu_x86_find_by_name(cpu
, def
, name
) < 0) {
1755 error_setg(errp
, "Unable to find CPU definition: %s", name
);
1759 if (kvm_enabled()) {
1760 def
->features
[FEAT_KVM
] |= kvm_default_features
;
1762 def
->features
[FEAT_1_ECX
] |= CPUID_EXT_HYPERVISOR
;
1764 object_property_set_str(OBJECT(cpu
), def
->vendor
, "vendor", errp
);
1765 object_property_set_int(OBJECT(cpu
), def
->level
, "level", errp
);
1766 object_property_set_int(OBJECT(cpu
), def
->family
, "family", errp
);
1767 object_property_set_int(OBJECT(cpu
), def
->model
, "model", errp
);
1768 object_property_set_int(OBJECT(cpu
), def
->stepping
, "stepping", errp
);
1769 env
->features
[FEAT_1_EDX
] = def
->features
[FEAT_1_EDX
];
1770 env
->features
[FEAT_1_ECX
] = def
->features
[FEAT_1_ECX
];
1771 env
->features
[FEAT_8000_0001_EDX
] = def
->features
[FEAT_8000_0001_EDX
];
1772 env
->features
[FEAT_8000_0001_ECX
] = def
->features
[FEAT_8000_0001_ECX
];
1773 object_property_set_int(OBJECT(cpu
), def
->xlevel
, "xlevel", errp
);
1774 env
->features
[FEAT_KVM
] = def
->features
[FEAT_KVM
];
1775 env
->features
[FEAT_SVM
] = def
->features
[FEAT_SVM
];
1776 env
->features
[FEAT_C000_0001_EDX
] = def
->features
[FEAT_C000_0001_EDX
];
1777 env
->features
[FEAT_7_0_EBX
] = def
->features
[FEAT_7_0_EBX
];
1778 env
->cpuid_xlevel2
= def
->xlevel2
;
1780 object_property_set_str(OBJECT(cpu
), def
->model_id
, "model-id", errp
);
1783 X86CPU
*cpu_x86_create(const char *cpu_model
, DeviceState
*icc_bridge
,
1788 gchar
**model_pieces
;
1789 char *name
, *features
;
1791 Error
*error
= NULL
;
1793 model_pieces
= g_strsplit(cpu_model
, ",", 2);
1794 if (!model_pieces
[0]) {
1795 error_setg(&error
, "Invalid/empty CPU model name");
1798 name
= model_pieces
[0];
1799 features
= model_pieces
[1];
1801 cpu
= X86_CPU(object_new(TYPE_X86_CPU
));
1802 #ifndef CONFIG_USER_ONLY
1803 if (icc_bridge
== NULL
) {
1804 error_setg(&error
, "Invalid icc-bridge value");
1807 qdev_set_parent_bus(DEVICE(cpu
), qdev_get_child_bus(icc_bridge
, "icc"));
1808 object_unref(OBJECT(cpu
));
1811 env
->cpu_model_str
= cpu_model
;
1813 cpu_x86_register(cpu
, name
, &error
);
1818 /* Emulate per-model subclasses for global properties */
1819 typename
= g_strdup_printf("%s-" TYPE_X86_CPU
, name
);
1820 qdev_prop_set_globals_for_type(DEVICE(cpu
), typename
, &error
);
1826 cpu_x86_parse_featurestr(cpu
, features
, &error
);
1832 if (error
!= NULL
) {
1833 error_propagate(errp
, error
);
1834 object_unref(OBJECT(cpu
));
1837 g_strfreev(model_pieces
);
1841 X86CPU
*cpu_x86_init(const char *cpu_model
)
1843 Error
*error
= NULL
;
1846 cpu
= cpu_x86_create(cpu_model
, NULL
, &error
);
1851 object_property_set_bool(OBJECT(cpu
), true, "realized", &error
);
1855 fprintf(stderr
, "%s\n", error_get_pretty(error
));
1858 object_unref(OBJECT(cpu
));
1865 #if !defined(CONFIG_USER_ONLY)
1867 void cpu_clear_apic_feature(CPUX86State
*env
)
1869 env
->features
[FEAT_1_EDX
] &= ~CPUID_APIC
;
1872 #endif /* !CONFIG_USER_ONLY */
1874 /* Initialize list of CPU models, filling some non-static fields if necessary
1876 void x86_cpudef_setup(void)
1879 static const char *model_with_versions
[] = { "qemu32", "qemu64", "athlon" };
1881 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); ++i
) {
1882 x86_def_t
*def
= &builtin_x86_defs
[i
];
1884 /* Look for specific "cpudef" models that */
1885 /* have the QEMU version in .model_id */
1886 for (j
= 0; j
< ARRAY_SIZE(model_with_versions
); j
++) {
1887 if (strcmp(model_with_versions
[j
], def
->name
) == 0) {
1888 pstrcpy(def
->model_id
, sizeof(def
->model_id
),
1889 "QEMU Virtual CPU version ");
1890 pstrcat(def
->model_id
, sizeof(def
->model_id
),
1891 qemu_get_version());
1898 static void get_cpuid_vendor(CPUX86State
*env
, uint32_t *ebx
,
1899 uint32_t *ecx
, uint32_t *edx
)
1901 *ebx
= env
->cpuid_vendor1
;
1902 *edx
= env
->cpuid_vendor2
;
1903 *ecx
= env
->cpuid_vendor3
;
1906 void cpu_x86_cpuid(CPUX86State
*env
, uint32_t index
, uint32_t count
,
1907 uint32_t *eax
, uint32_t *ebx
,
1908 uint32_t *ecx
, uint32_t *edx
)
1910 X86CPU
*cpu
= x86_env_get_cpu(env
);
1911 CPUState
*cs
= CPU(cpu
);
1913 /* test if maximum index reached */
1914 if (index
& 0x80000000) {
1915 if (index
> env
->cpuid_xlevel
) {
1916 if (env
->cpuid_xlevel2
> 0) {
1917 /* Handle the Centaur's CPUID instruction. */
1918 if (index
> env
->cpuid_xlevel2
) {
1919 index
= env
->cpuid_xlevel2
;
1920 } else if (index
< 0xC0000000) {
1921 index
= env
->cpuid_xlevel
;
1924 /* Intel documentation states that invalid EAX input will
1925 * return the same information as EAX=cpuid_level
1926 * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
1928 index
= env
->cpuid_level
;
1932 if (index
> env
->cpuid_level
)
1933 index
= env
->cpuid_level
;
1938 *eax
= env
->cpuid_level
;
1939 get_cpuid_vendor(env
, ebx
, ecx
, edx
);
1942 *eax
= env
->cpuid_version
;
1943 *ebx
= (env
->cpuid_apic_id
<< 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
1944 *ecx
= env
->features
[FEAT_1_ECX
];
1945 *edx
= env
->features
[FEAT_1_EDX
];
1946 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
1947 *ebx
|= (cs
->nr_cores
* cs
->nr_threads
) << 16;
1948 *edx
|= 1 << 28; /* HTT bit */
1952 /* cache info: needed for Pentium Pro compatibility */
1959 /* cache info: needed for Core compatibility */
1960 if (cs
->nr_cores
> 1) {
1961 *eax
= (cs
->nr_cores
- 1) << 26;
1966 case 0: /* L1 dcache info */
1972 case 1: /* L1 icache info */
1978 case 2: /* L2 cache info */
1980 if (cs
->nr_threads
> 1) {
1981 *eax
|= (cs
->nr_threads
- 1) << 14;
1987 default: /* end of info */
1996 /* mwait info: needed for Core compatibility */
1997 *eax
= 0; /* Smallest monitor-line size in bytes */
1998 *ebx
= 0; /* Largest monitor-line size in bytes */
1999 *ecx
= CPUID_MWAIT_EMX
| CPUID_MWAIT_IBE
;
2003 /* Thermal and Power Leaf */
2010 /* Structured Extended Feature Flags Enumeration Leaf */
2012 *eax
= 0; /* Maximum ECX value for sub-leaves */
2013 *ebx
= env
->features
[FEAT_7_0_EBX
]; /* Feature flags */
2014 *ecx
= 0; /* Reserved */
2015 *edx
= 0; /* Reserved */
2024 /* Direct Cache Access Information Leaf */
2025 *eax
= 0; /* Bits 0-31 in DCA_CAP MSR */
2031 /* Architectural Performance Monitoring Leaf */
2032 if (kvm_enabled() && cpu
->enable_pmu
) {
2033 KVMState
*s
= cs
->kvm_state
;
2035 *eax
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EAX
);
2036 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EBX
);
2037 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_ECX
);
2038 *edx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EDX
);
2047 /* Processor Extended State */
2048 if (!(env
->features
[FEAT_1_ECX
] & CPUID_EXT_XSAVE
)) {
2055 if (kvm_enabled()) {
2056 KVMState
*s
= cs
->kvm_state
;
2058 *eax
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EAX
);
2059 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EBX
);
2060 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_ECX
);
2061 *edx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EDX
);
2070 *eax
= env
->cpuid_xlevel
;
2071 *ebx
= env
->cpuid_vendor1
;
2072 *edx
= env
->cpuid_vendor2
;
2073 *ecx
= env
->cpuid_vendor3
;
2076 *eax
= env
->cpuid_version
;
2078 *ecx
= env
->features
[FEAT_8000_0001_ECX
];
2079 *edx
= env
->features
[FEAT_8000_0001_EDX
];
2081 /* The Linux kernel checks for the CMPLegacy bit and
2082 * discards multiple thread information if it is set.
2083 * So dont set it here for Intel to make Linux guests happy.
2085 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2086 uint32_t tebx
, tecx
, tedx
;
2087 get_cpuid_vendor(env
, &tebx
, &tecx
, &tedx
);
2088 if (tebx
!= CPUID_VENDOR_INTEL_1
||
2089 tedx
!= CPUID_VENDOR_INTEL_2
||
2090 tecx
!= CPUID_VENDOR_INTEL_3
) {
2091 *ecx
|= 1 << 1; /* CmpLegacy bit */
2098 *eax
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 0];
2099 *ebx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 1];
2100 *ecx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 2];
2101 *edx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 3];
2104 /* cache info (L1 cache) */
2111 /* cache info (L2 cache) */
2118 /* virtual & phys address size in low 2 bytes. */
2119 /* XXX: This value must match the one used in the MMU code. */
2120 if (env
->features
[FEAT_8000_0001_EDX
] & CPUID_EXT2_LM
) {
2121 /* 64 bit processor */
2122 /* XXX: The physical address space is limited to 42 bits in exec.c. */
2123 *eax
= 0x00003028; /* 48 bits virtual, 40 bits physical */
2125 if (env
->features
[FEAT_1_EDX
] & CPUID_PSE36
) {
2126 *eax
= 0x00000024; /* 36 bits physical */
2128 *eax
= 0x00000020; /* 32 bits physical */
2134 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
2135 *ecx
|= (cs
->nr_cores
* cs
->nr_threads
) - 1;
2139 if (env
->features
[FEAT_8000_0001_ECX
] & CPUID_EXT3_SVM
) {
2140 *eax
= 0x00000001; /* SVM Revision */
2141 *ebx
= 0x00000010; /* nr of ASIDs */
2143 *edx
= env
->features
[FEAT_SVM
]; /* optional features */
2152 *eax
= env
->cpuid_xlevel2
;
2158 /* Support for VIA CPU's CPUID instruction */
2159 *eax
= env
->cpuid_version
;
2162 *edx
= env
->features
[FEAT_C000_0001_EDX
];
2167 /* Reserved for the future, and now filled with zero */
2174 /* reserved values: zero */
2183 /* CPUClass::reset() */
2184 static void x86_cpu_reset(CPUState
*s
)
2186 X86CPU
*cpu
= X86_CPU(s
);
2187 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(cpu
);
2188 CPUX86State
*env
= &cpu
->env
;
2191 xcc
->parent_reset(s
);
2194 memset(env
, 0, offsetof(CPUX86State
, breakpoints
));
2198 env
->old_exception
= -1;
2200 /* init to reset state */
2202 #ifdef CONFIG_SOFTMMU
2203 env
->hflags
|= HF_SOFTMMU_MASK
;
2205 env
->hflags2
|= HF2_GIF_MASK
;
2207 cpu_x86_update_cr0(env
, 0x60000010);
2208 env
->a20_mask
= ~0x0;
2209 env
->smbase
= 0x30000;
2211 env
->idt
.limit
= 0xffff;
2212 env
->gdt
.limit
= 0xffff;
2213 env
->ldt
.limit
= 0xffff;
2214 env
->ldt
.flags
= DESC_P_MASK
| (2 << DESC_TYPE_SHIFT
);
2215 env
->tr
.limit
= 0xffff;
2216 env
->tr
.flags
= DESC_P_MASK
| (11 << DESC_TYPE_SHIFT
);
2218 cpu_x86_load_seg_cache(env
, R_CS
, 0xf000, 0xffff0000, 0xffff,
2219 DESC_P_MASK
| DESC_S_MASK
| DESC_CS_MASK
|
2220 DESC_R_MASK
| DESC_A_MASK
);
2221 cpu_x86_load_seg_cache(env
, R_DS
, 0, 0, 0xffff,
2222 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2224 cpu_x86_load_seg_cache(env
, R_ES
, 0, 0, 0xffff,
2225 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2227 cpu_x86_load_seg_cache(env
, R_SS
, 0, 0, 0xffff,
2228 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2230 cpu_x86_load_seg_cache(env
, R_FS
, 0, 0, 0xffff,
2231 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2233 cpu_x86_load_seg_cache(env
, R_GS
, 0, 0, 0xffff,
2234 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2238 env
->regs
[R_EDX
] = env
->cpuid_version
;
2243 for (i
= 0; i
< 8; i
++) {
2248 env
->mxcsr
= 0x1f80;
2250 env
->pat
= 0x0007040600070406ULL
;
2251 env
->msr_ia32_misc_enable
= MSR_IA32_MISC_ENABLE_DEFAULT
;
2253 memset(env
->dr
, 0, sizeof(env
->dr
));
2254 env
->dr
[6] = DR6_FIXED_1
;
2255 env
->dr
[7] = DR7_FIXED_1
;
2256 cpu_breakpoint_remove_all(env
, BP_CPU
);
2257 cpu_watchpoint_remove_all(env
, BP_CPU
);
2259 #if !defined(CONFIG_USER_ONLY)
2260 /* We hard-wire the BSP to the first CPU. */
2261 if (s
->cpu_index
== 0) {
2262 apic_designate_bsp(env
->apic_state
);
2265 s
->halted
= !cpu_is_bsp(cpu
);
2269 #ifndef CONFIG_USER_ONLY
2270 bool cpu_is_bsp(X86CPU
*cpu
)
2272 return cpu_get_apic_base(cpu
->env
.apic_state
) & MSR_IA32_APICBASE_BSP
;
2275 /* TODO: remove me, when reset over QOM tree is implemented */
2276 static void x86_cpu_machine_reset_cb(void *opaque
)
2278 X86CPU
*cpu
= opaque
;
2279 cpu_reset(CPU(cpu
));
2283 static void mce_init(X86CPU
*cpu
)
2285 CPUX86State
*cenv
= &cpu
->env
;
2288 if (((cenv
->cpuid_version
>> 8) & 0xf) >= 6
2289 && (cenv
->features
[FEAT_1_EDX
] & (CPUID_MCE
| CPUID_MCA
)) ==
2290 (CPUID_MCE
| CPUID_MCA
)) {
2291 cenv
->mcg_cap
= MCE_CAP_DEF
| MCE_BANKS_DEF
;
2292 cenv
->mcg_ctl
= ~(uint64_t)0;
2293 for (bank
= 0; bank
< MCE_BANKS_DEF
; bank
++) {
2294 cenv
->mce_banks
[bank
* 4] = ~(uint64_t)0;
2299 #ifndef CONFIG_USER_ONLY
2300 static void x86_cpu_apic_create(X86CPU
*cpu
, Error
**errp
)
2302 CPUX86State
*env
= &cpu
->env
;
2303 DeviceState
*dev
= DEVICE(cpu
);
2304 APICCommonState
*apic
;
2305 const char *apic_type
= "apic";
2307 if (kvm_irqchip_in_kernel()) {
2308 apic_type
= "kvm-apic";
2309 } else if (xen_enabled()) {
2310 apic_type
= "xen-apic";
2313 env
->apic_state
= qdev_try_create(qdev_get_parent_bus(dev
), apic_type
);
2314 if (env
->apic_state
== NULL
) {
2315 error_setg(errp
, "APIC device '%s' could not be created", apic_type
);
2319 object_property_add_child(OBJECT(cpu
), "apic",
2320 OBJECT(env
->apic_state
), NULL
);
2321 qdev_prop_set_uint8(env
->apic_state
, "id", env
->cpuid_apic_id
);
2322 /* TODO: convert to link<> */
2323 apic
= APIC_COMMON(env
->apic_state
);
2327 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2329 CPUX86State
*env
= &cpu
->env
;
2331 if (env
->apic_state
== NULL
) {
2335 if (qdev_init(env
->apic_state
)) {
2336 error_setg(errp
, "APIC device '%s' could not be initialized",
2337 object_get_typename(OBJECT(env
->apic_state
)));
2342 static void x86_cpu_apic_realize(X86CPU
*cpu
, Error
**errp
)
2347 static void x86_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
2349 CPUState
*cs
= CPU(dev
);
2350 X86CPU
*cpu
= X86_CPU(dev
);
2351 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(dev
);
2352 CPUX86State
*env
= &cpu
->env
;
2353 Error
*local_err
= NULL
;
2355 if (env
->features
[FEAT_7_0_EBX
] && env
->cpuid_level
< 7) {
2356 env
->cpuid_level
= 7;
2359 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
2362 if (env
->cpuid_vendor1
== CPUID_VENDOR_AMD_1
&&
2363 env
->cpuid_vendor2
== CPUID_VENDOR_AMD_2
&&
2364 env
->cpuid_vendor3
== CPUID_VENDOR_AMD_3
) {
2365 env
->features
[FEAT_8000_0001_EDX
] &= ~CPUID_EXT2_AMD_ALIASES
;
2366 env
->features
[FEAT_8000_0001_EDX
] |= (env
->features
[FEAT_1_EDX
]
2367 & CPUID_EXT2_AMD_ALIASES
);
2370 if (!kvm_enabled()) {
2371 env
->features
[FEAT_1_EDX
] &= TCG_FEATURES
;
2372 env
->features
[FEAT_1_ECX
] &= TCG_EXT_FEATURES
;
2373 env
->features
[FEAT_8000_0001_EDX
] &= (TCG_EXT2_FEATURES
2374 #ifdef TARGET_X86_64
2375 | CPUID_EXT2_SYSCALL
| CPUID_EXT2_LM
2378 env
->features
[FEAT_8000_0001_ECX
] &= TCG_EXT3_FEATURES
;
2379 env
->features
[FEAT_SVM
] &= TCG_SVM_FEATURES
;
2381 if (check_cpuid
&& kvm_check_features_against_host(cpu
)
2383 error_setg(&local_err
,
2384 "Host's CPU doesn't support requested features");
2388 filter_features_for_kvm(cpu
);
2392 #ifndef CONFIG_USER_ONLY
2393 qemu_register_reset(x86_cpu_machine_reset_cb
, cpu
);
2395 if (cpu
->env
.features
[FEAT_1_EDX
] & CPUID_APIC
|| smp_cpus
> 1) {
2396 x86_cpu_apic_create(cpu
, &local_err
);
2397 if (local_err
!= NULL
) {
2406 x86_cpu_apic_realize(cpu
, &local_err
);
2407 if (local_err
!= NULL
) {
2412 xcc
->parent_realize(dev
, &local_err
);
2414 if (local_err
!= NULL
) {
2415 error_propagate(errp
, local_err
);
2420 /* Enables contiguous-apic-ID mode, for compatibility */
2421 static bool compat_apic_id_mode
;
2423 void enable_compat_apic_id_mode(void)
2425 compat_apic_id_mode
= true;
2428 /* Calculates initial APIC ID for a specific CPU index
2430 * Currently we need to be able to calculate the APIC ID from the CPU index
2431 * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
2432 * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
2433 * all CPUs up to max_cpus.
2435 uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index
)
2437 uint32_t correct_id
;
2440 correct_id
= x86_apicid_from_cpu_idx(smp_cores
, smp_threads
, cpu_index
);
2441 if (compat_apic_id_mode
) {
2442 if (cpu_index
!= correct_id
&& !warned
) {
2443 error_report("APIC IDs set in compatibility mode, "
2444 "CPU topology won't match the configuration");
2453 static void x86_cpu_initfn(Object
*obj
)
2455 CPUState
*cs
= CPU(obj
);
2456 X86CPU
*cpu
= X86_CPU(obj
);
2457 CPUX86State
*env
= &cpu
->env
;
2463 object_property_add(obj
, "family", "int",
2464 x86_cpuid_version_get_family
,
2465 x86_cpuid_version_set_family
, NULL
, NULL
, NULL
);
2466 object_property_add(obj
, "model", "int",
2467 x86_cpuid_version_get_model
,
2468 x86_cpuid_version_set_model
, NULL
, NULL
, NULL
);
2469 object_property_add(obj
, "stepping", "int",
2470 x86_cpuid_version_get_stepping
,
2471 x86_cpuid_version_set_stepping
, NULL
, NULL
, NULL
);
2472 object_property_add(obj
, "level", "int",
2473 x86_cpuid_get_level
,
2474 x86_cpuid_set_level
, NULL
, NULL
, NULL
);
2475 object_property_add(obj
, "xlevel", "int",
2476 x86_cpuid_get_xlevel
,
2477 x86_cpuid_set_xlevel
, NULL
, NULL
, NULL
);
2478 object_property_add_str(obj
, "vendor",
2479 x86_cpuid_get_vendor
,
2480 x86_cpuid_set_vendor
, NULL
);
2481 object_property_add_str(obj
, "model-id",
2482 x86_cpuid_get_model_id
,
2483 x86_cpuid_set_model_id
, NULL
);
2484 object_property_add(obj
, "tsc-frequency", "int",
2485 x86_cpuid_get_tsc_freq
,
2486 x86_cpuid_set_tsc_freq
, NULL
, NULL
, NULL
);
2487 object_property_add(obj
, "apic-id", "int",
2488 x86_cpuid_get_apic_id
,
2489 x86_cpuid_set_apic_id
, NULL
, NULL
, NULL
);
2490 object_property_add(obj
, "feature-words", "X86CPUFeatureWordInfo",
2491 x86_cpu_get_feature_words
,
2492 NULL
, NULL
, (void *)env
->features
, NULL
);
2493 object_property_add(obj
, "filtered-features", "X86CPUFeatureWordInfo",
2494 x86_cpu_get_feature_words
,
2495 NULL
, NULL
, (void *)cpu
->filtered_features
, NULL
);
2497 cpu
->hyperv_spinlock_attempts
= HYPERV_SPINLOCK_NEVER_RETRY
;
2498 env
->cpuid_apic_id
= x86_cpu_apic_id_from_index(cs
->cpu_index
);
2500 /* init various static tables used in TCG mode */
2501 if (tcg_enabled() && !inited
) {
2503 optimize_flags_init();
2504 #ifndef CONFIG_USER_ONLY
2505 cpu_set_debug_excp_handler(breakpoint_handler
);
2510 static int64_t x86_cpu_get_arch_id(CPUState
*cs
)
2512 X86CPU
*cpu
= X86_CPU(cs
);
2513 CPUX86State
*env
= &cpu
->env
;
2515 return env
->cpuid_apic_id
;
2518 static bool x86_cpu_get_paging_enabled(const CPUState
*cs
)
2520 X86CPU
*cpu
= X86_CPU(cs
);
2522 return cpu
->env
.cr
[0] & CR0_PG_MASK
;
2525 static void x86_cpu_set_pc(CPUState
*cs
, vaddr value
)
2527 X86CPU
*cpu
= X86_CPU(cs
);
2529 cpu
->env
.eip
= value
;
2532 static void x86_cpu_synchronize_from_tb(CPUState
*cs
, TranslationBlock
*tb
)
2534 X86CPU
*cpu
= X86_CPU(cs
);
2536 cpu
->env
.eip
= tb
->pc
- tb
->cs_base
;
2539 static Property x86_cpu_properties
[] = {
2540 DEFINE_PROP_BOOL("pmu", X86CPU
, enable_pmu
, false),
2541 DEFINE_PROP_END_OF_LIST()
2544 static void x86_cpu_common_class_init(ObjectClass
*oc
, void *data
)
2546 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
2547 CPUClass
*cc
= CPU_CLASS(oc
);
2548 DeviceClass
*dc
= DEVICE_CLASS(oc
);
2550 xcc
->parent_realize
= dc
->realize
;
2551 dc
->realize
= x86_cpu_realizefn
;
2552 dc
->bus_type
= TYPE_ICC_BUS
;
2553 dc
->props
= x86_cpu_properties
;
2555 xcc
->parent_reset
= cc
->reset
;
2556 cc
->reset
= x86_cpu_reset
;
2557 cc
->reset_dump_flags
= CPU_DUMP_FPU
| CPU_DUMP_CCOP
;
2559 cc
->do_interrupt
= x86_cpu_do_interrupt
;
2560 cc
->dump_state
= x86_cpu_dump_state
;
2561 cc
->set_pc
= x86_cpu_set_pc
;
2562 cc
->synchronize_from_tb
= x86_cpu_synchronize_from_tb
;
2563 cc
->gdb_read_register
= x86_cpu_gdb_read_register
;
2564 cc
->gdb_write_register
= x86_cpu_gdb_write_register
;
2565 cc
->get_arch_id
= x86_cpu_get_arch_id
;
2566 cc
->get_paging_enabled
= x86_cpu_get_paging_enabled
;
2567 #ifndef CONFIG_USER_ONLY
2568 cc
->get_memory_mapping
= x86_cpu_get_memory_mapping
;
2569 cc
->get_phys_page_debug
= x86_cpu_get_phys_page_debug
;
2570 cc
->write_elf64_note
= x86_cpu_write_elf64_note
;
2571 cc
->write_elf64_qemunote
= x86_cpu_write_elf64_qemunote
;
2572 cc
->write_elf32_note
= x86_cpu_write_elf32_note
;
2573 cc
->write_elf32_qemunote
= x86_cpu_write_elf32_qemunote
;
2574 cc
->vmsd
= &vmstate_x86_cpu
;
2576 cc
->gdb_num_core_regs
= CPU_NB_REGS
* 2 + 25;
2579 static const TypeInfo x86_cpu_type_info
= {
2580 .name
= TYPE_X86_CPU
,
2582 .instance_size
= sizeof(X86CPU
),
2583 .instance_init
= x86_cpu_initfn
,
2585 .class_size
= sizeof(X86CPUClass
),
2586 .class_init
= x86_cpu_common_class_init
,
2589 static void x86_cpu_register_types(void)
2591 type_register_static(&x86_cpu_type_info
);
2594 type_init(x86_cpu_register_types
)