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"
27 #include "qemu/option.h"
28 #include "qemu/config-file.h"
29 #include "qapi/qmp/qerror.h"
31 #include "qapi/visitor.h"
32 #include "sysemu/arch_init.h"
37 #if defined(CONFIG_KVM)
38 #include <linux/kvm_para.h>
41 #include "sysemu/sysemu.h"
42 #ifndef CONFIG_USER_ONLY
44 #include "hw/sysbus.h"
45 #include "hw/apic_internal.h"
48 /* feature flags taken from "Intel Processor Identification and the CPUID
49 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
50 * between feature naming conventions, aliases may be added.
52 static const char *feature_name
[] = {
53 "fpu", "vme", "de", "pse",
54 "tsc", "msr", "pae", "mce",
55 "cx8", "apic", NULL
, "sep",
56 "mtrr", "pge", "mca", "cmov",
57 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
58 NULL
, "ds" /* Intel dts */, "acpi", "mmx",
59 "fxsr", "sse", "sse2", "ss",
60 "ht" /* Intel htt */, "tm", "ia64", "pbe",
62 static const char *ext_feature_name
[] = {
63 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
64 "ds_cpl", "vmx", "smx", "est",
65 "tm2", "ssse3", "cid", NULL
,
66 "fma", "cx16", "xtpr", "pdcm",
67 NULL
, "pcid", "dca", "sse4.1|sse4_1",
68 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
69 "tsc-deadline", "aes", "xsave", "osxsave",
70 "avx", "f16c", "rdrand", "hypervisor",
72 /* Feature names that are already defined on feature_name[] but are set on
73 * CPUID[8000_0001].EDX on AMD CPUs don't have their names on
74 * ext2_feature_name[]. They are copied automatically to cpuid_ext2_features
75 * if and only if CPU vendor is AMD.
77 static const char *ext2_feature_name
[] = {
78 NULL
/* fpu */, NULL
/* vme */, NULL
/* de */, NULL
/* pse */,
79 NULL
/* tsc */, NULL
/* msr */, NULL
/* pae */, NULL
/* mce */,
80 NULL
/* cx8 */ /* AMD CMPXCHG8B */, NULL
/* apic */, NULL
, "syscall",
81 NULL
/* mtrr */, NULL
/* pge */, NULL
/* mca */, NULL
/* cmov */,
82 NULL
/* pat */, NULL
/* pse36 */, NULL
, NULL
/* Linux mp */,
83 "nx|xd", NULL
, "mmxext", NULL
/* mmx */,
84 NULL
/* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
85 NULL
, "lm|i64", "3dnowext", "3dnow",
87 static const char *ext3_feature_name
[] = {
88 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
89 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
90 "3dnowprefetch", "osvw", "ibs", "xop",
91 "skinit", "wdt", NULL
, "lwp",
92 "fma4", "tce", NULL
, "nodeid_msr",
93 NULL
, "tbm", "topoext", "perfctr_core",
94 "perfctr_nb", NULL
, NULL
, NULL
,
95 NULL
, NULL
, NULL
, NULL
,
98 static const char *ext4_feature_name
[] = {
99 NULL
, NULL
, "xstore", "xstore-en",
100 NULL
, NULL
, "xcrypt", "xcrypt-en",
101 "ace2", "ace2-en", "phe", "phe-en",
102 "pmm", "pmm-en", NULL
, NULL
,
103 NULL
, NULL
, NULL
, NULL
,
104 NULL
, NULL
, NULL
, NULL
,
105 NULL
, NULL
, NULL
, NULL
,
106 NULL
, NULL
, NULL
, NULL
,
109 static const char *kvm_feature_name
[] = {
110 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
111 "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", NULL
,
112 NULL
, NULL
, NULL
, NULL
,
113 NULL
, NULL
, NULL
, NULL
,
114 NULL
, NULL
, NULL
, NULL
,
115 NULL
, NULL
, NULL
, NULL
,
116 NULL
, NULL
, NULL
, NULL
,
117 NULL
, NULL
, NULL
, NULL
,
120 static const char *svm_feature_name
[] = {
121 "npt", "lbrv", "svm_lock", "nrip_save",
122 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
123 NULL
, NULL
, "pause_filter", NULL
,
124 "pfthreshold", NULL
, NULL
, NULL
,
125 NULL
, NULL
, NULL
, NULL
,
126 NULL
, NULL
, NULL
, NULL
,
127 NULL
, NULL
, NULL
, NULL
,
128 NULL
, NULL
, NULL
, NULL
,
131 static const char *cpuid_7_0_ebx_feature_name
[] = {
132 "fsgsbase", NULL
, NULL
, "bmi1", "hle", "avx2", NULL
, "smep",
133 "bmi2", "erms", "invpcid", "rtm", NULL
, NULL
, NULL
, NULL
,
134 NULL
, NULL
, "rdseed", "adx", "smap", NULL
, NULL
, NULL
,
135 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
138 typedef struct FeatureWordInfo
{
139 const char **feat_names
;
140 uint32_t cpuid_eax
; /* Input EAX for CPUID */
141 int cpuid_reg
; /* R_* register constant */
144 static FeatureWordInfo feature_word_info
[FEATURE_WORDS
] = {
146 .feat_names
= feature_name
,
147 .cpuid_eax
= 1, .cpuid_reg
= R_EDX
,
150 .feat_names
= ext_feature_name
,
151 .cpuid_eax
= 1, .cpuid_reg
= R_ECX
,
153 [FEAT_8000_0001_EDX
] = {
154 .feat_names
= ext2_feature_name
,
155 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_EDX
,
157 [FEAT_8000_0001_ECX
] = {
158 .feat_names
= ext3_feature_name
,
159 .cpuid_eax
= 0x80000001, .cpuid_reg
= R_ECX
,
161 [FEAT_C000_0001_EDX
] = {
162 .feat_names
= ext4_feature_name
,
163 .cpuid_eax
= 0xC0000001, .cpuid_reg
= R_EDX
,
166 .feat_names
= kvm_feature_name
,
167 .cpuid_eax
= KVM_CPUID_FEATURES
, .cpuid_reg
= R_EAX
,
170 .feat_names
= svm_feature_name
,
171 .cpuid_eax
= 0x8000000A, .cpuid_reg
= R_EDX
,
174 .feat_names
= cpuid_7_0_ebx_feature_name
,
175 .cpuid_eax
= 7, .cpuid_reg
= R_EBX
,
179 const char *get_register_name_32(unsigned int reg
)
181 static const char *reg_names
[CPU_NB_REGS32
] = {
192 if (reg
> CPU_NB_REGS32
) {
195 return reg_names
[reg
];
198 /* collects per-function cpuid data
200 typedef struct model_features_t
{
201 uint32_t *guest_feat
;
203 FeatureWord feat_word
;
207 int enforce_cpuid
= 0;
209 #if defined(CONFIG_KVM)
210 static uint32_t kvm_default_features
= (1 << KVM_FEATURE_CLOCKSOURCE
) |
211 (1 << KVM_FEATURE_NOP_IO_DELAY
) |
212 (1 << KVM_FEATURE_CLOCKSOURCE2
) |
213 (1 << KVM_FEATURE_ASYNC_PF
) |
214 (1 << KVM_FEATURE_STEAL_TIME
) |
215 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT
);
216 static const uint32_t kvm_pv_eoi_features
= (0x1 << KVM_FEATURE_PV_EOI
);
218 static uint32_t kvm_default_features
= 0;
219 static const uint32_t kvm_pv_eoi_features
= 0;
222 void enable_kvm_pv_eoi(void)
224 kvm_default_features
|= kvm_pv_eoi_features
;
227 void host_cpuid(uint32_t function
, uint32_t count
,
228 uint32_t *eax
, uint32_t *ebx
, uint32_t *ecx
, uint32_t *edx
)
230 #if defined(CONFIG_KVM)
235 : "=a"(vec
[0]), "=b"(vec
[1]),
236 "=c"(vec
[2]), "=d"(vec
[3])
237 : "0"(function
), "c"(count
) : "cc");
239 asm volatile("pusha \n\t"
241 "mov %%eax, 0(%2) \n\t"
242 "mov %%ebx, 4(%2) \n\t"
243 "mov %%ecx, 8(%2) \n\t"
244 "mov %%edx, 12(%2) \n\t"
246 : : "a"(function
), "c"(count
), "S"(vec
)
261 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
263 /* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
264 * a substring. ex if !NULL points to the first char after a substring,
265 * otherwise the string is assumed to sized by a terminating nul.
266 * Return lexical ordering of *s1:*s2.
268 static int sstrcmp(const char *s1
, const char *e1
, const char *s2
,
272 if (!*s1
|| !*s2
|| *s1
!= *s2
)
275 if (s1
== e1
&& s2
== e2
)
284 /* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
285 * '|' delimited (possibly empty) strings in which case search for a match
286 * within the alternatives proceeds left to right. Return 0 for success,
287 * non-zero otherwise.
289 static int altcmp(const char *s
, const char *e
, const char *altstr
)
293 for (q
= p
= altstr
; ; ) {
294 while (*p
&& *p
!= '|')
296 if ((q
== p
&& !*s
) || (q
!= p
&& !sstrcmp(s
, e
, q
, p
)))
305 /* search featureset for flag *[s..e), if found set corresponding bit in
306 * *pval and return true, otherwise return false
308 static bool lookup_feature(uint32_t *pval
, const char *s
, const char *e
,
309 const char **featureset
)
315 for (mask
= 1, ppc
= featureset
; mask
; mask
<<= 1, ++ppc
) {
316 if (*ppc
&& !altcmp(s
, e
, *ppc
)) {
324 static void add_flagname_to_bitmaps(const char *flagname
,
325 FeatureWordArray words
)
328 for (w
= 0; w
< FEATURE_WORDS
; w
++) {
329 FeatureWordInfo
*wi
= &feature_word_info
[w
];
330 if (wi
->feat_names
&&
331 lookup_feature(&words
[w
], flagname
, NULL
, wi
->feat_names
)) {
335 if (w
== FEATURE_WORDS
) {
336 fprintf(stderr
, "CPU feature %s not found\n", flagname
);
340 typedef struct x86_def_t
{
341 struct x86_def_t
*next
;
344 uint32_t vendor1
, vendor2
, vendor3
;
349 uint32_t features
, ext_features
, ext2_features
, ext3_features
;
350 uint32_t kvm_features
, svm_features
;
354 /* Store the results of Centaur's CPUID instructions */
355 uint32_t ext4_features
;
357 /* The feature bits on CPUID[EAX=7,ECX=0].EBX */
358 uint32_t cpuid_7_0_ebx_features
;
361 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
362 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
363 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
364 #define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
365 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
366 CPUID_PSE36 | CPUID_FXSR)
367 #define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
368 #define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
369 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
370 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
371 CPUID_PAE | CPUID_SEP | CPUID_APIC)
373 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
374 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
375 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
376 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
377 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
378 /* partly implemented:
379 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64)
380 CPUID_PSE36 (needed for Solaris) */
382 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
383 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | \
384 CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT | \
385 CPUID_EXT_HYPERVISOR)
387 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_EST,
388 CPUID_EXT_TM2, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_XSAVE */
389 #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \
390 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
391 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT)
393 CPUID_EXT2_PDPE1GB */
394 #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
395 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
396 #define TCG_SVM_FEATURES 0
397 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP)
399 /* maintains list of cpu model definitions
401 static x86_def_t
*x86_defs
= {NULL
};
403 /* built-in cpu model definitions (deprecated)
405 static x86_def_t builtin_x86_defs
[] = {
409 .vendor1
= CPUID_VENDOR_AMD_1
,
410 .vendor2
= CPUID_VENDOR_AMD_2
,
411 .vendor3
= CPUID_VENDOR_AMD_3
,
415 .features
= PPRO_FEATURES
|
416 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
418 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_CX16
| CPUID_EXT_POPCNT
,
419 .ext2_features
= (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
420 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
421 .ext3_features
= CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
422 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
423 .xlevel
= 0x8000000A,
428 .vendor1
= CPUID_VENDOR_AMD_1
,
429 .vendor2
= CPUID_VENDOR_AMD_2
,
430 .vendor3
= CPUID_VENDOR_AMD_3
,
434 .features
= PPRO_FEATURES
|
435 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
436 CPUID_PSE36
| CPUID_VME
| CPUID_HT
,
437 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_CX16
|
439 .ext2_features
= (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
440 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
|
441 CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
| CPUID_EXT2_MMXEXT
|
442 CPUID_EXT2_FFXSR
| CPUID_EXT2_PDPE1GB
| CPUID_EXT2_RDTSCP
,
443 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
445 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
446 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
447 .ext3_features
= CPUID_EXT3_LAHF_LM
| CPUID_EXT3_SVM
|
448 CPUID_EXT3_ABM
| CPUID_EXT3_SSE4A
,
449 .svm_features
= CPUID_SVM_NPT
| CPUID_SVM_LBRV
,
450 .xlevel
= 0x8000001A,
451 .model_id
= "AMD Phenom(tm) 9550 Quad-Core Processor"
456 .vendor1
= CPUID_VENDOR_INTEL_1
,
457 .vendor2
= CPUID_VENDOR_INTEL_2
,
458 .vendor3
= CPUID_VENDOR_INTEL_3
,
462 .features
= PPRO_FEATURES
|
463 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
464 CPUID_PSE36
| CPUID_VME
| CPUID_DTS
| CPUID_ACPI
| CPUID_SS
|
465 CPUID_HT
| CPUID_TM
| CPUID_PBE
,
466 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
467 CPUID_EXT_DTES64
| CPUID_EXT_DSCPL
| CPUID_EXT_VMX
| CPUID_EXT_EST
|
468 CPUID_EXT_TM2
| CPUID_EXT_CX16
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
469 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
470 .ext3_features
= CPUID_EXT3_LAHF_LM
,
471 .xlevel
= 0x80000008,
472 .model_id
= "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
477 .vendor1
= CPUID_VENDOR_INTEL_1
,
478 .vendor2
= CPUID_VENDOR_INTEL_2
,
479 .vendor3
= CPUID_VENDOR_INTEL_3
,
483 /* Missing: CPUID_VME, CPUID_HT */
484 .features
= PPRO_FEATURES
|
485 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
|
487 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
488 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_CX16
,
489 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
490 .ext2_features
= (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
491 CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
492 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
493 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
494 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
495 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
497 .xlevel
= 0x80000008,
498 .model_id
= "Common KVM processor"
503 .vendor1
= CPUID_VENDOR_INTEL_1
,
504 .vendor2
= CPUID_VENDOR_INTEL_2
,
505 .vendor3
= CPUID_VENDOR_INTEL_3
,
509 .features
= PPRO_FEATURES
,
510 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_POPCNT
,
511 .xlevel
= 0x80000004,
516 .vendor1
= CPUID_VENDOR_INTEL_1
,
517 .vendor2
= CPUID_VENDOR_INTEL_2
,
518 .vendor3
= CPUID_VENDOR_INTEL_3
,
522 .features
= PPRO_FEATURES
|
523 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_PSE36
,
524 .ext_features
= CPUID_EXT_SSE3
,
525 .ext2_features
= PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
,
527 .xlevel
= 0x80000008,
528 .model_id
= "Common 32-bit KVM processor"
533 .vendor1
= CPUID_VENDOR_INTEL_1
,
534 .vendor2
= CPUID_VENDOR_INTEL_2
,
535 .vendor3
= CPUID_VENDOR_INTEL_3
,
539 .features
= PPRO_FEATURES
| CPUID_VME
|
540 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_DTS
| CPUID_ACPI
|
541 CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
542 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_VMX
|
543 CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
| CPUID_EXT_PDCM
,
544 .ext2_features
= CPUID_EXT2_NX
,
545 .xlevel
= 0x80000008,
546 .model_id
= "Genuine Intel(R) CPU T2600 @ 2.16GHz",
551 .vendor1
= CPUID_VENDOR_INTEL_1
,
552 .vendor2
= CPUID_VENDOR_INTEL_2
,
553 .vendor3
= CPUID_VENDOR_INTEL_3
,
557 .features
= I486_FEATURES
,
563 .vendor1
= CPUID_VENDOR_INTEL_1
,
564 .vendor2
= CPUID_VENDOR_INTEL_2
,
565 .vendor3
= CPUID_VENDOR_INTEL_3
,
569 .features
= PENTIUM_FEATURES
,
575 .vendor1
= CPUID_VENDOR_INTEL_1
,
576 .vendor2
= CPUID_VENDOR_INTEL_2
,
577 .vendor3
= CPUID_VENDOR_INTEL_3
,
581 .features
= PENTIUM2_FEATURES
,
587 .vendor1
= CPUID_VENDOR_INTEL_1
,
588 .vendor2
= CPUID_VENDOR_INTEL_2
,
589 .vendor3
= CPUID_VENDOR_INTEL_3
,
593 .features
= PENTIUM3_FEATURES
,
599 .vendor1
= CPUID_VENDOR_AMD_1
,
600 .vendor2
= CPUID_VENDOR_AMD_2
,
601 .vendor3
= CPUID_VENDOR_AMD_3
,
605 .features
= PPRO_FEATURES
| CPUID_PSE36
| CPUID_VME
| CPUID_MTRR
|
607 .ext2_features
= (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
608 CPUID_EXT2_MMXEXT
| CPUID_EXT2_3DNOW
| CPUID_EXT2_3DNOWEXT
,
609 .xlevel
= 0x80000008,
613 /* original is on level 10 */
615 .vendor1
= CPUID_VENDOR_INTEL_1
,
616 .vendor2
= CPUID_VENDOR_INTEL_2
,
617 .vendor3
= CPUID_VENDOR_INTEL_3
,
621 .features
= PPRO_FEATURES
|
622 CPUID_MTRR
| CPUID_CLFLUSH
| CPUID_MCA
| CPUID_VME
| CPUID_DTS
|
623 CPUID_ACPI
| CPUID_SS
| CPUID_HT
| CPUID_TM
| CPUID_PBE
,
624 /* Some CPUs got no CPUID_SEP */
625 .ext_features
= CPUID_EXT_SSE3
| CPUID_EXT_MONITOR
| CPUID_EXT_SSSE3
|
626 CPUID_EXT_DSCPL
| CPUID_EXT_EST
| CPUID_EXT_TM2
| CPUID_EXT_XTPR
,
627 .ext2_features
= (PPRO_FEATURES
& CPUID_EXT2_AMD_ALIASES
) |
629 .ext3_features
= CPUID_EXT3_LAHF_LM
,
630 .xlevel
= 0x8000000A,
631 .model_id
= "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
636 .vendor1
= CPUID_VENDOR_INTEL_1
,
637 .vendor2
= CPUID_VENDOR_INTEL_2
,
638 .vendor3
= CPUID_VENDOR_INTEL_3
,
642 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
643 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
644 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
645 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
646 CPUID_DE
| CPUID_FP87
,
647 .ext_features
= CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
648 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
649 .ext3_features
= CPUID_EXT3_LAHF_LM
,
650 .xlevel
= 0x8000000A,
651 .model_id
= "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
656 .vendor1
= CPUID_VENDOR_INTEL_1
,
657 .vendor2
= CPUID_VENDOR_INTEL_2
,
658 .vendor3
= CPUID_VENDOR_INTEL_3
,
662 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
663 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
664 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
665 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
666 CPUID_DE
| CPUID_FP87
,
667 .ext_features
= CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
669 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_NX
| CPUID_EXT2_SYSCALL
,
670 .ext3_features
= CPUID_EXT3_LAHF_LM
,
671 .xlevel
= 0x8000000A,
672 .model_id
= "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
677 .vendor1
= CPUID_VENDOR_INTEL_1
,
678 .vendor2
= CPUID_VENDOR_INTEL_2
,
679 .vendor3
= CPUID_VENDOR_INTEL_3
,
683 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
684 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
685 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
686 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
687 CPUID_DE
| CPUID_FP87
,
688 .ext_features
= CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
689 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_SSE3
,
690 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
691 .ext3_features
= CPUID_EXT3_LAHF_LM
,
692 .xlevel
= 0x8000000A,
693 .model_id
= "Intel Core i7 9xx (Nehalem Class Core i7)",
698 .vendor1
= CPUID_VENDOR_INTEL_1
,
699 .vendor2
= CPUID_VENDOR_INTEL_2
,
700 .vendor3
= CPUID_VENDOR_INTEL_3
,
704 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
705 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
706 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
707 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
708 CPUID_DE
| CPUID_FP87
,
709 .ext_features
= CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
710 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
712 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_NX
,
713 .ext3_features
= CPUID_EXT3_LAHF_LM
,
714 .xlevel
= 0x8000000A,
715 .model_id
= "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
718 .name
= "SandyBridge",
720 .vendor1
= CPUID_VENDOR_INTEL_1
,
721 .vendor2
= CPUID_VENDOR_INTEL_2
,
722 .vendor3
= CPUID_VENDOR_INTEL_3
,
726 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
727 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
728 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
729 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
730 CPUID_DE
| CPUID_FP87
,
731 .ext_features
= CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
732 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_POPCNT
|
733 CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
734 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
736 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
738 .ext3_features
= CPUID_EXT3_LAHF_LM
,
739 .xlevel
= 0x8000000A,
740 .model_id
= "Intel Xeon E312xx (Sandy Bridge)",
745 .vendor1
= CPUID_VENDOR_INTEL_1
,
746 .vendor2
= CPUID_VENDOR_INTEL_2
,
747 .vendor3
= CPUID_VENDOR_INTEL_3
,
751 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
752 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
753 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
754 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
755 CPUID_DE
| CPUID_FP87
,
756 .ext_features
= CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
757 CPUID_EXT_POPCNT
| CPUID_EXT_X2APIC
| CPUID_EXT_SSE42
|
758 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_SSSE3
|
759 CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
|
760 CPUID_EXT_TSC_DEADLINE_TIMER
| CPUID_EXT_FMA
| CPUID_EXT_MOVBE
|
762 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_NX
|
764 .ext3_features
= CPUID_EXT3_LAHF_LM
,
765 .cpuid_7_0_ebx_features
= CPUID_7_0_EBX_FSGSBASE
| CPUID_7_0_EBX_BMI1
|
766 CPUID_7_0_EBX_HLE
| CPUID_7_0_EBX_AVX2
| CPUID_7_0_EBX_SMEP
|
767 CPUID_7_0_EBX_BMI2
| CPUID_7_0_EBX_ERMS
| CPUID_7_0_EBX_INVPCID
|
769 .xlevel
= 0x8000000A,
770 .model_id
= "Intel Core Processor (Haswell)",
773 .name
= "Opteron_G1",
775 .vendor1
= CPUID_VENDOR_AMD_1
,
776 .vendor2
= CPUID_VENDOR_AMD_2
,
777 .vendor3
= CPUID_VENDOR_AMD_3
,
781 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
782 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
783 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
784 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
785 CPUID_DE
| CPUID_FP87
,
786 .ext_features
= CPUID_EXT_SSE3
,
787 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
788 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
789 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
790 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
791 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
792 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
793 .xlevel
= 0x80000008,
794 .model_id
= "AMD Opteron 240 (Gen 1 Class Opteron)",
797 .name
= "Opteron_G2",
799 .vendor1
= CPUID_VENDOR_AMD_1
,
800 .vendor2
= CPUID_VENDOR_AMD_2
,
801 .vendor3
= CPUID_VENDOR_AMD_3
,
805 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
806 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
807 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
808 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
809 CPUID_DE
| CPUID_FP87
,
810 .ext_features
= CPUID_EXT_CX16
| CPUID_EXT_SSE3
,
811 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
812 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
813 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
814 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
815 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
816 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
817 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
818 .ext3_features
= CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
819 .xlevel
= 0x80000008,
820 .model_id
= "AMD Opteron 22xx (Gen 2 Class Opteron)",
823 .name
= "Opteron_G3",
825 .vendor1
= CPUID_VENDOR_AMD_1
,
826 .vendor2
= CPUID_VENDOR_AMD_2
,
827 .vendor3
= CPUID_VENDOR_AMD_3
,
831 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
832 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
833 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
834 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
835 CPUID_DE
| CPUID_FP87
,
836 .ext_features
= CPUID_EXT_POPCNT
| CPUID_EXT_CX16
| CPUID_EXT_MONITOR
|
838 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
| CPUID_EXT2_FXSR
|
839 CPUID_EXT2_MMX
| CPUID_EXT2_NX
| CPUID_EXT2_PSE36
|
840 CPUID_EXT2_PAT
| CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
|
841 CPUID_EXT2_PGE
| CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
|
842 CPUID_EXT2_APIC
| CPUID_EXT2_CX8
| CPUID_EXT2_MCE
|
843 CPUID_EXT2_PAE
| CPUID_EXT2_MSR
| CPUID_EXT2_TSC
| CPUID_EXT2_PSE
|
844 CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
845 .ext3_features
= CPUID_EXT3_MISALIGNSSE
| CPUID_EXT3_SSE4A
|
846 CPUID_EXT3_ABM
| CPUID_EXT3_SVM
| CPUID_EXT3_LAHF_LM
,
847 .xlevel
= 0x80000008,
848 .model_id
= "AMD Opteron 23xx (Gen 3 Class Opteron)",
851 .name
= "Opteron_G4",
853 .vendor1
= CPUID_VENDOR_AMD_1
,
854 .vendor2
= CPUID_VENDOR_AMD_2
,
855 .vendor3
= CPUID_VENDOR_AMD_3
,
859 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
860 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
861 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
862 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
863 CPUID_DE
| CPUID_FP87
,
864 .ext_features
= CPUID_EXT_AVX
| CPUID_EXT_XSAVE
| CPUID_EXT_AES
|
865 CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
| CPUID_EXT_SSE41
|
866 CPUID_EXT_CX16
| CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
|
868 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
869 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
870 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
871 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
872 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
873 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
874 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
875 .ext3_features
= CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
876 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
877 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
879 .xlevel
= 0x8000001A,
880 .model_id
= "AMD Opteron 62xx class CPU",
883 .name
= "Opteron_G5",
885 .vendor1
= CPUID_VENDOR_AMD_1
,
886 .vendor2
= CPUID_VENDOR_AMD_2
,
887 .vendor3
= CPUID_VENDOR_AMD_3
,
891 .features
= CPUID_SSE2
| CPUID_SSE
| CPUID_FXSR
| CPUID_MMX
|
892 CPUID_CLFLUSH
| CPUID_PSE36
| CPUID_PAT
| CPUID_CMOV
| CPUID_MCA
|
893 CPUID_PGE
| CPUID_MTRR
| CPUID_SEP
| CPUID_APIC
| CPUID_CX8
|
894 CPUID_MCE
| CPUID_PAE
| CPUID_MSR
| CPUID_TSC
| CPUID_PSE
|
895 CPUID_DE
| CPUID_FP87
,
896 .ext_features
= CPUID_EXT_F16C
| CPUID_EXT_AVX
| CPUID_EXT_XSAVE
|
897 CPUID_EXT_AES
| CPUID_EXT_POPCNT
| CPUID_EXT_SSE42
|
898 CPUID_EXT_SSE41
| CPUID_EXT_CX16
| CPUID_EXT_FMA
|
899 CPUID_EXT_SSSE3
| CPUID_EXT_PCLMULQDQ
| CPUID_EXT_SSE3
,
900 .ext2_features
= CPUID_EXT2_LM
| CPUID_EXT2_RDTSCP
|
901 CPUID_EXT2_PDPE1GB
| CPUID_EXT2_FXSR
| CPUID_EXT2_MMX
|
902 CPUID_EXT2_NX
| CPUID_EXT2_PSE36
| CPUID_EXT2_PAT
|
903 CPUID_EXT2_CMOV
| CPUID_EXT2_MCA
| CPUID_EXT2_PGE
|
904 CPUID_EXT2_MTRR
| CPUID_EXT2_SYSCALL
| CPUID_EXT2_APIC
|
905 CPUID_EXT2_CX8
| CPUID_EXT2_MCE
| CPUID_EXT2_PAE
| CPUID_EXT2_MSR
|
906 CPUID_EXT2_TSC
| CPUID_EXT2_PSE
| CPUID_EXT2_DE
| CPUID_EXT2_FPU
,
907 .ext3_features
= CPUID_EXT3_TBM
| CPUID_EXT3_FMA4
| CPUID_EXT3_XOP
|
908 CPUID_EXT3_3DNOWPREFETCH
| CPUID_EXT3_MISALIGNSSE
|
909 CPUID_EXT3_SSE4A
| CPUID_EXT3_ABM
| CPUID_EXT3_SVM
|
911 .xlevel
= 0x8000001A,
912 .model_id
= "AMD Opteron 63xx class CPU",
917 static int cpu_x86_fill_model_id(char *str
)
919 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
922 for (i
= 0; i
< 3; i
++) {
923 host_cpuid(0x80000002 + i
, 0, &eax
, &ebx
, &ecx
, &edx
);
924 memcpy(str
+ i
* 16 + 0, &eax
, 4);
925 memcpy(str
+ i
* 16 + 4, &ebx
, 4);
926 memcpy(str
+ i
* 16 + 8, &ecx
, 4);
927 memcpy(str
+ i
* 16 + 12, &edx
, 4);
933 /* Fill a x86_def_t struct with information about the host CPU, and
934 * the CPU features supported by the host hardware + host kernel
936 * This function may be called only if KVM is enabled.
938 static void kvm_cpu_fill_host(x86_def_t
*x86_cpu_def
)
941 KVMState
*s
= kvm_state
;
942 uint32_t eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
944 assert(kvm_enabled());
946 x86_cpu_def
->name
= "host";
947 host_cpuid(0x0, 0, &eax
, &ebx
, &ecx
, &edx
);
948 x86_cpu_def
->vendor1
= ebx
;
949 x86_cpu_def
->vendor2
= edx
;
950 x86_cpu_def
->vendor3
= ecx
;
952 host_cpuid(0x1, 0, &eax
, &ebx
, &ecx
, &edx
);
953 x86_cpu_def
->family
= ((eax
>> 8) & 0x0F) + ((eax
>> 20) & 0xFF);
954 x86_cpu_def
->model
= ((eax
>> 4) & 0x0F) | ((eax
& 0xF0000) >> 12);
955 x86_cpu_def
->stepping
= eax
& 0x0F;
957 x86_cpu_def
->level
= kvm_arch_get_supported_cpuid(s
, 0x0, 0, R_EAX
);
958 x86_cpu_def
->features
= kvm_arch_get_supported_cpuid(s
, 0x1, 0, R_EDX
);
959 x86_cpu_def
->ext_features
= kvm_arch_get_supported_cpuid(s
, 0x1, 0, R_ECX
);
961 if (x86_cpu_def
->level
>= 7) {
962 x86_cpu_def
->cpuid_7_0_ebx_features
=
963 kvm_arch_get_supported_cpuid(s
, 0x7, 0, R_EBX
);
965 x86_cpu_def
->cpuid_7_0_ebx_features
= 0;
968 x86_cpu_def
->xlevel
= kvm_arch_get_supported_cpuid(s
, 0x80000000, 0, R_EAX
);
969 x86_cpu_def
->ext2_features
=
970 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_EDX
);
971 x86_cpu_def
->ext3_features
=
972 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_ECX
);
974 cpu_x86_fill_model_id(x86_cpu_def
->model_id
);
975 x86_cpu_def
->vendor_override
= 0;
977 /* Call Centaur's CPUID instruction. */
978 if (x86_cpu_def
->vendor1
== CPUID_VENDOR_VIA_1
&&
979 x86_cpu_def
->vendor2
== CPUID_VENDOR_VIA_2
&&
980 x86_cpu_def
->vendor3
== CPUID_VENDOR_VIA_3
) {
981 host_cpuid(0xC0000000, 0, &eax
, &ebx
, &ecx
, &edx
);
982 eax
= kvm_arch_get_supported_cpuid(s
, 0xC0000000, 0, R_EAX
);
983 if (eax
>= 0xC0000001) {
984 /* Support VIA max extended level */
985 x86_cpu_def
->xlevel2
= eax
;
986 host_cpuid(0xC0000001, 0, &eax
, &ebx
, &ecx
, &edx
);
987 x86_cpu_def
->ext4_features
=
988 kvm_arch_get_supported_cpuid(s
, 0xC0000001, 0, R_EDX
);
992 /* Other KVM-specific feature fields: */
993 x86_cpu_def
->svm_features
=
994 kvm_arch_get_supported_cpuid(s
, 0x8000000A, 0, R_EDX
);
995 x86_cpu_def
->kvm_features
=
996 kvm_arch_get_supported_cpuid(s
, KVM_CPUID_FEATURES
, 0, R_EAX
);
998 #endif /* CONFIG_KVM */
1001 static int unavailable_host_feature(FeatureWordInfo
*f
, uint32_t mask
)
1005 for (i
= 0; i
< 32; ++i
)
1006 if (1 << i
& mask
) {
1007 const char *reg
= get_register_name_32(f
->cpuid_reg
);
1009 fprintf(stderr
, "warning: host doesn't support requested feature: "
1010 "CPUID.%02XH:%s%s%s [bit %d]\n",
1012 f
->feat_names
[i
] ? "." : "",
1013 f
->feat_names
[i
] ? f
->feat_names
[i
] : "", i
);
1019 /* best effort attempt to inform user requested cpu flags aren't making
1020 * their way to the guest.
1022 * This function may be called only if KVM is enabled.
1024 static int kvm_check_features_against_host(x86_def_t
*guest_def
)
1029 struct model_features_t ft
[] = {
1030 {&guest_def
->features
, &host_def
.features
,
1032 {&guest_def
->ext_features
, &host_def
.ext_features
,
1034 {&guest_def
->ext2_features
, &host_def
.ext2_features
,
1035 FEAT_8000_0001_EDX
},
1036 {&guest_def
->ext3_features
, &host_def
.ext3_features
,
1037 FEAT_8000_0001_ECX
},
1040 assert(kvm_enabled());
1042 kvm_cpu_fill_host(&host_def
);
1043 for (rv
= 0, i
= 0; i
< ARRAY_SIZE(ft
); ++i
) {
1044 FeatureWord w
= ft
[i
].feat_word
;
1045 FeatureWordInfo
*wi
= &feature_word_info
[w
];
1046 for (mask
= 1; mask
; mask
<<= 1) {
1047 if (*ft
[i
].guest_feat
& mask
&&
1048 !(*ft
[i
].host_feat
& mask
)) {
1049 unavailable_host_feature(wi
, mask
);
1057 static void x86_cpuid_version_get_family(Object
*obj
, Visitor
*v
, void *opaque
,
1058 const char *name
, Error
**errp
)
1060 X86CPU
*cpu
= X86_CPU(obj
);
1061 CPUX86State
*env
= &cpu
->env
;
1064 value
= (env
->cpuid_version
>> 8) & 0xf;
1066 value
+= (env
->cpuid_version
>> 20) & 0xff;
1068 visit_type_int(v
, &value
, name
, errp
);
1071 static void x86_cpuid_version_set_family(Object
*obj
, Visitor
*v
, void *opaque
,
1072 const char *name
, Error
**errp
)
1074 X86CPU
*cpu
= X86_CPU(obj
);
1075 CPUX86State
*env
= &cpu
->env
;
1076 const int64_t min
= 0;
1077 const int64_t max
= 0xff + 0xf;
1080 visit_type_int(v
, &value
, name
, errp
);
1081 if (error_is_set(errp
)) {
1084 if (value
< min
|| value
> max
) {
1085 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1086 name
? name
: "null", value
, min
, max
);
1090 env
->cpuid_version
&= ~0xff00f00;
1092 env
->cpuid_version
|= 0xf00 | ((value
- 0x0f) << 20);
1094 env
->cpuid_version
|= value
<< 8;
1098 static void x86_cpuid_version_get_model(Object
*obj
, Visitor
*v
, void *opaque
,
1099 const char *name
, Error
**errp
)
1101 X86CPU
*cpu
= X86_CPU(obj
);
1102 CPUX86State
*env
= &cpu
->env
;
1105 value
= (env
->cpuid_version
>> 4) & 0xf;
1106 value
|= ((env
->cpuid_version
>> 16) & 0xf) << 4;
1107 visit_type_int(v
, &value
, name
, errp
);
1110 static void x86_cpuid_version_set_model(Object
*obj
, Visitor
*v
, void *opaque
,
1111 const char *name
, Error
**errp
)
1113 X86CPU
*cpu
= X86_CPU(obj
);
1114 CPUX86State
*env
= &cpu
->env
;
1115 const int64_t min
= 0;
1116 const int64_t max
= 0xff;
1119 visit_type_int(v
, &value
, name
, errp
);
1120 if (error_is_set(errp
)) {
1123 if (value
< min
|| value
> max
) {
1124 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1125 name
? name
: "null", value
, min
, max
);
1129 env
->cpuid_version
&= ~0xf00f0;
1130 env
->cpuid_version
|= ((value
& 0xf) << 4) | ((value
>> 4) << 16);
1133 static void x86_cpuid_version_get_stepping(Object
*obj
, Visitor
*v
,
1134 void *opaque
, const char *name
,
1137 X86CPU
*cpu
= X86_CPU(obj
);
1138 CPUX86State
*env
= &cpu
->env
;
1141 value
= env
->cpuid_version
& 0xf;
1142 visit_type_int(v
, &value
, name
, errp
);
1145 static void x86_cpuid_version_set_stepping(Object
*obj
, Visitor
*v
,
1146 void *opaque
, const char *name
,
1149 X86CPU
*cpu
= X86_CPU(obj
);
1150 CPUX86State
*env
= &cpu
->env
;
1151 const int64_t min
= 0;
1152 const int64_t max
= 0xf;
1155 visit_type_int(v
, &value
, name
, errp
);
1156 if (error_is_set(errp
)) {
1159 if (value
< min
|| value
> max
) {
1160 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1161 name
? name
: "null", value
, min
, max
);
1165 env
->cpuid_version
&= ~0xf;
1166 env
->cpuid_version
|= value
& 0xf;
1169 static void x86_cpuid_get_level(Object
*obj
, Visitor
*v
, void *opaque
,
1170 const char *name
, Error
**errp
)
1172 X86CPU
*cpu
= X86_CPU(obj
);
1174 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1177 static void x86_cpuid_set_level(Object
*obj
, Visitor
*v
, void *opaque
,
1178 const char *name
, Error
**errp
)
1180 X86CPU
*cpu
= X86_CPU(obj
);
1182 visit_type_uint32(v
, &cpu
->env
.cpuid_level
, name
, errp
);
1185 static void x86_cpuid_get_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1186 const char *name
, Error
**errp
)
1188 X86CPU
*cpu
= X86_CPU(obj
);
1190 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1193 static void x86_cpuid_set_xlevel(Object
*obj
, Visitor
*v
, void *opaque
,
1194 const char *name
, Error
**errp
)
1196 X86CPU
*cpu
= X86_CPU(obj
);
1198 visit_type_uint32(v
, &cpu
->env
.cpuid_xlevel
, name
, errp
);
1201 static char *x86_cpuid_get_vendor(Object
*obj
, Error
**errp
)
1203 X86CPU
*cpu
= X86_CPU(obj
);
1204 CPUX86State
*env
= &cpu
->env
;
1208 value
= (char *)g_malloc(CPUID_VENDOR_SZ
+ 1);
1209 for (i
= 0; i
< 4; i
++) {
1210 value
[i
] = env
->cpuid_vendor1
>> (8 * i
);
1211 value
[i
+ 4] = env
->cpuid_vendor2
>> (8 * i
);
1212 value
[i
+ 8] = env
->cpuid_vendor3
>> (8 * i
);
1214 value
[CPUID_VENDOR_SZ
] = '\0';
1218 static void x86_cpuid_set_vendor(Object
*obj
, const char *value
,
1221 X86CPU
*cpu
= X86_CPU(obj
);
1222 CPUX86State
*env
= &cpu
->env
;
1225 if (strlen(value
) != CPUID_VENDOR_SZ
) {
1226 error_set(errp
, QERR_PROPERTY_VALUE_BAD
, "",
1231 env
->cpuid_vendor1
= 0;
1232 env
->cpuid_vendor2
= 0;
1233 env
->cpuid_vendor3
= 0;
1234 for (i
= 0; i
< 4; i
++) {
1235 env
->cpuid_vendor1
|= ((uint8_t)value
[i
]) << (8 * i
);
1236 env
->cpuid_vendor2
|= ((uint8_t)value
[i
+ 4]) << (8 * i
);
1237 env
->cpuid_vendor3
|= ((uint8_t)value
[i
+ 8]) << (8 * i
);
1239 env
->cpuid_vendor_override
= 1;
1242 static char *x86_cpuid_get_model_id(Object
*obj
, Error
**errp
)
1244 X86CPU
*cpu
= X86_CPU(obj
);
1245 CPUX86State
*env
= &cpu
->env
;
1249 value
= g_malloc(48 + 1);
1250 for (i
= 0; i
< 48; i
++) {
1251 value
[i
] = env
->cpuid_model
[i
>> 2] >> (8 * (i
& 3));
1257 static void x86_cpuid_set_model_id(Object
*obj
, const char *model_id
,
1260 X86CPU
*cpu
= X86_CPU(obj
);
1261 CPUX86State
*env
= &cpu
->env
;
1264 if (model_id
== NULL
) {
1267 len
= strlen(model_id
);
1268 memset(env
->cpuid_model
, 0, 48);
1269 for (i
= 0; i
< 48; i
++) {
1273 c
= (uint8_t)model_id
[i
];
1275 env
->cpuid_model
[i
>> 2] |= c
<< (8 * (i
& 3));
1279 static void x86_cpuid_get_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1280 const char *name
, Error
**errp
)
1282 X86CPU
*cpu
= X86_CPU(obj
);
1285 value
= cpu
->env
.tsc_khz
* 1000;
1286 visit_type_int(v
, &value
, name
, errp
);
1289 static void x86_cpuid_set_tsc_freq(Object
*obj
, Visitor
*v
, void *opaque
,
1290 const char *name
, Error
**errp
)
1292 X86CPU
*cpu
= X86_CPU(obj
);
1293 const int64_t min
= 0;
1294 const int64_t max
= INT64_MAX
;
1297 visit_type_int(v
, &value
, name
, errp
);
1298 if (error_is_set(errp
)) {
1301 if (value
< min
|| value
> max
) {
1302 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
, "",
1303 name
? name
: "null", value
, min
, max
);
1307 cpu
->env
.tsc_khz
= value
/ 1000;
1310 static int cpu_x86_find_by_name(x86_def_t
*x86_cpu_def
, const char *name
)
1314 for (def
= x86_defs
; def
; def
= def
->next
) {
1315 if (name
&& !strcmp(name
, def
->name
)) {
1319 if (kvm_enabled() && name
&& strcmp(name
, "host") == 0) {
1320 kvm_cpu_fill_host(x86_cpu_def
);
1324 memcpy(x86_cpu_def
, def
, sizeof(*def
));
1330 /* Parse "+feature,-feature,feature=foo" CPU feature string
1332 static int cpu_x86_parse_featurestr(x86_def_t
*x86_cpu_def
, char *features
)
1335 char *featurestr
; /* Single 'key=value" string being parsed */
1336 /* Features to be added */
1337 FeatureWordArray plus_features
= {
1338 [FEAT_KVM
] = kvm_default_features
,
1340 /* Features to be removed */
1341 FeatureWordArray minus_features
= { 0 };
1344 add_flagname_to_bitmaps("hypervisor", plus_features
);
1346 featurestr
= features
? strtok(features
, ",") : NULL
;
1348 while (featurestr
) {
1350 if (featurestr
[0] == '+') {
1351 add_flagname_to_bitmaps(featurestr
+ 1, plus_features
);
1352 } else if (featurestr
[0] == '-') {
1353 add_flagname_to_bitmaps(featurestr
+ 1, minus_features
);
1354 } else if ((val
= strchr(featurestr
, '='))) {
1356 if (!strcmp(featurestr
, "family")) {
1358 numvalue
= strtoul(val
, &err
, 0);
1359 if (!*val
|| *err
|| numvalue
> 0xff + 0xf) {
1360 fprintf(stderr
, "bad numerical value %s\n", val
);
1363 x86_cpu_def
->family
= numvalue
;
1364 } else if (!strcmp(featurestr
, "model")) {
1366 numvalue
= strtoul(val
, &err
, 0);
1367 if (!*val
|| *err
|| numvalue
> 0xff) {
1368 fprintf(stderr
, "bad numerical value %s\n", val
);
1371 x86_cpu_def
->model
= numvalue
;
1372 } else if (!strcmp(featurestr
, "stepping")) {
1374 numvalue
= strtoul(val
, &err
, 0);
1375 if (!*val
|| *err
|| numvalue
> 0xf) {
1376 fprintf(stderr
, "bad numerical value %s\n", val
);
1379 x86_cpu_def
->stepping
= numvalue
;
1380 } else if (!strcmp(featurestr
, "level")) {
1382 numvalue
= strtoul(val
, &err
, 0);
1383 if (!*val
|| *err
) {
1384 fprintf(stderr
, "bad numerical value %s\n", val
);
1387 x86_cpu_def
->level
= numvalue
;
1388 } else if (!strcmp(featurestr
, "xlevel")) {
1390 numvalue
= strtoul(val
, &err
, 0);
1391 if (!*val
|| *err
) {
1392 fprintf(stderr
, "bad numerical value %s\n", val
);
1395 if (numvalue
< 0x80000000) {
1396 numvalue
+= 0x80000000;
1398 x86_cpu_def
->xlevel
= numvalue
;
1399 } else if (!strcmp(featurestr
, "vendor")) {
1400 if (strlen(val
) != 12) {
1401 fprintf(stderr
, "vendor string must be 12 chars long\n");
1404 x86_cpu_def
->vendor1
= 0;
1405 x86_cpu_def
->vendor2
= 0;
1406 x86_cpu_def
->vendor3
= 0;
1407 for(i
= 0; i
< 4; i
++) {
1408 x86_cpu_def
->vendor1
|= ((uint8_t)val
[i
]) << (8 * i
);
1409 x86_cpu_def
->vendor2
|= ((uint8_t)val
[i
+ 4]) << (8 * i
);
1410 x86_cpu_def
->vendor3
|= ((uint8_t)val
[i
+ 8]) << (8 * i
);
1412 x86_cpu_def
->vendor_override
= 1;
1413 } else if (!strcmp(featurestr
, "model_id")) {
1414 pstrcpy(x86_cpu_def
->model_id
, sizeof(x86_cpu_def
->model_id
),
1416 } else if (!strcmp(featurestr
, "tsc_freq")) {
1420 tsc_freq
= strtosz_suffix_unit(val
, &err
,
1421 STRTOSZ_DEFSUFFIX_B
, 1000);
1422 if (tsc_freq
< 0 || *err
) {
1423 fprintf(stderr
, "bad numerical value %s\n", val
);
1426 x86_cpu_def
->tsc_khz
= tsc_freq
/ 1000;
1427 } else if (!strcmp(featurestr
, "hv_spinlocks")) {
1429 numvalue
= strtoul(val
, &err
, 0);
1430 if (!*val
|| *err
) {
1431 fprintf(stderr
, "bad numerical value %s\n", val
);
1434 hyperv_set_spinlock_retries(numvalue
);
1436 fprintf(stderr
, "unrecognized feature %s\n", featurestr
);
1439 } else if (!strcmp(featurestr
, "check")) {
1441 } else if (!strcmp(featurestr
, "enforce")) {
1442 check_cpuid
= enforce_cpuid
= 1;
1443 } else if (!strcmp(featurestr
, "hv_relaxed")) {
1444 hyperv_enable_relaxed_timing(true);
1445 } else if (!strcmp(featurestr
, "hv_vapic")) {
1446 hyperv_enable_vapic_recommended(true);
1448 fprintf(stderr
, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr
);
1451 featurestr
= strtok(NULL
, ",");
1453 x86_cpu_def
->features
|= plus_features
[FEAT_1_EDX
];
1454 x86_cpu_def
->ext_features
|= plus_features
[FEAT_1_ECX
];
1455 x86_cpu_def
->ext2_features
|= plus_features
[FEAT_8000_0001_EDX
];
1456 x86_cpu_def
->ext3_features
|= plus_features
[FEAT_8000_0001_ECX
];
1457 x86_cpu_def
->ext4_features
|= plus_features
[FEAT_C000_0001_EDX
];
1458 x86_cpu_def
->kvm_features
|= plus_features
[FEAT_KVM
];
1459 x86_cpu_def
->svm_features
|= plus_features
[FEAT_SVM
];
1460 x86_cpu_def
->cpuid_7_0_ebx_features
|= plus_features
[FEAT_7_0_EBX
];
1461 x86_cpu_def
->features
&= ~minus_features
[FEAT_1_EDX
];
1462 x86_cpu_def
->ext_features
&= ~minus_features
[FEAT_1_ECX
];
1463 x86_cpu_def
->ext2_features
&= ~minus_features
[FEAT_8000_0001_EDX
];
1464 x86_cpu_def
->ext3_features
&= ~minus_features
[FEAT_8000_0001_ECX
];
1465 x86_cpu_def
->ext4_features
&= ~minus_features
[FEAT_C000_0001_EDX
];
1466 x86_cpu_def
->kvm_features
&= ~minus_features
[FEAT_KVM
];
1467 x86_cpu_def
->svm_features
&= ~minus_features
[FEAT_SVM
];
1468 x86_cpu_def
->cpuid_7_0_ebx_features
&= ~minus_features
[FEAT_7_0_EBX
];
1469 if (check_cpuid
&& kvm_enabled()) {
1470 if (kvm_check_features_against_host(x86_cpu_def
) && enforce_cpuid
)
1479 /* generate a composite string into buf of all cpuid names in featureset
1480 * selected by fbits. indicate truncation at bufsize in the event of overflow.
1481 * if flags, suppress names undefined in featureset.
1483 static void listflags(char *buf
, int bufsize
, uint32_t fbits
,
1484 const char **featureset
, uint32_t flags
)
1486 const char **p
= &featureset
[31];
1490 b
= 4 <= bufsize
? buf
+ (bufsize
-= 3) - 1 : NULL
;
1492 for (q
= buf
, bit
= 31; fbits
&& bufsize
; --p
, fbits
&= ~(1 << bit
), --bit
)
1493 if (fbits
& 1 << bit
&& (*p
|| !flags
)) {
1495 nc
= snprintf(q
, bufsize
, "%s%s", q
== buf
? "" : " ", *p
);
1497 nc
= snprintf(q
, bufsize
, "%s[%d]", q
== buf
? "" : " ", bit
);
1498 if (bufsize
<= nc
) {
1500 memcpy(b
, "...", sizeof("..."));
1509 /* generate CPU information. */
1510 void x86_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
1515 for (def
= x86_defs
; def
; def
= def
->next
) {
1516 snprintf(buf
, sizeof(buf
), "%s", def
->name
);
1517 (*cpu_fprintf
)(f
, "x86 %16s %-48s\n", buf
, def
->model_id
);
1519 if (kvm_enabled()) {
1520 (*cpu_fprintf
)(f
, "x86 %16s\n", "[host]");
1522 (*cpu_fprintf
)(f
, "\nRecognized CPUID flags:\n");
1523 listflags(buf
, sizeof(buf
), (uint32_t)~0, feature_name
, 1);
1524 (*cpu_fprintf
)(f
, " %s\n", buf
);
1525 listflags(buf
, sizeof(buf
), (uint32_t)~0, ext_feature_name
, 1);
1526 (*cpu_fprintf
)(f
, " %s\n", buf
);
1527 listflags(buf
, sizeof(buf
), (uint32_t)~0, ext2_feature_name
, 1);
1528 (*cpu_fprintf
)(f
, " %s\n", buf
);
1529 listflags(buf
, sizeof(buf
), (uint32_t)~0, ext3_feature_name
, 1);
1530 (*cpu_fprintf
)(f
, " %s\n", buf
);
1533 CpuDefinitionInfoList
*arch_query_cpu_definitions(Error
**errp
)
1535 CpuDefinitionInfoList
*cpu_list
= NULL
;
1538 for (def
= x86_defs
; def
; def
= def
->next
) {
1539 CpuDefinitionInfoList
*entry
;
1540 CpuDefinitionInfo
*info
;
1542 info
= g_malloc0(sizeof(*info
));
1543 info
->name
= g_strdup(def
->name
);
1545 entry
= g_malloc0(sizeof(*entry
));
1546 entry
->value
= info
;
1547 entry
->next
= cpu_list
;
1555 static void filter_features_for_kvm(X86CPU
*cpu
)
1557 CPUX86State
*env
= &cpu
->env
;
1558 KVMState
*s
= kvm_state
;
1560 env
->cpuid_features
&=
1561 kvm_arch_get_supported_cpuid(s
, 1, 0, R_EDX
);
1562 env
->cpuid_ext_features
&=
1563 kvm_arch_get_supported_cpuid(s
, 1, 0, R_ECX
);
1564 env
->cpuid_ext2_features
&=
1565 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_EDX
);
1566 env
->cpuid_ext3_features
&=
1567 kvm_arch_get_supported_cpuid(s
, 0x80000001, 0, R_ECX
);
1568 env
->cpuid_svm_features
&=
1569 kvm_arch_get_supported_cpuid(s
, 0x8000000A, 0, R_EDX
);
1570 env
->cpuid_7_0_ebx_features
&=
1571 kvm_arch_get_supported_cpuid(s
, 7, 0, R_EBX
);
1572 env
->cpuid_kvm_features
&=
1573 kvm_arch_get_supported_cpuid(s
, KVM_CPUID_FEATURES
, 0, R_EAX
);
1574 env
->cpuid_ext4_features
&=
1575 kvm_arch_get_supported_cpuid(s
, 0xC0000001, 0, R_EDX
);
1580 int cpu_x86_register(X86CPU
*cpu
, const char *cpu_model
)
1582 CPUX86State
*env
= &cpu
->env
;
1583 x86_def_t def1
, *def
= &def1
;
1584 Error
*error
= NULL
;
1585 char *name
, *features
;
1586 gchar
**model_pieces
;
1588 memset(def
, 0, sizeof(*def
));
1590 model_pieces
= g_strsplit(cpu_model
, ",", 2);
1591 if (!model_pieces
[0]) {
1594 name
= model_pieces
[0];
1595 features
= model_pieces
[1];
1597 if (cpu_x86_find_by_name(def
, name
) < 0) {
1601 if (cpu_x86_parse_featurestr(def
, features
) < 0) {
1604 assert(def
->vendor1
);
1605 env
->cpuid_vendor1
= def
->vendor1
;
1606 env
->cpuid_vendor2
= def
->vendor2
;
1607 env
->cpuid_vendor3
= def
->vendor3
;
1608 env
->cpuid_vendor_override
= def
->vendor_override
;
1609 object_property_set_int(OBJECT(cpu
), def
->level
, "level", &error
);
1610 object_property_set_int(OBJECT(cpu
), def
->family
, "family", &error
);
1611 object_property_set_int(OBJECT(cpu
), def
->model
, "model", &error
);
1612 object_property_set_int(OBJECT(cpu
), def
->stepping
, "stepping", &error
);
1613 env
->cpuid_features
= def
->features
;
1614 env
->cpuid_ext_features
= def
->ext_features
;
1615 env
->cpuid_ext2_features
= def
->ext2_features
;
1616 env
->cpuid_ext3_features
= def
->ext3_features
;
1617 object_property_set_int(OBJECT(cpu
), def
->xlevel
, "xlevel", &error
);
1618 env
->cpuid_kvm_features
= def
->kvm_features
;
1619 env
->cpuid_svm_features
= def
->svm_features
;
1620 env
->cpuid_ext4_features
= def
->ext4_features
;
1621 env
->cpuid_7_0_ebx_features
= def
->cpuid_7_0_ebx_features
;
1622 env
->cpuid_xlevel2
= def
->xlevel2
;
1623 object_property_set_int(OBJECT(cpu
), (int64_t)def
->tsc_khz
* 1000,
1624 "tsc-frequency", &error
);
1626 object_property_set_str(OBJECT(cpu
), def
->model_id
, "model-id", &error
);
1628 fprintf(stderr
, "%s\n", error_get_pretty(error
));
1633 g_strfreev(model_pieces
);
1636 g_strfreev(model_pieces
);
1640 #if !defined(CONFIG_USER_ONLY)
1642 void cpu_clear_apic_feature(CPUX86State
*env
)
1644 env
->cpuid_features
&= ~CPUID_APIC
;
1647 #endif /* !CONFIG_USER_ONLY */
1649 /* Initialize list of CPU models, filling some non-static fields if necessary
1651 void x86_cpudef_setup(void)
1654 static const char *model_with_versions
[] = { "qemu32", "qemu64", "athlon" };
1656 for (i
= 0; i
< ARRAY_SIZE(builtin_x86_defs
); ++i
) {
1657 x86_def_t
*def
= &builtin_x86_defs
[i
];
1658 def
->next
= x86_defs
;
1660 /* Look for specific "cpudef" models that */
1661 /* have the QEMU version in .model_id */
1662 for (j
= 0; j
< ARRAY_SIZE(model_with_versions
); j
++) {
1663 if (strcmp(model_with_versions
[j
], def
->name
) == 0) {
1664 pstrcpy(def
->model_id
, sizeof(def
->model_id
),
1665 "QEMU Virtual CPU version ");
1666 pstrcat(def
->model_id
, sizeof(def
->model_id
),
1667 qemu_get_version());
1676 static void get_cpuid_vendor(CPUX86State
*env
, uint32_t *ebx
,
1677 uint32_t *ecx
, uint32_t *edx
)
1679 *ebx
= env
->cpuid_vendor1
;
1680 *edx
= env
->cpuid_vendor2
;
1681 *ecx
= env
->cpuid_vendor3
;
1683 /* sysenter isn't supported on compatibility mode on AMD, syscall
1684 * isn't supported in compatibility mode on Intel.
1685 * Normally we advertise the actual cpu vendor, but you can override
1686 * this if you want to use KVM's sysenter/syscall emulation
1687 * in compatibility mode and when doing cross vendor migration
1689 if (kvm_enabled() && ! env
->cpuid_vendor_override
) {
1690 host_cpuid(0, 0, NULL
, ebx
, ecx
, edx
);
1694 void cpu_x86_cpuid(CPUX86State
*env
, uint32_t index
, uint32_t count
,
1695 uint32_t *eax
, uint32_t *ebx
,
1696 uint32_t *ecx
, uint32_t *edx
)
1698 X86CPU
*cpu
= x86_env_get_cpu(env
);
1699 CPUState
*cs
= CPU(cpu
);
1701 /* test if maximum index reached */
1702 if (index
& 0x80000000) {
1703 if (index
> env
->cpuid_xlevel
) {
1704 if (env
->cpuid_xlevel2
> 0) {
1705 /* Handle the Centaur's CPUID instruction. */
1706 if (index
> env
->cpuid_xlevel2
) {
1707 index
= env
->cpuid_xlevel2
;
1708 } else if (index
< 0xC0000000) {
1709 index
= env
->cpuid_xlevel
;
1712 /* Intel documentation states that invalid EAX input will
1713 * return the same information as EAX=cpuid_level
1714 * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
1716 index
= env
->cpuid_level
;
1720 if (index
> env
->cpuid_level
)
1721 index
= env
->cpuid_level
;
1726 *eax
= env
->cpuid_level
;
1727 get_cpuid_vendor(env
, ebx
, ecx
, edx
);
1730 *eax
= env
->cpuid_version
;
1731 *ebx
= (env
->cpuid_apic_id
<< 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
1732 *ecx
= env
->cpuid_ext_features
;
1733 *edx
= env
->cpuid_features
;
1734 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
1735 *ebx
|= (cs
->nr_cores
* cs
->nr_threads
) << 16;
1736 *edx
|= 1 << 28; /* HTT bit */
1740 /* cache info: needed for Pentium Pro compatibility */
1747 /* cache info: needed for Core compatibility */
1748 if (cs
->nr_cores
> 1) {
1749 *eax
= (cs
->nr_cores
- 1) << 26;
1754 case 0: /* L1 dcache info */
1760 case 1: /* L1 icache info */
1766 case 2: /* L2 cache info */
1768 if (cs
->nr_threads
> 1) {
1769 *eax
|= (cs
->nr_threads
- 1) << 14;
1775 default: /* end of info */
1784 /* mwait info: needed for Core compatibility */
1785 *eax
= 0; /* Smallest monitor-line size in bytes */
1786 *ebx
= 0; /* Largest monitor-line size in bytes */
1787 *ecx
= CPUID_MWAIT_EMX
| CPUID_MWAIT_IBE
;
1791 /* Thermal and Power Leaf */
1798 /* Structured Extended Feature Flags Enumeration Leaf */
1800 *eax
= 0; /* Maximum ECX value for sub-leaves */
1801 *ebx
= env
->cpuid_7_0_ebx_features
; /* Feature flags */
1802 *ecx
= 0; /* Reserved */
1803 *edx
= 0; /* Reserved */
1812 /* Direct Cache Access Information Leaf */
1813 *eax
= 0; /* Bits 0-31 in DCA_CAP MSR */
1819 /* Architectural Performance Monitoring Leaf */
1820 if (kvm_enabled()) {
1821 KVMState
*s
= cs
->kvm_state
;
1823 *eax
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EAX
);
1824 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EBX
);
1825 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_ECX
);
1826 *edx
= kvm_arch_get_supported_cpuid(s
, 0xA, count
, R_EDX
);
1835 /* Processor Extended State */
1836 if (!(env
->cpuid_ext_features
& CPUID_EXT_XSAVE
)) {
1843 if (kvm_enabled()) {
1844 KVMState
*s
= cs
->kvm_state
;
1846 *eax
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EAX
);
1847 *ebx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EBX
);
1848 *ecx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_ECX
);
1849 *edx
= kvm_arch_get_supported_cpuid(s
, 0xd, count
, R_EDX
);
1858 *eax
= env
->cpuid_xlevel
;
1859 *ebx
= env
->cpuid_vendor1
;
1860 *edx
= env
->cpuid_vendor2
;
1861 *ecx
= env
->cpuid_vendor3
;
1864 *eax
= env
->cpuid_version
;
1866 *ecx
= env
->cpuid_ext3_features
;
1867 *edx
= env
->cpuid_ext2_features
;
1869 /* The Linux kernel checks for the CMPLegacy bit and
1870 * discards multiple thread information if it is set.
1871 * So dont set it here for Intel to make Linux guests happy.
1873 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
1874 uint32_t tebx
, tecx
, tedx
;
1875 get_cpuid_vendor(env
, &tebx
, &tecx
, &tedx
);
1876 if (tebx
!= CPUID_VENDOR_INTEL_1
||
1877 tedx
!= CPUID_VENDOR_INTEL_2
||
1878 tecx
!= CPUID_VENDOR_INTEL_3
) {
1879 *ecx
|= 1 << 1; /* CmpLegacy bit */
1886 *eax
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 0];
1887 *ebx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 1];
1888 *ecx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 2];
1889 *edx
= env
->cpuid_model
[(index
- 0x80000002) * 4 + 3];
1892 /* cache info (L1 cache) */
1899 /* cache info (L2 cache) */
1906 /* virtual & phys address size in low 2 bytes. */
1907 /* XXX: This value must match the one used in the MMU code. */
1908 if (env
->cpuid_ext2_features
& CPUID_EXT2_LM
) {
1909 /* 64 bit processor */
1910 /* XXX: The physical address space is limited to 42 bits in exec.c. */
1911 *eax
= 0x00003028; /* 48 bits virtual, 40 bits physical */
1913 if (env
->cpuid_features
& CPUID_PSE36
)
1914 *eax
= 0x00000024; /* 36 bits physical */
1916 *eax
= 0x00000020; /* 32 bits physical */
1921 if (cs
->nr_cores
* cs
->nr_threads
> 1) {
1922 *ecx
|= (cs
->nr_cores
* cs
->nr_threads
) - 1;
1926 if (env
->cpuid_ext3_features
& CPUID_EXT3_SVM
) {
1927 *eax
= 0x00000001; /* SVM Revision */
1928 *ebx
= 0x00000010; /* nr of ASIDs */
1930 *edx
= env
->cpuid_svm_features
; /* optional features */
1939 *eax
= env
->cpuid_xlevel2
;
1945 /* Support for VIA CPU's CPUID instruction */
1946 *eax
= env
->cpuid_version
;
1949 *edx
= env
->cpuid_ext4_features
;
1954 /* Reserved for the future, and now filled with zero */
1961 /* reserved values: zero */
1970 /* CPUClass::reset() */
1971 static void x86_cpu_reset(CPUState
*s
)
1973 X86CPU
*cpu
= X86_CPU(s
);
1974 X86CPUClass
*xcc
= X86_CPU_GET_CLASS(cpu
);
1975 CPUX86State
*env
= &cpu
->env
;
1978 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
1979 qemu_log("CPU Reset (CPU %d)\n", s
->cpu_index
);
1980 log_cpu_state(env
, CPU_DUMP_FPU
| CPU_DUMP_CCOP
);
1983 xcc
->parent_reset(s
);
1986 memset(env
, 0, offsetof(CPUX86State
, breakpoints
));
1990 env
->old_exception
= -1;
1992 /* init to reset state */
1994 #ifdef CONFIG_SOFTMMU
1995 env
->hflags
|= HF_SOFTMMU_MASK
;
1997 env
->hflags2
|= HF2_GIF_MASK
;
1999 cpu_x86_update_cr0(env
, 0x60000010);
2000 env
->a20_mask
= ~0x0;
2001 env
->smbase
= 0x30000;
2003 env
->idt
.limit
= 0xffff;
2004 env
->gdt
.limit
= 0xffff;
2005 env
->ldt
.limit
= 0xffff;
2006 env
->ldt
.flags
= DESC_P_MASK
| (2 << DESC_TYPE_SHIFT
);
2007 env
->tr
.limit
= 0xffff;
2008 env
->tr
.flags
= DESC_P_MASK
| (11 << DESC_TYPE_SHIFT
);
2010 cpu_x86_load_seg_cache(env
, R_CS
, 0xf000, 0xffff0000, 0xffff,
2011 DESC_P_MASK
| DESC_S_MASK
| DESC_CS_MASK
|
2012 DESC_R_MASK
| DESC_A_MASK
);
2013 cpu_x86_load_seg_cache(env
, R_DS
, 0, 0, 0xffff,
2014 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2016 cpu_x86_load_seg_cache(env
, R_ES
, 0, 0, 0xffff,
2017 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2019 cpu_x86_load_seg_cache(env
, R_SS
, 0, 0, 0xffff,
2020 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2022 cpu_x86_load_seg_cache(env
, R_FS
, 0, 0, 0xffff,
2023 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2025 cpu_x86_load_seg_cache(env
, R_GS
, 0, 0, 0xffff,
2026 DESC_P_MASK
| DESC_S_MASK
| DESC_W_MASK
|
2030 env
->regs
[R_EDX
] = env
->cpuid_version
;
2035 for (i
= 0; i
< 8; i
++) {
2040 env
->mxcsr
= 0x1f80;
2042 env
->pat
= 0x0007040600070406ULL
;
2043 env
->msr_ia32_misc_enable
= MSR_IA32_MISC_ENABLE_DEFAULT
;
2045 memset(env
->dr
, 0, sizeof(env
->dr
));
2046 env
->dr
[6] = DR6_FIXED_1
;
2047 env
->dr
[7] = DR7_FIXED_1
;
2048 cpu_breakpoint_remove_all(env
, BP_CPU
);
2049 cpu_watchpoint_remove_all(env
, BP_CPU
);
2051 #if !defined(CONFIG_USER_ONLY)
2052 /* We hard-wire the BSP to the first CPU. */
2053 if (s
->cpu_index
== 0) {
2054 apic_designate_bsp(env
->apic_state
);
2057 env
->halted
= !cpu_is_bsp(cpu
);
2061 #ifndef CONFIG_USER_ONLY
2062 bool cpu_is_bsp(X86CPU
*cpu
)
2064 return cpu_get_apic_base(cpu
->env
.apic_state
) & MSR_IA32_APICBASE_BSP
;
2067 /* TODO: remove me, when reset over QOM tree is implemented */
2068 static void x86_cpu_machine_reset_cb(void *opaque
)
2070 X86CPU
*cpu
= opaque
;
2071 cpu_reset(CPU(cpu
));
2075 static void mce_init(X86CPU
*cpu
)
2077 CPUX86State
*cenv
= &cpu
->env
;
2080 if (((cenv
->cpuid_version
>> 8) & 0xf) >= 6
2081 && (cenv
->cpuid_features
& (CPUID_MCE
| CPUID_MCA
)) ==
2082 (CPUID_MCE
| CPUID_MCA
)) {
2083 cenv
->mcg_cap
= MCE_CAP_DEF
| MCE_BANKS_DEF
;
2084 cenv
->mcg_ctl
= ~(uint64_t)0;
2085 for (bank
= 0; bank
< MCE_BANKS_DEF
; bank
++) {
2086 cenv
->mce_banks
[bank
* 4] = ~(uint64_t)0;
2091 #define MSI_ADDR_BASE 0xfee00000
2093 #ifndef CONFIG_USER_ONLY
2094 static void x86_cpu_apic_init(X86CPU
*cpu
, Error
**errp
)
2096 static int apic_mapped
;
2097 CPUX86State
*env
= &cpu
->env
;
2098 APICCommonState
*apic
;
2099 const char *apic_type
= "apic";
2101 if (kvm_irqchip_in_kernel()) {
2102 apic_type
= "kvm-apic";
2103 } else if (xen_enabled()) {
2104 apic_type
= "xen-apic";
2107 env
->apic_state
= qdev_try_create(NULL
, apic_type
);
2108 if (env
->apic_state
== NULL
) {
2109 error_setg(errp
, "APIC device '%s' could not be created", apic_type
);
2113 object_property_add_child(OBJECT(cpu
), "apic",
2114 OBJECT(env
->apic_state
), NULL
);
2115 qdev_prop_set_uint8(env
->apic_state
, "id", env
->cpuid_apic_id
);
2116 /* TODO: convert to link<> */
2117 apic
= APIC_COMMON(env
->apic_state
);
2120 if (qdev_init(env
->apic_state
)) {
2121 error_setg(errp
, "APIC device '%s' could not be initialized",
2122 object_get_typename(OBJECT(env
->apic_state
)));
2126 /* XXX: mapping more APICs at the same memory location */
2127 if (apic_mapped
== 0) {
2128 /* NOTE: the APIC is directly connected to the CPU - it is not
2129 on the global memory bus. */
2130 /* XXX: what if the base changes? */
2131 sysbus_mmio_map(sysbus_from_qdev(env
->apic_state
), 0, MSI_ADDR_BASE
);
2137 void x86_cpu_realize(Object
*obj
, Error
**errp
)
2139 X86CPU
*cpu
= X86_CPU(obj
);
2140 CPUX86State
*env
= &cpu
->env
;
2142 if (env
->cpuid_7_0_ebx_features
&& env
->cpuid_level
< 7) {
2143 env
->cpuid_level
= 7;
2146 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
2149 if (env
->cpuid_vendor1
== CPUID_VENDOR_AMD_1
&&
2150 env
->cpuid_vendor2
== CPUID_VENDOR_AMD_2
&&
2151 env
->cpuid_vendor3
== CPUID_VENDOR_AMD_3
) {
2152 env
->cpuid_ext2_features
&= ~CPUID_EXT2_AMD_ALIASES
;
2153 env
->cpuid_ext2_features
|= (env
->cpuid_features
2154 & CPUID_EXT2_AMD_ALIASES
);
2157 if (!kvm_enabled()) {
2158 env
->cpuid_features
&= TCG_FEATURES
;
2159 env
->cpuid_ext_features
&= TCG_EXT_FEATURES
;
2160 env
->cpuid_ext2_features
&= (TCG_EXT2_FEATURES
2161 #ifdef TARGET_X86_64
2162 | CPUID_EXT2_SYSCALL
| CPUID_EXT2_LM
2165 env
->cpuid_ext3_features
&= TCG_EXT3_FEATURES
;
2166 env
->cpuid_svm_features
&= TCG_SVM_FEATURES
;
2169 filter_features_for_kvm(cpu
);
2173 #ifndef CONFIG_USER_ONLY
2174 qemu_register_reset(x86_cpu_machine_reset_cb
, cpu
);
2176 if (cpu
->env
.cpuid_features
& CPUID_APIC
|| smp_cpus
> 1) {
2177 x86_cpu_apic_init(cpu
, errp
);
2178 if (error_is_set(errp
)) {
2185 qemu_init_vcpu(&cpu
->env
);
2186 cpu_reset(CPU(cpu
));
2189 static void x86_cpu_initfn(Object
*obj
)
2191 CPUState
*cs
= CPU(obj
);
2192 X86CPU
*cpu
= X86_CPU(obj
);
2193 CPUX86State
*env
= &cpu
->env
;
2198 object_property_add(obj
, "family", "int",
2199 x86_cpuid_version_get_family
,
2200 x86_cpuid_version_set_family
, NULL
, NULL
, NULL
);
2201 object_property_add(obj
, "model", "int",
2202 x86_cpuid_version_get_model
,
2203 x86_cpuid_version_set_model
, NULL
, NULL
, NULL
);
2204 object_property_add(obj
, "stepping", "int",
2205 x86_cpuid_version_get_stepping
,
2206 x86_cpuid_version_set_stepping
, NULL
, NULL
, NULL
);
2207 object_property_add(obj
, "level", "int",
2208 x86_cpuid_get_level
,
2209 x86_cpuid_set_level
, NULL
, NULL
, NULL
);
2210 object_property_add(obj
, "xlevel", "int",
2211 x86_cpuid_get_xlevel
,
2212 x86_cpuid_set_xlevel
, NULL
, NULL
, NULL
);
2213 object_property_add_str(obj
, "vendor",
2214 x86_cpuid_get_vendor
,
2215 x86_cpuid_set_vendor
, NULL
);
2216 object_property_add_str(obj
, "model-id",
2217 x86_cpuid_get_model_id
,
2218 x86_cpuid_set_model_id
, NULL
);
2219 object_property_add(obj
, "tsc-frequency", "int",
2220 x86_cpuid_get_tsc_freq
,
2221 x86_cpuid_set_tsc_freq
, NULL
, NULL
, NULL
);
2223 env
->cpuid_apic_id
= cs
->cpu_index
;
2225 /* init various static tables used in TCG mode */
2226 if (tcg_enabled() && !inited
) {
2228 optimize_flags_init();
2229 #ifndef CONFIG_USER_ONLY
2230 cpu_set_debug_excp_handler(breakpoint_handler
);
2235 static void x86_cpu_common_class_init(ObjectClass
*oc
, void *data
)
2237 X86CPUClass
*xcc
= X86_CPU_CLASS(oc
);
2238 CPUClass
*cc
= CPU_CLASS(oc
);
2240 xcc
->parent_reset
= cc
->reset
;
2241 cc
->reset
= x86_cpu_reset
;
2244 static const TypeInfo x86_cpu_type_info
= {
2245 .name
= TYPE_X86_CPU
,
2247 .instance_size
= sizeof(X86CPU
),
2248 .instance_init
= x86_cpu_initfn
,
2250 .class_size
= sizeof(X86CPUClass
),
2251 .class_init
= x86_cpu_common_class_init
,
2254 static void x86_cpu_register_types(void)
2256 type_register_static(&x86_cpu_type_info
);
2259 type_init(x86_cpu_register_types
)