VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUM.cpp@ 41783

Last change on this file since 41783 was 41783, checked in by vboxsync, 13 years ago

Doxygen, comment typos.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 190.3 KB
Line 
1/* $Id: CPUM.cpp 41783 2012-06-16 19:24:15Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor / Manager.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/** @page pg_cpum CPUM - CPU Monitor / Manager
19 *
20 * The CPU Monitor / Manager keeps track of all the CPU registers. It is
21 * also responsible for lazy FPU handling and some of the context loading
22 * in raw mode.
23 *
24 * There are three CPU contexts, the most important one is the guest one (GC).
25 * When running in raw-mode (RC) there is a special hyper context for the VMM
26 * part that floats around inside the guest address space. When running in
27 * raw-mode, CPUM also maintains a host context for saving and restoring
28 * registers across world switches. This latter is done in cooperation with the
29 * world switcher (@see pg_vmm).
30 *
31 * @see grp_cpum
32 */
33
34/*******************************************************************************
35* Header Files *
36*******************************************************************************/
37#define LOG_GROUP LOG_GROUP_CPUM
38#include <VBox/vmm/cpum.h>
39#include <VBox/vmm/cpumdis.h>
40#include <VBox/vmm/pgm.h>
41#include <VBox/vmm/mm.h>
42#include <VBox/vmm/selm.h>
43#include <VBox/vmm/dbgf.h>
44#include <VBox/vmm/patm.h>
45#include <VBox/vmm/hwaccm.h>
46#include <VBox/vmm/ssm.h>
47#include "CPUMInternal.h"
48#include <VBox/vmm/vm.h>
49
50#include <VBox/param.h>
51#include <VBox/dis.h>
52#include <VBox/err.h>
53#include <VBox/log.h>
54#include <iprt/assert.h>
55#include <iprt/asm-amd64-x86.h>
56#include <iprt/string.h>
57#include <iprt/mp.h>
58#include <iprt/cpuset.h>
59#include "internal/pgm.h"
60
61
62/*******************************************************************************
63* Defined Constants And Macros *
64*******************************************************************************/
65/** The current saved state version. */
66#define CPUM_SAVED_STATE_VERSION 13
67/** The saved state version before introducing the MSR size field. */
68#define CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE 12
69/** The saved state version of 3.2, 3.1 and 3.3 trunk before the hidden
70 * selector register change (CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID). */
71#define CPUM_SAVED_STATE_VERSION_VER3_2 11
72/** The saved state version of 3.0 and 3.1 trunk before the teleportation
73 * changes. */
74#define CPUM_SAVED_STATE_VERSION_VER3_0 10
75/** The saved state version for the 2.1 trunk before the MSR changes. */
76#define CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR 9
77/** The saved state version of 2.0, used for backwards compatibility. */
78#define CPUM_SAVED_STATE_VERSION_VER2_0 8
79/** The saved state version of 1.6, used for backwards compatibility. */
80#define CPUM_SAVED_STATE_VERSION_VER1_6 6
81
82
83/*******************************************************************************
84* Structures and Typedefs *
85*******************************************************************************/
86
87/**
88 * What kind of cpu info dump to perform.
89 */
90typedef enum CPUMDUMPTYPE
91{
92 CPUMDUMPTYPE_TERSE,
93 CPUMDUMPTYPE_DEFAULT,
94 CPUMDUMPTYPE_VERBOSE
95} CPUMDUMPTYPE;
96/** Pointer to a cpu info dump type. */
97typedef CPUMDUMPTYPE *PCPUMDUMPTYPE;
98
99
100/*******************************************************************************
101* Internal Functions *
102*******************************************************************************/
103static CPUMCPUVENDOR cpumR3DetectVendor(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX);
104static int cpumR3CpuIdInit(PVM pVM);
105static DECLCALLBACK(int) cpumR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
106static DECLCALLBACK(int) cpumR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
107static DECLCALLBACK(int) cpumR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
108static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
109static DECLCALLBACK(int) cpumR3LoadDone(PVM pVM, PSSMHANDLE pSSM);
110static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
111static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
112static DECLCALLBACK(void) cpumR3InfoGuestInstr(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
113static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
114static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
115static DECLCALLBACK(void) cpumR3CpuIdInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
116
117
118/**
119 * Initializes the CPUM.
120 *
121 * @returns VBox status code.
122 * @param pVM The VM to operate on.
123 */
124VMMR3DECL(int) CPUMR3Init(PVM pVM)
125{
126 LogFlow(("CPUMR3Init\n"));
127
128 /*
129 * Assert alignment and sizes.
130 */
131 AssertCompileMemberAlignment(VM, cpum.s, 32);
132 AssertCompile(sizeof(pVM->cpum.s) <= sizeof(pVM->cpum.padding));
133 AssertCompileSizeAlignment(CPUMCTX, 64);
134 AssertCompileSizeAlignment(CPUMCTXMSRS, 64);
135 AssertCompileSizeAlignment(CPUMHOSTCTX, 64);
136 AssertCompileMemberAlignment(VM, cpum, 64);
137 AssertCompileMemberAlignment(VM, aCpus, 64);
138 AssertCompileMemberAlignment(VMCPU, cpum.s, 64);
139 AssertCompileMemberSizeAlignment(VM, aCpus[0].cpum.s, 64);
140
141 /* Calculate the offset from CPUM to CPUMCPU for the first CPU. */
142 pVM->cpum.s.offCPUMCPU0 = RT_OFFSETOF(VM, aCpus[0].cpum) - RT_OFFSETOF(VM, cpum);
143 Assert((uintptr_t)&pVM->cpum + pVM->cpum.s.offCPUMCPU0 == (uintptr_t)&pVM->aCpus[0].cpum);
144
145 /* Calculate the offset from CPUMCPU to CPUM. */
146 for (VMCPUID i = 0; i < pVM->cCpus; i++)
147 {
148 PVMCPU pVCpu = &pVM->aCpus[i];
149
150 /*
151 * Setup any fixed pointers and offsets.
152 */
153 pVCpu->cpum.s.pHyperCoreR3 = CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
154 pVCpu->cpum.s.pHyperCoreR0 = VM_R0_ADDR(pVM, CPUMCTX2CORE(&pVCpu->cpum.s.Hyper));
155
156 pVCpu->cpum.s.offCPUM = RT_OFFSETOF(VM, aCpus[i].cpum) - RT_OFFSETOF(VM, cpum);
157 Assert((uintptr_t)&pVCpu->cpum - pVCpu->cpum.s.offCPUM == (uintptr_t)&pVM->cpum);
158 }
159
160 /*
161 * Check that the CPU supports the minimum features we require.
162 */
163 if (!ASMHasCpuId())
164 {
165 Log(("The CPU doesn't support CPUID!\n"));
166 return VERR_UNSUPPORTED_CPU;
167 }
168 ASMCpuId_ECX_EDX(1, &pVM->cpum.s.CPUFeatures.ecx, &pVM->cpum.s.CPUFeatures.edx);
169 ASMCpuId_ECX_EDX(0x80000001, &pVM->cpum.s.CPUFeaturesExt.ecx, &pVM->cpum.s.CPUFeaturesExt.edx);
170
171 /* Setup the CR4 AND and OR masks used in the switcher */
172 /* Depends on the presence of FXSAVE(SSE) support on the host CPU */
173 if (!pVM->cpum.s.CPUFeatures.edx.u1FXSR)
174 {
175 Log(("The CPU doesn't support FXSAVE/FXRSTOR!\n"));
176 /* No FXSAVE implies no SSE */
177 pVM->cpum.s.CR4.AndMask = X86_CR4_PVI | X86_CR4_VME;
178 pVM->cpum.s.CR4.OrMask = 0;
179 }
180 else
181 {
182 pVM->cpum.s.CR4.AndMask = X86_CR4_OSXMMEEXCPT | X86_CR4_PVI | X86_CR4_VME;
183 pVM->cpum.s.CR4.OrMask = X86_CR4_OSFSXR;
184 }
185
186 if (!pVM->cpum.s.CPUFeatures.edx.u1MMX)
187 {
188 Log(("The CPU doesn't support MMX!\n"));
189 return VERR_UNSUPPORTED_CPU;
190 }
191 if (!pVM->cpum.s.CPUFeatures.edx.u1TSC)
192 {
193 Log(("The CPU doesn't support TSC!\n"));
194 return VERR_UNSUPPORTED_CPU;
195 }
196 /* Bogus on AMD? */
197 if (!pVM->cpum.s.CPUFeatures.edx.u1SEP)
198 Log(("The CPU doesn't support SYSENTER/SYSEXIT!\n"));
199
200 /*
201 * Detect the host CPU vendor.
202 * (The guest CPU vendor is re-detected later on.)
203 */
204 uint32_t uEAX, uEBX, uECX, uEDX;
205 ASMCpuId(0, &uEAX, &uEBX, &uECX, &uEDX);
206 pVM->cpum.s.enmHostCpuVendor = cpumR3DetectVendor(uEAX, uEBX, uECX, uEDX);
207 pVM->cpum.s.enmGuestCpuVendor = pVM->cpum.s.enmHostCpuVendor;
208
209 /*
210 * Setup hypervisor startup values.
211 */
212
213 /*
214 * Register saved state data item.
215 */
216 int rc = SSMR3RegisterInternal(pVM, "cpum", 1, CPUM_SAVED_STATE_VERSION, sizeof(CPUM),
217 NULL, cpumR3LiveExec, NULL,
218 NULL, cpumR3SaveExec, NULL,
219 cpumR3LoadPrep, cpumR3LoadExec, cpumR3LoadDone);
220 if (RT_FAILURE(rc))
221 return rc;
222
223 /*
224 * Register info handlers and registers with the debugger facility.
225 */
226 DBGFR3InfoRegisterInternal(pVM, "cpum", "Displays the all the cpu states.", &cpumR3InfoAll);
227 DBGFR3InfoRegisterInternal(pVM, "cpumguest", "Displays the guest cpu state.", &cpumR3InfoGuest);
228 DBGFR3InfoRegisterInternal(pVM, "cpumhyper", "Displays the hypervisor cpu state.", &cpumR3InfoHyper);
229 DBGFR3InfoRegisterInternal(pVM, "cpumhost", "Displays the host cpu state.", &cpumR3InfoHost);
230 DBGFR3InfoRegisterInternal(pVM, "cpuid", "Displays the guest cpuid leaves.", &cpumR3CpuIdInfo);
231 DBGFR3InfoRegisterInternal(pVM, "cpumguestinstr", "Displays the current guest instruction.", &cpumR3InfoGuestInstr);
232
233 rc = cpumR3DbgInit(pVM);
234 if (RT_FAILURE(rc))
235 return rc;
236
237 /*
238 * Initialize the Guest CPUID state.
239 */
240 rc = cpumR3CpuIdInit(pVM);
241 if (RT_FAILURE(rc))
242 return rc;
243 CPUMR3Reset(pVM);
244 return VINF_SUCCESS;
245}
246
247
248/**
249 * Detect the CPU vendor give n the
250 *
251 * @returns The vendor.
252 * @param uEAX EAX from CPUID(0).
253 * @param uEBX EBX from CPUID(0).
254 * @param uECX ECX from CPUID(0).
255 * @param uEDX EDX from CPUID(0).
256 */
257static CPUMCPUVENDOR cpumR3DetectVendor(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX)
258{
259 if ( uEAX >= 1
260 && uEBX == X86_CPUID_VENDOR_AMD_EBX
261 && uECX == X86_CPUID_VENDOR_AMD_ECX
262 && uEDX == X86_CPUID_VENDOR_AMD_EDX)
263 return CPUMCPUVENDOR_AMD;
264
265 if ( uEAX >= 1
266 && uEBX == X86_CPUID_VENDOR_INTEL_EBX
267 && uECX == X86_CPUID_VENDOR_INTEL_ECX
268 && uEDX == X86_CPUID_VENDOR_INTEL_EDX)
269 return CPUMCPUVENDOR_INTEL;
270
271 /** @todo detect the other buggers... */
272 return CPUMCPUVENDOR_UNKNOWN;
273}
274
275
276/**
277 * Fetches overrides for a CPUID leaf.
278 *
279 * @returns VBox status code.
280 * @param pLeaf The leaf to load the overrides into.
281 * @param pCfgNode The CFGM node containing the overrides
282 * (/CPUM/HostCPUID/ or /CPUM/CPUID/).
283 * @param iLeaf The CPUID leaf number.
284 */
285static int cpumR3CpuIdFetchLeafOverride(PCPUMCPUID pLeaf, PCFGMNODE pCfgNode, uint32_t iLeaf)
286{
287 PCFGMNODE pLeafNode = CFGMR3GetChildF(pCfgNode, "%RX32", iLeaf);
288 if (pLeafNode)
289 {
290 uint32_t u32;
291 int rc = CFGMR3QueryU32(pLeafNode, "eax", &u32);
292 if (RT_SUCCESS(rc))
293 pLeaf->eax = u32;
294 else
295 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
296
297 rc = CFGMR3QueryU32(pLeafNode, "ebx", &u32);
298 if (RT_SUCCESS(rc))
299 pLeaf->ebx = u32;
300 else
301 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
302
303 rc = CFGMR3QueryU32(pLeafNode, "ecx", &u32);
304 if (RT_SUCCESS(rc))
305 pLeaf->ecx = u32;
306 else
307 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
308
309 rc = CFGMR3QueryU32(pLeafNode, "edx", &u32);
310 if (RT_SUCCESS(rc))
311 pLeaf->edx = u32;
312 else
313 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
314
315 }
316 return VINF_SUCCESS;
317}
318
319
320/**
321 * Load the overrides for a set of CPUID leaves.
322 *
323 * @returns VBox status code.
324 * @param paLeaves The leaf array.
325 * @param cLeaves The number of leaves.
326 * @param uStart The start leaf number.
327 * @param pCfgNode The CFGM node containing the overrides
328 * (/CPUM/HostCPUID/ or /CPUM/CPUID/).
329 */
330static int cpumR3CpuIdInitLoadOverrideSet(uint32_t uStart, PCPUMCPUID paLeaves, uint32_t cLeaves, PCFGMNODE pCfgNode)
331{
332 for (uint32_t i = 0; i < cLeaves; i++)
333 {
334 int rc = cpumR3CpuIdFetchLeafOverride(&paLeaves[i], pCfgNode, uStart + i);
335 if (RT_FAILURE(rc))
336 return rc;
337 }
338
339 return VINF_SUCCESS;
340}
341
342/**
343 * Init a set of host CPUID leaves.
344 *
345 * @returns VBox status code.
346 * @param paLeaves The leaf array.
347 * @param cLeaves The number of leaves.
348 * @param uStart The start leaf number.
349 * @param pCfgNode The /CPUM/HostCPUID/ node.
350 */
351static int cpumR3CpuIdInitHostSet(uint32_t uStart, PCPUMCPUID paLeaves, uint32_t cLeaves, PCFGMNODE pCfgNode)
352{
353 /* Using the ECX variant for all of them can't hurt... */
354 for (uint32_t i = 0; i < cLeaves; i++)
355 ASMCpuId_Idx_ECX(uStart + i, 0, &paLeaves[i].eax, &paLeaves[i].ebx, &paLeaves[i].ecx, &paLeaves[i].edx);
356
357 /* Load CPUID leaf override; we currently don't care if the user
358 specifies features the host CPU doesn't support. */
359 return cpumR3CpuIdInitLoadOverrideSet(uStart, paLeaves, cLeaves, pCfgNode);
360}
361
362
363/**
364 * Initializes the emulated CPU's cpuid information.
365 *
366 * @returns VBox status code.
367 * @param pVM The VM to operate on.
368 */
369static int cpumR3CpuIdInit(PVM pVM)
370{
371 PCPUM pCPUM = &pVM->cpum.s;
372 PCFGMNODE pCpumCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM");
373 uint32_t i;
374 int rc;
375
376#define PORTABLE_CLEAR_BITS_WHEN(Lvl, LeafSuffReg, FeatNm, fMask, uValue) \
377 if (pCPUM->u8PortableCpuIdLevel >= (Lvl) && (pCPUM->aGuestCpuId##LeafSuffReg & (fMask)) == (uValue) ) \
378 { \
379 LogRel(("PortableCpuId: " #LeafSuffReg "[" #FeatNm "]: %#x -> 0\n", pCPUM->aGuestCpuId##LeafSuffReg & (fMask))); \
380 pCPUM->aGuestCpuId##LeafSuffReg &= ~(uint32_t)(fMask); \
381 }
382#define PORTABLE_DISABLE_FEATURE_BIT(Lvl, LeafSuffReg, FeatNm, fBitMask) \
383 if (pCPUM->u8PortableCpuIdLevel >= (Lvl) && (pCPUM->aGuestCpuId##LeafSuffReg & (fBitMask)) ) \
384 { \
385 LogRel(("PortableCpuId: " #LeafSuffReg "[" #FeatNm "]: 1 -> 0\n")); \
386 pCPUM->aGuestCpuId##LeafSuffReg &= ~(uint32_t)(fBitMask); \
387 }
388
389 /*
390 * Read the configuration.
391 */
392 /** @cfgm{CPUM/SyntheticCpu, boolean, false}
393 * Enables the Synthetic CPU. The Vendor ID and Processor Name are
394 * completely overridden by VirtualBox custom strings. Some
395 * CPUID information is withheld, like the cache info. */
396 rc = CFGMR3QueryBoolDef(pCpumCfg, "SyntheticCpu", &pCPUM->fSyntheticCpu, false);
397 AssertRCReturn(rc, rc);
398
399 /** @cfgm{CPUM/PortableCpuIdLevel, 8-bit, 0, 3, 0}
400 * When non-zero CPUID features that could cause portability issues will be
401 * stripped. The higher the value the more features gets stripped. Higher
402 * values should only be used when older CPUs are involved since it may
403 * harm performance and maybe also cause problems with specific guests. */
404 rc = CFGMR3QueryU8Def(pCpumCfg, "PortableCpuIdLevel", &pCPUM->u8PortableCpuIdLevel, 0);
405 AssertRCReturn(rc, rc);
406
407 AssertLogRelReturn(!pCPUM->fSyntheticCpu || !pCPUM->u8PortableCpuIdLevel, VERR_CPUM_INCOMPATIBLE_CONFIG);
408
409 /*
410 * Get the host CPUID leaves and redetect the guest CPU vendor (could've
411 * been overridden).
412 */
413 /** @cfgm{CPUM/HostCPUID/[000000xx|800000xx|c000000x]/[eax|ebx|ecx|edx],32-bit}
414 * Overrides the host CPUID leaf values used for calculating the guest CPUID
415 * leaves. This can be used to preserve the CPUID values when moving a VM
416 * to a different machine. Another use is restricting (or extending) the
417 * feature set exposed to the guest. */
418 PCFGMNODE pHostOverrideCfg = CFGMR3GetChild(pCpumCfg, "HostCPUID");
419 rc = cpumR3CpuIdInitHostSet(UINT32_C(0x00000000), &pCPUM->aGuestCpuIdStd[0], RT_ELEMENTS(pCPUM->aGuestCpuIdStd), pHostOverrideCfg);
420 AssertRCReturn(rc, rc);
421 rc = cpumR3CpuIdInitHostSet(UINT32_C(0x80000000), &pCPUM->aGuestCpuIdExt[0], RT_ELEMENTS(pCPUM->aGuestCpuIdExt), pHostOverrideCfg);
422 AssertRCReturn(rc, rc);
423 rc = cpumR3CpuIdInitHostSet(UINT32_C(0xc0000000), &pCPUM->aGuestCpuIdCentaur[0], RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur), pHostOverrideCfg);
424 AssertRCReturn(rc, rc);
425
426 pCPUM->enmGuestCpuVendor = cpumR3DetectVendor(pCPUM->aGuestCpuIdStd[0].eax, pCPUM->aGuestCpuIdStd[0].ebx,
427 pCPUM->aGuestCpuIdStd[0].ecx, pCPUM->aGuestCpuIdStd[0].edx);
428
429 /*
430 * Determine the default leaf.
431 *
432 * Intel returns values of the highest standard function, while AMD
433 * returns zeros. VIA on the other hand seems to returning nothing or
434 * perhaps some random garbage, we don't try to duplicate this behavior.
435 */
436 ASMCpuId(pCPUM->aGuestCpuIdStd[0].eax + 10, /** @todo r=bird: Use the host value here in case of overrides and more than 10 leaves being stripped already. */
437 &pCPUM->GuestCpuIdDef.eax, &pCPUM->GuestCpuIdDef.ebx,
438 &pCPUM->GuestCpuIdDef.ecx, &pCPUM->GuestCpuIdDef.edx);
439
440
441 /* Cpuid 1 & 0x80000001:
442 * Only report features we can support.
443 *
444 * Note! When enabling new features the Synthetic CPU and Portable CPUID
445 * options may require adjusting (i.e. stripping what was enabled).
446 */
447 pCPUM->aGuestCpuIdStd[1].edx &= X86_CPUID_FEATURE_EDX_FPU
448 | X86_CPUID_FEATURE_EDX_VME
449 | X86_CPUID_FEATURE_EDX_DE
450 | X86_CPUID_FEATURE_EDX_PSE
451 | X86_CPUID_FEATURE_EDX_TSC
452 | X86_CPUID_FEATURE_EDX_MSR
453 //| X86_CPUID_FEATURE_EDX_PAE - set later if configured.
454 | X86_CPUID_FEATURE_EDX_MCE
455 | X86_CPUID_FEATURE_EDX_CX8
456 //| X86_CPUID_FEATURE_EDX_APIC - set by the APIC device if present.
457 /* Note! we don't report sysenter/sysexit support due to our inability to keep the IOPL part of eflags in sync while in ring 1 (see @bugref{1757}) */
458 //| X86_CPUID_FEATURE_EDX_SEP
459 | X86_CPUID_FEATURE_EDX_MTRR
460 | X86_CPUID_FEATURE_EDX_PGE
461 | X86_CPUID_FEATURE_EDX_MCA
462 | X86_CPUID_FEATURE_EDX_CMOV
463 | X86_CPUID_FEATURE_EDX_PAT
464 | X86_CPUID_FEATURE_EDX_PSE36
465 //| X86_CPUID_FEATURE_EDX_PSN - no serial number.
466 | X86_CPUID_FEATURE_EDX_CLFSH
467 //| X86_CPUID_FEATURE_EDX_DS - no debug store.
468 //| X86_CPUID_FEATURE_EDX_ACPI - not virtualized yet.
469 | X86_CPUID_FEATURE_EDX_MMX
470 | X86_CPUID_FEATURE_EDX_FXSR
471 | X86_CPUID_FEATURE_EDX_SSE
472 | X86_CPUID_FEATURE_EDX_SSE2
473 //| X86_CPUID_FEATURE_EDX_SS - no self snoop.
474 //| X86_CPUID_FEATURE_EDX_HTT - no hyperthreading.
475 //| X86_CPUID_FEATURE_EDX_TM - no thermal monitor.
476 //| X86_CPUID_FEATURE_EDX_PBE - no pending break enabled.
477 | 0;
478 pCPUM->aGuestCpuIdStd[1].ecx &= 0
479 | X86_CPUID_FEATURE_ECX_SSE3
480 /* Can't properly emulate monitor & mwait with guest SMP; force the guest to use hlt for idling VCPUs. */
481 | ((pVM->cCpus == 1) ? X86_CPUID_FEATURE_ECX_MONITOR : 0)
482 //| X86_CPUID_FEATURE_ECX_CPLDS - no CPL qualified debug store.
483 //| X86_CPUID_FEATURE_ECX_VMX - not virtualized.
484 //| X86_CPUID_FEATURE_ECX_EST - no extended speed step.
485 //| X86_CPUID_FEATURE_ECX_TM2 - no thermal monitor 2.
486 | X86_CPUID_FEATURE_ECX_SSSE3
487 //| X86_CPUID_FEATURE_ECX_CNTXID - no L1 context id (MSR++).
488 //| X86_CPUID_FEATURE_ECX_CX16 - no cmpxchg16b
489 /* ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
490 //| X86_CPUID_FEATURE_ECX_TPRUPDATE
491 /* ECX Bit 21 - x2APIC support - not yet. */
492 // | X86_CPUID_FEATURE_ECX_X2APIC
493 /* ECX Bit 23 - POPCNT instruction. */
494 //| X86_CPUID_FEATURE_ECX_POPCNT
495 | 0;
496 if (pCPUM->u8PortableCpuIdLevel > 0)
497 {
498 PORTABLE_CLEAR_BITS_WHEN(1, Std[1].eax, ProcessorType, (UINT32_C(3) << 12), (UINT32_C(2) << 12));
499 PORTABLE_DISABLE_FEATURE_BIT(1, Std[1].ecx, SSSE3, X86_CPUID_FEATURE_ECX_SSSE3);
500 PORTABLE_DISABLE_FEATURE_BIT(1, Std[1].ecx, SSE3, X86_CPUID_FEATURE_ECX_SSE3);
501 PORTABLE_DISABLE_FEATURE_BIT(2, Std[1].edx, SSE2, X86_CPUID_FEATURE_EDX_SSE2);
502 PORTABLE_DISABLE_FEATURE_BIT(3, Std[1].edx, SSE, X86_CPUID_FEATURE_EDX_SSE);
503 PORTABLE_DISABLE_FEATURE_BIT(3, Std[1].edx, CLFSH, X86_CPUID_FEATURE_EDX_CLFSH);
504 PORTABLE_DISABLE_FEATURE_BIT(3, Std[1].edx, CMOV, X86_CPUID_FEATURE_EDX_CMOV);
505
506 Assert(!(pCPUM->aGuestCpuIdStd[1].edx & ( X86_CPUID_FEATURE_EDX_SEP
507 | X86_CPUID_FEATURE_EDX_PSN
508 | X86_CPUID_FEATURE_EDX_DS
509 | X86_CPUID_FEATURE_EDX_ACPI
510 | X86_CPUID_FEATURE_EDX_SS
511 | X86_CPUID_FEATURE_EDX_TM
512 | X86_CPUID_FEATURE_EDX_PBE
513 )));
514 Assert(!(pCPUM->aGuestCpuIdStd[1].ecx & ( X86_CPUID_FEATURE_ECX_PCLMUL
515 | X86_CPUID_FEATURE_ECX_DTES64
516 | X86_CPUID_FEATURE_ECX_CPLDS
517 | X86_CPUID_FEATURE_ECX_VMX
518 | X86_CPUID_FEATURE_ECX_SMX
519 | X86_CPUID_FEATURE_ECX_EST
520 | X86_CPUID_FEATURE_ECX_TM2
521 | X86_CPUID_FEATURE_ECX_CNTXID
522 | X86_CPUID_FEATURE_ECX_FMA
523 | X86_CPUID_FEATURE_ECX_CX16
524 | X86_CPUID_FEATURE_ECX_TPRUPDATE
525 | X86_CPUID_FEATURE_ECX_PDCM
526 | X86_CPUID_FEATURE_ECX_DCA
527 | X86_CPUID_FEATURE_ECX_MOVBE
528 | X86_CPUID_FEATURE_ECX_AES
529 | X86_CPUID_FEATURE_ECX_POPCNT
530 | X86_CPUID_FEATURE_ECX_XSAVE
531 | X86_CPUID_FEATURE_ECX_OSXSAVE
532 | X86_CPUID_FEATURE_ECX_AVX
533 )));
534 }
535
536 /* Cpuid 0x80000001:
537 * Only report features we can support.
538 *
539 * Note! When enabling new features the Synthetic CPU and Portable CPUID
540 * options may require adjusting (i.e. stripping what was enabled).
541 *
542 * ASSUMES that this is ALWAYS the AMD defined feature set if present.
543 */
544 pCPUM->aGuestCpuIdExt[1].edx &= X86_CPUID_AMD_FEATURE_EDX_FPU
545 | X86_CPUID_AMD_FEATURE_EDX_VME
546 | X86_CPUID_AMD_FEATURE_EDX_DE
547 | X86_CPUID_AMD_FEATURE_EDX_PSE
548 | X86_CPUID_AMD_FEATURE_EDX_TSC
549 | X86_CPUID_AMD_FEATURE_EDX_MSR //?? this means AMD MSRs..
550 //| X86_CPUID_AMD_FEATURE_EDX_PAE - not implemented yet.
551 //| X86_CPUID_AMD_FEATURE_EDX_MCE - not virtualized yet.
552 | X86_CPUID_AMD_FEATURE_EDX_CX8
553 //| X86_CPUID_AMD_FEATURE_EDX_APIC - set by the APIC device if present.
554 /* Note! we don't report sysenter/sysexit support due to our inability to keep the IOPL part of eflags in sync while in ring 1 (see @bugref{1757}) */
555 //| X86_CPUID_AMD_FEATURE_EDX_SEP
556 | X86_CPUID_AMD_FEATURE_EDX_MTRR
557 | X86_CPUID_AMD_FEATURE_EDX_PGE
558 | X86_CPUID_AMD_FEATURE_EDX_MCA
559 | X86_CPUID_AMD_FEATURE_EDX_CMOV
560 | X86_CPUID_AMD_FEATURE_EDX_PAT
561 | X86_CPUID_AMD_FEATURE_EDX_PSE36
562 //| X86_CPUID_AMD_FEATURE_EDX_NX - not virtualized, requires PAE.
563 //| X86_CPUID_AMD_FEATURE_EDX_AXMMX
564 | X86_CPUID_AMD_FEATURE_EDX_MMX
565 | X86_CPUID_AMD_FEATURE_EDX_FXSR
566 | X86_CPUID_AMD_FEATURE_EDX_FFXSR
567 //| X86_CPUID_AMD_FEATURE_EDX_PAGE1GB
568 //| X86_CPUID_AMD_FEATURE_EDX_RDTSCP - AMD only; turned on when necessary
569 //| X86_CPUID_AMD_FEATURE_EDX_LONG_MODE - turned on when necessary
570 | X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX
571 | X86_CPUID_AMD_FEATURE_EDX_3DNOW
572 | 0;
573 pCPUM->aGuestCpuIdExt[1].ecx &= 0
574 //| X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF
575 //| X86_CPUID_AMD_FEATURE_ECX_CMPL
576 //| X86_CPUID_AMD_FEATURE_ECX_SVM - not virtualized.
577 //| X86_CPUID_AMD_FEATURE_ECX_EXT_APIC
578 /* Note: This could prevent teleporting from AMD to Intel CPUs! */
579 | X86_CPUID_AMD_FEATURE_ECX_CR8L /* expose lock mov cr0 = mov cr8 hack for guests that can use this feature to access the TPR. */
580 //| X86_CPUID_AMD_FEATURE_ECX_ABM
581 //| X86_CPUID_AMD_FEATURE_ECX_SSE4A
582 //| X86_CPUID_AMD_FEATURE_ECX_MISALNSSE
583 //| X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF
584 //| X86_CPUID_AMD_FEATURE_ECX_OSVW
585 //| X86_CPUID_AMD_FEATURE_ECX_IBS
586 //| X86_CPUID_AMD_FEATURE_ECX_SSE5
587 //| X86_CPUID_AMD_FEATURE_ECX_SKINIT
588 //| X86_CPUID_AMD_FEATURE_ECX_WDT
589 | 0;
590 if (pCPUM->u8PortableCpuIdLevel > 0)
591 {
592 PORTABLE_DISABLE_FEATURE_BIT(1, Ext[1].ecx, CR8L, X86_CPUID_AMD_FEATURE_ECX_CR8L);
593 PORTABLE_DISABLE_FEATURE_BIT(1, Ext[1].edx, 3DNOW, X86_CPUID_AMD_FEATURE_EDX_3DNOW);
594 PORTABLE_DISABLE_FEATURE_BIT(1, Ext[1].edx, 3DNOW_EX, X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX);
595 PORTABLE_DISABLE_FEATURE_BIT(1, Ext[1].edx, FFXSR, X86_CPUID_AMD_FEATURE_EDX_FFXSR);
596 PORTABLE_DISABLE_FEATURE_BIT(1, Ext[1].edx, RDTSCP, X86_CPUID_AMD_FEATURE_EDX_RDTSCP);
597 PORTABLE_DISABLE_FEATURE_BIT(2, Ext[1].ecx, LAHF_SAHF, X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF);
598 PORTABLE_DISABLE_FEATURE_BIT(3, Ext[1].ecx, CMOV, X86_CPUID_AMD_FEATURE_EDX_CMOV);
599
600 Assert(!(pCPUM->aGuestCpuIdExt[1].ecx & ( X86_CPUID_AMD_FEATURE_ECX_CMPL
601 | X86_CPUID_AMD_FEATURE_ECX_SVM
602 | X86_CPUID_AMD_FEATURE_ECX_EXT_APIC
603 | X86_CPUID_AMD_FEATURE_ECX_CR8L
604 | X86_CPUID_AMD_FEATURE_ECX_ABM
605 | X86_CPUID_AMD_FEATURE_ECX_SSE4A
606 | X86_CPUID_AMD_FEATURE_ECX_MISALNSSE
607 | X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF
608 | X86_CPUID_AMD_FEATURE_ECX_OSVW
609 | X86_CPUID_AMD_FEATURE_ECX_IBS
610 | X86_CPUID_AMD_FEATURE_ECX_SSE5
611 | X86_CPUID_AMD_FEATURE_ECX_SKINIT
612 | X86_CPUID_AMD_FEATURE_ECX_WDT
613 | UINT32_C(0xffffc000)
614 )));
615 Assert(!(pCPUM->aGuestCpuIdExt[1].edx & ( RT_BIT(10)
616 | X86_CPUID_AMD_FEATURE_EDX_SEP
617 | RT_BIT(18)
618 | RT_BIT(19)
619 | RT_BIT(21)
620 | X86_CPUID_AMD_FEATURE_EDX_AXMMX
621 | X86_CPUID_AMD_FEATURE_EDX_PAGE1GB
622 | RT_BIT(28)
623 )));
624 }
625
626 /*
627 * Apply the Synthetic CPU modifications. (TODO: move this up)
628 */
629 if (pCPUM->fSyntheticCpu)
630 {
631 static const char s_szVendor[13] = "VirtualBox ";
632 static const char s_szProcessor[48] = "VirtualBox SPARCx86 Processor v1000 "; /* includes null terminator */
633
634 pCPUM->enmGuestCpuVendor = CPUMCPUVENDOR_SYNTHETIC;
635
636 /* Limit the nr of standard leaves; 5 for monitor/mwait */
637 pCPUM->aGuestCpuIdStd[0].eax = RT_MIN(pCPUM->aGuestCpuIdStd[0].eax, 5);
638
639 /* 0: Vendor */
640 pCPUM->aGuestCpuIdStd[0].ebx = pCPUM->aGuestCpuIdExt[0].ebx = ((uint32_t *)s_szVendor)[0];
641 pCPUM->aGuestCpuIdStd[0].ecx = pCPUM->aGuestCpuIdExt[0].ecx = ((uint32_t *)s_szVendor)[2];
642 pCPUM->aGuestCpuIdStd[0].edx = pCPUM->aGuestCpuIdExt[0].edx = ((uint32_t *)s_szVendor)[1];
643
644 /* 1.eax: Version information. family : model : stepping */
645 pCPUM->aGuestCpuIdStd[1].eax = (0xf << 8) + (0x1 << 4) + 1;
646
647 /* Leaves 2 - 4 are Intel only - zero them out */
648 memset(&pCPUM->aGuestCpuIdStd[2], 0, sizeof(pCPUM->aGuestCpuIdStd[2]));
649 memset(&pCPUM->aGuestCpuIdStd[3], 0, sizeof(pCPUM->aGuestCpuIdStd[3]));
650 memset(&pCPUM->aGuestCpuIdStd[4], 0, sizeof(pCPUM->aGuestCpuIdStd[4]));
651
652 /* Leaf 5 = monitor/mwait */
653
654 /* Limit the nr of extended leaves: 0x80000008 to include the max virtual and physical address size (64 bits guests). */
655 pCPUM->aGuestCpuIdExt[0].eax = RT_MIN(pCPUM->aGuestCpuIdExt[0].eax, 0x80000008);
656 /* AMD only - set to zero. */
657 pCPUM->aGuestCpuIdExt[0].ebx = pCPUM->aGuestCpuIdExt[0].ecx = pCPUM->aGuestCpuIdExt[0].edx = 0;
658
659 /* 0x800000001: AMD only; shared feature bits are set dynamically. */
660 memset(&pCPUM->aGuestCpuIdExt[1], 0, sizeof(pCPUM->aGuestCpuIdExt[1]));
661
662 /* 0x800000002-4: Processor Name String Identifier. */
663 pCPUM->aGuestCpuIdExt[2].eax = ((uint32_t *)s_szProcessor)[0];
664 pCPUM->aGuestCpuIdExt[2].ebx = ((uint32_t *)s_szProcessor)[1];
665 pCPUM->aGuestCpuIdExt[2].ecx = ((uint32_t *)s_szProcessor)[2];
666 pCPUM->aGuestCpuIdExt[2].edx = ((uint32_t *)s_szProcessor)[3];
667 pCPUM->aGuestCpuIdExt[3].eax = ((uint32_t *)s_szProcessor)[4];
668 pCPUM->aGuestCpuIdExt[3].ebx = ((uint32_t *)s_szProcessor)[5];
669 pCPUM->aGuestCpuIdExt[3].ecx = ((uint32_t *)s_szProcessor)[6];
670 pCPUM->aGuestCpuIdExt[3].edx = ((uint32_t *)s_szProcessor)[7];
671 pCPUM->aGuestCpuIdExt[4].eax = ((uint32_t *)s_szProcessor)[8];
672 pCPUM->aGuestCpuIdExt[4].ebx = ((uint32_t *)s_szProcessor)[9];
673 pCPUM->aGuestCpuIdExt[4].ecx = ((uint32_t *)s_szProcessor)[10];
674 pCPUM->aGuestCpuIdExt[4].edx = ((uint32_t *)s_szProcessor)[11];
675
676 /* 0x800000005-7 - reserved -> zero */
677 memset(&pCPUM->aGuestCpuIdExt[5], 0, sizeof(pCPUM->aGuestCpuIdExt[5]));
678 memset(&pCPUM->aGuestCpuIdExt[6], 0, sizeof(pCPUM->aGuestCpuIdExt[6]));
679 memset(&pCPUM->aGuestCpuIdExt[7], 0, sizeof(pCPUM->aGuestCpuIdExt[7]));
680
681 /* 0x800000008: only the max virtual and physical address size. */
682 pCPUM->aGuestCpuIdExt[8].ecx = pCPUM->aGuestCpuIdExt[8].ebx = pCPUM->aGuestCpuIdExt[8].edx = 0; /* reserved */
683 }
684
685 /*
686 * Hide HTT, multicode, SMP, whatever.
687 * (APIC-ID := 0 and #LogCpus := 0)
688 */
689 pCPUM->aGuestCpuIdStd[1].ebx &= 0x0000ffff;
690#ifdef VBOX_WITH_MULTI_CORE
691 if ( pCPUM->enmGuestCpuVendor != CPUMCPUVENDOR_SYNTHETIC
692 && pVM->cCpus > 1)
693 {
694 /* If CPUID Fn0000_0001_EDX[HTT] = 1 then LogicalProcessorCount is the number of threads per CPU core times the number of CPU cores per processor */
695 pCPUM->aGuestCpuIdStd[1].ebx |= (pVM->cCpus << 16);
696 pCPUM->aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_HTT; /* necessary for hyper-threading *or* multi-core CPUs */
697 }
698#endif
699
700 /* Cpuid 2:
701 * Intel: Cache and TLB information
702 * AMD: Reserved
703 * Safe to expose; restrict the number of calls to 1 for the portable case.
704 */
705 if ( pCPUM->u8PortableCpuIdLevel > 0
706 && pCPUM->aGuestCpuIdStd[0].eax >= 2
707 && (pCPUM->aGuestCpuIdStd[2].eax & 0xff) > 1)
708 {
709 LogRel(("PortableCpuId: Std[2].al: %d -> 1\n", pCPUM->aGuestCpuIdStd[2].eax & 0xff));
710 pCPUM->aGuestCpuIdStd[2].eax &= UINT32_C(0xfffffffe);
711 }
712
713 /* Cpuid 3:
714 * Intel: EAX, EBX - reserved (transmeta uses these)
715 * ECX, EDX - Processor Serial Number if available, otherwise reserved
716 * AMD: Reserved
717 * Safe to expose
718 */
719 if (!(pCPUM->aGuestCpuIdStd[1].edx & X86_CPUID_FEATURE_EDX_PSN))
720 {
721 pCPUM->aGuestCpuIdStd[3].ecx = pCPUM->aGuestCpuIdStd[3].edx = 0;
722 if (pCPUM->u8PortableCpuIdLevel > 0)
723 pCPUM->aGuestCpuIdStd[3].eax = pCPUM->aGuestCpuIdStd[3].ebx = 0;
724 }
725
726 /* Cpuid 4:
727 * Intel: Deterministic Cache Parameters Leaf
728 * Note: Depends on the ECX input! -> Feeling rather lazy now, so we just return 0
729 * AMD: Reserved
730 * Safe to expose, except for EAX:
731 * Bits 25-14: Maximum number of addressable IDs for logical processors sharing this cache (see note)**
732 * Bits 31-26: Maximum number of processor cores in this physical package**
733 * Note: These SMP values are constant regardless of ECX
734 */
735 pCPUM->aGuestCpuIdStd[4].ecx = pCPUM->aGuestCpuIdStd[4].edx = 0;
736 pCPUM->aGuestCpuIdStd[4].eax = pCPUM->aGuestCpuIdStd[4].ebx = 0;
737#ifdef VBOX_WITH_MULTI_CORE
738 if ( pVM->cCpus > 1
739 && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_INTEL)
740 {
741 AssertReturn(pVM->cCpus <= 64, VERR_TOO_MANY_CPUS);
742 /* One logical processor with possibly multiple cores. */
743 /* See http://www.intel.com/Assets/PDF/appnote/241618.pdf p. 29 */
744 pCPUM->aGuestCpuIdStd[4].eax |= ((pVM->cCpus - 1) << 26); /* 6 bits only -> 64 cores! */
745 }
746#endif
747
748 /* Cpuid 5: Monitor/mwait Leaf
749 * Intel: ECX, EDX - reserved
750 * EAX, EBX - Smallest and largest monitor line size
751 * AMD: EDX - reserved
752 * EAX, EBX - Smallest and largest monitor line size
753 * ECX - extensions (ignored for now)
754 * Safe to expose
755 */
756 if (!(pCPUM->aGuestCpuIdStd[1].ecx & X86_CPUID_FEATURE_ECX_MONITOR))
757 pCPUM->aGuestCpuIdStd[5].eax = pCPUM->aGuestCpuIdStd[5].ebx = 0;
758
759 pCPUM->aGuestCpuIdStd[5].ecx = pCPUM->aGuestCpuIdStd[5].edx = 0;
760 /** @cfgm{/CPUM/MWaitExtensions, boolean, false}
761 * Expose MWAIT extended features to the guest. For now we expose
762 * just MWAIT break on interrupt feature (bit 1).
763 */
764 bool fMWaitExtensions;
765 rc = CFGMR3QueryBoolDef(pCpumCfg, "MWaitExtensions", &fMWaitExtensions, false); AssertRCReturn(rc, rc);
766 if (fMWaitExtensions)
767 {
768 pCPUM->aGuestCpuIdStd[5].ecx = X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0;
769 /* @todo: for now we just expose host's MWAIT C-states, although conceptually
770 it shall be part of our power management virtualization model */
771#if 0
772 /* MWAIT sub C-states */
773 pCPUM->aGuestCpuIdStd[5].edx =
774 (0 << 0) /* 0 in C0 */ |
775 (2 << 4) /* 2 in C1 */ |
776 (2 << 8) /* 2 in C2 */ |
777 (2 << 12) /* 2 in C3 */ |
778 (0 << 16) /* 0 in C4 */
779 ;
780#endif
781 }
782 else
783 pCPUM->aGuestCpuIdStd[5].ecx = pCPUM->aGuestCpuIdStd[5].edx = 0;
784
785 /* Cpuid 0x800000005 & 0x800000006 contain information about L1, L2 & L3 cache and TLB identifiers.
786 * Safe to pass on to the guest.
787 *
788 * Intel: 0x800000005 reserved
789 * 0x800000006 L2 cache information
790 * AMD: 0x800000005 L1 cache information
791 * 0x800000006 L2/L3 cache information
792 */
793
794 /* Cpuid 0x800000007:
795 * AMD: EAX, EBX, ECX - reserved
796 * EDX: Advanced Power Management Information
797 * Intel: Reserved
798 */
799 if (pCPUM->aGuestCpuIdExt[0].eax >= UINT32_C(0x80000007))
800 {
801 Assert(pVM->cpum.s.enmGuestCpuVendor != CPUMCPUVENDOR_INVALID);
802
803 pCPUM->aGuestCpuIdExt[7].eax = pCPUM->aGuestCpuIdExt[7].ebx = pCPUM->aGuestCpuIdExt[7].ecx = 0;
804
805 if (pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
806 {
807 /* Only expose the TSC invariant capability bit to the guest. */
808 pCPUM->aGuestCpuIdExt[7].edx &= 0
809 //| X86_CPUID_AMD_ADVPOWER_EDX_TS
810 //| X86_CPUID_AMD_ADVPOWER_EDX_FID
811 //| X86_CPUID_AMD_ADVPOWER_EDX_VID
812 //| X86_CPUID_AMD_ADVPOWER_EDX_TTP
813 //| X86_CPUID_AMD_ADVPOWER_EDX_TM
814 //| X86_CPUID_AMD_ADVPOWER_EDX_STC
815 //| X86_CPUID_AMD_ADVPOWER_EDX_MC
816 //| X86_CPUID_AMD_ADVPOWER_EDX_HWPSTATE
817#if 0 /* We don't expose X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR, because newer
818 * Linux kernels blindly assume that the AMD performance counters work
819 * if this is set for 64 bits guests. (Can't really find a CPUID feature
820 * bit for them though.) */
821 | X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR
822#endif
823 | 0;
824 }
825 else
826 pCPUM->aGuestCpuIdExt[7].edx = 0;
827 }
828
829 /* Cpuid 0x800000008:
830 * AMD: EBX, EDX - reserved
831 * EAX: Virtual/Physical/Guest address Size
832 * ECX: Number of cores + APICIdCoreIdSize
833 * Intel: EAX: Virtual/Physical address Size
834 * EBX, ECX, EDX - reserved
835 */
836 if (pCPUM->aGuestCpuIdExt[0].eax >= UINT32_C(0x80000008))
837 {
838 /* Only expose the virtual and physical address sizes to the guest. */
839 pCPUM->aGuestCpuIdExt[8].eax &= UINT32_C(0x0000ffff);
840 pCPUM->aGuestCpuIdExt[8].ebx = pCPUM->aGuestCpuIdExt[8].edx = 0; /* reserved */
841 /* Set APICIdCoreIdSize to zero (use legacy method to determine the number of cores per cpu)
842 * NC (0-7) Number of cores; 0 equals 1 core */
843 pCPUM->aGuestCpuIdExt[8].ecx = 0;
844#ifdef VBOX_WITH_MULTI_CORE
845 if ( pVM->cCpus > 1
846 && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
847 {
848 /* Legacy method to determine the number of cores. */
849 pCPUM->aGuestCpuIdExt[1].ecx |= X86_CPUID_AMD_FEATURE_ECX_CMPL;
850 pCPUM->aGuestCpuIdExt[8].ecx |= (pVM->cCpus - 1); /* NC: Number of CPU cores - 1; 8 bits */
851 }
852#endif
853 }
854
855 /** @cfgm{/CPUM/NT4LeafLimit, boolean, false}
856 * Limit the number of standard CPUID leaves to 0..3 to prevent NT4 from
857 * bugchecking with MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED (0x3e).
858 * This option corresponds somewhat to IA32_MISC_ENABLES.BOOT_NT4[bit 22].
859 */
860 bool fNt4LeafLimit;
861 rc = CFGMR3QueryBoolDef(pCpumCfg, "NT4LeafLimit", &fNt4LeafLimit, false); AssertRCReturn(rc, rc);
862 if (fNt4LeafLimit)
863 pCPUM->aGuestCpuIdStd[0].eax = 3; /** @todo r=bird: shouldn't we check if pCPUM->aGuestCpuIdStd[0].eax > 3 before setting it 3 here? */
864
865 /*
866 * Limit it the number of entries and fill the remaining with the defaults.
867 *
868 * The limits are masking off stuff about power saving and similar, this
869 * is perhaps a bit crudely done as there is probably some relatively harmless
870 * info too in these leaves (like words about having a constant TSC).
871 */
872 if (pCPUM->aGuestCpuIdStd[0].eax > 5)
873 pCPUM->aGuestCpuIdStd[0].eax = 5;
874 for (i = pCPUM->aGuestCpuIdStd[0].eax + 1; i < RT_ELEMENTS(pCPUM->aGuestCpuIdStd); i++)
875 pCPUM->aGuestCpuIdStd[i] = pCPUM->GuestCpuIdDef;
876
877 if (pCPUM->aGuestCpuIdExt[0].eax > UINT32_C(0x80000008))
878 pCPUM->aGuestCpuIdExt[0].eax = UINT32_C(0x80000008);
879 for (i = pCPUM->aGuestCpuIdExt[0].eax >= UINT32_C(0x80000000)
880 ? pCPUM->aGuestCpuIdExt[0].eax - UINT32_C(0x80000000) + 1
881 : 0;
882 i < RT_ELEMENTS(pCPUM->aGuestCpuIdExt);
883 i++)
884 pCPUM->aGuestCpuIdExt[i] = pCPUM->GuestCpuIdDef;
885
886 /*
887 * Centaur stuff (VIA).
888 *
889 * The important part here (we think) is to make sure the 0xc0000000
890 * function returns 0xc0000001. As for the features, we don't currently
891 * let on about any of those... 0xc0000002 seems to be some
892 * temperature/hz/++ stuff, include it as well (static).
893 */
894 if ( pCPUM->aGuestCpuIdCentaur[0].eax >= UINT32_C(0xc0000000)
895 && pCPUM->aGuestCpuIdCentaur[0].eax <= UINT32_C(0xc0000004))
896 {
897 pCPUM->aGuestCpuIdCentaur[0].eax = RT_MIN(pCPUM->aGuestCpuIdCentaur[0].eax, UINT32_C(0xc0000002));
898 pCPUM->aGuestCpuIdCentaur[1].edx = 0; /* all features hidden */
899 for (i = pCPUM->aGuestCpuIdCentaur[0].eax - UINT32_C(0xc0000000);
900 i < RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur);
901 i++)
902 pCPUM->aGuestCpuIdCentaur[i] = pCPUM->GuestCpuIdDef;
903 }
904 else
905 for (i = 0; i < RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur); i++)
906 pCPUM->aGuestCpuIdCentaur[i] = pCPUM->GuestCpuIdDef;
907
908 /*
909 * Hypervisor identification.
910 *
911 * We only return minimal information, primarily ensuring that the
912 * 0x40000000 function returns 0x40000001 and identifying ourselves.
913 * Currently we do not support any hypervisor-specific interface.
914 */
915 pCPUM->aGuestCpuIdHyper[0].eax = UINT32_C(0x40000001);
916 pCPUM->aGuestCpuIdHyper[0].ebx = pCPUM->aGuestCpuIdHyper[0].ecx
917 = pCPUM->aGuestCpuIdHyper[0].edx = 0x786f4256; /* 'VBox' */
918 pCPUM->aGuestCpuIdHyper[1].eax = 0x656e6f6e; /* 'none' */
919 pCPUM->aGuestCpuIdHyper[1].ebx = pCPUM->aGuestCpuIdHyper[1].ecx
920 = pCPUM->aGuestCpuIdHyper[1].edx = 0; /* Reserved */
921
922 /*
923 * Load CPUID overrides from configuration.
924 * Note: Kind of redundant now, but allows unchanged overrides
925 */
926 /** @cfgm{CPUM/CPUID/[000000xx|800000xx|c000000x]/[eax|ebx|ecx|edx],32-bit}
927 * Overrides the CPUID leaf values. */
928 PCFGMNODE pOverrideCfg = CFGMR3GetChild(pCpumCfg, "CPUID");
929 rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &pCPUM->aGuestCpuIdStd[0], RT_ELEMENTS(pCPUM->aGuestCpuIdStd), pOverrideCfg);
930 AssertRCReturn(rc, rc);
931 rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &pCPUM->aGuestCpuIdExt[0], RT_ELEMENTS(pCPUM->aGuestCpuIdExt), pOverrideCfg);
932 AssertRCReturn(rc, rc);
933 rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0xc0000000), &pCPUM->aGuestCpuIdCentaur[0], RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur), pOverrideCfg);
934 AssertRCReturn(rc, rc);
935
936 /*
937 * Check if PAE was explicitely enabled by the user.
938 */
939 bool fEnable;
940 rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnablePAE", &fEnable, false); AssertRCReturn(rc, rc);
941 if (fEnable)
942 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
943
944 /*
945 * We don't normally enable NX for raw-mode, so give the user a chance to
946 * force it on.
947 */
948 rc = CFGMR3QueryBoolDef(pCpumCfg, "EnableNX", &fEnable, false); AssertRCReturn(rc, rc);
949 if (fEnable)
950 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NXE);
951
952 /*
953 * We don't enable the Hypervisor Present bit by default, but it may
954 * be needed by some guests.
955 */
956 rc = CFGMR3QueryBoolDef(pCpumCfg, "EnableHVP", &fEnable, false); AssertRCReturn(rc, rc);
957 if (fEnable)
958 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
959 /*
960 * Log the cpuid and we're good.
961 */
962 bool fOldBuffered = RTLogRelSetBuffering(true /*fBuffered*/);
963 RTCPUSET OnlineSet;
964 LogRel(("Logical host processors: %u present, %u max, %u online, online mask: %016RX64\n",
965 (unsigned)RTMpGetPresentCount(), (unsigned)RTMpGetCount(), (unsigned)RTMpGetOnlineCount(),
966 RTCpuSetToU64(RTMpGetOnlineSet(&OnlineSet)) ));
967 LogRel(("************************* CPUID dump ************************\n"));
968 DBGFR3Info(pVM, "cpuid", "verbose", DBGFR3InfoLogRelHlp());
969 LogRel(("\n"));
970 DBGFR3InfoLog(pVM, "cpuid", "verbose"); /* macro */
971 RTLogRelSetBuffering(fOldBuffered);
972 LogRel(("******************** End of CPUID dump **********************\n"));
973
974#undef PORTABLE_DISABLE_FEATURE_BIT
975#undef PORTABLE_CLEAR_BITS_WHEN
976
977 return VINF_SUCCESS;
978}
979
980
981/**
982 * Applies relocations to data and code managed by this
983 * component. This function will be called at init and
984 * whenever the VMM need to relocate it self inside the GC.
985 *
986 * The CPUM will update the addresses used by the switcher.
987 *
988 * @param pVM The VM.
989 */
990VMMR3DECL(void) CPUMR3Relocate(PVM pVM)
991{
992 LogFlow(("CPUMR3Relocate\n"));
993 for (VMCPUID i = 0; i < pVM->cCpus; i++)
994 {
995 /*
996 * Switcher pointers.
997 */
998 PVMCPU pVCpu = &pVM->aCpus[i];
999 pVCpu->cpum.s.pHyperCoreRC = MMHyperCCToRC(pVM, pVCpu->cpum.s.pHyperCoreR3);
1000 Assert(pVCpu->cpum.s.pHyperCoreRC != NIL_RTRCPTR);
1001
1002 }
1003}
1004
1005
1006/**
1007 * Apply late CPUM property changes based on the fHWVirtEx setting
1008 *
1009 * @param pVM The VM to operate on.
1010 * @param fHWVirtExEnabled HWVirtEx enabled/disabled
1011 */
1012VMMR3DECL(void) CPUMR3SetHWVirtEx(PVM pVM, bool fHWVirtExEnabled)
1013{
1014 /*
1015 * Workaround for missing cpuid(0) patches when leaf 4 returns GuestCpuIdDef:
1016 * If we miss to patch a cpuid(0).eax then Linux tries to determine the number
1017 * of processors from (cpuid(4).eax >> 26) + 1.
1018 *
1019 * Note: this code is obsolete, but let's keep it here for reference.
1020 * Purpose is valid when we artificially cap the max std id to less than 4.
1021 */
1022 if (!fHWVirtExEnabled)
1023 {
1024 Assert( pVM->cpum.s.aGuestCpuIdStd[4].eax == 0
1025 || pVM->cpum.s.aGuestCpuIdStd[0].eax < 0x4);
1026 pVM->cpum.s.aGuestCpuIdStd[4].eax = 0;
1027 }
1028}
1029
1030/**
1031 * Terminates the CPUM.
1032 *
1033 * Termination means cleaning up and freeing all resources,
1034 * the VM it self is at this point powered off or suspended.
1035 *
1036 * @returns VBox status code.
1037 * @param pVM The VM to operate on.
1038 */
1039VMMR3DECL(int) CPUMR3Term(PVM pVM)
1040{
1041#ifdef VBOX_WITH_CRASHDUMP_MAGIC
1042 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1043 {
1044 PVMCPU pVCpu = &pVM->aCpus[i];
1045 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
1046
1047 memset(pVCpu->cpum.s.aMagic, 0, sizeof(pVCpu->cpum.s.aMagic));
1048 pVCpu->cpum.s.uMagic = 0;
1049 pCtx->dr[5] = 0;
1050 }
1051#else
1052 NOREF(pVM);
1053#endif
1054 return VINF_SUCCESS;
1055}
1056
1057
1058/**
1059 * Resets a virtual CPU.
1060 *
1061 * Used by CPUMR3Reset and CPU hot plugging.
1062 *
1063 * @param pVCpu The virtual CPU handle.
1064 */
1065VMMR3DECL(void) CPUMR3ResetCpu(PVMCPU pVCpu)
1066{
1067 /** @todo anything different for VCPU > 0? */
1068 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
1069
1070 /*
1071 * Initialize everything to ZERO first.
1072 */
1073 uint32_t fUseFlags = pVCpu->cpum.s.fUseFlags & ~CPUM_USED_FPU_SINCE_REM;
1074 memset(pCtx, 0, sizeof(*pCtx));
1075 pVCpu->cpum.s.fUseFlags = fUseFlags;
1076
1077 pCtx->cr0 = X86_CR0_CD | X86_CR0_NW | X86_CR0_ET; //0x60000010
1078 pCtx->eip = 0x0000fff0;
1079 pCtx->edx = 0x00000600; /* P6 processor */
1080 pCtx->eflags.Bits.u1Reserved0 = 1;
1081
1082 pCtx->cs = 0xf000;
1083 pCtx->csHid.u64Base = UINT64_C(0xffff0000);
1084 pCtx->csHid.u32Limit = 0x0000ffff;
1085 pCtx->csHid.Attr.n.u1DescType = 1; /* code/data segment */
1086 pCtx->csHid.Attr.n.u1Present = 1;
1087 pCtx->csHid.Attr.n.u4Type = X86_SEL_TYPE_READ | X86_SEL_TYPE_CODE;
1088
1089 pCtx->dsHid.u32Limit = 0x0000ffff;
1090 pCtx->dsHid.Attr.n.u1DescType = 1; /* code/data segment */
1091 pCtx->dsHid.Attr.n.u1Present = 1;
1092 pCtx->dsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
1093
1094 pCtx->esHid.u32Limit = 0x0000ffff;
1095 pCtx->esHid.Attr.n.u1DescType = 1; /* code/data segment */
1096 pCtx->esHid.Attr.n.u1Present = 1;
1097 pCtx->esHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
1098
1099 pCtx->fsHid.u32Limit = 0x0000ffff;
1100 pCtx->fsHid.Attr.n.u1DescType = 1; /* code/data segment */
1101 pCtx->fsHid.Attr.n.u1Present = 1;
1102 pCtx->fsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
1103
1104 pCtx->gsHid.u32Limit = 0x0000ffff;
1105 pCtx->gsHid.Attr.n.u1DescType = 1; /* code/data segment */
1106 pCtx->gsHid.Attr.n.u1Present = 1;
1107 pCtx->gsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
1108
1109 pCtx->ssHid.u32Limit = 0x0000ffff;
1110 pCtx->ssHid.Attr.n.u1Present = 1;
1111 pCtx->ssHid.Attr.n.u1DescType = 1; /* code/data segment */
1112 pCtx->ssHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
1113
1114 pCtx->idtr.cbIdt = 0xffff;
1115 pCtx->gdtr.cbGdt = 0xffff;
1116
1117 pCtx->ldtrHid.u32Limit = 0xffff;
1118 pCtx->ldtrHid.Attr.n.u1Present = 1;
1119 pCtx->ldtrHid.Attr.n.u4Type = X86_SEL_TYPE_SYS_LDT;
1120
1121 pCtx->trHid.u32Limit = 0xffff;
1122 pCtx->trHid.Attr.n.u1Present = 1;
1123 pCtx->trHid.Attr.n.u4Type = X86_SEL_TYPE_SYS_386_TSS_BUSY; /* Deduction, not properly documented by Intel. */
1124
1125 pCtx->dr[6] = X86_DR6_INIT_VAL;
1126 pCtx->dr[7] = X86_DR7_INIT_VAL;
1127
1128 pCtx->fpu.FTW = 0x00; /* All empty (abbridged tag reg edition). */
1129 pCtx->fpu.FCW = 0x37f;
1130
1131 /* Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3A, Table 8-1.
1132 IA-32 Processor States Following Power-up, Reset, or INIT */
1133 pCtx->fpu.MXCSR = 0x1F80;
1134 pCtx->fpu.MXCSR_MASK = 0xffff; /** @todo REM always changed this for us. Should probably check if the HW really
1135 supports all bits, since a zero value here should be read as 0xffbf. */
1136
1137 /* Init PAT MSR */
1138 pCtx->msrPAT = UINT64_C(0x0007040600070406); /** @todo correct? */
1139
1140 /* Reset EFER; see AMD64 Architecture Programmer's Manual Volume 2: Table 14-1. Initial Processor State
1141 * The Intel docs don't mention it.
1142 */
1143 pCtx->msrEFER = 0;
1144}
1145
1146
1147/**
1148 * Resets the CPU.
1149 *
1150 * @returns VINF_SUCCESS.
1151 * @param pVM Pointer to the VM.
1152 */
1153VMMR3DECL(void) CPUMR3Reset(PVM pVM)
1154{
1155 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1156 {
1157 CPUMR3ResetCpu(&pVM->aCpus[i]);
1158
1159#ifdef VBOX_WITH_CRASHDUMP_MAGIC
1160 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(&pVM->aCpus[i]);
1161
1162 /* Magic marker for searching in crash dumps. */
1163 strcpy((char *)pVM->aCpus[i].cpum.s.aMagic, "CPUMCPU Magic");
1164 pVM->aCpus[i].cpum.s.uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
1165 pCtx->dr[5] = UINT64_C(0xDEADBEEFDEADBEEF);
1166#endif
1167 }
1168}
1169
1170
1171/**
1172 * Called both in pass 0 and the final pass.
1173 *
1174 * @param pVM Pointer to the VM.
1175 * @param pSSM The saved state handle.
1176 */
1177static void cpumR3SaveCpuId(PVM pVM, PSSMHANDLE pSSM)
1178{
1179 /*
1180 * Save all the CPU ID leaves here so we can check them for compatibility
1181 * upon loading.
1182 */
1183 SSMR3PutU32(pSSM, RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd));
1184 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdStd[0], sizeof(pVM->cpum.s.aGuestCpuIdStd));
1185
1186 SSMR3PutU32(pSSM, RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt));
1187 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdExt[0], sizeof(pVM->cpum.s.aGuestCpuIdExt));
1188
1189 SSMR3PutU32(pSSM, RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur));
1190 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdCentaur[0], sizeof(pVM->cpum.s.aGuestCpuIdCentaur));
1191
1192 SSMR3PutMem(pSSM, &pVM->cpum.s.GuestCpuIdDef, sizeof(pVM->cpum.s.GuestCpuIdDef));
1193
1194 /*
1195 * Save a good portion of the raw CPU IDs as well as they may come in
1196 * handy when validating features for raw mode.
1197 */
1198 CPUMCPUID aRawStd[16];
1199 for (unsigned i = 0; i < RT_ELEMENTS(aRawStd); i++)
1200 ASMCpuId(i, &aRawStd[i].eax, &aRawStd[i].ebx, &aRawStd[i].ecx, &aRawStd[i].edx);
1201 SSMR3PutU32(pSSM, RT_ELEMENTS(aRawStd));
1202 SSMR3PutMem(pSSM, &aRawStd[0], sizeof(aRawStd));
1203
1204 CPUMCPUID aRawExt[32];
1205 for (unsigned i = 0; i < RT_ELEMENTS(aRawExt); i++)
1206 ASMCpuId(i | UINT32_C(0x80000000), &aRawExt[i].eax, &aRawExt[i].ebx, &aRawExt[i].ecx, &aRawExt[i].edx);
1207 SSMR3PutU32(pSSM, RT_ELEMENTS(aRawExt));
1208 SSMR3PutMem(pSSM, &aRawExt[0], sizeof(aRawExt));
1209}
1210
1211
1212/**
1213 * Loads the CPU ID leaves saved by pass 0.
1214 *
1215 * @returns VBox status code.
1216 * @param pVM Pointer to the VM.
1217 * @param pSSM The saved state handle.
1218 * @param uVersion The format version.
1219 */
1220static int cpumR3LoadCpuId(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion)
1221{
1222 AssertMsgReturn(uVersion >= CPUM_SAVED_STATE_VERSION_VER3_2, ("%u\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
1223
1224 /*
1225 * Define a bunch of macros for simplifying the code.
1226 */
1227 /* Generic expression + failure message. */
1228#define CPUID_CHECK_RET(expr, fmt) \
1229 do { \
1230 if (!(expr)) \
1231 { \
1232 char *pszMsg = RTStrAPrintf2 fmt; /* lack of variadic macros sucks */ \
1233 if (fStrictCpuIdChecks) \
1234 { \
1235 int rcCpuid = SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, "%s", pszMsg); \
1236 RTStrFree(pszMsg); \
1237 return rcCpuid; \
1238 } \
1239 LogRel(("CPUM: %s\n", pszMsg)); \
1240 RTStrFree(pszMsg); \
1241 } \
1242 } while (0)
1243#define CPUID_CHECK_WRN(expr, fmt) \
1244 do { \
1245 if (!(expr)) \
1246 LogRel(fmt); \
1247 } while (0)
1248
1249 /* For comparing two values and bitch if they differs. */
1250#define CPUID_CHECK2_RET(what, host, saved) \
1251 do { \
1252 if ((host) != (saved)) \
1253 { \
1254 if (fStrictCpuIdChecks) \
1255 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
1256 N_(#what " mismatch: host=%#x saved=%#x"), (host), (saved)); \
1257 LogRel(("CPUM: " #what " differs: host=%#x saved=%#x\n", (host), (saved))); \
1258 } \
1259 } while (0)
1260#define CPUID_CHECK2_WRN(what, host, saved) \
1261 do { \
1262 if ((host) != (saved)) \
1263 LogRel(("CPUM: " #what " differs: host=%#x saved=%#x\n", (host), (saved))); \
1264 } while (0)
1265
1266 /* For checking raw cpu features (raw mode). */
1267#define CPUID_RAW_FEATURE_RET(set, reg, bit) \
1268 do { \
1269 if ((aHostRaw##set [1].reg & bit) != (aRaw##set [1].reg & bit)) \
1270 { \
1271 if (fStrictCpuIdChecks) \
1272 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
1273 N_(#bit " mismatch: host=%d saved=%d"), \
1274 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) ); \
1275 LogRel(("CPUM: " #bit" differs: host=%d saved=%d\n", \
1276 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) )); \
1277 } \
1278 } while (0)
1279#define CPUID_RAW_FEATURE_WRN(set, reg, bit) \
1280 do { \
1281 if ((aHostRaw##set [1].reg & bit) != (aRaw##set [1].reg & bit)) \
1282 LogRel(("CPUM: " #bit" differs: host=%d saved=%d\n", \
1283 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) )); \
1284 } while (0)
1285#define CPUID_RAW_FEATURE_IGN(set, reg, bit) do { } while (0)
1286
1287 /* For checking guest features. */
1288#define CPUID_GST_FEATURE_RET(set, reg, bit) \
1289 do { \
1290 if ( (aGuestCpuId##set [1].reg & bit) \
1291 && !(aHostRaw##set [1].reg & bit) \
1292 && !(aHostOverride##set [1].reg & bit) \
1293 && !(aGuestOverride##set [1].reg & bit) \
1294 ) \
1295 { \
1296 if (fStrictCpuIdChecks) \
1297 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
1298 N_(#bit " is not supported by the host but has already exposed to the guest")); \
1299 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
1300 } \
1301 } while (0)
1302#define CPUID_GST_FEATURE_WRN(set, reg, bit) \
1303 do { \
1304 if ( (aGuestCpuId##set [1].reg & bit) \
1305 && !(aHostRaw##set [1].reg & bit) \
1306 && !(aHostOverride##set [1].reg & bit) \
1307 && !(aGuestOverride##set [1].reg & bit) \
1308 ) \
1309 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
1310 } while (0)
1311#define CPUID_GST_FEATURE_EMU(set, reg, bit) \
1312 do { \
1313 if ( (aGuestCpuId##set [1].reg & bit) \
1314 && !(aHostRaw##set [1].reg & bit) \
1315 && !(aHostOverride##set [1].reg & bit) \
1316 && !(aGuestOverride##set [1].reg & bit) \
1317 ) \
1318 LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
1319 } while (0)
1320#define CPUID_GST_FEATURE_IGN(set, reg, bit) do { } while (0)
1321
1322 /* For checking guest features if AMD guest CPU. */
1323#define CPUID_GST_AMD_FEATURE_RET(set, reg, bit) \
1324 do { \
1325 if ( (aGuestCpuId##set [1].reg & bit) \
1326 && fGuestAmd \
1327 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
1328 && !(aHostOverride##set [1].reg & bit) \
1329 && !(aGuestOverride##set [1].reg & bit) \
1330 ) \
1331 { \
1332 if (fStrictCpuIdChecks) \
1333 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
1334 N_(#bit " is not supported by the host but has already exposed to the guest")); \
1335 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
1336 } \
1337 } while (0)
1338#define CPUID_GST_AMD_FEATURE_WRN(set, reg, bit) \
1339 do { \
1340 if ( (aGuestCpuId##set [1].reg & bit) \
1341 && fGuestAmd \
1342 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
1343 && !(aHostOverride##set [1].reg & bit) \
1344 && !(aGuestOverride##set [1].reg & bit) \
1345 ) \
1346 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
1347 } while (0)
1348#define CPUID_GST_AMD_FEATURE_EMU(set, reg, bit) \
1349 do { \
1350 if ( (aGuestCpuId##set [1].reg & bit) \
1351 && fGuestAmd \
1352 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
1353 && !(aHostOverride##set [1].reg & bit) \
1354 && !(aGuestOverride##set [1].reg & bit) \
1355 ) \
1356 LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
1357 } while (0)
1358#define CPUID_GST_AMD_FEATURE_IGN(set, reg, bit) do { } while (0)
1359
1360 /* For checking AMD features which have a corresponding bit in the standard
1361 range. (Intel defines very few bits in the extended feature sets.) */
1362#define CPUID_GST_FEATURE2_RET(reg, ExtBit, StdBit) \
1363 do { \
1364 if ( (aGuestCpuIdExt [1].reg & (ExtBit)) \
1365 && !(fHostAmd \
1366 ? aHostRawExt[1].reg & (ExtBit) \
1367 : aHostRawStd[1].reg & (StdBit)) \
1368 && !(aHostOverrideExt[1].reg & (ExtBit)) \
1369 && !(aGuestOverrideExt[1].reg & (ExtBit)) \
1370 ) \
1371 { \
1372 if (fStrictCpuIdChecks) \
1373 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
1374 N_(#ExtBit " is not supported by the host but has already exposed to the guest")); \
1375 LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
1376 } \
1377 } while (0)
1378#define CPUID_GST_FEATURE2_WRN(reg, ExtBit, StdBit) \
1379 do { \
1380 if ( (aGuestCpuIdExt [1].reg & (ExtBit)) \
1381 && !(fHostAmd \
1382 ? aHostRawExt[1].reg & (ExtBit) \
1383 : aHostRawStd[1].reg & (StdBit)) \
1384 && !(aHostOverrideExt[1].reg & (ExtBit)) \
1385 && !(aGuestOverrideExt[1].reg & (ExtBit)) \
1386 ) \
1387 LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
1388 } while (0)
1389#define CPUID_GST_FEATURE2_EMU(reg, ExtBit, StdBit) \
1390 do { \
1391 if ( (aGuestCpuIdExt [1].reg & (ExtBit)) \
1392 && !(fHostAmd \
1393 ? aHostRawExt[1].reg & (ExtBit) \
1394 : aHostRawStd[1].reg & (StdBit)) \
1395 && !(aHostOverrideExt[1].reg & (ExtBit)) \
1396 && !(aGuestOverrideExt[1].reg & (ExtBit)) \
1397 ) \
1398 LogRel(("CPUM: Warning - " #ExtBit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
1399 } while (0)
1400#define CPUID_GST_FEATURE2_IGN(reg, ExtBit, StdBit) do { } while (0)
1401
1402 /*
1403 * Load them into stack buffers first.
1404 */
1405 CPUMCPUID aGuestCpuIdStd[RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd)];
1406 uint32_t cGuestCpuIdStd;
1407 int rc = SSMR3GetU32(pSSM, &cGuestCpuIdStd); AssertRCReturn(rc, rc);
1408 if (cGuestCpuIdStd > RT_ELEMENTS(aGuestCpuIdStd))
1409 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1410 SSMR3GetMem(pSSM, &aGuestCpuIdStd[0], cGuestCpuIdStd * sizeof(aGuestCpuIdStd[0]));
1411
1412 CPUMCPUID aGuestCpuIdExt[RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt)];
1413 uint32_t cGuestCpuIdExt;
1414 rc = SSMR3GetU32(pSSM, &cGuestCpuIdExt); AssertRCReturn(rc, rc);
1415 if (cGuestCpuIdExt > RT_ELEMENTS(aGuestCpuIdExt))
1416 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1417 SSMR3GetMem(pSSM, &aGuestCpuIdExt[0], cGuestCpuIdExt * sizeof(aGuestCpuIdExt[0]));
1418
1419 CPUMCPUID aGuestCpuIdCentaur[RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur)];
1420 uint32_t cGuestCpuIdCentaur;
1421 rc = SSMR3GetU32(pSSM, &cGuestCpuIdCentaur); AssertRCReturn(rc, rc);
1422 if (cGuestCpuIdCentaur > RT_ELEMENTS(aGuestCpuIdCentaur))
1423 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1424 SSMR3GetMem(pSSM, &aGuestCpuIdCentaur[0], cGuestCpuIdCentaur * sizeof(aGuestCpuIdCentaur[0]));
1425
1426 CPUMCPUID GuestCpuIdDef;
1427 rc = SSMR3GetMem(pSSM, &GuestCpuIdDef, sizeof(GuestCpuIdDef));
1428 AssertRCReturn(rc, rc);
1429
1430 CPUMCPUID aRawStd[16];
1431 uint32_t cRawStd;
1432 rc = SSMR3GetU32(pSSM, &cRawStd); AssertRCReturn(rc, rc);
1433 if (cRawStd > RT_ELEMENTS(aRawStd))
1434 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1435 SSMR3GetMem(pSSM, &aRawStd[0], cRawStd * sizeof(aRawStd[0]));
1436
1437 CPUMCPUID aRawExt[32];
1438 uint32_t cRawExt;
1439 rc = SSMR3GetU32(pSSM, &cRawExt); AssertRCReturn(rc, rc);
1440 if (cRawExt > RT_ELEMENTS(aRawExt))
1441 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
1442 rc = SSMR3GetMem(pSSM, &aRawExt[0], cRawExt * sizeof(aRawExt[0]));
1443 AssertRCReturn(rc, rc);
1444
1445 /*
1446 * Note that we support restoring less than the current amount of standard
1447 * leaves because we've been allowed more is newer version of VBox.
1448 *
1449 * So, pad new entries with the default.
1450 */
1451 for (uint32_t i = cGuestCpuIdStd; i < RT_ELEMENTS(aGuestCpuIdStd); i++)
1452 aGuestCpuIdStd[i] = GuestCpuIdDef;
1453
1454 for (uint32_t i = cGuestCpuIdExt; i < RT_ELEMENTS(aGuestCpuIdExt); i++)
1455 aGuestCpuIdExt[i] = GuestCpuIdDef;
1456
1457 for (uint32_t i = cGuestCpuIdCentaur; i < RT_ELEMENTS(aGuestCpuIdCentaur); i++)
1458 aGuestCpuIdCentaur[i] = GuestCpuIdDef;
1459
1460 for (uint32_t i = cRawStd; i < RT_ELEMENTS(aRawStd); i++)
1461 ASMCpuId(i, &aRawStd[i].eax, &aRawStd[i].ebx, &aRawStd[i].ecx, &aRawStd[i].edx);
1462
1463 for (uint32_t i = cRawExt; i < RT_ELEMENTS(aRawExt); i++)
1464 ASMCpuId(i | UINT32_C(0x80000000), &aRawExt[i].eax, &aRawExt[i].ebx, &aRawExt[i].ecx, &aRawExt[i].edx);
1465
1466 /*
1467 * Get the raw CPU IDs for the current host.
1468 */
1469 CPUMCPUID aHostRawStd[16];
1470 for (unsigned i = 0; i < RT_ELEMENTS(aHostRawStd); i++)
1471 ASMCpuId(i, &aHostRawStd[i].eax, &aHostRawStd[i].ebx, &aHostRawStd[i].ecx, &aHostRawStd[i].edx);
1472
1473 CPUMCPUID aHostRawExt[32];
1474 for (unsigned i = 0; i < RT_ELEMENTS(aHostRawExt); i++)
1475 ASMCpuId(i | UINT32_C(0x80000000), &aHostRawExt[i].eax, &aHostRawExt[i].ebx, &aHostRawExt[i].ecx, &aHostRawExt[i].edx);
1476
1477 /*
1478 * Get the host and guest overrides so we don't reject the state because
1479 * some feature was enabled thru these interfaces.
1480 * Note! We currently only need the feature leaves, so skip rest.
1481 */
1482 PCFGMNODE pOverrideCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM/CPUID");
1483 CPUMCPUID aGuestOverrideStd[2];
1484 memcpy(&aGuestOverrideStd[0], &aHostRawStd[0], sizeof(aGuestOverrideStd));
1485 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &aGuestOverrideStd[0], RT_ELEMENTS(aGuestOverrideStd), pOverrideCfg);
1486
1487 CPUMCPUID aGuestOverrideExt[2];
1488 memcpy(&aGuestOverrideExt[0], &aHostRawExt[0], sizeof(aGuestOverrideExt));
1489 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &aGuestOverrideExt[0], RT_ELEMENTS(aGuestOverrideExt), pOverrideCfg);
1490
1491 pOverrideCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM/HostCPUID");
1492 CPUMCPUID aHostOverrideStd[2];
1493 memcpy(&aHostOverrideStd[0], &aHostRawStd[0], sizeof(aHostOverrideStd));
1494 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &aHostOverrideStd[0], RT_ELEMENTS(aHostOverrideStd), pOverrideCfg);
1495
1496 CPUMCPUID aHostOverrideExt[2];
1497 memcpy(&aHostOverrideExt[0], &aHostRawExt[0], sizeof(aHostOverrideExt));
1498 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &aHostOverrideExt[0], RT_ELEMENTS(aHostOverrideExt), pOverrideCfg);
1499
1500 /*
1501 * This can be skipped.
1502 */
1503 bool fStrictCpuIdChecks;
1504 CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM"), "StrictCpuIdChecks", &fStrictCpuIdChecks, true);
1505
1506
1507
1508 /*
1509 * For raw-mode we'll require that the CPUs are very similar since we don't
1510 * intercept CPUID instructions for user mode applications.
1511 */
1512 if (!HWACCMIsEnabled(pVM))
1513 {
1514 /* CPUID(0) */
1515 CPUID_CHECK_RET( aHostRawStd[0].ebx == aRawStd[0].ebx
1516 && aHostRawStd[0].ecx == aRawStd[0].ecx
1517 && aHostRawStd[0].edx == aRawStd[0].edx,
1518 (N_("CPU vendor mismatch: host='%.4s%.4s%.4s' saved='%.4s%.4s%.4s'"),
1519 &aHostRawStd[0].ebx, &aHostRawStd[0].edx, &aHostRawStd[0].ecx,
1520 &aRawStd[0].ebx, &aRawStd[0].edx, &aRawStd[0].ecx));
1521 CPUID_CHECK2_WRN("Std CPUID max leaf", aHostRawStd[0].eax, aRawStd[0].eax);
1522 CPUID_CHECK2_WRN("Reserved bits 15:14", (aHostRawExt[1].eax >> 14) & 3, (aRawExt[1].eax >> 14) & 3);
1523 CPUID_CHECK2_WRN("Reserved bits 31:28", aHostRawExt[1].eax >> 28, aRawExt[1].eax >> 28);
1524
1525 bool const fIntel = ASMIsIntelCpuEx(aRawStd[0].ebx, aRawStd[0].ecx, aRawStd[0].edx);
1526
1527 /* CPUID(1).eax */
1528 CPUID_CHECK2_RET("CPU family", ASMGetCpuFamily(aHostRawStd[1].eax), ASMGetCpuFamily(aRawStd[1].eax));
1529 CPUID_CHECK2_RET("CPU model", ASMGetCpuModel(aHostRawStd[1].eax, fIntel), ASMGetCpuModel(aRawStd[1].eax, fIntel));
1530 CPUID_CHECK2_WRN("CPU type", (aHostRawStd[1].eax >> 12) & 3, (aRawStd[1].eax >> 12) & 3 );
1531
1532 /* CPUID(1).ebx - completely ignore CPU count and APIC ID. */
1533 CPUID_CHECK2_RET("CPU brand ID", aHostRawStd[1].ebx & 0xff, aRawStd[1].ebx & 0xff);
1534 CPUID_CHECK2_WRN("CLFLUSH chunk count", (aHostRawStd[1].ebx >> 8) & 0xff, (aRawStd[1].ebx >> 8) & 0xff);
1535
1536 /* CPUID(1).ecx */
1537 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE3);
1538 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_PCLMUL);
1539 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_DTES64);
1540 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_MONITOR);
1541 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_CPLDS);
1542 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_VMX);
1543 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_SMX);
1544 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_EST);
1545 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_TM2);
1546 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSSE3);
1547 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_CNTXID);
1548 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(11) /*reserved*/ );
1549 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_FMA);
1550 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_CX16);
1551 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_TPRUPDATE);
1552 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_PDCM);
1553 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(16) /*reserved*/);
1554 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(17) /*reserved*/);
1555 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_DCA);
1556 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE4_1);
1557 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE4_2);
1558 CPUID_RAW_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_X2APIC);
1559 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_MOVBE);
1560 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_POPCNT);
1561 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(24) /*reserved*/);
1562 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_AES);
1563 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_XSAVE);
1564 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_OSXSAVE);
1565 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_AVX);
1566 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(29) /*reserved*/);
1567 CPUID_RAW_FEATURE_RET(Std, ecx, RT_BIT_32(30) /*reserved*/);
1568 CPUID_RAW_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_HVP);
1569
1570 /* CPUID(1).edx */
1571 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_FPU);
1572 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_VME);
1573 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_DE);
1574 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSE);
1575 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_TSC);
1576 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_MSR);
1577 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PAE);
1578 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MCE);
1579 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CX8);
1580 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_APIC);
1581 CPUID_RAW_FEATURE_RET(Std, edx, RT_BIT_32(10) /*reserved*/);
1582 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_SEP);
1583 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MTRR);
1584 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PGE);
1585 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MCA);
1586 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CMOV);
1587 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PAT);
1588 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSE36);
1589 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSN);
1590 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CLFSH);
1591 CPUID_RAW_FEATURE_RET(Std, edx, RT_BIT_32(20) /*reserved*/);
1592 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_DS);
1593 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_ACPI);
1594 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_MMX);
1595 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_FXSR);
1596 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_SSE);
1597 CPUID_RAW_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_SSE2);
1598 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_SS);
1599 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_HTT);
1600 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_TM);
1601 CPUID_RAW_FEATURE_RET(Std, edx, RT_BIT_32(30) /*JMPE/IA64*/);
1602 CPUID_RAW_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PBE);
1603
1604 /* CPUID(2) - config, mostly about caches. ignore. */
1605 /* CPUID(3) - processor serial number. ignore. */
1606 /* CPUID(4) - config, cache and topology - takes ECX as input. ignore. */
1607 /* CPUID(5) - mwait/monitor config. ignore. */
1608 /* CPUID(6) - power management. ignore. */
1609 /* CPUID(7) - ???. ignore. */
1610 /* CPUID(8) - ???. ignore. */
1611 /* CPUID(9) - DCA. ignore for now. */
1612 /* CPUID(a) - PeMo info. ignore for now. */
1613 /* CPUID(b) - topology info - takes ECX as input. ignore. */
1614
1615 /* CPUID(d) - XCR0 stuff - takes ECX as input. We only warn about the main level (ECX=0) for now. */
1616 CPUID_CHECK_WRN( aRawStd[0].eax < UINT32_C(0x0000000d)
1617 || aHostRawStd[0].eax >= UINT32_C(0x0000000d),
1618 ("CPUM: Standard leaf D was present on saved state host, not present on current.\n"));
1619 if ( aRawStd[0].eax >= UINT32_C(0x0000000d)
1620 && aHostRawStd[0].eax >= UINT32_C(0x0000000d))
1621 {
1622 CPUID_CHECK2_WRN("Valid low XCR0 bits", aHostRawStd[0xd].eax, aRawStd[0xd].eax);
1623 CPUID_CHECK2_WRN("Valid high XCR0 bits", aHostRawStd[0xd].edx, aRawStd[0xd].edx);
1624 CPUID_CHECK2_WRN("Current XSAVE/XRSTOR area size", aHostRawStd[0xd].ebx, aRawStd[0xd].ebx);
1625 CPUID_CHECK2_WRN("Max XSAVE/XRSTOR area size", aHostRawStd[0xd].ecx, aRawStd[0xd].ecx);
1626 }
1627
1628 /* CPUID(0x80000000) - same as CPUID(0) except for eax.
1629 Note! Intel have/is marking many of the fields here as reserved. We
1630 will verify them as if it's an AMD CPU. */
1631 CPUID_CHECK_RET( (aHostRawExt[0].eax >= UINT32_C(0x80000001) && aHostRawExt[0].eax <= UINT32_C(0x8000007f))
1632 || !(aRawExt[0].eax >= UINT32_C(0x80000001) && aRawExt[0].eax <= UINT32_C(0x8000007f)),
1633 (N_("Extended leaves was present on saved state host, but is missing on the current\n")));
1634 if (aRawExt[0].eax >= UINT32_C(0x80000001) && aRawExt[0].eax <= UINT32_C(0x8000007f))
1635 {
1636 CPUID_CHECK_RET( aHostRawExt[0].ebx == aRawExt[0].ebx
1637 && aHostRawExt[0].ecx == aRawExt[0].ecx
1638 && aHostRawExt[0].edx == aRawExt[0].edx,
1639 (N_("CPU vendor mismatch: host='%.4s%.4s%.4s' saved='%.4s%.4s%.4s'"),
1640 &aHostRawExt[0].ebx, &aHostRawExt[0].edx, &aHostRawExt[0].ecx,
1641 &aRawExt[0].ebx, &aRawExt[0].edx, &aRawExt[0].ecx));
1642 CPUID_CHECK2_WRN("Ext CPUID max leaf", aHostRawExt[0].eax, aRawExt[0].eax);
1643
1644 /* CPUID(0x80000001).eax - same as CPUID(0).eax. */
1645 CPUID_CHECK2_RET("CPU family", ASMGetCpuFamily(aHostRawExt[1].eax), ASMGetCpuFamily(aRawExt[1].eax));
1646 CPUID_CHECK2_RET("CPU model", ASMGetCpuModel(aHostRawExt[1].eax, fIntel), ASMGetCpuModel(aRawExt[1].eax, fIntel));
1647 CPUID_CHECK2_WRN("CPU type", (aHostRawExt[1].eax >> 12) & 3, (aRawExt[1].eax >> 12) & 3 );
1648 CPUID_CHECK2_WRN("Reserved bits 15:14", (aHostRawExt[1].eax >> 14) & 3, (aRawExt[1].eax >> 14) & 3 );
1649 CPUID_CHECK2_WRN("Reserved bits 31:28", aHostRawExt[1].eax >> 28, aRawExt[1].eax >> 28);
1650
1651 /* CPUID(0x80000001).ebx - Brand ID (maybe), just warn if things differs. */
1652 CPUID_CHECK2_WRN("CPU BrandID", aHostRawExt[1].ebx & 0xffff, aRawExt[1].ebx & 0xffff);
1653 CPUID_CHECK2_WRN("Reserved bits 16:27", (aHostRawExt[1].ebx >> 16) & 0xfff, (aRawExt[1].ebx >> 16) & 0xfff);
1654 CPUID_CHECK2_WRN("PkgType", (aHostRawExt[1].ebx >> 28) & 0xf, (aRawExt[1].ebx >> 28) & 0xf);
1655
1656 /* CPUID(0x80000001).ecx */
1657 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF);
1658 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_CMPL);
1659 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SVM);
1660 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_EXT_APIC);
1661 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_CR8L);
1662 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_ABM);
1663 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SSE4A);
1664 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_MISALNSSE);
1665 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF);
1666 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_OSVW);
1667 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_IBS);
1668 CPUID_RAW_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SSE5);
1669 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SKINIT);
1670 CPUID_RAW_FEATURE_IGN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_WDT);
1671 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(14));
1672 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(15));
1673 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(16));
1674 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(17));
1675 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(18));
1676 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(19));
1677 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(20));
1678 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(21));
1679 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(22));
1680 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(23));
1681 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(24));
1682 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(25));
1683 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(26));
1684 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(27));
1685 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(28));
1686 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(29));
1687 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(30));
1688 CPUID_RAW_FEATURE_WRN(Ext, ecx, RT_BIT_32(31));
1689
1690 /* CPUID(0x80000001).edx */
1691 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_FPU);
1692 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_VME);
1693 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_DE);
1694 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PSE);
1695 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_TSC);
1696 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_MSR);
1697 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PAE);
1698 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_MCE);
1699 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_CX8);
1700 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_APIC);
1701 CPUID_RAW_FEATURE_IGN(Ext, edx, RT_BIT_32(10) /*reserved*/);
1702 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_SEP);
1703 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_MTRR);
1704 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PGE);
1705 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_MCA);
1706 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_CMOV);
1707 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PAT);
1708 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PSE36);
1709 CPUID_RAW_FEATURE_IGN(Ext, edx, RT_BIT_32(18) /*reserved*/);
1710 CPUID_RAW_FEATURE_IGN(Ext, edx, RT_BIT_32(19) /*reserved*/);
1711 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_NX);
1712 CPUID_RAW_FEATURE_IGN(Ext, edx, RT_BIT_32(21) /*reserved*/);
1713 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_AXMMX);
1714 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_MMX);
1715 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_FXSR);
1716 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_FFXSR);
1717 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PAGE1GB);
1718 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_RDTSCP);
1719 CPUID_RAW_FEATURE_IGN(Ext, edx, RT_BIT_32(28) /*reserved*/);
1720 CPUID_RAW_FEATURE_IGN(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_LONG_MODE);
1721 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX);
1722 CPUID_RAW_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_3DNOW);
1723
1724 /** @todo verify the rest as well. */
1725 }
1726 }
1727
1728
1729
1730 /*
1731 * Verify that we can support the features already exposed to the guest on
1732 * this host.
1733 *
1734 * Most of the features we're emulating requires intercepting instruction
1735 * and doing it the slow way, so there is no need to warn when they aren't
1736 * present in the host CPU. Thus we use IGN instead of EMU on these.
1737 *
1738 * Trailing comments:
1739 * "EMU" - Possible to emulate, could be lots of work and very slow.
1740 * "EMU?" - Can this be emulated?
1741 */
1742 /* CPUID(1).ecx */
1743 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE3); // -> EMU
1744 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_PCLMUL); // -> EMU?
1745 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_DTES64); // -> EMU?
1746 CPUID_GST_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_MONITOR);
1747 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_CPLDS); // -> EMU?
1748 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_VMX); // -> EMU
1749 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SMX); // -> EMU
1750 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_EST); // -> EMU
1751 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_TM2); // -> EMU?
1752 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSSE3); // -> EMU
1753 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_CNTXID); // -> EMU
1754 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(11) /*reserved*/ );
1755 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_FMA); // -> EMU? what's this?
1756 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_CX16); // -> EMU?
1757 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_TPRUPDATE);//-> EMU
1758 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_PDCM); // -> EMU
1759 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(16) /*reserved*/);
1760 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(17) /*reserved*/);
1761 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_DCA); // -> EMU?
1762 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE4_1); // -> EMU
1763 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_SSE4_2); // -> EMU
1764 CPUID_GST_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_X2APIC);
1765 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_MOVBE); // -> EMU
1766 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_POPCNT); // -> EMU
1767 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(24) /*reserved*/);
1768 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_AES); // -> EMU
1769 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_XSAVE); // -> EMU
1770 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_OSXSAVE); // -> EMU
1771 CPUID_GST_FEATURE_RET(Std, ecx, X86_CPUID_FEATURE_ECX_AVX); // -> EMU?
1772 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(29) /*reserved*/);
1773 CPUID_GST_FEATURE_RET(Std, ecx, RT_BIT_32(30) /*reserved*/);
1774 CPUID_GST_FEATURE_IGN(Std, ecx, X86_CPUID_FEATURE_ECX_HVP); // Normally not set by host
1775
1776 /* CPUID(1).edx */
1777 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_FPU);
1778 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_VME);
1779 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_DE); // -> EMU?
1780 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSE);
1781 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_TSC); // -> EMU
1782 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_MSR); // -> EMU
1783 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_PAE);
1784 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MCE);
1785 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CX8); // -> EMU?
1786 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_APIC);
1787 CPUID_GST_FEATURE_RET(Std, edx, RT_BIT_32(10) /*reserved*/);
1788 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_SEP);
1789 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MTRR);
1790 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PGE);
1791 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_MCA);
1792 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CMOV); // -> EMU
1793 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PAT);
1794 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSE36);
1795 CPUID_GST_FEATURE_IGN(Std, edx, X86_CPUID_FEATURE_EDX_PSN);
1796 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_CLFSH); // -> EMU
1797 CPUID_GST_FEATURE_RET(Std, edx, RT_BIT_32(20) /*reserved*/);
1798 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_DS); // -> EMU?
1799 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_ACPI); // -> EMU?
1800 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_MMX); // -> EMU
1801 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_FXSR); // -> EMU
1802 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_SSE); // -> EMU
1803 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_SSE2); // -> EMU
1804 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_SS); // -> EMU?
1805 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_HTT); // -> EMU?
1806 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_TM); // -> EMU?
1807 CPUID_GST_FEATURE_RET(Std, edx, RT_BIT_32(30) /*JMPE/IA64*/); // -> EMU
1808 CPUID_GST_FEATURE_RET(Std, edx, X86_CPUID_FEATURE_EDX_PBE); // -> EMU?
1809
1810 /* CPUID(0x80000000). */
1811 if ( aGuestCpuIdExt[0].eax >= UINT32_C(0x80000001)
1812 && aGuestCpuIdExt[0].eax < UINT32_C(0x8000007f))
1813 {
1814 /** @todo deal with no 0x80000001 on the host. */
1815 bool const fHostAmd = ASMIsAmdCpuEx(aHostRawStd[0].ebx, aHostRawStd[0].ecx, aHostRawStd[0].edx);
1816 bool const fGuestAmd = ASMIsAmdCpuEx(aGuestCpuIdExt[0].ebx, aGuestCpuIdExt[0].ecx, aGuestCpuIdExt[0].edx);
1817
1818 /* CPUID(0x80000001).ecx */
1819 CPUID_GST_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF); // -> EMU
1820 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_CMPL); // -> EMU
1821 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SVM); // -> EMU
1822 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_EXT_APIC);// ???
1823 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_CR8L); // -> EMU
1824 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_ABM); // -> EMU
1825 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SSE4A); // -> EMU
1826 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_MISALNSSE);//-> EMU
1827 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF);// -> EMU
1828 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_OSVW); // -> EMU?
1829 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_IBS); // -> EMU
1830 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SSE5); // -> EMU
1831 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_SKINIT); // -> EMU
1832 CPUID_GST_AMD_FEATURE_RET(Ext, ecx, X86_CPUID_AMD_FEATURE_ECX_WDT); // -> EMU
1833 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(14));
1834 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(15));
1835 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(16));
1836 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(17));
1837 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(18));
1838 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(19));
1839 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(20));
1840 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(21));
1841 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(22));
1842 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(23));
1843 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(24));
1844 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(25));
1845 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(26));
1846 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(27));
1847 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(28));
1848 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(29));
1849 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(30));
1850 CPUID_GST_AMD_FEATURE_WRN(Ext, ecx, RT_BIT_32(31));
1851
1852 /* CPUID(0x80000001).edx */
1853 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_FPU, X86_CPUID_FEATURE_EDX_FPU); // -> EMU
1854 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_VME, X86_CPUID_FEATURE_EDX_VME); // -> EMU
1855 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_DE, X86_CPUID_FEATURE_EDX_DE); // -> EMU
1856 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_PSE, X86_CPUID_FEATURE_EDX_PSE);
1857 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_TSC, X86_CPUID_FEATURE_EDX_TSC); // -> EMU
1858 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_MSR, X86_CPUID_FEATURE_EDX_MSR); // -> EMU
1859 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_PAE, X86_CPUID_FEATURE_EDX_PAE);
1860 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_MCE, X86_CPUID_FEATURE_EDX_MCE);
1861 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_CX8, X86_CPUID_FEATURE_EDX_CX8); // -> EMU?
1862 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_APIC, X86_CPUID_FEATURE_EDX_APIC);
1863 CPUID_GST_AMD_FEATURE_WRN(Ext, edx, RT_BIT_32(10) /*reserved*/);
1864 CPUID_GST_FEATURE_IGN( Ext, edx, X86_CPUID_AMD_FEATURE_EDX_SEP); // Intel: long mode only.
1865 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_MTRR, X86_CPUID_FEATURE_EDX_MTRR);
1866 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_PGE, X86_CPUID_FEATURE_EDX_PGE);
1867 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_MCA, X86_CPUID_FEATURE_EDX_MCA);
1868 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_CMOV, X86_CPUID_FEATURE_EDX_CMOV); // -> EMU
1869 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_PAT, X86_CPUID_FEATURE_EDX_PAT);
1870 CPUID_GST_FEATURE2_IGN( edx, X86_CPUID_AMD_FEATURE_EDX_PSE36, X86_CPUID_FEATURE_EDX_PSE36);
1871 CPUID_GST_AMD_FEATURE_WRN(Ext, edx, RT_BIT_32(18) /*reserved*/);
1872 CPUID_GST_AMD_FEATURE_WRN(Ext, edx, RT_BIT_32(19) /*reserved*/);
1873 CPUID_GST_FEATURE_RET( Ext, edx, X86_CPUID_AMD_FEATURE_EDX_NX);
1874 CPUID_GST_FEATURE_WRN( Ext, edx, RT_BIT_32(21) /*reserved*/);
1875 CPUID_GST_FEATURE_RET( Ext, edx, X86_CPUID_AMD_FEATURE_EDX_AXMMX);
1876 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_MMX, X86_CPUID_FEATURE_EDX_MMX); // -> EMU
1877 CPUID_GST_FEATURE2_RET( edx, X86_CPUID_AMD_FEATURE_EDX_FXSR, X86_CPUID_FEATURE_EDX_FXSR); // -> EMU
1878 CPUID_GST_AMD_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_FFXSR);
1879 CPUID_GST_AMD_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_PAGE1GB);
1880 CPUID_GST_AMD_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_RDTSCP);
1881 CPUID_GST_FEATURE_IGN( Ext, edx, RT_BIT_32(28) /*reserved*/);
1882 CPUID_GST_FEATURE_RET( Ext, edx, X86_CPUID_AMD_FEATURE_EDX_LONG_MODE);
1883 CPUID_GST_AMD_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX);
1884 CPUID_GST_AMD_FEATURE_RET(Ext, edx, X86_CPUID_AMD_FEATURE_EDX_3DNOW);
1885 }
1886
1887 /*
1888 * We're good, commit the CPU ID leaves.
1889 */
1890 memcpy(&pVM->cpum.s.aGuestCpuIdStd[0], &aGuestCpuIdStd[0], sizeof(aGuestCpuIdStd));
1891 memcpy(&pVM->cpum.s.aGuestCpuIdExt[0], &aGuestCpuIdExt[0], sizeof(aGuestCpuIdExt));
1892 memcpy(&pVM->cpum.s.aGuestCpuIdCentaur[0], &aGuestCpuIdCentaur[0], sizeof(aGuestCpuIdCentaur));
1893 pVM->cpum.s.GuestCpuIdDef = GuestCpuIdDef;
1894
1895#undef CPUID_CHECK_RET
1896#undef CPUID_CHECK_WRN
1897#undef CPUID_CHECK2_RET
1898#undef CPUID_CHECK2_WRN
1899#undef CPUID_RAW_FEATURE_RET
1900#undef CPUID_RAW_FEATURE_WRN
1901#undef CPUID_RAW_FEATURE_IGN
1902#undef CPUID_GST_FEATURE_RET
1903#undef CPUID_GST_FEATURE_WRN
1904#undef CPUID_GST_FEATURE_EMU
1905#undef CPUID_GST_FEATURE_IGN
1906#undef CPUID_GST_FEATURE2_RET
1907#undef CPUID_GST_FEATURE2_WRN
1908#undef CPUID_GST_FEATURE2_EMU
1909#undef CPUID_GST_FEATURE2_IGN
1910#undef CPUID_GST_AMD_FEATURE_RET
1911#undef CPUID_GST_AMD_FEATURE_WRN
1912#undef CPUID_GST_AMD_FEATURE_EMU
1913#undef CPUID_GST_AMD_FEATURE_IGN
1914
1915 return VINF_SUCCESS;
1916}
1917
1918
1919/**
1920 * Pass 0 live exec callback.
1921 *
1922 * @returns VINF_SSM_DONT_CALL_AGAIN.
1923 * @param pVM Pointer to the VM.
1924 * @param pSSM The saved state handle.
1925 * @param uPass The pass (0).
1926 */
1927static DECLCALLBACK(int) cpumR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
1928{
1929 AssertReturn(uPass == 0, VERR_SSM_UNEXPECTED_PASS);
1930 cpumR3SaveCpuId(pVM, pSSM);
1931 return VINF_SSM_DONT_CALL_AGAIN;
1932}
1933
1934
1935/**
1936 * Execute state save operation.
1937 *
1938 * @returns VBox status code.
1939 * @param pVM VM Handle.
1940 * @param pSSM SSM operation handle.
1941 */
1942static DECLCALLBACK(int) cpumR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
1943{
1944 /*
1945 * Save.
1946 */
1947 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1948 {
1949 PVMCPU pVCpu = &pVM->aCpus[i];
1950
1951 SSMR3PutMem(pSSM, &pVCpu->cpum.s.Hyper, sizeof(pVCpu->cpum.s.Hyper));
1952 }
1953
1954 SSMR3PutU32(pSSM, pVM->cCpus);
1955 SSMR3PutU32(pSSM, sizeof(pVM->aCpus[0].cpum.s.GuestMsrs.msr));
1956 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1957 {
1958 PVMCPU pVCpu = &pVM->aCpus[i];
1959
1960 SSMR3PutMem(pSSM, &pVCpu->cpum.s.Guest, sizeof(pVCpu->cpum.s.Guest));
1961 SSMR3PutU32(pSSM, pVCpu->cpum.s.fUseFlags);
1962 SSMR3PutU32(pSSM, pVCpu->cpum.s.fChanged);
1963 AssertCompileSizeAlignment(pVM->aCpus[i].cpum.s.GuestMsrs.msr, sizeof(uint64_t));
1964 SSMR3PutMem(pSSM, &pVCpu->cpum.s.GuestMsrs, sizeof(pVM->aCpus[i].cpum.s.GuestMsrs.msr));
1965 }
1966
1967 cpumR3SaveCpuId(pVM, pSSM);
1968 return VINF_SUCCESS;
1969}
1970
1971
1972/**
1973 * Load a version 1.6 CPUMCTX structure.
1974 *
1975 * @returns VBox status code.
1976 * @param pVM VM Handle.
1977 * @param pCpumctx16 Version 1.6 CPUMCTX
1978 */
1979static void cpumR3LoadCPUM1_6(PVM pVM, CPUMCTX_VER1_6 *pCpumctx16)
1980{
1981#define CPUMCTX16_LOADREG(RegName) \
1982 pVM->aCpus[0].cpum.s.Guest.RegName = pCpumctx16->RegName;
1983
1984#define CPUMCTX16_LOADDRXREG(RegName) \
1985 pVM->aCpus[0].cpum.s.Guest.dr[RegName] = pCpumctx16->dr##RegName;
1986
1987#define CPUMCTX16_LOADHIDREG(RegName) \
1988 pVM->aCpus[0].cpum.s.Guest.RegName##Hid.u64Base = pCpumctx16->RegName##Hid.u32Base; \
1989 pVM->aCpus[0].cpum.s.Guest.RegName##Hid.u32Limit = pCpumctx16->RegName##Hid.u32Limit; \
1990 pVM->aCpus[0].cpum.s.Guest.RegName##Hid.Attr = pCpumctx16->RegName##Hid.Attr;
1991
1992#define CPUMCTX16_LOADSEGREG(RegName) \
1993 pVM->aCpus[0].cpum.s.Guest.RegName = pCpumctx16->RegName; \
1994 CPUMCTX16_LOADHIDREG(RegName);
1995
1996 pVM->aCpus[0].cpum.s.Guest.fpu = pCpumctx16->fpu;
1997
1998 CPUMCTX16_LOADREG(rax);
1999 CPUMCTX16_LOADREG(rbx);
2000 CPUMCTX16_LOADREG(rcx);
2001 CPUMCTX16_LOADREG(rdx);
2002 CPUMCTX16_LOADREG(rdi);
2003 CPUMCTX16_LOADREG(rsi);
2004 CPUMCTX16_LOADREG(rbp);
2005 CPUMCTX16_LOADREG(esp);
2006 CPUMCTX16_LOADREG(rip);
2007 CPUMCTX16_LOADREG(rflags);
2008
2009 CPUMCTX16_LOADSEGREG(cs);
2010 CPUMCTX16_LOADSEGREG(ds);
2011 CPUMCTX16_LOADSEGREG(es);
2012 CPUMCTX16_LOADSEGREG(fs);
2013 CPUMCTX16_LOADSEGREG(gs);
2014 CPUMCTX16_LOADSEGREG(ss);
2015
2016 CPUMCTX16_LOADREG(r8);
2017 CPUMCTX16_LOADREG(r9);
2018 CPUMCTX16_LOADREG(r10);
2019 CPUMCTX16_LOADREG(r11);
2020 CPUMCTX16_LOADREG(r12);
2021 CPUMCTX16_LOADREG(r13);
2022 CPUMCTX16_LOADREG(r14);
2023 CPUMCTX16_LOADREG(r15);
2024
2025 CPUMCTX16_LOADREG(cr0);
2026 CPUMCTX16_LOADREG(cr2);
2027 CPUMCTX16_LOADREG(cr3);
2028 CPUMCTX16_LOADREG(cr4);
2029
2030 CPUMCTX16_LOADDRXREG(0);
2031 CPUMCTX16_LOADDRXREG(1);
2032 CPUMCTX16_LOADDRXREG(2);
2033 CPUMCTX16_LOADDRXREG(3);
2034 CPUMCTX16_LOADDRXREG(4);
2035 CPUMCTX16_LOADDRXREG(5);
2036 CPUMCTX16_LOADDRXREG(6);
2037 CPUMCTX16_LOADDRXREG(7);
2038
2039 pVM->aCpus[0].cpum.s.Guest.gdtr.cbGdt = pCpumctx16->gdtr.cbGdt;
2040 pVM->aCpus[0].cpum.s.Guest.gdtr.pGdt = pCpumctx16->gdtr.pGdt;
2041 pVM->aCpus[0].cpum.s.Guest.idtr.cbIdt = pCpumctx16->idtr.cbIdt;
2042 pVM->aCpus[0].cpum.s.Guest.idtr.pIdt = pCpumctx16->idtr.pIdt;
2043
2044 CPUMCTX16_LOADREG(ldtr);
2045 CPUMCTX16_LOADREG(tr);
2046
2047 pVM->aCpus[0].cpum.s.Guest.SysEnter = pCpumctx16->SysEnter;
2048
2049 CPUMCTX16_LOADREG(msrEFER);
2050 CPUMCTX16_LOADREG(msrSTAR);
2051 CPUMCTX16_LOADREG(msrPAT);
2052 CPUMCTX16_LOADREG(msrLSTAR);
2053 CPUMCTX16_LOADREG(msrCSTAR);
2054 CPUMCTX16_LOADREG(msrSFMASK);
2055 CPUMCTX16_LOADREG(msrKERNELGSBASE);
2056
2057 CPUMCTX16_LOADHIDREG(ldtr);
2058 CPUMCTX16_LOADHIDREG(tr);
2059
2060#undef CPUMCTX16_LOADSEGREG
2061#undef CPUMCTX16_LOADHIDREG
2062#undef CPUMCTX16_LOADDRXREG
2063#undef CPUMCTX16_LOADREG
2064}
2065
2066
2067/**
2068 * @copydoc FNSSMINTLOADPREP
2069 */
2070static DECLCALLBACK(int) cpumR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
2071{
2072 NOREF(pSSM);
2073 pVM->cpum.s.fPendingRestore = true;
2074 return VINF_SUCCESS;
2075}
2076
2077
2078/**
2079 * @copydoc FNSSMINTLOADEXEC
2080 */
2081static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2082{
2083 /*
2084 * Validate version.
2085 */
2086 if ( uVersion != CPUM_SAVED_STATE_VERSION
2087 && uVersion != CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE
2088 && uVersion != CPUM_SAVED_STATE_VERSION_VER3_2
2089 && uVersion != CPUM_SAVED_STATE_VERSION_VER3_0
2090 && uVersion != CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR
2091 && uVersion != CPUM_SAVED_STATE_VERSION_VER2_0
2092 && uVersion != CPUM_SAVED_STATE_VERSION_VER1_6)
2093 {
2094 AssertMsgFailed(("cpumR3LoadExec: Invalid version uVersion=%d!\n", uVersion));
2095 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2096 }
2097
2098 if (uPass == SSM_PASS_FINAL)
2099 {
2100 /*
2101 * Set the size of RTGCPTR for SSMR3GetGCPtr. (Only necessary for
2102 * really old SSM file versions.)
2103 */
2104 if (uVersion == CPUM_SAVED_STATE_VERSION_VER1_6)
2105 SSMR3HandleSetGCPtrSize(pSSM, sizeof(RTGCPTR32));
2106 else if (uVersion <= CPUM_SAVED_STATE_VERSION_VER3_0)
2107 SSMR3HandleSetGCPtrSize(pSSM, HC_ARCH_BITS == 32 ? sizeof(RTGCPTR32) : sizeof(RTGCPTR));
2108
2109 /*
2110 * Restore.
2111 */
2112 for (VMCPUID i = 0; i < pVM->cCpus; i++)
2113 {
2114 PVMCPU pVCpu = &pVM->aCpus[i];
2115 uint32_t uCR3 = pVCpu->cpum.s.Hyper.cr3;
2116 uint32_t uESP = pVCpu->cpum.s.Hyper.esp; /* see VMMR3Relocate(). */
2117
2118 SSMR3GetMem(pSSM, &pVCpu->cpum.s.Hyper, sizeof(pVCpu->cpum.s.Hyper));
2119 pVCpu->cpum.s.Hyper.cr3 = uCR3;
2120 pVCpu->cpum.s.Hyper.esp = uESP;
2121 }
2122
2123 if (uVersion == CPUM_SAVED_STATE_VERSION_VER1_6)
2124 {
2125 CPUMCTX_VER1_6 cpumctx16;
2126 memset(&pVM->aCpus[0].cpum.s.Guest, 0, sizeof(pVM->aCpus[0].cpum.s.Guest));
2127 SSMR3GetMem(pSSM, &cpumctx16, sizeof(cpumctx16));
2128
2129 /* Save the old cpumctx state into the new one. */
2130 cpumR3LoadCPUM1_6(pVM, &cpumctx16);
2131
2132 SSMR3GetU32(pSSM, &pVM->aCpus[0].cpum.s.fUseFlags);
2133 SSMR3GetU32(pSSM, &pVM->aCpus[0].cpum.s.fChanged);
2134 }
2135 else
2136 {
2137 if (uVersion >= CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR)
2138 {
2139 uint32_t cCpus;
2140 int rc = SSMR3GetU32(pSSM, &cCpus); AssertRCReturn(rc, rc);
2141 AssertLogRelMsgReturn(cCpus == pVM->cCpus, ("Mismatching CPU counts: saved: %u; configured: %u \n", cCpus, pVM->cCpus),
2142 VERR_SSM_UNEXPECTED_DATA);
2143 }
2144 AssertLogRelMsgReturn( uVersion != CPUM_SAVED_STATE_VERSION_VER2_0
2145 || pVM->cCpus == 1,
2146 ("cCpus=%u\n", pVM->cCpus),
2147 VERR_SSM_UNEXPECTED_DATA);
2148
2149 uint32_t cbMsrs = 0;
2150 if (uVersion > CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE)
2151 {
2152 int rc = SSMR3GetU32(pSSM, &cbMsrs); AssertRCReturn(rc, rc);
2153 AssertLogRelMsgReturn(RT_ALIGN(cbMsrs, sizeof(uint64_t)) == cbMsrs, ("Size of MSRs is misaligned: %#x\n", cbMsrs),
2154 VERR_SSM_UNEXPECTED_DATA);
2155 AssertLogRelMsgReturn(cbMsrs <= sizeof(CPUMCTXMSRS) && cbMsrs > 0, ("Size of MSRs is out of range: %#x\n", cbMsrs),
2156 VERR_SSM_UNEXPECTED_DATA);
2157 }
2158
2159 for (VMCPUID i = 0; i < pVM->cCpus; i++)
2160 {
2161 SSMR3GetMem(pSSM, &pVM->aCpus[i].cpum.s.Guest, sizeof(pVM->aCpus[i].cpum.s.Guest));
2162 SSMR3GetU32(pSSM, &pVM->aCpus[i].cpum.s.fUseFlags);
2163 SSMR3GetU32(pSSM, &pVM->aCpus[i].cpum.s.fChanged);
2164 if (uVersion > CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE)
2165 SSMR3GetMem(pSSM, &pVM->aCpus[i].cpum.s.GuestMsrs.au64[0], cbMsrs);
2166 else if (uVersion >= CPUM_SAVED_STATE_VERSION_VER3_0)
2167 {
2168 SSMR3GetMem(pSSM, &pVM->aCpus[i].cpum.s.GuestMsrs.au64[0], 2 * sizeof(uint64_t)); /* Restore two MSRs. */
2169 SSMR3Skip(pSSM, 62 * sizeof(uint64_t));
2170 }
2171 }
2172 }
2173
2174 /* Older states does not set CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID for
2175 raw-mode guest, so we have to do it ourselves. */
2176 if ( uVersion <= CPUM_SAVED_STATE_VERSION_VER3_2
2177 && !HWACCMIsEnabled(pVM))
2178 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
2179 pVM->aCpus[iCpu].cpum.s.fChanged |= CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID;
2180 }
2181
2182 pVM->cpum.s.fPendingRestore = false;
2183
2184 /*
2185 * Guest CPUIDs.
2186 */
2187 if (uVersion > CPUM_SAVED_STATE_VERSION_VER3_0)
2188 return cpumR3LoadCpuId(pVM, pSSM, uVersion);
2189
2190 /** @todo Merge the code below into cpumR3LoadCpuId when we've found out what is
2191 * actually required. */
2192
2193 /*
2194 * Restore the CPUID leaves.
2195 *
2196 * Note that we support restoring less than the current amount of standard
2197 * leaves because we've been allowed more is newer version of VBox.
2198 */
2199 uint32_t cElements;
2200 int rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
2201 if (cElements > RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd))
2202 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
2203 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdStd[0], cElements*sizeof(pVM->cpum.s.aGuestCpuIdStd[0]));
2204
2205 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
2206 if (cElements != RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt))
2207 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
2208 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdExt[0], sizeof(pVM->cpum.s.aGuestCpuIdExt));
2209
2210 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
2211 if (cElements != RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur))
2212 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
2213 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdCentaur[0], sizeof(pVM->cpum.s.aGuestCpuIdCentaur));
2214
2215 SSMR3GetMem(pSSM, &pVM->cpum.s.GuestCpuIdDef, sizeof(pVM->cpum.s.GuestCpuIdDef));
2216
2217 /*
2218 * Check that the basic cpuid id information is unchanged.
2219 */
2220 /** @todo we should check the 64 bits capabilities too! */
2221 uint32_t au32CpuId[8] = {0,0,0,0, 0,0,0,0};
2222 ASMCpuId(0, &au32CpuId[0], &au32CpuId[1], &au32CpuId[2], &au32CpuId[3]);
2223 ASMCpuId(1, &au32CpuId[4], &au32CpuId[5], &au32CpuId[6], &au32CpuId[7]);
2224 uint32_t au32CpuIdSaved[8];
2225 rc = SSMR3GetMem(pSSM, &au32CpuIdSaved[0], sizeof(au32CpuIdSaved));
2226 if (RT_SUCCESS(rc))
2227 {
2228 /* Ignore CPU stepping. */
2229 au32CpuId[4] &= 0xfffffff0;
2230 au32CpuIdSaved[4] &= 0xfffffff0;
2231
2232 /* Ignore APIC ID (AMD specs). */
2233 au32CpuId[5] &= ~0xff000000;
2234 au32CpuIdSaved[5] &= ~0xff000000;
2235
2236 /* Ignore the number of Logical CPUs (AMD specs). */
2237 au32CpuId[5] &= ~0x00ff0000;
2238 au32CpuIdSaved[5] &= ~0x00ff0000;
2239
2240 /* Ignore some advanced capability bits, that we don't expose to the guest. */
2241 au32CpuId[6] &= ~( X86_CPUID_FEATURE_ECX_DTES64
2242 | X86_CPUID_FEATURE_ECX_VMX
2243 | X86_CPUID_FEATURE_ECX_SMX
2244 | X86_CPUID_FEATURE_ECX_EST
2245 | X86_CPUID_FEATURE_ECX_TM2
2246 | X86_CPUID_FEATURE_ECX_CNTXID
2247 | X86_CPUID_FEATURE_ECX_TPRUPDATE
2248 | X86_CPUID_FEATURE_ECX_PDCM
2249 | X86_CPUID_FEATURE_ECX_DCA
2250 | X86_CPUID_FEATURE_ECX_X2APIC
2251 );
2252 au32CpuIdSaved[6] &= ~( X86_CPUID_FEATURE_ECX_DTES64
2253 | X86_CPUID_FEATURE_ECX_VMX
2254 | X86_CPUID_FEATURE_ECX_SMX
2255 | X86_CPUID_FEATURE_ECX_EST
2256 | X86_CPUID_FEATURE_ECX_TM2
2257 | X86_CPUID_FEATURE_ECX_CNTXID
2258 | X86_CPUID_FEATURE_ECX_TPRUPDATE
2259 | X86_CPUID_FEATURE_ECX_PDCM
2260 | X86_CPUID_FEATURE_ECX_DCA
2261 | X86_CPUID_FEATURE_ECX_X2APIC
2262 );
2263
2264 /* Make sure we don't forget to update the masks when enabling
2265 * features in the future.
2266 */
2267 AssertRelease(!(pVM->cpum.s.aGuestCpuIdStd[1].ecx &
2268 ( X86_CPUID_FEATURE_ECX_DTES64
2269 | X86_CPUID_FEATURE_ECX_VMX
2270 | X86_CPUID_FEATURE_ECX_SMX
2271 | X86_CPUID_FEATURE_ECX_EST
2272 | X86_CPUID_FEATURE_ECX_TM2
2273 | X86_CPUID_FEATURE_ECX_CNTXID
2274 | X86_CPUID_FEATURE_ECX_TPRUPDATE
2275 | X86_CPUID_FEATURE_ECX_PDCM
2276 | X86_CPUID_FEATURE_ECX_DCA
2277 | X86_CPUID_FEATURE_ECX_X2APIC
2278 )));
2279 /* do the compare */
2280 if (memcmp(au32CpuIdSaved, au32CpuId, sizeof(au32CpuIdSaved)))
2281 {
2282 if (SSMR3HandleGetAfter(pSSM) == SSMAFTER_DEBUG_IT)
2283 LogRel(("cpumR3LoadExec: CpuId mismatch! (ignored due to SSMAFTER_DEBUG_IT)\n"
2284 "Saved=%.*Rhxs\n"
2285 "Real =%.*Rhxs\n",
2286 sizeof(au32CpuIdSaved), au32CpuIdSaved,
2287 sizeof(au32CpuId), au32CpuId));
2288 else
2289 {
2290 LogRel(("cpumR3LoadExec: CpuId mismatch!\n"
2291 "Saved=%.*Rhxs\n"
2292 "Real =%.*Rhxs\n",
2293 sizeof(au32CpuIdSaved), au32CpuIdSaved,
2294 sizeof(au32CpuId), au32CpuId));
2295 rc = VERR_SSM_LOAD_CPUID_MISMATCH;
2296 }
2297 }
2298 }
2299
2300 return rc;
2301}
2302
2303
2304/**
2305 * @copydoc FNSSMINTLOADPREP
2306 */
2307static DECLCALLBACK(int) cpumR3LoadDone(PVM pVM, PSSMHANDLE pSSM)
2308{
2309 if (RT_FAILURE(SSMR3HandleGetStatus(pSSM)))
2310 return VINF_SUCCESS;
2311
2312 /* just check this since we can. */ /** @todo Add a SSM unit flag for indicating that it's mandatory during a restore. */
2313 if (pVM->cpum.s.fPendingRestore)
2314 {
2315 LogRel(("CPUM: Missing state!\n"));
2316 return VERR_INTERNAL_ERROR_2;
2317 }
2318
2319 /* Notify PGM of the NXE states in case they've changed. */
2320 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
2321 PGMNotifyNxeChanged(&pVM->aCpus[iCpu], !!(pVM->aCpus[iCpu].cpum.s.Guest.msrEFER & MSR_K6_EFER_NXE));
2322 return VINF_SUCCESS;
2323}
2324
2325
2326/**
2327 * Checks if the CPUM state restore is still pending.
2328 *
2329 * @returns true / false.
2330 * @param pVM Pointer to the VM.
2331 */
2332VMMDECL(bool) CPUMR3IsStateRestorePending(PVM pVM)
2333{
2334 return pVM->cpum.s.fPendingRestore;
2335}
2336
2337
2338/**
2339 * Formats the EFLAGS value into mnemonics.
2340 *
2341 * @param pszEFlags Where to write the mnemonics. (Assumes sufficient buffer space.)
2342 * @param efl The EFLAGS value.
2343 */
2344static void cpumR3InfoFormatFlags(char *pszEFlags, uint32_t efl)
2345{
2346 /*
2347 * Format the flags.
2348 */
2349 static const struct
2350 {
2351 const char *pszSet; const char *pszClear; uint32_t fFlag;
2352 } s_aFlags[] =
2353 {
2354 { "vip",NULL, X86_EFL_VIP },
2355 { "vif",NULL, X86_EFL_VIF },
2356 { "ac", NULL, X86_EFL_AC },
2357 { "vm", NULL, X86_EFL_VM },
2358 { "rf", NULL, X86_EFL_RF },
2359 { "nt", NULL, X86_EFL_NT },
2360 { "ov", "nv", X86_EFL_OF },
2361 { "dn", "up", X86_EFL_DF },
2362 { "ei", "di", X86_EFL_IF },
2363 { "tf", NULL, X86_EFL_TF },
2364 { "nt", "pl", X86_EFL_SF },
2365 { "nz", "zr", X86_EFL_ZF },
2366 { "ac", "na", X86_EFL_AF },
2367 { "po", "pe", X86_EFL_PF },
2368 { "cy", "nc", X86_EFL_CF },
2369 };
2370 char *psz = pszEFlags;
2371 for (unsigned i = 0; i < RT_ELEMENTS(s_aFlags); i++)
2372 {
2373 const char *pszAdd = s_aFlags[i].fFlag & efl ? s_aFlags[i].pszSet : s_aFlags[i].pszClear;
2374 if (pszAdd)
2375 {
2376 strcpy(psz, pszAdd);
2377 psz += strlen(pszAdd);
2378 *psz++ = ' ';
2379 }
2380 }
2381 psz[-1] = '\0';
2382}
2383
2384
2385/**
2386 * Formats a full register dump.
2387 *
2388 * @param pVM VM Handle.
2389 * @param pCtx The context to format.
2390 * @param pCtxCore The context core to format.
2391 * @param pHlp Output functions.
2392 * @param enmType The dump type.
2393 * @param pszPrefix Register name prefix.
2394 */
2395static void cpumR3InfoOne(PVM pVM, PCPUMCTX pCtx, PCCPUMCTXCORE pCtxCore, PCDBGFINFOHLP pHlp, CPUMDUMPTYPE enmType,
2396 const char *pszPrefix)
2397{
2398 NOREF(pVM);
2399
2400 /*
2401 * Format the EFLAGS.
2402 */
2403 uint32_t efl = pCtxCore->eflags.u32;
2404 char szEFlags[80];
2405 cpumR3InfoFormatFlags(&szEFlags[0], efl);
2406
2407 /*
2408 * Format the registers.
2409 */
2410 switch (enmType)
2411 {
2412 case CPUMDUMPTYPE_TERSE:
2413 if (CPUMIsGuestIn64BitCodeEx(pCtx))
2414 pHlp->pfnPrintf(pHlp,
2415 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
2416 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
2417 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
2418 "%sr14=%016RX64 %sr15=%016RX64\n"
2419 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
2420 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
2421 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
2422 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
2423 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
2424 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2425 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
2426 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, efl);
2427 else
2428 pHlp->pfnPrintf(pHlp,
2429 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
2430 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
2431 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
2432 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
2433 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2434 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
2435 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, efl);
2436 break;
2437
2438 case CPUMDUMPTYPE_DEFAULT:
2439 if (CPUMIsGuestIn64BitCodeEx(pCtx))
2440 pHlp->pfnPrintf(pHlp,
2441 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
2442 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
2443 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
2444 "%sr14=%016RX64 %sr15=%016RX64\n"
2445 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
2446 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
2447 "%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%016RX64:%04x %sldtr=%04x\n"
2448 ,
2449 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
2450 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
2451 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
2452 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2453 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
2454 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtx->tr, pszPrefix, efl,
2455 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
2456 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, (RTSEL)pCtx->ldtr);
2457 else
2458 pHlp->pfnPrintf(pHlp,
2459 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
2460 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
2461 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
2462 "%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%08RX64:%04x %sldtr=%04x\n"
2463 ,
2464 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
2465 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2466 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
2467 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtx->tr, pszPrefix, efl,
2468 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
2469 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, (RTSEL)pCtx->ldtr);
2470 break;
2471
2472 case CPUMDUMPTYPE_VERBOSE:
2473 if (CPUMIsGuestIn64BitCodeEx(pCtx))
2474 pHlp->pfnPrintf(pHlp,
2475 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
2476 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
2477 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
2478 "%sr14=%016RX64 %sr15=%016RX64\n"
2479 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
2480 "%scs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2481 "%sds={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2482 "%ses={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2483 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2484 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2485 "%sss={%04x base=%016RX64 limit=%08x flags=%08x}\n"
2486 "%scr0=%016RX64 %scr2=%016RX64 %scr3=%016RX64 %scr4=%016RX64\n"
2487 "%sdr0=%016RX64 %sdr1=%016RX64 %sdr2=%016RX64 %sdr3=%016RX64\n"
2488 "%sdr4=%016RX64 %sdr5=%016RX64 %sdr6=%016RX64 %sdr7=%016RX64\n"
2489 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
2490 "%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
2491 "%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
2492 "%sSysEnter={cs=%04llx eip=%016RX64 esp=%016RX64}\n"
2493 ,
2494 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
2495 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
2496 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
2497 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2498 pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u64Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u,
2499 pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u64Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u,
2500 pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u64Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u,
2501 pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u64Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u,
2502 pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u64Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u,
2503 pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u64Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u,
2504 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
2505 pszPrefix, pCtx->dr[0], pszPrefix, pCtx->dr[1], pszPrefix, pCtx->dr[2], pszPrefix, pCtx->dr[3],
2506 pszPrefix, pCtx->dr[4], pszPrefix, pCtx->dr[5], pszPrefix, pCtx->dr[6], pszPrefix, pCtx->dr[7],
2507 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
2508 pszPrefix, (RTSEL)pCtx->ldtr, pCtx->ldtrHid.u64Base, pCtx->ldtrHid.u32Limit, pCtx->ldtrHid.Attr.u,
2509 pszPrefix, (RTSEL)pCtx->tr, pCtx->trHid.u64Base, pCtx->trHid.u32Limit, pCtx->trHid.Attr.u,
2510 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
2511 else
2512 pHlp->pfnPrintf(pHlp,
2513 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
2514 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
2515 "%scs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr0=%08RX64 %sdr1=%08RX64\n"
2516 "%sds={%04x base=%016RX64 limit=%08x flags=%08x} %sdr2=%08RX64 %sdr3=%08RX64\n"
2517 "%ses={%04x base=%016RX64 limit=%08x flags=%08x} %sdr4=%08RX64 %sdr5=%08RX64\n"
2518 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr6=%08RX64 %sdr7=%08RX64\n"
2519 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x} %scr0=%08RX64 %scr2=%08RX64\n"
2520 "%sss={%04x base=%016RX64 limit=%08x flags=%08x} %scr3=%08RX64 %scr4=%08RX64\n"
2521 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
2522 "%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
2523 "%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
2524 "%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
2525 ,
2526 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
2527 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
2528 pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u64Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u, pszPrefix, pCtx->dr[0], pszPrefix, pCtx->dr[1],
2529 pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u64Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u, pszPrefix, pCtx->dr[2], pszPrefix, pCtx->dr[3],
2530 pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u64Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u, pszPrefix, pCtx->dr[4], pszPrefix, pCtx->dr[5],
2531 pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u64Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u, pszPrefix, pCtx->dr[6], pszPrefix, pCtx->dr[7],
2532 pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u64Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u, pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2,
2533 pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u64Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
2534 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
2535 pszPrefix, (RTSEL)pCtx->ldtr, pCtx->ldtrHid.u64Base, pCtx->ldtrHid.u32Limit, pCtx->ldtrHid.Attr.u,
2536 pszPrefix, (RTSEL)pCtx->tr, pCtx->trHid.u64Base, pCtx->trHid.u32Limit, pCtx->trHid.Attr.u,
2537 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
2538
2539 pHlp->pfnPrintf(pHlp,
2540 "%sFCW=%04x %sFSW=%04x %sFTW=%04x %sFOP=%04x %sMXCSR=%08x %sMXCSR_MASK=%08x\n"
2541 "%sFPUIP=%08x %sCS=%04x %sRsrvd1=%04x %sFPUDP=%08x %sDS=%04x %sRsvrd2=%04x\n"
2542 ,
2543 pszPrefix, pCtx->fpu.FCW, pszPrefix, pCtx->fpu.FSW, pszPrefix, pCtx->fpu.FTW, pszPrefix, pCtx->fpu.FOP,
2544 pszPrefix, pCtx->fpu.MXCSR, pszPrefix, pCtx->fpu.MXCSR_MASK,
2545 pszPrefix, pCtx->fpu.FPUIP, pszPrefix, pCtx->fpu.CS, pszPrefix, pCtx->fpu.Rsrvd1,
2546 pszPrefix, pCtx->fpu.FPUDP, pszPrefix, pCtx->fpu.DS, pszPrefix, pCtx->fpu.Rsrvd2
2547 );
2548 unsigned iShift = (pCtx->fpu.FSW >> 11) & 7;
2549 for (unsigned iST = 0; iST < RT_ELEMENTS(pCtx->fpu.aRegs); iST++)
2550 {
2551 unsigned iFPR = (iST + iShift) % RT_ELEMENTS(pCtx->fpu.aRegs);
2552 unsigned uTag = pCtx->fpu.FTW & (1 << iFPR) ? 1 : 0;
2553 char chSign = pCtx->fpu.aRegs[0].au16[4] & 0x8000 ? '-' : '+';
2554 unsigned iInteger = (unsigned)(pCtx->fpu.aRegs[0].au64[0] >> 63);
2555 uint64_t u64Fraction = pCtx->fpu.aRegs[0].au64[0] & UINT64_C(0x7fffffffffffffff);
2556 unsigned uExponent = pCtx->fpu.aRegs[0].au16[4] & 0x7fff;
2557 /** @todo This isn't entirenly correct and needs more work! */
2558 pHlp->pfnPrintf(pHlp,
2559 "%sST(%u)=%sFPR%u={%04RX16'%08RX32'%08RX32} t%d %c%u.%022llu ^ %u",
2560 pszPrefix, iST, pszPrefix, iFPR,
2561 pCtx->fpu.aRegs[0].au16[4], pCtx->fpu.aRegs[0].au32[1], pCtx->fpu.aRegs[0].au32[0],
2562 uTag, chSign, iInteger, u64Fraction, uExponent);
2563 if (pCtx->fpu.aRegs[0].au16[5] || pCtx->fpu.aRegs[0].au16[6] || pCtx->fpu.aRegs[0].au16[7])
2564 pHlp->pfnPrintf(pHlp, " res={%04RX16,%04RX16,%04RX16}\n",
2565 pCtx->fpu.aRegs[0].au16[5], pCtx->fpu.aRegs[0].au16[6], pCtx->fpu.aRegs[0].au16[7]);
2566 else
2567 pHlp->pfnPrintf(pHlp, "\n");
2568 }
2569 for (unsigned iXMM = 0; iXMM < RT_ELEMENTS(pCtx->fpu.aXMM); iXMM++)
2570 pHlp->pfnPrintf(pHlp,
2571 iXMM & 1
2572 ? "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32\n"
2573 : "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32 ",
2574 pszPrefix, iXMM, iXMM < 10 ? " " : "",
2575 pCtx->fpu.aXMM[iXMM].au32[3],
2576 pCtx->fpu.aXMM[iXMM].au32[2],
2577 pCtx->fpu.aXMM[iXMM].au32[1],
2578 pCtx->fpu.aXMM[iXMM].au32[0]);
2579 for (unsigned i = 0; i < RT_ELEMENTS(pCtx->fpu.au32RsrvdRest); i++)
2580 if (pCtx->fpu.au32RsrvdRest[i])
2581 pHlp->pfnPrintf(pHlp, "%sRsrvdRest[i]=%RX32 (offset=%#x)\n",
2582 pszPrefix, i, pCtx->fpu.au32RsrvdRest[i], RT_OFFSETOF(X86FXSTATE, au32RsrvdRest[i]) );
2583
2584 pHlp->pfnPrintf(pHlp,
2585 "%sEFER =%016RX64\n"
2586 "%sPAT =%016RX64\n"
2587 "%sSTAR =%016RX64\n"
2588 "%sCSTAR =%016RX64\n"
2589 "%sLSTAR =%016RX64\n"
2590 "%sSFMASK =%016RX64\n"
2591 "%sKERNELGSBASE =%016RX64\n",
2592 pszPrefix, pCtx->msrEFER,
2593 pszPrefix, pCtx->msrPAT,
2594 pszPrefix, pCtx->msrSTAR,
2595 pszPrefix, pCtx->msrCSTAR,
2596 pszPrefix, pCtx->msrLSTAR,
2597 pszPrefix, pCtx->msrSFMASK,
2598 pszPrefix, pCtx->msrKERNELGSBASE);
2599 break;
2600 }
2601}
2602
2603
2604/**
2605 * Display all cpu states and any other cpum info.
2606 *
2607 * @param pVM VM Handle.
2608 * @param pHlp The info helper functions.
2609 * @param pszArgs Arguments, ignored.
2610 */
2611static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2612{
2613 cpumR3InfoGuest(pVM, pHlp, pszArgs);
2614 cpumR3InfoGuestInstr(pVM, pHlp, pszArgs);
2615 cpumR3InfoHyper(pVM, pHlp, pszArgs);
2616 cpumR3InfoHost(pVM, pHlp, pszArgs);
2617}
2618
2619
2620/**
2621 * Parses the info argument.
2622 *
2623 * The argument starts with 'verbose', 'terse' or 'default' and then
2624 * continues with the comment string.
2625 *
2626 * @param pszArgs The pointer to the argument string.
2627 * @param penmType Where to store the dump type request.
2628 * @param ppszComment Where to store the pointer to the comment string.
2629 */
2630static void cpumR3InfoParseArg(const char *pszArgs, CPUMDUMPTYPE *penmType, const char **ppszComment)
2631{
2632 if (!pszArgs)
2633 {
2634 *penmType = CPUMDUMPTYPE_DEFAULT;
2635 *ppszComment = "";
2636 }
2637 else
2638 {
2639 if (!strncmp(pszArgs, "verbose", sizeof("verbose") - 1))
2640 {
2641 pszArgs += 7;
2642 *penmType = CPUMDUMPTYPE_VERBOSE;
2643 }
2644 else if (!strncmp(pszArgs, "terse", sizeof("terse") - 1))
2645 {
2646 pszArgs += 5;
2647 *penmType = CPUMDUMPTYPE_TERSE;
2648 }
2649 else if (!strncmp(pszArgs, "default", sizeof("default") - 1))
2650 {
2651 pszArgs += 7;
2652 *penmType = CPUMDUMPTYPE_DEFAULT;
2653 }
2654 else
2655 *penmType = CPUMDUMPTYPE_DEFAULT;
2656 *ppszComment = RTStrStripL(pszArgs);
2657 }
2658}
2659
2660
2661/**
2662 * Display the guest cpu state.
2663 *
2664 * @param pVM VM Handle.
2665 * @param pHlp The info helper functions.
2666 * @param pszArgs Arguments, ignored.
2667 */
2668static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2669{
2670 CPUMDUMPTYPE enmType;
2671 const char *pszComment;
2672 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
2673
2674 /* @todo SMP support! */
2675 PVMCPU pVCpu = VMMGetCpu(pVM);
2676 if (!pVCpu)
2677 pVCpu = &pVM->aCpus[0];
2678
2679 pHlp->pfnPrintf(pHlp, "Guest CPUM (VCPU %d) state: %s\n", pVCpu->idCpu, pszComment);
2680
2681 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
2682 cpumR3InfoOne(pVM, pCtx, CPUMCTX2CORE(pCtx), pHlp, enmType, "");
2683}
2684
2685
2686/**
2687 * Display the current guest instruction
2688 *
2689 * @param pVM VM Handle.
2690 * @param pHlp The info helper functions.
2691 * @param pszArgs Arguments, ignored.
2692 */
2693static DECLCALLBACK(void) cpumR3InfoGuestInstr(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2694{
2695 NOREF(pszArgs);
2696
2697 /** @todo SMP support! */
2698 PVMCPU pVCpu = VMMGetCpu(pVM);
2699 if (!pVCpu)
2700 pVCpu = &pVM->aCpus[0];
2701
2702 char szInstruction[256];
2703 int rc = DBGFR3DisasInstrCurrent(pVCpu, szInstruction, sizeof(szInstruction));
2704 if (RT_SUCCESS(rc))
2705 pHlp->pfnPrintf(pHlp, "\nCPUM: %s\n\n", szInstruction);
2706}
2707
2708
2709/**
2710 * Display the hypervisor cpu state.
2711 *
2712 * @param pVM VM Handle.
2713 * @param pHlp The info helper functions.
2714 * @param pszArgs Arguments, ignored.
2715 */
2716static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2717{
2718 CPUMDUMPTYPE enmType;
2719 const char *pszComment;
2720 /* @todo SMP */
2721 PVMCPU pVCpu = &pVM->aCpus[0];
2722
2723 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
2724 pHlp->pfnPrintf(pHlp, "Hypervisor CPUM state: %s\n", pszComment);
2725 cpumR3InfoOne(pVM, &pVCpu->cpum.s.Hyper, pVCpu->cpum.s.pHyperCoreR3, pHlp, enmType, ".");
2726 pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
2727}
2728
2729
2730/**
2731 * Display the host cpu state.
2732 *
2733 * @param pVM VM Handle.
2734 * @param pHlp The info helper functions.
2735 * @param pszArgs Arguments, ignored.
2736 */
2737static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2738{
2739 CPUMDUMPTYPE enmType;
2740 const char *pszComment;
2741 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
2742 pHlp->pfnPrintf(pHlp, "Host CPUM state: %s\n", pszComment);
2743
2744 /*
2745 * Format the EFLAGS.
2746 */
2747 /* @todo SMP */
2748 PCPUMHOSTCTX pCtx = &pVM->aCpus[0].cpum.s.Host;
2749#if HC_ARCH_BITS == 32
2750 uint32_t efl = pCtx->eflags.u32;
2751#else
2752 uint64_t efl = pCtx->rflags;
2753#endif
2754 char szEFlags[80];
2755 cpumR3InfoFormatFlags(&szEFlags[0], efl);
2756
2757 /*
2758 * Format the registers.
2759 */
2760#if HC_ARCH_BITS == 32
2761# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
2762 if (!(pCtx->efer & MSR_K6_EFER_LMA))
2763# endif
2764 {
2765 pHlp->pfnPrintf(pHlp,
2766 "eax=xxxxxxxx ebx=%08x ecx=xxxxxxxx edx=xxxxxxxx esi=%08x edi=%08x\n"
2767 "eip=xxxxxxxx esp=%08x ebp=%08x iopl=%d %31s\n"
2768 "cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
2769 "cr0=%08RX64 cr2=xxxxxxxx cr3=%08RX64 cr4=%08RX64 gdtr=%08x:%04x ldtr=%04x\n"
2770 "dr[0]=%08RX64 dr[1]=%08RX64x dr[2]=%08RX64 dr[3]=%08RX64x dr[6]=%08RX64 dr[7]=%08RX64\n"
2771 "SysEnter={cs=%04x eip=%08x esp=%08x}\n"
2772 ,
2773 /*pCtx->eax,*/ pCtx->ebx, /*pCtx->ecx, pCtx->edx,*/ pCtx->esi, pCtx->edi,
2774 /*pCtx->eip,*/ pCtx->esp, pCtx->ebp, X86_EFL_GET_IOPL(efl), szEFlags,
2775 (RTSEL)pCtx->cs, (RTSEL)pCtx->ds, (RTSEL)pCtx->es, (RTSEL)pCtx->fs, (RTSEL)pCtx->gs, efl,
2776 pCtx->cr0, /*pCtx->cr2,*/ pCtx->cr3, pCtx->cr4,
2777 pCtx->dr0, pCtx->dr1, pCtx->dr2, pCtx->dr3, pCtx->dr6, pCtx->dr7,
2778 (uint32_t)pCtx->gdtr.uAddr, pCtx->gdtr.cb, (RTSEL)pCtx->ldtr,
2779 pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
2780 }
2781# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
2782 else
2783# endif
2784#endif
2785#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
2786 {
2787 pHlp->pfnPrintf(pHlp,
2788 "rax=xxxxxxxxxxxxxxxx rbx=%016RX64 rcx=xxxxxxxxxxxxxxxx\n"
2789 "rdx=xxxxxxxxxxxxxxxx rsi=%016RX64 rdi=%016RX64\n"
2790 "rip=xxxxxxxxxxxxxxxx rsp=%016RX64 rbp=%016RX64\n"
2791 " r8=xxxxxxxxxxxxxxxx r9=xxxxxxxxxxxxxxxx r10=%016RX64\n"
2792 "r11=%016RX64 r12=%016RX64 r13=%016RX64\n"
2793 "r14=%016RX64 r15=%016RX64\n"
2794 "iopl=%d %31s\n"
2795 "cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08RX64\n"
2796 "cr0=%016RX64 cr2=xxxxxxxxxxxxxxxx cr3=%016RX64\n"
2797 "cr4=%016RX64 ldtr=%04x tr=%04x\n"
2798 "dr[0]=%016RX64 dr[1]=%016RX64 dr[2]=%016RX64\n"
2799 "dr[3]=%016RX64 dr[6]=%016RX64 dr[7]=%016RX64\n"
2800 "gdtr=%016RX64:%04x idtr=%016RX64:%04x\n"
2801 "SysEnter={cs=%04x eip=%08x esp=%08x}\n"
2802 "FSbase=%016RX64 GSbase=%016RX64 efer=%08RX64\n"
2803 ,
2804 /*pCtx->rax,*/ pCtx->rbx, /*pCtx->rcx,
2805 pCtx->rdx,*/ pCtx->rsi, pCtx->rdi,
2806 /*pCtx->rip,*/ pCtx->rsp, pCtx->rbp,
2807 /*pCtx->r8, pCtx->r9,*/ pCtx->r10,
2808 pCtx->r11, pCtx->r12, pCtx->r13,
2809 pCtx->r14, pCtx->r15,
2810 X86_EFL_GET_IOPL(efl), szEFlags,
2811 (RTSEL)pCtx->cs, (RTSEL)pCtx->ds, (RTSEL)pCtx->es, (RTSEL)pCtx->fs, (RTSEL)pCtx->gs, efl,
2812 pCtx->cr0, /*pCtx->cr2,*/ pCtx->cr3,
2813 pCtx->cr4, pCtx->ldtr, pCtx->tr,
2814 pCtx->dr0, pCtx->dr1, pCtx->dr2,
2815 pCtx->dr3, pCtx->dr6, pCtx->dr7,
2816 pCtx->gdtr.uAddr, pCtx->gdtr.cb, pCtx->idtr.uAddr, pCtx->idtr.cb,
2817 pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp,
2818 pCtx->FSbase, pCtx->GSbase, pCtx->efer);
2819 }
2820#endif
2821}
2822
2823
2824/**
2825 * Get L1 cache / TLS associativity.
2826 */
2827static const char *getCacheAss(unsigned u, char *pszBuf)
2828{
2829 if (u == 0)
2830 return "res0 ";
2831 if (u == 1)
2832 return "direct";
2833 if (u == 255)
2834 return "fully";
2835 if (u >= 256)
2836 return "???";
2837
2838 RTStrPrintf(pszBuf, 16, "%d way", u);
2839 return pszBuf;
2840}
2841
2842
2843/**
2844 * Get L2 cache associativity.
2845 */
2846const char *getL2CacheAss(unsigned u)
2847{
2848 switch (u)
2849 {
2850 case 0: return "off ";
2851 case 1: return "direct";
2852 case 2: return "2 way ";
2853 case 3: return "res3 ";
2854 case 4: return "4 way ";
2855 case 5: return "res5 ";
2856 case 6: return "8 way ";
2857 case 7: return "res7 ";
2858 case 8: return "16 way";
2859 case 9: return "res9 ";
2860 case 10: return "res10 ";
2861 case 11: return "res11 ";
2862 case 12: return "res12 ";
2863 case 13: return "res13 ";
2864 case 14: return "res14 ";
2865 case 15: return "fully ";
2866 default: return "????";
2867 }
2868}
2869
2870
2871/**
2872 * Display the guest CpuId leaves.
2873 *
2874 * @param pVM VM Handle.
2875 * @param pHlp The info helper functions.
2876 * @param pszArgs "terse", "default" or "verbose".
2877 */
2878static DECLCALLBACK(void) cpumR3CpuIdInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
2879{
2880 /*
2881 * Parse the argument.
2882 */
2883 unsigned iVerbosity = 1;
2884 if (pszArgs)
2885 {
2886 pszArgs = RTStrStripL(pszArgs);
2887 if (!strcmp(pszArgs, "terse"))
2888 iVerbosity--;
2889 else if (!strcmp(pszArgs, "verbose"))
2890 iVerbosity++;
2891 }
2892
2893 /*
2894 * Start cracking.
2895 */
2896 CPUMCPUID Host;
2897 CPUMCPUID Guest;
2898 unsigned cStdMax = pVM->cpum.s.aGuestCpuIdStd[0].eax;
2899
2900 pHlp->pfnPrintf(pHlp,
2901 " RAW Standard CPUIDs\n"
2902 " Function eax ebx ecx edx\n");
2903 for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd); i++)
2904 {
2905 Guest = pVM->cpum.s.aGuestCpuIdStd[i];
2906 ASMCpuId_Idx_ECX(i, 0, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
2907
2908 pHlp->pfnPrintf(pHlp,
2909 "Gst: %08x %08x %08x %08x %08x%s\n"
2910 "Hst: %08x %08x %08x %08x\n",
2911 i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
2912 i <= cStdMax ? "" : "*",
2913 Host.eax, Host.ebx, Host.ecx, Host.edx);
2914 }
2915
2916 /*
2917 * If verbose, decode it.
2918 */
2919 if (iVerbosity)
2920 {
2921 Guest = pVM->cpum.s.aGuestCpuIdStd[0];
2922 pHlp->pfnPrintf(pHlp,
2923 "Name: %.04s%.04s%.04s\n"
2924 "Supports: 0-%x\n",
2925 &Guest.ebx, &Guest.edx, &Guest.ecx, Guest.eax);
2926 }
2927
2928 /*
2929 * Get Features.
2930 */
2931 bool const fIntel = ASMIsIntelCpuEx(pVM->cpum.s.aGuestCpuIdStd[0].ebx,
2932 pVM->cpum.s.aGuestCpuIdStd[0].ecx,
2933 pVM->cpum.s.aGuestCpuIdStd[0].edx);
2934 if (cStdMax >= 1 && iVerbosity)
2935 {
2936 static const char * const s_apszTypes[4] = { "primary", "overdrive", "MP", "reserved" };
2937
2938 Guest = pVM->cpum.s.aGuestCpuIdStd[1];
2939 uint32_t uEAX = Guest.eax;
2940
2941 pHlp->pfnPrintf(pHlp,
2942 "Family: %d \tExtended: %d \tEffective: %d\n"
2943 "Model: %d \tExtended: %d \tEffective: %d\n"
2944 "Stepping: %d\n"
2945 "Type: %d (%s)\n"
2946 "APIC ID: %#04x\n"
2947 "Logical CPUs: %d\n"
2948 "CLFLUSH Size: %d\n"
2949 "Brand ID: %#04x\n",
2950 (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
2951 (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
2952 ASMGetCpuStepping(uEAX),
2953 (uEAX >> 12) & 3, s_apszTypes[(uEAX >> 12) & 3],
2954 (Guest.ebx >> 24) & 0xff,
2955 (Guest.ebx >> 16) & 0xff,
2956 (Guest.ebx >> 8) & 0xff,
2957 (Guest.ebx >> 0) & 0xff);
2958 if (iVerbosity == 1)
2959 {
2960 uint32_t uEDX = Guest.edx;
2961 pHlp->pfnPrintf(pHlp, "Features EDX: ");
2962 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " FPU");
2963 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " VME");
2964 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " DE");
2965 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " PSE");
2966 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TSC");
2967 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " MSR");
2968 if (uEDX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " PAE");
2969 if (uEDX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MCE");
2970 if (uEDX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " CX8");
2971 if (uEDX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " APIC");
2972 if (uEDX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " 10");
2973 if (uEDX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SEP");
2974 if (uEDX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " MTRR");
2975 if (uEDX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PGE");
2976 if (uEDX & RT_BIT(14)) pHlp->pfnPrintf(pHlp, " MCA");
2977 if (uEDX & RT_BIT(15)) pHlp->pfnPrintf(pHlp, " CMOV");
2978 if (uEDX & RT_BIT(16)) pHlp->pfnPrintf(pHlp, " PAT");
2979 if (uEDX & RT_BIT(17)) pHlp->pfnPrintf(pHlp, " PSE36");
2980 if (uEDX & RT_BIT(18)) pHlp->pfnPrintf(pHlp, " PSN");
2981 if (uEDX & RT_BIT(19)) pHlp->pfnPrintf(pHlp, " CLFSH");
2982 if (uEDX & RT_BIT(20)) pHlp->pfnPrintf(pHlp, " 20");
2983 if (uEDX & RT_BIT(21)) pHlp->pfnPrintf(pHlp, " DS");
2984 if (uEDX & RT_BIT(22)) pHlp->pfnPrintf(pHlp, " ACPI");
2985 if (uEDX & RT_BIT(23)) pHlp->pfnPrintf(pHlp, " MMX");
2986 if (uEDX & RT_BIT(24)) pHlp->pfnPrintf(pHlp, " FXSR");
2987 if (uEDX & RT_BIT(25)) pHlp->pfnPrintf(pHlp, " SSE");
2988 if (uEDX & RT_BIT(26)) pHlp->pfnPrintf(pHlp, " SSE2");
2989 if (uEDX & RT_BIT(27)) pHlp->pfnPrintf(pHlp, " SS");
2990 if (uEDX & RT_BIT(28)) pHlp->pfnPrintf(pHlp, " HTT");
2991 if (uEDX & RT_BIT(29)) pHlp->pfnPrintf(pHlp, " TM");
2992 if (uEDX & RT_BIT(30)) pHlp->pfnPrintf(pHlp, " 30");
2993 if (uEDX & RT_BIT(31)) pHlp->pfnPrintf(pHlp, " PBE");
2994 pHlp->pfnPrintf(pHlp, "\n");
2995
2996 uint32_t uECX = Guest.ecx;
2997 pHlp->pfnPrintf(pHlp, "Features ECX: ");
2998 if (uECX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " SSE3");
2999 if (uECX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " PCLMUL");
3000 if (uECX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " DTES64");
3001 if (uECX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " MONITOR");
3002 if (uECX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " DS-CPL");
3003 if (uECX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " VMX");
3004 if (uECX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " SMX");
3005 if (uECX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " EST");
3006 if (uECX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " TM2");
3007 if (uECX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " SSSE3");
3008 if (uECX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " CNXT-ID");
3009 if (uECX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " 11");
3010 if (uECX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " FMA");
3011 if (uECX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " CX16");
3012 if (uECX & RT_BIT(14)) pHlp->pfnPrintf(pHlp, " TPRUPDATE");
3013 if (uECX & RT_BIT(15)) pHlp->pfnPrintf(pHlp, " PDCM");
3014 if (uECX & RT_BIT(16)) pHlp->pfnPrintf(pHlp, " 16");
3015 if (uECX & RT_BIT(17)) pHlp->pfnPrintf(pHlp, " PCID");
3016 if (uECX & RT_BIT(18)) pHlp->pfnPrintf(pHlp, " DCA");
3017 if (uECX & RT_BIT(19)) pHlp->pfnPrintf(pHlp, " SSE4.1");
3018 if (uECX & RT_BIT(20)) pHlp->pfnPrintf(pHlp, " SSE4.2");
3019 if (uECX & RT_BIT(21)) pHlp->pfnPrintf(pHlp, " X2APIC");
3020 if (uECX & RT_BIT(22)) pHlp->pfnPrintf(pHlp, " MOVBE");
3021 if (uECX & RT_BIT(23)) pHlp->pfnPrintf(pHlp, " POPCNT");
3022 if (uECX & RT_BIT(24)) pHlp->pfnPrintf(pHlp, " TSCDEADL");
3023 if (uECX & RT_BIT(25)) pHlp->pfnPrintf(pHlp, " AES");
3024 if (uECX & RT_BIT(26)) pHlp->pfnPrintf(pHlp, " XSAVE");
3025 if (uECX & RT_BIT(27)) pHlp->pfnPrintf(pHlp, " OSXSAVE");
3026 if (uECX & RT_BIT(28)) pHlp->pfnPrintf(pHlp, " AVX");
3027 if (uECX & RT_BIT(29)) pHlp->pfnPrintf(pHlp, " 29");
3028 if (uECX & RT_BIT(30)) pHlp->pfnPrintf(pHlp, " 30");
3029 if (uECX & RT_BIT(31)) pHlp->pfnPrintf(pHlp, " 31");
3030 pHlp->pfnPrintf(pHlp, "\n");
3031 }
3032 else
3033 {
3034 ASMCpuId(1, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
3035
3036 X86CPUIDFEATEDX EdxHost = *(PX86CPUIDFEATEDX)&Host.edx;
3037 X86CPUIDFEATECX EcxHost = *(PX86CPUIDFEATECX)&Host.ecx;
3038 X86CPUIDFEATEDX EdxGuest = *(PX86CPUIDFEATEDX)&Guest.edx;
3039 X86CPUIDFEATECX EcxGuest = *(PX86CPUIDFEATECX)&Guest.ecx;
3040
3041 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
3042 pHlp->pfnPrintf(pHlp, "FPU - x87 FPU on Chip = %d (%d)\n", EdxGuest.u1FPU, EdxHost.u1FPU);
3043 pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", EdxGuest.u1VME, EdxHost.u1VME);
3044 pHlp->pfnPrintf(pHlp, "DE - Debugging extensions = %d (%d)\n", EdxGuest.u1DE, EdxHost.u1DE);
3045 pHlp->pfnPrintf(pHlp, "PSE - Page Size Extension = %d (%d)\n", EdxGuest.u1PSE, EdxHost.u1PSE);
3046 pHlp->pfnPrintf(pHlp, "TSC - Time Stamp Counter = %d (%d)\n", EdxGuest.u1TSC, EdxHost.u1TSC);
3047 pHlp->pfnPrintf(pHlp, "MSR - Model Specific Registers = %d (%d)\n", EdxGuest.u1MSR, EdxHost.u1MSR);
3048 pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", EdxGuest.u1PAE, EdxHost.u1PAE);
3049 pHlp->pfnPrintf(pHlp, "MCE - Machine Check Exception = %d (%d)\n", EdxGuest.u1MCE, EdxHost.u1MCE);
3050 pHlp->pfnPrintf(pHlp, "CX8 - CMPXCHG8B instruction = %d (%d)\n", EdxGuest.u1CX8, EdxHost.u1CX8);
3051 pHlp->pfnPrintf(pHlp, "APIC - APIC On-Chip = %d (%d)\n", EdxGuest.u1APIC, EdxHost.u1APIC);
3052 pHlp->pfnPrintf(pHlp, "10 - Reserved = %d (%d)\n", EdxGuest.u1Reserved1, EdxHost.u1Reserved1);
3053 pHlp->pfnPrintf(pHlp, "SEP - SYSENTER and SYSEXIT = %d (%d)\n", EdxGuest.u1SEP, EdxHost.u1SEP);
3054 pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", EdxGuest.u1MTRR, EdxHost.u1MTRR);
3055 pHlp->pfnPrintf(pHlp, "PGE - PTE Global Bit = %d (%d)\n", EdxGuest.u1PGE, EdxHost.u1PGE);
3056 pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", EdxGuest.u1MCA, EdxHost.u1MCA);
3057 pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", EdxGuest.u1CMOV, EdxHost.u1CMOV);
3058 pHlp->pfnPrintf(pHlp, "PAT - Page Attribute Table = %d (%d)\n", EdxGuest.u1PAT, EdxHost.u1PAT);
3059 pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", EdxGuest.u1PSE36, EdxHost.u1PSE36);
3060 pHlp->pfnPrintf(pHlp, "PSN - Processor Serial Number = %d (%d)\n", EdxGuest.u1PSN, EdxHost.u1PSN);
3061 pHlp->pfnPrintf(pHlp, "CLFSH - CLFLUSH Instruction. = %d (%d)\n", EdxGuest.u1CLFSH, EdxHost.u1CLFSH);
3062 pHlp->pfnPrintf(pHlp, "20 - Reserved = %d (%d)\n", EdxGuest.u1Reserved2, EdxHost.u1Reserved2);
3063 pHlp->pfnPrintf(pHlp, "DS - Debug Store = %d (%d)\n", EdxGuest.u1DS, EdxHost.u1DS);
3064 pHlp->pfnPrintf(pHlp, "ACPI - Thermal Mon. & Soft. Clock Ctrl.= %d (%d)\n", EdxGuest.u1ACPI, EdxHost.u1ACPI);
3065 pHlp->pfnPrintf(pHlp, "MMX - Intel MMX Technology = %d (%d)\n", EdxGuest.u1MMX, EdxHost.u1MMX);
3066 pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", EdxGuest.u1FXSR, EdxHost.u1FXSR);
3067 pHlp->pfnPrintf(pHlp, "SSE - SSE Support = %d (%d)\n", EdxGuest.u1SSE, EdxHost.u1SSE);
3068 pHlp->pfnPrintf(pHlp, "SSE2 - SSE2 Support = %d (%d)\n", EdxGuest.u1SSE2, EdxHost.u1SSE2);
3069 pHlp->pfnPrintf(pHlp, "SS - Self Snoop = %d (%d)\n", EdxGuest.u1SS, EdxHost.u1SS);
3070 pHlp->pfnPrintf(pHlp, "HTT - Hyper-Threading Technology = %d (%d)\n", EdxGuest.u1HTT, EdxHost.u1HTT);
3071 pHlp->pfnPrintf(pHlp, "TM - Thermal Monitor = %d (%d)\n", EdxGuest.u1TM, EdxHost.u1TM);
3072 pHlp->pfnPrintf(pHlp, "30 - Reserved = %d (%d)\n", EdxGuest.u1Reserved3, EdxHost.u1Reserved3);
3073 pHlp->pfnPrintf(pHlp, "PBE - Pending Break Enable = %d (%d)\n", EdxGuest.u1PBE, EdxHost.u1PBE);
3074
3075 pHlp->pfnPrintf(pHlp, "Supports SSE3 = %d (%d)\n", EcxGuest.u1SSE3, EcxHost.u1SSE3);
3076 pHlp->pfnPrintf(pHlp, "PCLMULQDQ = %d (%d)\n", EcxGuest.u1PCLMULQDQ, EcxHost.u1PCLMULQDQ);
3077 pHlp->pfnPrintf(pHlp, "DS Area 64-bit layout = %d (%d)\n", EcxGuest.u1DTE64, EcxHost.u1DTE64);
3078 pHlp->pfnPrintf(pHlp, "Supports MONITOR/MWAIT = %d (%d)\n", EcxGuest.u1Monitor, EcxHost.u1Monitor);
3079 pHlp->pfnPrintf(pHlp, "CPL-DS - CPL Qualified Debug Store = %d (%d)\n", EcxGuest.u1CPLDS, EcxHost.u1CPLDS);
3080 pHlp->pfnPrintf(pHlp, "VMX - Virtual Machine Technology = %d (%d)\n", EcxGuest.u1VMX, EcxHost.u1VMX);
3081 pHlp->pfnPrintf(pHlp, "SMX - Safer Mode Extensions = %d (%d)\n", EcxGuest.u1SMX, EcxHost.u1SMX);
3082 pHlp->pfnPrintf(pHlp, "Enhanced SpeedStep Technology = %d (%d)\n", EcxGuest.u1EST, EcxHost.u1EST);
3083 pHlp->pfnPrintf(pHlp, "Terminal Monitor 2 = %d (%d)\n", EcxGuest.u1TM2, EcxHost.u1TM2);
3084 pHlp->pfnPrintf(pHlp, "Supplemental SSE3 instructions = %d (%d)\n", EcxGuest.u1SSSE3, EcxHost.u1SSSE3);
3085 pHlp->pfnPrintf(pHlp, "L1 Context ID = %d (%d)\n", EcxGuest.u1CNTXID, EcxHost.u1CNTXID);
3086 pHlp->pfnPrintf(pHlp, "11 - Reserved = %d (%d)\n", EcxGuest.u1Reserved1, EcxHost.u1Reserved1);
3087 pHlp->pfnPrintf(pHlp, "FMA extensions using YMM state = %d (%d)\n", EcxGuest.u1FMA, EcxHost.u1FMA);
3088 pHlp->pfnPrintf(pHlp, "CMPXCHG16B instruction = %d (%d)\n", EcxGuest.u1CX16, EcxHost.u1CX16);
3089 pHlp->pfnPrintf(pHlp, "xTPR Update Control = %d (%d)\n", EcxGuest.u1TPRUpdate, EcxHost.u1TPRUpdate);
3090 pHlp->pfnPrintf(pHlp, "Perf/Debug Capability MSR = %d (%d)\n", EcxGuest.u1PDCM, EcxHost.u1PDCM);
3091 pHlp->pfnPrintf(pHlp, "16 - Reserved = %d (%d)\n", EcxGuest.u1Reserved2, EcxHost.u1Reserved2);
3092 pHlp->pfnPrintf(pHlp, "PCID - Process-context identifiers = %d (%d)\n", EcxGuest.u1PCID, EcxHost.u1PCID);
3093 pHlp->pfnPrintf(pHlp, "DCA - Direct Cache Access = %d (%d)\n", EcxGuest.u1DCA, EcxHost.u1DCA);
3094 pHlp->pfnPrintf(pHlp, "SSE4.1 instruction extensions = %d (%d)\n", EcxGuest.u1SSE4_1, EcxHost.u1SSE4_1);
3095 pHlp->pfnPrintf(pHlp, "SSE4.2 instruction extensions = %d (%d)\n", EcxGuest.u1SSE4_2, EcxHost.u1SSE4_2);
3096 pHlp->pfnPrintf(pHlp, "Supports the x2APIC extensions = %d (%d)\n", EcxGuest.u1x2APIC, EcxHost.u1x2APIC);
3097 pHlp->pfnPrintf(pHlp, "MOVBE instruction = %d (%d)\n", EcxGuest.u1MOVBE, EcxHost.u1MOVBE);
3098 pHlp->pfnPrintf(pHlp, "POPCNT instruction = %d (%d)\n", EcxGuest.u1POPCNT, EcxHost.u1POPCNT);
3099 pHlp->pfnPrintf(pHlp, "TSC-Deadline LAPIC timer mode = %d (%d)\n", EcxGuest.u1TSCDEADLINE,EcxHost.u1TSCDEADLINE);
3100 pHlp->pfnPrintf(pHlp, "AESNI instruction extensions = %d (%d)\n", EcxGuest.u1AES, EcxHost.u1AES);
3101 pHlp->pfnPrintf(pHlp, "XSAVE/XRSTOR extended state feature = %d (%d)\n", EcxGuest.u1XSAVE, EcxHost.u1XSAVE);
3102 pHlp->pfnPrintf(pHlp, "Supports OSXSAVE = %d (%d)\n", EcxGuest.u1OSXSAVE, EcxHost.u1OSXSAVE);
3103 pHlp->pfnPrintf(pHlp, "AVX instruction extensions = %d (%d)\n", EcxGuest.u1AVX, EcxHost.u1AVX);
3104 pHlp->pfnPrintf(pHlp, "29/30 - Reserved = %#x (%#x)\n",EcxGuest.u2Reserved3, EcxHost.u2Reserved3);
3105 pHlp->pfnPrintf(pHlp, "Hypervisor Present (we're a guest) = %d (%d)\n", EcxGuest.u1HVP, EcxHost.u1HVP);
3106 }
3107 }
3108 if (cStdMax >= 2 && iVerbosity)
3109 {
3110 /** @todo */
3111 }
3112
3113 /*
3114 * Extended.
3115 * Implemented after AMD specs.
3116 */
3117 unsigned cExtMax = pVM->cpum.s.aGuestCpuIdExt[0].eax & 0xffff;
3118
3119 pHlp->pfnPrintf(pHlp,
3120 "\n"
3121 " RAW Extended CPUIDs\n"
3122 " Function eax ebx ecx edx\n");
3123 for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt); i++)
3124 {
3125 Guest = pVM->cpum.s.aGuestCpuIdExt[i];
3126 ASMCpuId(0x80000000 | i, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
3127
3128 pHlp->pfnPrintf(pHlp,
3129 "Gst: %08x %08x %08x %08x %08x%s\n"
3130 "Hst: %08x %08x %08x %08x\n",
3131 0x80000000 | i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
3132 i <= cExtMax ? "" : "*",
3133 Host.eax, Host.ebx, Host.ecx, Host.edx);
3134 }
3135
3136 /*
3137 * Understandable output
3138 */
3139 if (iVerbosity)
3140 {
3141 Guest = pVM->cpum.s.aGuestCpuIdExt[0];
3142 pHlp->pfnPrintf(pHlp,
3143 "Ext Name: %.4s%.4s%.4s\n"
3144 "Ext Supports: 0x80000000-%#010x\n",
3145 &Guest.ebx, &Guest.edx, &Guest.ecx, Guest.eax);
3146 }
3147
3148 if (iVerbosity && cExtMax >= 1)
3149 {
3150 Guest = pVM->cpum.s.aGuestCpuIdExt[1];
3151 uint32_t uEAX = Guest.eax;
3152 pHlp->pfnPrintf(pHlp,
3153 "Family: %d \tExtended: %d \tEffective: %d\n"
3154 "Model: %d \tExtended: %d \tEffective: %d\n"
3155 "Stepping: %d\n"
3156 "Brand ID: %#05x\n",
3157 (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
3158 (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
3159 ASMGetCpuStepping(uEAX),
3160 Guest.ebx & 0xfff);
3161
3162 if (iVerbosity == 1)
3163 {
3164 uint32_t uEDX = Guest.edx;
3165 pHlp->pfnPrintf(pHlp, "Features EDX: ");
3166 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " FPU");
3167 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " VME");
3168 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " DE");
3169 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " PSE");
3170 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TSC");
3171 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " MSR");
3172 if (uEDX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " PAE");
3173 if (uEDX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MCE");
3174 if (uEDX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " CX8");
3175 if (uEDX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " APIC");
3176 if (uEDX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " 10");
3177 if (uEDX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SCR");
3178 if (uEDX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " MTRR");
3179 if (uEDX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PGE");
3180 if (uEDX & RT_BIT(14)) pHlp->pfnPrintf(pHlp, " MCA");
3181 if (uEDX & RT_BIT(15)) pHlp->pfnPrintf(pHlp, " CMOV");
3182 if (uEDX & RT_BIT(16)) pHlp->pfnPrintf(pHlp, " PAT");
3183 if (uEDX & RT_BIT(17)) pHlp->pfnPrintf(pHlp, " PSE36");
3184 if (uEDX & RT_BIT(18)) pHlp->pfnPrintf(pHlp, " 18");
3185 if (uEDX & RT_BIT(19)) pHlp->pfnPrintf(pHlp, " 19");
3186 if (uEDX & RT_BIT(20)) pHlp->pfnPrintf(pHlp, " NX");
3187 if (uEDX & RT_BIT(21)) pHlp->pfnPrintf(pHlp, " 21");
3188 if (uEDX & RT_BIT(22)) pHlp->pfnPrintf(pHlp, " ExtMMX");
3189 if (uEDX & RT_BIT(23)) pHlp->pfnPrintf(pHlp, " MMX");
3190 if (uEDX & RT_BIT(24)) pHlp->pfnPrintf(pHlp, " FXSR");
3191 if (uEDX & RT_BIT(25)) pHlp->pfnPrintf(pHlp, " FastFXSR");
3192 if (uEDX & RT_BIT(26)) pHlp->pfnPrintf(pHlp, " Page1GB");
3193 if (uEDX & RT_BIT(27)) pHlp->pfnPrintf(pHlp, " RDTSCP");
3194 if (uEDX & RT_BIT(28)) pHlp->pfnPrintf(pHlp, " 28");
3195 if (uEDX & RT_BIT(29)) pHlp->pfnPrintf(pHlp, " LongMode");
3196 if (uEDX & RT_BIT(30)) pHlp->pfnPrintf(pHlp, " Ext3DNow");
3197 if (uEDX & RT_BIT(31)) pHlp->pfnPrintf(pHlp, " 3DNow");
3198 pHlp->pfnPrintf(pHlp, "\n");
3199
3200 uint32_t uECX = Guest.ecx;
3201 pHlp->pfnPrintf(pHlp, "Features ECX: ");
3202 if (uECX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " LAHF/SAHF");
3203 if (uECX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " CMPL");
3204 if (uECX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " SVM");
3205 if (uECX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " ExtAPIC");
3206 if (uECX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " CR8L");
3207 if (uECX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " ABM");
3208 if (uECX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " SSE4A");
3209 if (uECX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MISALNSSE");
3210 if (uECX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " 3DNOWPRF");
3211 if (uECX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " OSVW");
3212 if (uECX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " IBS");
3213 if (uECX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SSE5");
3214 if (uECX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " SKINIT");
3215 if (uECX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " WDT");
3216 for (unsigned iBit = 5; iBit < 32; iBit++)
3217 if (uECX & RT_BIT(iBit))
3218 pHlp->pfnPrintf(pHlp, " %d", iBit);
3219 pHlp->pfnPrintf(pHlp, "\n");
3220 }
3221 else
3222 {
3223 ASMCpuId(0x80000001, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
3224
3225 uint32_t uEdxGst = Guest.edx;
3226 uint32_t uEdxHst = Host.edx;
3227 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
3228 pHlp->pfnPrintf(pHlp, "FPU - x87 FPU on Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
3229 pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
3230 pHlp->pfnPrintf(pHlp, "DE - Debugging extensions = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
3231 pHlp->pfnPrintf(pHlp, "PSE - Page Size Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
3232 pHlp->pfnPrintf(pHlp, "TSC - Time Stamp Counter = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
3233 pHlp->pfnPrintf(pHlp, "MSR - K86 Model Specific Registers = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
3234 pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
3235 pHlp->pfnPrintf(pHlp, "MCE - Machine Check Exception = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
3236 pHlp->pfnPrintf(pHlp, "CX8 - CMPXCHG8B instruction = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
3237 pHlp->pfnPrintf(pHlp, "APIC - APIC On-Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
3238 pHlp->pfnPrintf(pHlp, "10 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
3239 pHlp->pfnPrintf(pHlp, "SEP - SYSCALL and SYSRET = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
3240 pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
3241 pHlp->pfnPrintf(pHlp, "PGE - PTE Global Bit = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
3242 pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", !!(uEdxGst & RT_BIT(14)), !!(uEdxHst & RT_BIT(14)));
3243 pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(15)), !!(uEdxHst & RT_BIT(15)));
3244 pHlp->pfnPrintf(pHlp, "PAT - Page Attribute Table = %d (%d)\n", !!(uEdxGst & RT_BIT(16)), !!(uEdxHst & RT_BIT(16)));
3245 pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", !!(uEdxGst & RT_BIT(17)), !!(uEdxHst & RT_BIT(17)));
3246 pHlp->pfnPrintf(pHlp, "18 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(18)), !!(uEdxHst & RT_BIT(18)));
3247 pHlp->pfnPrintf(pHlp, "19 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(19)), !!(uEdxHst & RT_BIT(19)));
3248 pHlp->pfnPrintf(pHlp, "NX - No-Execute Page Protection = %d (%d)\n", !!(uEdxGst & RT_BIT(20)), !!(uEdxHst & RT_BIT(20)));
3249 pHlp->pfnPrintf(pHlp, "DS - Debug Store = %d (%d)\n", !!(uEdxGst & RT_BIT(21)), !!(uEdxHst & RT_BIT(21)));
3250 pHlp->pfnPrintf(pHlp, "AXMMX - AMD Extensions to MMX Instr. = %d (%d)\n", !!(uEdxGst & RT_BIT(22)), !!(uEdxHst & RT_BIT(22)));
3251 pHlp->pfnPrintf(pHlp, "MMX - Intel MMX Technology = %d (%d)\n", !!(uEdxGst & RT_BIT(23)), !!(uEdxHst & RT_BIT(23)));
3252 pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(24)), !!(uEdxHst & RT_BIT(24)));
3253 pHlp->pfnPrintf(pHlp, "25 - AMD fast FXSAVE and FXRSTOR Instr.= %d (%d)\n", !!(uEdxGst & RT_BIT(25)), !!(uEdxHst & RT_BIT(25)));
3254 pHlp->pfnPrintf(pHlp, "26 - 1 GB large page support = %d (%d)\n", !!(uEdxGst & RT_BIT(26)), !!(uEdxHst & RT_BIT(26)));
3255 pHlp->pfnPrintf(pHlp, "27 - RDTSCP instruction = %d (%d)\n", !!(uEdxGst & RT_BIT(27)), !!(uEdxHst & RT_BIT(27)));
3256 pHlp->pfnPrintf(pHlp, "28 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(28)), !!(uEdxHst & RT_BIT(28)));
3257 pHlp->pfnPrintf(pHlp, "29 - AMD Long Mode = %d (%d)\n", !!(uEdxGst & RT_BIT(29)), !!(uEdxHst & RT_BIT(29)));
3258 pHlp->pfnPrintf(pHlp, "30 - AMD Extensions to 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(30)), !!(uEdxHst & RT_BIT(30)));
3259 pHlp->pfnPrintf(pHlp, "31 - AMD 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(31)), !!(uEdxHst & RT_BIT(31)));
3260
3261 uint32_t uEcxGst = Guest.ecx;
3262 uint32_t uEcxHst = Host.ecx;
3263 pHlp->pfnPrintf(pHlp, "LahfSahf - LAHF/SAHF in 64-bit mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 0)), !!(uEcxHst & RT_BIT( 0)));
3264 pHlp->pfnPrintf(pHlp, "CmpLegacy - Core MP legacy mode (depr) = %d (%d)\n", !!(uEcxGst & RT_BIT( 1)), !!(uEcxHst & RT_BIT( 1)));
3265 pHlp->pfnPrintf(pHlp, "SVM - AMD VM Extensions = %d (%d)\n", !!(uEcxGst & RT_BIT( 2)), !!(uEcxHst & RT_BIT( 2)));
3266 pHlp->pfnPrintf(pHlp, "APIC registers starting at 0x400 = %d (%d)\n", !!(uEcxGst & RT_BIT( 3)), !!(uEcxHst & RT_BIT( 3)));
3267 pHlp->pfnPrintf(pHlp, "AltMovCR8 - LOCK MOV CR0 means MOV CR8 = %d (%d)\n", !!(uEcxGst & RT_BIT( 4)), !!(uEcxHst & RT_BIT( 4)));
3268 pHlp->pfnPrintf(pHlp, "Advanced bit manipulation = %d (%d)\n", !!(uEcxGst & RT_BIT( 5)), !!(uEcxHst & RT_BIT( 5)));
3269 pHlp->pfnPrintf(pHlp, "SSE4A instruction support = %d (%d)\n", !!(uEcxGst & RT_BIT( 6)), !!(uEcxHst & RT_BIT( 6)));
3270 pHlp->pfnPrintf(pHlp, "Misaligned SSE mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 7)), !!(uEcxHst & RT_BIT( 7)));
3271 pHlp->pfnPrintf(pHlp, "PREFETCH and PREFETCHW instruction = %d (%d)\n", !!(uEcxGst & RT_BIT( 8)), !!(uEcxHst & RT_BIT( 8)));
3272 pHlp->pfnPrintf(pHlp, "OS visible workaround = %d (%d)\n", !!(uEcxGst & RT_BIT( 9)), !!(uEcxHst & RT_BIT( 9)));
3273 pHlp->pfnPrintf(pHlp, "Instruction based sampling = %d (%d)\n", !!(uEcxGst & RT_BIT(10)), !!(uEcxHst & RT_BIT(10)));
3274 pHlp->pfnPrintf(pHlp, "SSE5 support = %d (%d)\n", !!(uEcxGst & RT_BIT(11)), !!(uEcxHst & RT_BIT(11)));
3275 pHlp->pfnPrintf(pHlp, "SKINIT, STGI, and DEV support = %d (%d)\n", !!(uEcxGst & RT_BIT(12)), !!(uEcxHst & RT_BIT(12)));
3276 pHlp->pfnPrintf(pHlp, "Watchdog timer support. = %d (%d)\n", !!(uEcxGst & RT_BIT(13)), !!(uEcxHst & RT_BIT(13)));
3277 pHlp->pfnPrintf(pHlp, "31:14 - Reserved = %#x (%#x)\n", uEcxGst >> 14, uEcxHst >> 14);
3278 }
3279 }
3280
3281 if (iVerbosity && cExtMax >= 2)
3282 {
3283 char szString[4*4*3+1] = {0};
3284 uint32_t *pu32 = (uint32_t *)szString;
3285 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].eax;
3286 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].ebx;
3287 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].ecx;
3288 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].edx;
3289 if (cExtMax >= 3)
3290 {
3291 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].eax;
3292 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].ebx;
3293 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].ecx;
3294 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].edx;
3295 }
3296 if (cExtMax >= 4)
3297 {
3298 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].eax;
3299 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].ebx;
3300 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].ecx;
3301 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].edx;
3302 }
3303 pHlp->pfnPrintf(pHlp, "Full Name: %s\n", szString);
3304 }
3305
3306 if (iVerbosity && cExtMax >= 5)
3307 {
3308 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[5].eax;
3309 uint32_t uEBX = pVM->cpum.s.aGuestCpuIdExt[5].ebx;
3310 uint32_t uECX = pVM->cpum.s.aGuestCpuIdExt[5].ecx;
3311 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[5].edx;
3312 char sz1[32];
3313 char sz2[32];
3314
3315 pHlp->pfnPrintf(pHlp,
3316 "TLB 2/4M Instr/Uni: %s %3d entries\n"
3317 "TLB 2/4M Data: %s %3d entries\n",
3318 getCacheAss((uEAX >> 8) & 0xff, sz1), (uEAX >> 0) & 0xff,
3319 getCacheAss((uEAX >> 24) & 0xff, sz2), (uEAX >> 16) & 0xff);
3320 pHlp->pfnPrintf(pHlp,
3321 "TLB 4K Instr/Uni: %s %3d entries\n"
3322 "TLB 4K Data: %s %3d entries\n",
3323 getCacheAss((uEBX >> 8) & 0xff, sz1), (uEBX >> 0) & 0xff,
3324 getCacheAss((uEBX >> 24) & 0xff, sz2), (uEBX >> 16) & 0xff);
3325 pHlp->pfnPrintf(pHlp, "L1 Instr Cache Line Size: %d bytes\n"
3326 "L1 Instr Cache Lines Per Tag: %d\n"
3327 "L1 Instr Cache Associativity: %s\n"
3328 "L1 Instr Cache Size: %d KB\n",
3329 (uEDX >> 0) & 0xff,
3330 (uEDX >> 8) & 0xff,
3331 getCacheAss((uEDX >> 16) & 0xff, sz1),
3332 (uEDX >> 24) & 0xff);
3333 pHlp->pfnPrintf(pHlp,
3334 "L1 Data Cache Line Size: %d bytes\n"
3335 "L1 Data Cache Lines Per Tag: %d\n"
3336 "L1 Data Cache Associativity: %s\n"
3337 "L1 Data Cache Size: %d KB\n",
3338 (uECX >> 0) & 0xff,
3339 (uECX >> 8) & 0xff,
3340 getCacheAss((uECX >> 16) & 0xff, sz1),
3341 (uECX >> 24) & 0xff);
3342 }
3343
3344 if (iVerbosity && cExtMax >= 6)
3345 {
3346 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[6].eax;
3347 uint32_t uEBX = pVM->cpum.s.aGuestCpuIdExt[6].ebx;
3348 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[6].edx;
3349
3350 pHlp->pfnPrintf(pHlp,
3351 "L2 TLB 2/4M Instr/Uni: %s %4d entries\n"
3352 "L2 TLB 2/4M Data: %s %4d entries\n",
3353 getL2CacheAss((uEAX >> 12) & 0xf), (uEAX >> 0) & 0xfff,
3354 getL2CacheAss((uEAX >> 28) & 0xf), (uEAX >> 16) & 0xfff);
3355 pHlp->pfnPrintf(pHlp,
3356 "L2 TLB 4K Instr/Uni: %s %4d entries\n"
3357 "L2 TLB 4K Data: %s %4d entries\n",
3358 getL2CacheAss((uEBX >> 12) & 0xf), (uEBX >> 0) & 0xfff,
3359 getL2CacheAss((uEBX >> 28) & 0xf), (uEBX >> 16) & 0xfff);
3360 pHlp->pfnPrintf(pHlp,
3361 "L2 Cache Line Size: %d bytes\n"
3362 "L2 Cache Lines Per Tag: %d\n"
3363 "L2 Cache Associativity: %s\n"
3364 "L2 Cache Size: %d KB\n",
3365 (uEDX >> 0) & 0xff,
3366 (uEDX >> 8) & 0xf,
3367 getL2CacheAss((uEDX >> 12) & 0xf),
3368 (uEDX >> 16) & 0xffff);
3369 }
3370
3371 if (iVerbosity && cExtMax >= 7)
3372 {
3373 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[7].edx;
3374
3375 pHlp->pfnPrintf(pHlp, "APM Features: ");
3376 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " TS");
3377 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " FID");
3378 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " VID");
3379 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " TTP");
3380 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TM");
3381 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " STC");
3382 for (unsigned iBit = 6; iBit < 32; iBit++)
3383 if (uEDX & RT_BIT(iBit))
3384 pHlp->pfnPrintf(pHlp, " %d", iBit);
3385 pHlp->pfnPrintf(pHlp, "\n");
3386 }
3387
3388 if (iVerbosity && cExtMax >= 8)
3389 {
3390 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[8].eax;
3391 uint32_t uECX = pVM->cpum.s.aGuestCpuIdExt[8].ecx;
3392
3393 pHlp->pfnPrintf(pHlp,
3394 "Physical Address Width: %d bits\n"
3395 "Virtual Address Width: %d bits\n"
3396 "Guest Physical Address Width: %d bits\n",
3397 (uEAX >> 0) & 0xff,
3398 (uEAX >> 8) & 0xff,
3399 (uEAX >> 16) & 0xff);
3400 pHlp->pfnPrintf(pHlp,
3401 "Physical Core Count: %d\n",
3402 (uECX >> 0) & 0xff);
3403 }
3404
3405
3406 /*
3407 * Centaur.
3408 */
3409 unsigned cCentaurMax = pVM->cpum.s.aGuestCpuIdCentaur[0].eax & 0xffff;
3410
3411 pHlp->pfnPrintf(pHlp,
3412 "\n"
3413 " RAW Centaur CPUIDs\n"
3414 " Function eax ebx ecx edx\n");
3415 for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur); i++)
3416 {
3417 Guest = pVM->cpum.s.aGuestCpuIdCentaur[i];
3418 ASMCpuId(0xc0000000 | i, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
3419
3420 pHlp->pfnPrintf(pHlp,
3421 "Gst: %08x %08x %08x %08x %08x%s\n"
3422 "Hst: %08x %08x %08x %08x\n",
3423 0xc0000000 | i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
3424 i <= cCentaurMax ? "" : "*",
3425 Host.eax, Host.ebx, Host.ecx, Host.edx);
3426 }
3427
3428 /*
3429 * Understandable output
3430 */
3431 if (iVerbosity)
3432 {
3433 Guest = pVM->cpum.s.aGuestCpuIdCentaur[0];
3434 pHlp->pfnPrintf(pHlp,
3435 "Centaur Supports: 0xc0000000-%#010x\n",
3436 Guest.eax);
3437 }
3438
3439 if (iVerbosity && cCentaurMax >= 1)
3440 {
3441 ASMCpuId(0xc0000001, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
3442 uint32_t uEdxGst = pVM->cpum.s.aGuestCpuIdExt[1].edx;
3443 uint32_t uEdxHst = Host.edx;
3444
3445 if (iVerbosity == 1)
3446 {
3447 pHlp->pfnPrintf(pHlp, "Centaur Features EDX: ");
3448 if (uEdxGst & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " AIS");
3449 if (uEdxGst & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " AIS-E");
3450 if (uEdxGst & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " RNG");
3451 if (uEdxGst & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " RNG-E");
3452 if (uEdxGst & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " LH");
3453 if (uEdxGst & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " FEMMS");
3454 if (uEdxGst & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " ACE");
3455 if (uEdxGst & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " ACE-E");
3456 /* possibly indicating MM/HE and MM/HE-E on older chips... */
3457 if (uEdxGst & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " ACE2");
3458 if (uEdxGst & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " ACE2-E");
3459 if (uEdxGst & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " PHE");
3460 if (uEdxGst & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " PHE-E");
3461 if (uEdxGst & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " PMM");
3462 if (uEdxGst & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PMM-E");
3463 for (unsigned iBit = 14; iBit < 32; iBit++)
3464 if (uEdxGst & RT_BIT(iBit))
3465 pHlp->pfnPrintf(pHlp, " %d", iBit);
3466 pHlp->pfnPrintf(pHlp, "\n");
3467 }
3468 else
3469 {
3470 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
3471 pHlp->pfnPrintf(pHlp, "AIS - Alternate Instruction Set = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
3472 pHlp->pfnPrintf(pHlp, "AIS-E - AIS enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
3473 pHlp->pfnPrintf(pHlp, "RNG - Random Number Generator = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
3474 pHlp->pfnPrintf(pHlp, "RNG-E - RNG enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
3475 pHlp->pfnPrintf(pHlp, "LH - LongHaul MSR 0000_110Ah = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
3476 pHlp->pfnPrintf(pHlp, "FEMMS - FEMMS = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
3477 pHlp->pfnPrintf(pHlp, "ACE - Advanced Cryptography Engine = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
3478 pHlp->pfnPrintf(pHlp, "ACE-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
3479 /* possibly indicating MM/HE and MM/HE-E on older chips... */
3480 pHlp->pfnPrintf(pHlp, "ACE2 - Advanced Cryptography Engine 2 = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
3481 pHlp->pfnPrintf(pHlp, "ACE2-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
3482 pHlp->pfnPrintf(pHlp, "PHE - Hash Engine = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
3483 pHlp->pfnPrintf(pHlp, "PHE-E - PHE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
3484 pHlp->pfnPrintf(pHlp, "PMM - Montgomery Multiplier = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
3485 pHlp->pfnPrintf(pHlp, "PMM-E - PMM enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
3486 for (unsigned iBit = 14; iBit < 32; iBit++)
3487 if ((uEdxGst | uEdxHst) & RT_BIT(iBit))
3488 pHlp->pfnPrintf(pHlp, "Bit %d = %d (%d)\n", !!(uEdxGst & RT_BIT(iBit)), !!(uEdxHst & RT_BIT(iBit)));
3489 pHlp->pfnPrintf(pHlp, "\n");
3490 }
3491 }
3492}
3493
3494
3495/**
3496 * Structure used when disassembling and instructions in DBGF.
3497 * This is used so the reader function can get the stuff it needs.
3498 */
3499typedef struct CPUMDISASSTATE
3500{
3501 /** Pointer to the CPU structure. */
3502 PDISCPUSTATE pCpu;
3503 /** Pointer to the VM. */
3504 PVM pVM;
3505 /** The VMCPU handle. */
3506 PVMCPU pVCpu;
3507 /** Pointer to the first byte in the segment. */
3508 RTGCUINTPTR GCPtrSegBase;
3509 /** Pointer to the byte after the end of the segment. (might have wrapped!) */
3510 RTGCUINTPTR GCPtrSegEnd;
3511 /** The size of the segment minus 1. */
3512 RTGCUINTPTR cbSegLimit;
3513 /** Pointer to the current page - R3 Ptr. */
3514 void const *pvPageR3;
3515 /** Pointer to the current page - GC Ptr. */
3516 RTGCPTR pvPageGC;
3517 /** The lock information that PGMPhysReleasePageMappingLock needs. */
3518 PGMPAGEMAPLOCK PageMapLock;
3519 /** Whether the PageMapLock is valid or not. */
3520 bool fLocked;
3521 /** 64 bits mode or not. */
3522 bool f64Bits;
3523} CPUMDISASSTATE, *PCPUMDISASSTATE;
3524
3525
3526/**
3527 * @callback_method_impl{FNDISREADBYTES}
3528 */
3529static DECLCALLBACK(int) cpumR3DisasInstrRead(PDISCPUSTATE pDis, uint8_t offInstr, uint8_t cbMinRead, uint8_t cbMaxRead)
3530{
3531 PCPUMDISASSTATE pState = (PCPUMDISASSTATE)pDis->pvUser;
3532 for (;;)
3533 {
3534 RTGCUINTPTR GCPtr = pDis->uInstrAddr + offInstr + pState->GCPtrSegBase;
3535
3536 /*
3537 * Need to update the page translation?
3538 */
3539 if ( !pState->pvPageR3
3540 || (GCPtr >> PAGE_SHIFT) != (pState->pvPageGC >> PAGE_SHIFT))
3541 {
3542 int rc = VINF_SUCCESS;
3543
3544 /* translate the address */
3545 pState->pvPageGC = GCPtr & PAGE_BASE_GC_MASK;
3546 if ( MMHyperIsInsideArea(pState->pVM, pState->pvPageGC)
3547 && !HWACCMIsEnabled(pState->pVM))
3548 {
3549 pState->pvPageR3 = MMHyperRCToR3(pState->pVM, (RTRCPTR)pState->pvPageGC);
3550 if (!pState->pvPageR3)
3551 rc = VERR_INVALID_POINTER;
3552 }
3553 else
3554 {
3555 /* Release mapping lock previously acquired. */
3556 if (pState->fLocked)
3557 PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
3558 rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVCpu, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
3559 pState->fLocked = RT_SUCCESS_NP(rc);
3560 }
3561 if (RT_FAILURE(rc))
3562 {
3563 pState->pvPageR3 = NULL;
3564 return rc;
3565 }
3566 }
3567
3568 /*
3569 * Check the segment limit.
3570 */
3571 if (!pState->f64Bits && pDis->uInstrAddr + offInstr > pState->cbSegLimit)
3572 return VERR_OUT_OF_SELECTOR_BOUNDS;
3573
3574 /*
3575 * Calc how much we can read.
3576 */
3577 uint32_t cb = PAGE_SIZE - (GCPtr & PAGE_OFFSET_MASK);
3578 if (!pState->f64Bits)
3579 {
3580 RTGCUINTPTR cbSeg = pState->GCPtrSegEnd - GCPtr;
3581 if (cb > cbSeg && cbSeg)
3582 cb = cbSeg;
3583 }
3584 if (cb > cbMaxRead)
3585 cb = cbMaxRead;
3586
3587 /*
3588 * Read and advance or exit.
3589 */
3590 memcpy(&pDis->abInstr[offInstr], (uint8_t *)pState->pvPageR3 + (GCPtr & PAGE_OFFSET_MASK), cb);
3591 offInstr += (uint8_t)cb;
3592 if (cb >= cbMinRead)
3593 {
3594 pDis->cbCachedInstr = offInstr;
3595 return VINF_SUCCESS;
3596 }
3597 cbMinRead -= (uint8_t)cb;
3598 cbMaxRead -= (uint8_t)cb;
3599 }
3600}
3601
3602
3603/**
3604 * Disassemble an instruction and return the information in the provided structure.
3605 *
3606 * @returns VBox status code.
3607 * @param pVM VM Handle
3608 * @param pVCpu VMCPU Handle
3609 * @param pCtx CPU context
3610 * @param GCPtrPC Program counter (relative to CS) to disassemble from.
3611 * @param pCpu Disassembly state
3612 * @param pszPrefix String prefix for logging (debug only)
3613 *
3614 */
3615VMMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu, const char *pszPrefix)
3616{
3617 CPUMDISASSTATE State;
3618 int rc;
3619
3620 const PGMMODE enmMode = PGMGetGuestMode(pVCpu);
3621 State.pCpu = pCpu;
3622 State.pvPageGC = 0;
3623 State.pvPageR3 = NULL;
3624 State.pVM = pVM;
3625 State.pVCpu = pVCpu;
3626 State.fLocked = false;
3627 State.f64Bits = false;
3628
3629 /*
3630 * Get selector information.
3631 */
3632 DISCPUMODE enmDisCpuMode;
3633 if ( (pCtx->cr0 & X86_CR0_PE)
3634 && pCtx->eflags.Bits.u1VM == 0)
3635 {
3636 if (CPUMAreHiddenSelRegsValid(pVCpu))
3637 {
3638 State.f64Bits = enmMode >= PGMMODE_AMD64 && pCtx->csHid.Attr.n.u1Long;
3639 State.GCPtrSegBase = pCtx->csHid.u64Base;
3640 State.GCPtrSegEnd = pCtx->csHid.u32Limit + 1 + (RTGCUINTPTR)pCtx->csHid.u64Base;
3641 State.cbSegLimit = pCtx->csHid.u32Limit;
3642 enmDisCpuMode = (State.f64Bits)
3643 ? DISCPUMODE_64BIT
3644 : pCtx->csHid.Attr.n.u1DefBig
3645 ? DISCPUMODE_32BIT
3646 : DISCPUMODE_16BIT;
3647 }
3648 else
3649 {
3650 DBGFSELINFO SelInfo;
3651
3652 rc = SELMR3GetShadowSelectorInfo(pVM, pCtx->cs, &SelInfo);
3653 if (RT_FAILURE(rc))
3654 {
3655 AssertMsgFailed(("SELMR3GetShadowSelectorInfo failed for %04X:%RGv rc=%d\n", pCtx->cs, GCPtrPC, rc));
3656 return rc;
3657 }
3658
3659 /*
3660 * Validate the selector.
3661 */
3662 rc = DBGFR3SelInfoValidateCS(&SelInfo, pCtx->ss);
3663 if (RT_FAILURE(rc))
3664 {
3665 AssertMsgFailed(("SELMSelInfoValidateCS failed for %04X:%RGv rc=%d\n", pCtx->cs, GCPtrPC, rc));
3666 return rc;
3667 }
3668 State.GCPtrSegBase = SelInfo.GCPtrBase;
3669 State.GCPtrSegEnd = SelInfo.cbLimit + 1 + (RTGCUINTPTR)SelInfo.GCPtrBase;
3670 State.cbSegLimit = SelInfo.cbLimit;
3671 enmDisCpuMode = SelInfo.u.Raw.Gen.u1DefBig ? DISCPUMODE_32BIT : DISCPUMODE_16BIT;
3672 }
3673 }
3674 else
3675 {
3676 /* real or V86 mode */
3677 enmDisCpuMode = DISCPUMODE_16BIT;
3678 State.GCPtrSegBase = pCtx->cs * 16;
3679 State.GCPtrSegEnd = 0xFFFFFFFF;
3680 State.cbSegLimit = 0xFFFFFFFF;
3681 }
3682
3683 /*
3684 * Disassemble the instruction.
3685 */
3686 uint32_t cbInstr;
3687#ifndef LOG_ENABLED
3688 rc = DISInstrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr);
3689 if (RT_SUCCESS(rc))
3690 {
3691#else
3692 char szOutput[160];
3693 rc = DISInstrToStrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State,
3694 pCpu, &cbInstr, szOutput, sizeof(szOutput));
3695 if (RT_SUCCESS(rc))
3696 {
3697 /* log it */
3698 if (pszPrefix)
3699 Log(("%s-CPU%d: %s", pszPrefix, pVCpu->idCpu, szOutput));
3700 else
3701 Log(("%s", szOutput));
3702#endif
3703 rc = VINF_SUCCESS;
3704 }
3705 else
3706 Log(("CPUMR3DisasmInstrCPU: DISInstr failed for %04X:%RGv rc=%Rrc\n", pCtx->cs, GCPtrPC, rc));
3707
3708 /* Release mapping lock acquired in cpumR3DisasInstrRead. */
3709 if (State.fLocked)
3710 PGMPhysReleasePageMappingLock(pVM, &State.PageMapLock);
3711
3712 return rc;
3713}
3714
3715#ifdef DEBUG
3716
3717/**
3718 * Debug helper - Saves guest context on raw mode entry (for fatal dump)
3719 *
3720 * @internal
3721 */
3722VMMR3DECL(void) CPUMR3SaveEntryCtx(PVM pVM)
3723{
3724 /** @todo SMP support!! */
3725 pVM->cpum.s.GuestEntry = *CPUMQueryGuestCtxPtr(VMMGetCpu(pVM));
3726}
3727
3728#endif /* DEBUG */
3729
3730/**
3731 * API for controlling a few of the CPU features found in CR4.
3732 *
3733 * Currently only X86_CR4_TSD is accepted as input.
3734 *
3735 * @returns VBox status code.
3736 *
3737 * @param pVM Pointer to the VM.
3738 * @param fOr The CR4 OR mask.
3739 * @param fAnd The CR4 AND mask.
3740 */
3741VMMR3DECL(int) CPUMR3SetCR4Feature(PVM pVM, RTHCUINTREG fOr, RTHCUINTREG fAnd)
3742{
3743 AssertMsgReturn(!(fOr & ~(X86_CR4_TSD)), ("%#x\n", fOr), VERR_INVALID_PARAMETER);
3744 AssertMsgReturn((fAnd & ~(X86_CR4_TSD)) == ~(X86_CR4_TSD), ("%#x\n", fAnd), VERR_INVALID_PARAMETER);
3745
3746 pVM->cpum.s.CR4.OrMask &= fAnd;
3747 pVM->cpum.s.CR4.OrMask |= fOr;
3748
3749 return VINF_SUCCESS;
3750}
3751
3752
3753/**
3754 * Gets a pointer to the array of standard CPUID leaves.
3755 *
3756 * CPUMR3GetGuestCpuIdStdMax() give the size of the array.
3757 *
3758 * @returns Pointer to the standard CPUID leaves (read-only).
3759 * @param pVM Pointer to the VM.
3760 * @remark Intended for PATM.
3761 */
3762VMMR3DECL(RCPTRTYPE(PCCPUMCPUID)) CPUMR3GetGuestCpuIdStdRCPtr(PVM pVM)
3763{
3764 return RCPTRTYPE(PCCPUMCPUID)VM_RC_ADDR(pVM, &pVM->cpum.s.aGuestCpuIdStd[0]);
3765}
3766
3767
3768/**
3769 * Gets a pointer to the array of extended CPUID leaves.
3770 *
3771 * CPUMGetGuestCpuIdExtMax() give the size of the array.
3772 *
3773 * @returns Pointer to the extended CPUID leaves (read-only).
3774 * @param pVM Pointer to the VM.
3775 * @remark Intended for PATM.
3776 */
3777VMMR3DECL(RCPTRTYPE(PCCPUMCPUID)) CPUMR3GetGuestCpuIdExtRCPtr(PVM pVM)
3778{
3779 return (RCPTRTYPE(PCCPUMCPUID))VM_RC_ADDR(pVM, &pVM->cpum.s.aGuestCpuIdExt[0]);
3780}
3781
3782
3783/**
3784 * Gets a pointer to the array of centaur CPUID leaves.
3785 *
3786 * CPUMGetGuestCpuIdCentaurMax() give the size of the array.
3787 *
3788 * @returns Pointer to the centaur CPUID leaves (read-only).
3789 * @param pVM Pointer to the VM.
3790 * @remark Intended for PATM.
3791 */
3792VMMR3DECL(RCPTRTYPE(PCCPUMCPUID)) CPUMR3GetGuestCpuIdCentaurRCPtr(PVM pVM)
3793{
3794 return (RCPTRTYPE(PCCPUMCPUID))VM_RC_ADDR(pVM, &pVM->cpum.s.aGuestCpuIdCentaur[0]);
3795}
3796
3797
3798/**
3799 * Gets a pointer to the default CPUID leaf.
3800 *
3801 * @returns Pointer to the default CPUID leaf (read-only).
3802 * @param pVM Pointer to the VM.
3803 * @remark Intended for PATM.
3804 */
3805VMMR3DECL(RCPTRTYPE(PCCPUMCPUID)) CPUMR3GetGuestCpuIdDefRCPtr(PVM pVM)
3806{
3807 return (RCPTRTYPE(PCCPUMCPUID))VM_RC_ADDR(pVM, &pVM->cpum.s.GuestCpuIdDef);
3808}
3809
3810
3811/**
3812 * Transforms the guest CPU state to raw-ring mode.
3813 *
3814 * This function will change the any of the cs and ss register with DPL=0 to DPL=1.
3815 *
3816 * @returns VBox status. (recompiler failure)
3817 * @param pVCpu The VMCPU handle.
3818 * @param pCtxCore The context core (for trap usage).
3819 * @see @ref pg_raw
3820 */
3821VMMR3DECL(int) CPUMR3RawEnter(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore)
3822{
3823 PVM pVM = pVCpu->CTX_SUFF(pVM);
3824
3825 Assert(!pVCpu->cpum.s.fRawEntered);
3826 Assert(!pVCpu->cpum.s.fRemEntered);
3827 if (!pCtxCore)
3828 pCtxCore = CPUMCTX2CORE(&pVCpu->cpum.s.Guest);
3829
3830 /*
3831 * Are we in Ring-0?
3832 */
3833 if ( pCtxCore->ss && (pCtxCore->ss & X86_SEL_RPL) == 0
3834 && !pCtxCore->eflags.Bits.u1VM)
3835 {
3836 /*
3837 * Enter execution mode.
3838 */
3839 PATMRawEnter(pVM, pCtxCore);
3840
3841 /*
3842 * Set CPL to Ring-1.
3843 */
3844 pCtxCore->ss |= 1;
3845 if (pCtxCore->cs && (pCtxCore->cs & X86_SEL_RPL) == 0)
3846 pCtxCore->cs |= 1;
3847 }
3848 else
3849 {
3850 AssertMsg((pCtxCore->ss & X86_SEL_RPL) >= 2 || pCtxCore->eflags.Bits.u1VM,
3851 ("ring-1 code not supported\n"));
3852 /*
3853 * PATM takes care of IOPL and IF flags for Ring-3 and Ring-2 code as well.
3854 */
3855 PATMRawEnter(pVM, pCtxCore);
3856 }
3857
3858 /*
3859 * Invalidate the hidden registers.
3860 */
3861 pVCpu->cpum.s.fChanged |= CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID;
3862
3863 /*
3864 * Assert sanity.
3865 */
3866 AssertMsg((pCtxCore->eflags.u32 & X86_EFL_IF), ("X86_EFL_IF is clear\n"));
3867 AssertReleaseMsg( pCtxCore->eflags.Bits.u2IOPL < (unsigned)(pCtxCore->ss & X86_SEL_RPL)
3868 || pCtxCore->eflags.Bits.u1VM,
3869 ("X86_EFL_IOPL=%d CPL=%d\n", pCtxCore->eflags.Bits.u2IOPL, pCtxCore->ss & X86_SEL_RPL));
3870 Assert((pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PG | X86_CR0_WP | X86_CR0_PE)) == (X86_CR0_PG | X86_CR0_PE | X86_CR0_WP));
3871
3872 pCtxCore->eflags.u32 |= X86_EFL_IF; /* paranoia */
3873
3874 pVCpu->cpum.s.fRawEntered = true;
3875 return VINF_SUCCESS;
3876}
3877
3878
3879/**
3880 * Transforms the guest CPU state from raw-ring mode to correct values.
3881 *
3882 * This function will change any selector registers with DPL=1 to DPL=0.
3883 *
3884 * @returns Adjusted rc.
3885 * @param pVCpu The VMCPU handle.
3886 * @param rc Raw mode return code
3887 * @param pCtxCore The context core (for trap usage).
3888 * @see @ref pg_raw
3889 */
3890VMMR3DECL(int) CPUMR3RawLeave(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, int rc)
3891{
3892 PVM pVM = pVCpu->CTX_SUFF(pVM);
3893
3894 /*
3895 * Don't leave if we've already left (in GC).
3896 */
3897 Assert(pVCpu->cpum.s.fRawEntered);
3898 Assert(!pVCpu->cpum.s.fRemEntered);
3899 if (!pVCpu->cpum.s.fRawEntered)
3900 return rc;
3901 pVCpu->cpum.s.fRawEntered = false;
3902
3903 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
3904 if (!pCtxCore)
3905 pCtxCore = CPUMCTX2CORE(pCtx);
3906 Assert(pCtxCore->eflags.Bits.u1VM || (pCtxCore->ss & X86_SEL_RPL));
3907 AssertMsg(pCtxCore->eflags.Bits.u1VM || pCtxCore->eflags.Bits.u2IOPL < (unsigned)(pCtxCore->ss & X86_SEL_RPL),
3908 ("X86_EFL_IOPL=%d CPL=%d\n", pCtxCore->eflags.Bits.u2IOPL, pCtxCore->ss & X86_SEL_RPL));
3909
3910 /*
3911 * Are we executing in raw ring-1?
3912 */
3913 if ( (pCtxCore->ss & X86_SEL_RPL) == 1
3914 && !pCtxCore->eflags.Bits.u1VM)
3915 {
3916 /*
3917 * Leave execution mode.
3918 */
3919 PATMRawLeave(pVM, pCtxCore, rc);
3920 /* Not quite sure if this is really required, but shouldn't harm (too much anyways). */
3921 /** @todo See what happens if we remove this. */
3922 if ((pCtxCore->ds & X86_SEL_RPL) == 1)
3923 pCtxCore->ds &= ~X86_SEL_RPL;
3924 if ((pCtxCore->es & X86_SEL_RPL) == 1)
3925 pCtxCore->es &= ~X86_SEL_RPL;
3926 if ((pCtxCore->fs & X86_SEL_RPL) == 1)
3927 pCtxCore->fs &= ~X86_SEL_RPL;
3928 if ((pCtxCore->gs & X86_SEL_RPL) == 1)
3929 pCtxCore->gs &= ~X86_SEL_RPL;
3930
3931 /*
3932 * Ring-1 selector => Ring-0.
3933 */
3934 pCtxCore->ss &= ~X86_SEL_RPL;
3935 if ((pCtxCore->cs & X86_SEL_RPL) == 1)
3936 pCtxCore->cs &= ~X86_SEL_RPL;
3937 }
3938 else
3939 {
3940 /*
3941 * PATM is taking care of the IOPL and IF flags for us.
3942 */
3943 PATMRawLeave(pVM, pCtxCore, rc);
3944 if (!pCtxCore->eflags.Bits.u1VM)
3945 {
3946 /** @todo See what happens if we remove this. */
3947 if ((pCtxCore->ds & X86_SEL_RPL) == 1)
3948 pCtxCore->ds &= ~X86_SEL_RPL;
3949 if ((pCtxCore->es & X86_SEL_RPL) == 1)
3950 pCtxCore->es &= ~X86_SEL_RPL;
3951 if ((pCtxCore->fs & X86_SEL_RPL) == 1)
3952 pCtxCore->fs &= ~X86_SEL_RPL;
3953 if ((pCtxCore->gs & X86_SEL_RPL) == 1)
3954 pCtxCore->gs &= ~X86_SEL_RPL;
3955 }
3956 }
3957
3958 return rc;
3959}
3960
3961
3962/**
3963 * Enters REM, gets and resets the changed flags (CPUM_CHANGED_*).
3964 *
3965 * Only REM should ever call this function!
3966 *
3967 * @returns The changed flags.
3968 * @param pVCpu The VMCPU handle.
3969 * @param puCpl Where to return the current privilege level (CPL).
3970 */
3971VMMR3DECL(uint32_t) CPUMR3RemEnter(PVMCPU pVCpu, uint32_t *puCpl)
3972{
3973 Assert(!pVCpu->cpum.s.fRawEntered);
3974 Assert(!pVCpu->cpum.s.fRemEntered);
3975
3976 /*
3977 * Get the CPL first.
3978 */
3979 *puCpl = CPUMGetGuestCPL(pVCpu, CPUMCTX2CORE(&pVCpu->cpum.s.Guest));
3980
3981 /*
3982 * Get and reset the flags, leaving CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID set.
3983 */
3984 uint32_t fFlags = pVCpu->cpum.s.fChanged;
3985 pVCpu->cpum.s.fChanged &= CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID; /* leave it set */
3986
3987 /** @todo change the switcher to use the fChanged flags. */
3988 if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_SINCE_REM)
3989 {
3990 fFlags |= CPUM_CHANGED_FPU_REM;
3991 pVCpu->cpum.s.fUseFlags &= ~CPUM_USED_FPU_SINCE_REM;
3992 }
3993
3994 pVCpu->cpum.s.fRemEntered = true;
3995 return fFlags;
3996}
3997
3998
3999/**
4000 * Leaves REM and works the CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID flag.
4001 *
4002 * @param pVCpu The virtual CPU handle.
4003 * @param fNoOutOfSyncSels This is @c false if there are out of sync
4004 * registers.
4005 */
4006VMMR3DECL(void) CPUMR3RemLeave(PVMCPU pVCpu, bool fNoOutOfSyncSels)
4007{
4008 Assert(!pVCpu->cpum.s.fRawEntered);
4009 Assert(pVCpu->cpum.s.fRemEntered);
4010
4011 if (fNoOutOfSyncSels)
4012 pVCpu->cpum.s.fChanged &= ~CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID;
4013 else
4014 pVCpu->cpum.s.fChanged |= ~CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID;
4015
4016 pVCpu->cpum.s.fRemEntered = false;
4017}
4018
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette