CPUM.cpp revision 4306e52e991acec6ff7cfdadd4235a70689c9700
/* $Id$ */
/** @file
* CPUM - CPU Monitor / Manager.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/** @page pg_cpum CPUM - CPU Monitor / Manager
*
* The CPU Monitor / Manager keeps track of all the CPU registers. It is
* also responsible for lazy FPU handling and some of the context loading
* in raw mode.
*
* There are three CPU contexts, the most important one is the guest one (GC).
* When running in raw-mode (RC) there is a special hyper context for the VMM
* part that floats around inside the guest address space. When running in
* raw-mode, CPUM also maintains a host context for saving and restoring
* registers across world switches. This latter is done in cooperation with the
* world switcher (@see pg_vmm).
*
* @see grp_cpum
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_CPUM
#include "CPUMInternal.h"
#include <iprt/asm-amd64-x86.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The current saved state version. */
#define CPUM_SAVED_STATE_VERSION 12
/** The saved state version of 3.2, 3.1 and 3.3 trunk before the hidden
* selector register change (CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID). */
#define CPUM_SAVED_STATE_VERSION_VER3_2 11
/** The saved state version of 3.0 and 3.1 trunk before the teleportation
* changes. */
#define CPUM_SAVED_STATE_VERSION_VER3_0 10
/** The saved state version for the 2.1 trunk before the MSR changes. */
#define CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR 9
/** The saved state version of 2.0, used for backwards compatibility. */
#define CPUM_SAVED_STATE_VERSION_VER2_0 8
/** The saved state version of 1.6, used for backwards compatibility. */
#define CPUM_SAVED_STATE_VERSION_VER1_6 6
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* What kind of cpu info dump to perform.
*/
typedef enum CPUMDUMPTYPE
{
} CPUMDUMPTYPE;
/** Pointer to a cpu info dump type. */
typedef CPUMDUMPTYPE *PCPUMDUMPTYPE;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static CPUMCPUVENDOR cpumR3DetectVendor(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX);
static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
/**
* Initializes the CPUM.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
LogFlow(("CPUMR3Init\n"));
/*
* Assert alignment and sizes.
*/
/* Calculate the offset from CPUM to CPUMCPU for the first CPU. */
/* Calculate the offset from CPUMCPU to CPUM. */
{
/*
* Setup any fixed pointers and offsets.
*/
}
/*
* Check that the CPU supports the minimum features we require.
*/
if (!ASMHasCpuId())
{
Log(("The CPU doesn't support CPUID!\n"));
return VERR_UNSUPPORTED_CPU;
}
/* Setup the CR4 AND and OR masks used in the switcher */
/* Depends on the presence of FXSAVE(SSE) support on the host CPU */
{
/* No FXSAVE implies no SSE */
}
else
{
}
{
Log(("The CPU doesn't support MMX!\n"));
return VERR_UNSUPPORTED_CPU;
}
{
Log(("The CPU doesn't support TSC!\n"));
return VERR_UNSUPPORTED_CPU;
}
/* Bogus on AMD? */
/*
* Detect the host CPU vendor.
* (The guest CPU vendor is re-detected later on.)
*/
/*
* Setup hypervisor startup values.
*/
/*
* Register saved state data item.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Register info handlers and registers with the debugger facility.
*/
DBGFR3InfoRegisterInternal(pVM, "cpumhyper", "Displays the hypervisor cpu state.", &cpumR3InfoHyper);
DBGFR3InfoRegisterInternal(pVM, "cpumguestinstr", "Displays the current guest instruction.", &cpumR3InfoGuestInstr);
if (RT_FAILURE(rc))
return rc;
/*
* Initialize the Guest CPUID state.
*/
if (RT_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/**
* Detect the CPU vendor give n the
*
* @returns The vendor.
* @param uEAX EAX from CPUID(0).
* @param uEBX EBX from CPUID(0).
* @param uECX ECX from CPUID(0).
* @param uEDX EDX from CPUID(0).
*/
{
if ( uEAX >= 1
&& uEBX == X86_CPUID_VENDOR_AMD_EBX
&& uECX == X86_CPUID_VENDOR_AMD_ECX
&& uEDX == X86_CPUID_VENDOR_AMD_EDX)
return CPUMCPUVENDOR_AMD;
if ( uEAX >= 1
&& uEDX == X86_CPUID_VENDOR_INTEL_EDX)
return CPUMCPUVENDOR_INTEL;
/** @todo detect the other buggers... */
return CPUMCPUVENDOR_UNKNOWN;
}
/**
* Fetches overrides for a CPUID leaf.
*
* @returns VBox status code.
* @param pLeaf The leaf to load the overrides into.
* @param pCfgNode The CFGM node containing the overrides
* @param iLeaf The CPUID leaf number.
*/
{
if (pLeafNode)
{
if (RT_SUCCESS(rc))
else
if (RT_SUCCESS(rc))
else
if (RT_SUCCESS(rc))
else
if (RT_SUCCESS(rc))
else
}
return VINF_SUCCESS;
}
/**
* Load the overrides for a set of CPUID leaves.
*
* @returns VBox status code.
* @param paLeaves The leaf array.
* @param cLeaves The number of leaves.
* @param uStart The start leaf number.
* @param pCfgNode The CFGM node containing the overrides
*/
static int cpumR3CpuIdInitLoadOverrideSet(uint32_t uStart, PCPUMCPUID paLeaves, uint32_t cLeaves, PCFGMNODE pCfgNode)
{
{
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/**
* Init a set of host CPUID leaves.
*
* @returns VBox status code.
* @param paLeaves The leaf array.
* @param cLeaves The number of leaves.
* @param uStart The start leaf number.
*/
static int cpumR3CpuIdInitHostSet(uint32_t uStart, PCPUMCPUID paLeaves, uint32_t cLeaves, PCFGMNODE pCfgNode)
{
/* Using the ECX variant for all of them can't hurt... */
ASMCpuId_Idx_ECX(uStart + i, 0, &paLeaves[i].eax, &paLeaves[i].ebx, &paLeaves[i].ecx, &paLeaves[i].edx);
/* Load CPUID leaf override; we currently don't care if the user
specifies features the host CPU doesn't support. */
}
/**
* Initializes the emulated CPU's cpuid information.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
uint32_t i;
int rc;
if (pCPUM->u8PortableCpuIdLevel >= (Lvl) && (pCPUM->aGuestCpuId##LeafSuffReg & (fMask)) == (uValue) ) \
{ \
LogRel(("PortableCpuId: " #LeafSuffReg "[" #FeatNm "]: %#x -> 0\n", pCPUM->aGuestCpuId##LeafSuffReg & (fMask))); \
}
{ \
}
/*
* Read the configuration.
*/
/** @cfgm{CPUM/SyntheticCpu, boolean, false}
* Enables the Synthetic CPU. The Vendor ID and Processor Name are
* completely overridden by VirtualBox custom strings. Some
* CPUID information is withheld, like the cache info. */
/** @cfgm{CPUM/PortableCpuIdLevel, 8-bit, 0, 3, 0}
* When non-zero CPUID features that could cause portability issues will be
* stripped. The higher the value the more features gets stripped. Higher
* values should only be used when older CPUs are involved since it may
* harm performance and maybe also cause problems with specific guests. */
/*
* Get the host CPUID leaves and redetect the guest CPU vendor (could've
* been overridden).
*/
* Overrides the host CPUID leaf values used for calculating the guest CPUID
* leaves. This can be used to preserve the CPUID values when moving a VM
* to a different machine. Another use is restricting (or extending) the
* feature set exposed to the guest. */
rc = cpumR3CpuIdInitHostSet(UINT32_C(0x00000000), &pCPUM->aGuestCpuIdStd[0], RT_ELEMENTS(pCPUM->aGuestCpuIdStd), pHostOverrideCfg);
rc = cpumR3CpuIdInitHostSet(UINT32_C(0x80000000), &pCPUM->aGuestCpuIdExt[0], RT_ELEMENTS(pCPUM->aGuestCpuIdExt), pHostOverrideCfg);
rc = cpumR3CpuIdInitHostSet(UINT32_C(0xc0000000), &pCPUM->aGuestCpuIdCentaur[0], RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur), pHostOverrideCfg);
pCPUM->enmGuestCpuVendor = cpumR3DetectVendor(pCPUM->aGuestCpuIdStd[0].eax, pCPUM->aGuestCpuIdStd[0].ebx,
/*
* Determine the default leaf.
*
* Intel returns values of the highest standard function, while AMD
* returns zeros. VIA on the other hand seems to returning nothing or
* perhaps some random garbage, we don't try to duplicate this behavior.
*/
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. */
/* Cpuid 1 & 0x80000001:
* Only report features we can support.
*
* Note! When enabling new features the Synthetic CPU and Portable CPUID
* options may require adjusting (i.e. stripping what was enabled).
*/
//| X86_CPUID_FEATURE_EDX_PAE - set later if configured.
//| X86_CPUID_FEATURE_EDX_APIC - set by the APIC device if present.
/* 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 #1757) */
//| X86_CPUID_FEATURE_EDX_SEP
//| X86_CPUID_FEATURE_EDX_PSN - no serial number.
//| X86_CPUID_FEATURE_EDX_DS - no debug store.
//| X86_CPUID_FEATURE_EDX_ACPI - not virtualized yet.
//| X86_CPUID_FEATURE_EDX_SS - no self snoop.
//| X86_CPUID_FEATURE_EDX_HTT - no hyperthreading.
//| X86_CPUID_FEATURE_EDX_TM - no thermal monitor.
//| X86_CPUID_FEATURE_EDX_PBE - no pending break enabled.
| 0;
/* Can't properly emulate monitor & mwait with guest SMP; force the guest to use hlt for idling VCPUs. */
//| X86_CPUID_FEATURE_ECX_CPLDS - no CPL qualified debug store.
//| X86_CPUID_FEATURE_ECX_VMX - not virtualized.
//| X86_CPUID_FEATURE_ECX_EST - no extended speed step.
//| X86_CPUID_FEATURE_ECX_TM2 - no thermal monitor 2.
//| X86_CPUID_FEATURE_ECX_CNTXID - no L1 context id (MSR++).
//| X86_CPUID_FEATURE_ECX_CX16 - no cmpxchg16b
/* ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
//| X86_CPUID_FEATURE_ECX_TPRUPDATE
/* ECX Bit 21 - x2APIC support - not yet. */
// | X86_CPUID_FEATURE_ECX_X2APIC
/* ECX Bit 23 - POPCNT instruction. */
//| X86_CPUID_FEATURE_ECX_POPCNT
| 0;
if (pCPUM->u8PortableCpuIdLevel > 0)
{
)));
)));
}
/* Cpuid 0x80000001:
* Only report features we can support.
*
* Note! When enabling new features the Synthetic CPU and Portable CPUID
* options may require adjusting (i.e. stripping what was enabled).
*
* ASSUMES that this is ALWAYS the AMD defined feature set if present.
*/
| X86_CPUID_AMD_FEATURE_EDX_MSR //?? this means AMD MSRs..
//| X86_CPUID_AMD_FEATURE_EDX_PAE - not implemented yet.
//| X86_CPUID_AMD_FEATURE_EDX_MCE - not virtualized yet.
//| X86_CPUID_AMD_FEATURE_EDX_APIC - set by the APIC device if present.
/* 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 #1757) */
//| X86_CPUID_AMD_FEATURE_EDX_SEP
//| X86_CPUID_AMD_FEATURE_EDX_NX - not virtualized, requires PAE.
//| X86_CPUID_AMD_FEATURE_EDX_AXMMX
//| X86_CPUID_AMD_FEATURE_EDX_PAGE1GB
//| X86_CPUID_AMD_FEATURE_EDX_RDTSCP - AMD only; turned on when necessary
//| X86_CPUID_AMD_FEATURE_EDX_LONG_MODE - turned on when necessary
| 0;
//| X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF
//| X86_CPUID_AMD_FEATURE_ECX_CMPL
//| X86_CPUID_AMD_FEATURE_ECX_SVM - not virtualized.
//| X86_CPUID_AMD_FEATURE_ECX_EXT_APIC
/* Note: This could prevent teleporting from AMD to Intel CPUs! */
| X86_CPUID_AMD_FEATURE_ECX_CR8L /* expose lock mov cr0 = mov cr8 hack for guests that can use this feature to access the TPR. */
//| X86_CPUID_AMD_FEATURE_ECX_ABM
//| X86_CPUID_AMD_FEATURE_ECX_SSE4A
//| X86_CPUID_AMD_FEATURE_ECX_MISALNSSE
//| X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF
//| X86_CPUID_AMD_FEATURE_ECX_OSVW
//| X86_CPUID_AMD_FEATURE_ECX_IBS
//| X86_CPUID_AMD_FEATURE_ECX_SSE5
//| X86_CPUID_AMD_FEATURE_ECX_SKINIT
//| X86_CPUID_AMD_FEATURE_ECX_WDT
| 0;
if (pCPUM->u8PortableCpuIdLevel > 0)
{
| UINT32_C(0xffffc000)
)));
| RT_BIT(18)
| RT_BIT(19)
| RT_BIT(21)
| RT_BIT(28)
)));
}
/*
* Apply the Synthetic CPU modifications. (TODO: move this up)
*/
if (pCPUM->fSyntheticCpu)
{
static const char s_szProcessor[48] = "VirtualBox SPARCx86 Processor v1000 "; /* includes null terminator */
/* 0: Vendor */
/* 1.eax: Version information. family : model : stepping */
/* Leaves 2 - 4 are Intel only - zero them out */
/* Limit the nr of extended leaves: 0x80000008 to include the max virtual and physical address size (64 bits guests). */
/* AMD only - set to zero. */
/* 0x800000001: AMD only; shared feature bits are set dynamically. */
/* 0x800000002-4: Processor Name String Identifier. */
/* 0x800000005-7 - reserved -> zero */
/* 0x800000008: only the max virtual and physical address size. */
pCPUM->aGuestCpuIdExt[8].ecx = pCPUM->aGuestCpuIdExt[8].ebx = pCPUM->aGuestCpuIdExt[8].edx = 0; /* reserved */
}
/*
* Hide HTT, multicode, SMP, whatever.
* (APIC-ID := 0 and #LogCpus := 0)
*/
#ifdef VBOX_WITH_MULTI_CORE
{
/* 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 */
pCPUM->aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_HTT; /* necessary for hyper-threading *or* multi-core CPUs */
}
#endif
/* Cpuid 2:
* Intel: Cache and TLB information
* AMD: Reserved
* Safe to expose; restrict the number of calls to 1 for the portable case.
*/
if ( pCPUM->u8PortableCpuIdLevel > 0
{
}
/* Cpuid 3:
* Intel: EAX, EBX - reserved (transmeta uses these)
* ECX, EDX - Processor Serial Number if available, otherwise reserved
* AMD: Reserved
* Safe to expose
*/
{
if (pCPUM->u8PortableCpuIdLevel > 0)
}
/* Cpuid 4:
* Intel: Deterministic Cache Parameters Leaf
* Note: Depends on the ECX input! -> Feeling rather lazy now, so we just return 0
* AMD: Reserved
* Safe to expose, except for EAX:
* Bits 25-14: Maximum number of addressable IDs for logical processors sharing this cache (see note)**
* Bits 31-26: Maximum number of processor cores in this physical package**
* Note: These SMP values are constant regardless of ECX
*/
#ifdef VBOX_WITH_MULTI_CORE
{
/* One logical processor with possibly multiple cores. */
/* See http://www.intel.com/Assets/PDF/appnote/241618.pdf p. 29 */
}
#endif
* Intel: ECX, EDX - reserved
* EAX, EBX - Smallest and largest monitor line size
* AMD: EDX - reserved
* EAX, EBX - Smallest and largest monitor line size
* ECX - extensions (ignored for now)
* Safe to expose
*/
/** @cfgm{/CPUM/MWaitExtensions, boolean, false}
* Expose MWAIT extended features to the guest. For now we expose
* just MWAIT break on interrupt feature (bit 1).
*/
bool fMWaitExtensions;
rc = CFGMR3QueryBoolDef(pCpumCfg, "MWaitExtensions", &fMWaitExtensions, false); AssertRCReturn(rc, rc);
if (fMWaitExtensions)
{
/* @todo: for now we just expose host's MWAIT C-states, although conceptually
it shall be part of our power management virtualization model */
#if 0
/* MWAIT sub C-states */
(0 << 0) /* 0 in C0 */ |
(2 << 4) /* 2 in C1 */ |
(2 << 8) /* 2 in C2 */ |
(2 << 12) /* 2 in C3 */ |
(0 << 16) /* 0 in C4 */
;
#endif
}
else
/* Cpuid 0x800000005 & 0x800000006 contain information about L1, L2 & L3 cache and TLB identifiers.
* Safe to pass on to the guest.
*
* Intel: 0x800000005 reserved
* 0x800000006 L2 cache information
* AMD: 0x800000005 L1 cache information
*/
/* Cpuid 0x800000007:
* AMD: EAX, EBX, ECX - reserved
* EDX: Advanced Power Management Information
* Intel: Reserved
*/
{
{
/* Only expose the TSC invariant capability bit to the guest. */
//| X86_CPUID_AMD_ADVPOWER_EDX_TS
//| X86_CPUID_AMD_ADVPOWER_EDX_FID
//| X86_CPUID_AMD_ADVPOWER_EDX_VID
//| X86_CPUID_AMD_ADVPOWER_EDX_TTP
//| X86_CPUID_AMD_ADVPOWER_EDX_TM
//| X86_CPUID_AMD_ADVPOWER_EDX_STC
//| X86_CPUID_AMD_ADVPOWER_EDX_MC
//| X86_CPUID_AMD_ADVPOWER_EDX_HWPSTATE
#if 0 /* We don't expose X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR, because newer
* Linux kernels blindly assume that the AMD performance counters work
* if this is set for 64 bits guests. (Can't really find a CPUID feature
* bit for them though.) */
#endif
| 0;
}
else
}
/* Cpuid 0x800000008:
* AMD: EBX, EDX - reserved
* ECX: Number of cores + APICIdCoreIdSize
* EBX, ECX, EDX - reserved
*/
{
/* Only expose the virtual and physical address sizes to the guest. */
/* Set APICIdCoreIdSize to zero (use legacy method to determine the number of cores per cpu)
* NC (0-7) Number of cores; 0 equals 1 core */
#ifdef VBOX_WITH_MULTI_CORE
{
/* Legacy method to determine the number of cores. */
}
#endif
}
/** @cfgm{/CPUM/NT4LeafLimit, boolean, false}
* Limit the number of standard CPUID leaves to 0..3 to prevent NT4 from
* bugchecking with MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED (0x3e).
* This option corresponds somewhat to IA32_MISC_ENABLES.BOOT_NT4[bit 22].
*/
bool fNt4LeafLimit;
if (fNt4LeafLimit)
pCPUM->aGuestCpuIdStd[0].eax = 3; /** @todo r=bird: shouldn't we check if pCPUM->aGuestCpuIdStd[0].eax > 3 before setting it 3 here? */
/*
* Limit it the number of entries and fill the remaining with the defaults.
*
* The limits are masking off stuff about power saving and similar, this
* is perhaps a bit crudely done as there is probably some relatively harmless
* info too in these leaves (like words about having a constant TSC).
*/
: 0;
i++)
/*
* Centaur stuff (VIA).
*
* The important part here (we think) is to make sure the 0xc0000000
* function returns 0xc0000001. As for the features, we don't currently
* let on about any of those... 0xc0000002 seems to be some
* temperature/hz/++ stuff, include it as well (static).
*/
{
i++)
}
else
/*
* Load CPUID overrides from configuration.
* Note: Kind of redundant now, but allows unchanged overrides
*/
* Overrides the CPUID leaf values. */
rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &pCPUM->aGuestCpuIdStd[0], RT_ELEMENTS(pCPUM->aGuestCpuIdStd), pOverrideCfg);
rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &pCPUM->aGuestCpuIdExt[0], RT_ELEMENTS(pCPUM->aGuestCpuIdExt), pOverrideCfg);
rc = cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0xc0000000), &pCPUM->aGuestCpuIdCentaur[0], RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur), pOverrideCfg);
/*
* Check if PAE was explicitely enabled by the user.
*/
bool fEnable;
if (fEnable)
/*
* We don't normally enable NX for raw-mode, so give the user a chance to
* force it on.
*/
if (fEnable)
/*
* Log the cpuid and we're good.
*/
LogRel(("Logical host processors: %u present, %u max, %u online, online mask: %016RX64\n",
LogRel(("************************* CPUID dump ************************\n"));
LogRel(("\n"));
LogRel(("******************** End of CPUID dump **********************\n"));
return VINF_SUCCESS;
}
/**
* Applies relocations to data and code managed by this
* component. This function will be called at init and
* whenever the VMM need to relocate it self inside the GC.
*
* The CPUM will update the addresses used by the switcher.
*
* @param pVM The VM.
*/
{
LogFlow(("CPUMR3Relocate\n"));
{
/*
* Switcher pointers.
*/
}
}
/**
* Apply late CPUM property changes based on the fHWVirtEx setting
*
* @param pVM The VM to operate on.
*/
{
/*
* Workaround for missing cpuid(0) patches when leaf 4 returns GuestCpuIdDef:
* If we miss to patch a cpuid(0).eax then Linux tries to determine the number
* of processors from (cpuid(4).eax >> 26) + 1.
*
* Note: this code is obsolete, but let's keep it here for reference.
* Purpose is valid when we artificially cap the max std id to less than 4.
*/
if (!fHWVirtExEnabled)
{
}
}
/**
* Terminates the CPUM.
*
* Termination means cleaning up and freeing all resources,
* the VM it self is at this point powered off or suspended.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
#ifdef VBOX_WITH_CRASHDUMP_MAGIC
{
}
#endif
return 0;
}
/**
* Resets a virtual CPU.
*
* Used by CPUMR3Reset and CPU hot plugging.
*
* @param pVCpu The virtual CPU handle.
*/
{
/** @todo anything different for VCPU > 0? */
/*
* Initialize everything to ZERO first.
*/
pCtx->trHid.Attr.n.u4Type = X86_SEL_TYPE_SYS_386_TSS_BUSY; /* Deduction, not properly documented by Intel. */
/* Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3A, Table 8-1. IA-32 Processor States Following Power-up, Reset, or INIT */
/* Init PAT MSR */
/* Reset EFER; see AMD64 Architecture Programmer's Manual Volume 2: Table 14-1. Initial Processor State
* The Intel docs don't mention it.
*/
}
/**
* Resets the CPU.
*
* @returns VINF_SUCCESS.
* @param pVM The VM handle.
*/
{
{
#ifdef VBOX_WITH_CRASHDUMP_MAGIC
/* Magic marker for searching in crash dumps. */
#endif
}
}
/**
* Called both in pass 0 and the final pass.
*
* @param pVM The VM handle.
* @param pSSM The saved state handle.
*/
{
/*
* Save all the CPU ID leaves here so we can check them for compatibility
* upon loading.
*/
/*
* Save a good portion of the raw CPU IDs as well as they may come in
* handy when validating features for raw mode.
*/
for (unsigned i = 0; i < RT_ELEMENTS(aRawStd); i++)
for (unsigned i = 0; i < RT_ELEMENTS(aRawExt); i++)
ASMCpuId(i | UINT32_C(0x80000000), &aRawExt[i].eax, &aRawExt[i].ebx, &aRawExt[i].ecx, &aRawExt[i].edx);
}
/**
* Loads the CPU ID leaves saved by pass 0.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The saved state handle.
* @param uVersion The format version.
*/
{
AssertMsgReturn(uVersion >= CPUM_SAVED_STATE_VERSION_VER3_2, ("%u\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
/*
* Define a bunch of macros for simplifying the code.
*/
/* Generic expression + failure message. */
do { \
if (!(expr)) \
{ \
if (fStrictCpuIdChecks) \
{ \
return rcCpuid; \
} \
} \
} while (0)
do { \
if (!(expr)) \
} while (0)
/* For comparing two values and bitch if they differs. */
do { \
{ \
if (fStrictCpuIdChecks) \
} \
} while (0)
do { \
} while (0)
/* For checking raw cpu features (raw mode). */
do { \
{ \
if (fStrictCpuIdChecks) \
} \
} while (0)
do { \
} while (0)
/* For checking guest features. */
do { \
) \
{ \
if (fStrictCpuIdChecks) \
} \
} while (0)
do { \
) \
} while (0)
do { \
) \
LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
} while (0)
/* For checking guest features if AMD guest CPU. */
do { \
&& fGuestAmd \
) \
{ \
if (fStrictCpuIdChecks) \
} \
} while (0)
do { \
&& fGuestAmd \
) \
} while (0)
do { \
&& fGuestAmd \
) \
LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
} while (0)
/* For checking AMD features which have a corresponding bit in the standard
range. (Intel defines very few bits in the extended feature sets.) */
do { \
&& !(fHostAmd \
) \
{ \
if (fStrictCpuIdChecks) \
LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
} \
} while (0)
do { \
&& !(fHostAmd \
) \
LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
} while (0)
do { \
&& !(fHostAmd \
) \
LogRel(("CPUM: Warning - " #ExtBit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
} while (0)
/*
* Load them into stack buffers first.
*/
/*
* Note that we support restoring less than the current amount of standard
* leaves because we've been allowed more is newer version of VBox.
*
* So, pad new entries with the default.
*/
aGuestCpuIdStd[i] = GuestCpuIdDef;
aGuestCpuIdExt[i] = GuestCpuIdDef;
ASMCpuId(i | UINT32_C(0x80000000), &aRawExt[i].eax, &aRawExt[i].ebx, &aRawExt[i].ecx, &aRawExt[i].edx);
/*
* Get the raw CPU IDs for the current host.
*/
for (unsigned i = 0; i < RT_ELEMENTS(aHostRawStd); i++)
for (unsigned i = 0; i < RT_ELEMENTS(aHostRawExt); i++)
ASMCpuId(i | UINT32_C(0x80000000), &aHostRawExt[i].eax, &aHostRawExt[i].ebx, &aHostRawExt[i].ecx, &aHostRawExt[i].edx);
/*
* Get the host and guest overrides so we don't reject the state because
* some feature was enabled thru these interfaces.
* Note! We currently only need the feature leaves, so skip rest.
*/
cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &aGuestOverrideStd[0], RT_ELEMENTS(aGuestOverrideStd), pOverrideCfg);
cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &aGuestOverrideExt[0], RT_ELEMENTS(aGuestOverrideExt), pOverrideCfg);
cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &aHostOverrideStd[0], RT_ELEMENTS(aHostOverrideStd), pOverrideCfg);
cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &aHostOverrideExt[0], RT_ELEMENTS(aHostOverrideExt), pOverrideCfg);
/*
* This can be skipped.
*/
bool fStrictCpuIdChecks;
CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM"), "StrictCpuIdChecks", &fStrictCpuIdChecks, true);
/*
* For raw-mode we'll require that the CPUs are very similar since we don't
* intercept CPUID instructions for user mode applications.
*/
if (!HWACCMIsEnabled(pVM))
{
/* CPUID(0) */
(N_("CPU vendor mismatch: host='%.4s%.4s%.4s' saved='%.4s%.4s%.4s'"),
CPUID_CHECK2_WRN("Reserved bits 15:14", (aHostRawExt[1].eax >> 14) & 3, (aRawExt[1].eax >> 14) & 3);
/* CPUID(1).eax */
CPUID_CHECK2_RET("CPU family", ASMGetCpuFamily(aHostRawStd[1].eax), ASMGetCpuFamily(aRawStd[1].eax));
CPUID_CHECK2_RET("CPU model", ASMGetCpuModel(aHostRawStd[1].eax, fIntel), ASMGetCpuModel(aRawStd[1].eax, fIntel));
/* CPUID(1).ebx - completely ignore CPU count and APIC ID. */
CPUID_CHECK2_WRN("CLFLUSH chunk count", (aHostRawStd[1].ebx >> 8) & 0xff, (aRawStd[1].ebx >> 8) & 0xff);
/* CPUID(1).ecx */
/* CPUID(1).edx */
/* CPUID(2) - config, mostly about caches. ignore. */
/* CPUID(3) - processor serial number. ignore. */
/* CPUID(4) - config, cache and topology - takes ECX as input. ignore. */
/* CPUID(6) - power management. ignore. */
/* CPUID(7) - ???. ignore. */
/* CPUID(8) - ???. ignore. */
/* CPUID(9) - DCA. ignore for now. */
/* CPUID(a) - PeMo info. ignore for now. */
/* CPUID(b) - topology info - takes ECX as input. ignore. */
/* CPUID(d) - XCR0 stuff - takes ECX as input. We only warn about the main level (ECX=0) for now. */
("CPUM: Standard leaf D was present on saved state host, not present on current.\n"));
{
}
/* CPUID(0x80000000) - same as CPUID(0) except for eax.
will verify them as if it's an AMD CPU. */
CPUID_CHECK_RET( (aHostRawExt[0].eax >= UINT32_C(0x80000001) && aHostRawExt[0].eax <= UINT32_C(0x8000007f))
(N_("Extended leaves was present on saved state host, but is missing on the current\n")));
{
(N_("CPU vendor mismatch: host='%.4s%.4s%.4s' saved='%.4s%.4s%.4s'"),
/* CPUID(0x80000001).eax - same as CPUID(0).eax. */
CPUID_CHECK2_RET("CPU family", ASMGetCpuFamily(aHostRawExt[1].eax), ASMGetCpuFamily(aRawExt[1].eax));
CPUID_CHECK2_RET("CPU model", ASMGetCpuModel(aHostRawExt[1].eax, fIntel), ASMGetCpuModel(aRawExt[1].eax, fIntel));
CPUID_CHECK2_WRN("Reserved bits 15:14", (aHostRawExt[1].eax >> 14) & 3, (aRawExt[1].eax >> 14) & 3 );
/* CPUID(0x80000001).ebx - Brand ID (maybe), just warn if things differs. */
CPUID_CHECK2_WRN("Reserved bits 16:27", (aHostRawExt[1].ebx >> 16) & 0xfff, (aRawExt[1].ebx >> 16) & 0xfff);
/* CPUID(0x80000001).ecx */
/* CPUID(0x80000001).edx */
/** @todo verify the rest as well. */
}
}
/*
* Verify that we can support the features already exposed to the guest on
* this host.
*
* Most of the features we're emulating requires intercepting instruction
* and doing it the slow way, so there is no need to warn when they aren't
* present in the host CPU. Thus we use IGN instead of EMU on these.
*
* Trailing comments:
* "EMU" - Possible to emulate, could be lots of work and very slow.
* "EMU?" - Can this be emulated?
*/
/* CPUID(1).ecx */
/* CPUID(1).edx */
/* CPUID(0x80000000). */
{
/** @todo deal with no 0x80000001 on the host. */
bool const fGuestAmd = ASMIsAmdCpuEx(aGuestCpuIdExt[0].ebx, aGuestCpuIdExt[0].ecx, aGuestCpuIdExt[0].edx);
/* CPUID(0x80000001).ecx */
/* CPUID(0x80000001).edx */
}
/*
* We're good, commit the CPU ID leaves.
*/
return VINF_SUCCESS;
}
/**
* Pass 0 live exec callback.
*
* @returns VINF_SSM_DONT_CALL_AGAIN.
* @param pVM The VM handle.
* @param pSSM The saved state handle.
* @param uPass The pass (0).
*/
{
return VINF_SSM_DONT_CALL_AGAIN;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Save.
*/
{
}
{
}
return VINF_SUCCESS;
}
/**
* Load a version 1.6 CPUMCTX structure.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pCpumctx16 Version 1.6 CPUMCTX
*/
{
#define CPUMCTX16_LOADREG(RegName) \
#define CPUMCTX16_LOADDRXREG(RegName) \
#define CPUMCTX16_LOADHIDREG(RegName) \
#define CPUMCTX16_LOADSEGREG(RegName) \
}
/**
* @copydoc FNSSMINTLOADPREP
*/
{
return VINF_SUCCESS;
}
/**
* @copydoc FNSSMINTLOADEXEC
*/
static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
/*
* Validate version.
*/
if ( uVersion != CPUM_SAVED_STATE_VERSION
{
}
if (uPass == SSM_PASS_FINAL)
{
/*
* Set the size of RTGCPTR for SSMR3GetGCPtr. (Only necessary for
* really old SSM file versions.)
*/
else if (uVersion <= CPUM_SAVED_STATE_VERSION_VER3_0)
/*
* Restore.
*/
{
}
{
/* Save the old cpumctx state into the new one. */
}
else
{
{
AssertLogRelMsgReturn(cCpus == pVM->cCpus, ("Mismatching CPU counts: saved: %u; configured: %u \n", cCpus, pVM->cCpus),
}
{
}
}
/* Older states does not set CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID for
raw-mode guest, so we have to do it ourselves. */
&& !HWACCMIsEnabled(pVM))
}
/*
* Guest CPUIDs.
*/
/** @todo Merge the code below into cpumR3LoadCpuId when we've found out what is
* actually required. */
/*
* Restore the CPUID leaves.
*
* Note that we support restoring less than the current amount of standard
* leaves because we've been allowed more is newer version of VBox.
*/
/*
* Check that the basic cpuid id information is unchanged.
*/
/** @todo we should check the 64 bits capabilities too! */
if (RT_SUCCESS(rc))
{
/* Ignore CPU stepping. */
/* Ignore APIC ID (AMD specs). */
/* Ignore the number of Logical CPUs (AMD specs). */
/* Ignore some advanced capability bits, that we don't expose to the guest. */
);
);
/* Make sure we don't forget to update the masks when enabling
* features in the future.
*/
)));
/* do the compare */
{
LogRel(("cpumR3LoadExec: CpuId mismatch! (ignored due to SSMAFTER_DEBUG_IT)\n"
"Saved=%.*Rhxs\n"
"Real =%.*Rhxs\n",
sizeof(au32CpuIdSaved), au32CpuIdSaved,
else
{
LogRel(("cpumR3LoadExec: CpuId mismatch!\n"
"Saved=%.*Rhxs\n"
"Real =%.*Rhxs\n",
sizeof(au32CpuIdSaved), au32CpuIdSaved,
}
}
}
return rc;
}
/**
* @copydoc FNSSMINTLOADPREP
*/
{
return VINF_SUCCESS;
/* just check this since we can. */ /** @todo Add a SSM unit flag for indicating that it's mandatory during a restore. */
{
LogRel(("CPUM: Missing state!\n"));
return VERR_INTERNAL_ERROR_2;
}
/* Notify PGM of the NXE states in case they've changed. */
PGMNotifyNxeChanged(&pVM->aCpus[iCpu], !!(pVM->aCpus[iCpu].cpum.s.Guest.msrEFER & MSR_K6_EFER_NXE));
return VINF_SUCCESS;
}
/**
* Checks if the CPUM state restore is still pending.
*
* @returns true / false.
* @param pVM The VM handle.
*/
{
}
/**
* Formats the EFLAGS value into mnemonics.
*
* @param pszEFlags Where to write the mnemonics. (Assumes sufficient buffer space.)
* @param efl The EFLAGS value.
*/
{
/*
* Format the flags.
*/
static const struct
{
} s_aFlags[] =
{
};
for (unsigned i = 0; i < RT_ELEMENTS(s_aFlags); i++)
{
if (pszAdd)
{
*psz++ = ' ';
}
}
}
/**
* Formats a full register dump.
*
* @param pVM VM Handle.
* @param pCtx The context to format.
* @param pCtxCore The context core to format.
* @param pHlp Output functions.
* @param enmType The dump type.
* @param pszPrefix Register name prefix.
*/
static void cpumR3InfoOne(PVM pVM, PCPUMCTX pCtx, PCCPUMCTXCORE pCtxCore, PCDBGFINFOHLP pHlp, CPUMDUMPTYPE enmType, const char *pszPrefix)
{
/*
* Format the EFLAGS.
*/
char szEFlags[80];
/*
* Format the registers.
*/
switch (enmType)
{
case CPUMDUMPTYPE_TERSE:
if (CPUMIsGuestIn64BitCodeEx(pCtx))
"%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
"%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
"%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
"%sr14=%016RX64 %sr15=%016RX64\n"
"%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
"%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
else
"%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
"%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
"%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
break;
case CPUMDUMPTYPE_DEFAULT:
if (CPUMIsGuestIn64BitCodeEx(pCtx))
"%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
"%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
"%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
"%sr14=%016RX64 %sr15=%016RX64\n"
"%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
"%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
"%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%016RX64:%04x %sldtr=%04x\n"
,
pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtx->tr, pszPrefix, efl,
else
"%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
"%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
"%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
"%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%08RX64:%04x %sldtr=%04x\n"
,
pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtx->tr, pszPrefix, efl,
break;
case CPUMDUMPTYPE_VERBOSE:
if (CPUMIsGuestIn64BitCodeEx(pCtx))
"%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
"%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
"%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
"%sr14=%016RX64 %sr15=%016RX64\n"
"%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
"%scs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%sds={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%ses={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%sfs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%sgs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%sss={%04x base=%016RX64 limit=%08x flags=%08x}\n"
"%scr0=%016RX64 %scr2=%016RX64 %scr3=%016RX64 %scr4=%016RX64\n"
"%sdr0=%016RX64 %sdr1=%016RX64 %sdr2=%016RX64 %sdr3=%016RX64\n"
"%sdr4=%016RX64 %sdr5=%016RX64 %sdr6=%016RX64 %sdr7=%016RX64\n"
"%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
"%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"%sSysEnter={cs=%04llx eip=%016RX64 esp=%016RX64}\n"
,
pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
else
"%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
"%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
"%scs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr0=%08RX64 %sdr1=%08RX64\n"
"%sds={%04x base=%016RX64 limit=%08x flags=%08x} %sdr2=%08RX64 %sdr3=%08RX64\n"
"%ses={%04x base=%016RX64 limit=%08x flags=%08x} %sdr4=%08RX64 %sdr5=%08RX64\n"
"%sfs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr6=%08RX64 %sdr7=%08RX64\n"
"%sgs={%04x base=%016RX64 limit=%08x flags=%08x} %scr0=%08RX64 %scr2=%08RX64\n"
"%sss={%04x base=%016RX64 limit=%08x flags=%08x} %scr3=%08RX64 %scr4=%08RX64\n"
"%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
"%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
"%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
,
pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u64Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u, pszPrefix, pCtx->dr[0], pszPrefix, pCtx->dr[1],
pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u64Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u, pszPrefix, pCtx->dr[2], pszPrefix, pCtx->dr[3],
pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u64Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u, pszPrefix, pCtx->dr[4], pszPrefix, pCtx->dr[5],
pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u64Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u, pszPrefix, pCtx->dr[6], pszPrefix, pCtx->dr[7],
pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u64Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u, pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2,
pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u64Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
"%sFCW=%04x %sFSW=%04x %sFTW=%04x %sFOP=%04x %sMXCSR=%08x %sMXCSR_MASK=%08x\n"
"%sFPUIP=%08x %sCS=%04x %sRsrvd1=%04x %sFPUDP=%08x %sDS=%04x %sRsvrd2=%04x\n"
,
pszPrefix, pCtx->fpu.FCW, pszPrefix, pCtx->fpu.FSW, pszPrefix, pCtx->fpu.FTW, pszPrefix, pCtx->fpu.FOP,
);
{
/** @todo This isn't entirenly correct and needs more work! */
"%sST(%u)=%sFPR%u={%04RX16'%08RX32'%08RX32} t%d %c%u.%022llu ^ %u",
else
}
iXMM & 1
? "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32\n"
: "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32 ",
"%sEFER =%016RX64\n"
"%sPAT =%016RX64\n"
"%sSTAR =%016RX64\n"
"%sCSTAR =%016RX64\n"
"%sLSTAR =%016RX64\n"
"%sSFMASK =%016RX64\n"
"%sKERNELGSBASE =%016RX64\n",
break;
}
}
/**
* Display all cpu states and any other cpum info.
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs Arguments, ignored.
*/
{
}
/**
* Parses the info argument.
*
* The argument starts with 'verbose', 'terse' or 'default' and then
* continues with the comment string.
*
* @param pszArgs The pointer to the argument string.
* @param penmType Where to store the dump type request.
* @param ppszComment Where to store the pointer to the comment string.
*/
static void cpumR3InfoParseArg(const char *pszArgs, CPUMDUMPTYPE *penmType, const char **ppszComment)
{
if (!pszArgs)
{
*ppszComment = "";
}
else
{
{
pszArgs += 5;
}
{
pszArgs += 5;
}
{
pszArgs += 7;
}
else
}
}
/**
* Display the guest cpu state.
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs Arguments, ignored.
*/
{
const char *pszComment;
/* @todo SMP support! */
if (!pVCpu)
}
/**
* Display the current guest instruction
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs Arguments, ignored.
*/
{
char szInstruction[256];
/* @todo SMP support! */
if (!pVCpu)
if (RT_SUCCESS(rc))
}
/**
* Display the hypervisor cpu state.
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs Arguments, ignored.
*/
{
const char *pszComment;
/* @todo SMP */
pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
}
/**
* Display the host cpu state.
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs Arguments, ignored.
*/
{
const char *pszComment;
/*
* Format the EFLAGS.
*/
/* @todo SMP */
#if HC_ARCH_BITS == 32
#else
#endif
char szEFlags[80];
/*
* Format the registers.
*/
#if HC_ARCH_BITS == 32
# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
# endif
{
"eax=xxxxxxxx ebx=%08x ecx=xxxxxxxx edx=xxxxxxxx esi=%08x edi=%08x\n"
"eip=xxxxxxxx esp=%08x ebp=%08x iopl=%d %31s\n"
"cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
"cr0=%08RX64 cr2=xxxxxxxx cr3=%08RX64 cr4=%08RX64 gdtr=%08x:%04x ldtr=%04x\n"
"dr[0]=%08RX64 dr[1]=%08RX64x dr[2]=%08RX64 dr[3]=%08RX64x dr[6]=%08RX64 dr[7]=%08RX64\n"
"SysEnter={cs=%04x eip=%08x esp=%08x}\n"
,
}
# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
else
# endif
#endif
{
"rax=xxxxxxxxxxxxxxxx rbx=%016RX64 rcx=xxxxxxxxxxxxxxxx\n"
"rdx=xxxxxxxxxxxxxxxx rsi=%016RX64 rdi=%016RX64\n"
"rip=xxxxxxxxxxxxxxxx rsp=%016RX64 rbp=%016RX64\n"
" r8=xxxxxxxxxxxxxxxx r9=xxxxxxxxxxxxxxxx r10=%016RX64\n"
"r11=%016RX64 r12=%016RX64 r13=%016RX64\n"
"r14=%016RX64 r15=%016RX64\n"
"iopl=%d %31s\n"
"cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08RX64\n"
"cr0=%016RX64 cr2=xxxxxxxxxxxxxxxx cr3=%016RX64\n"
"cr4=%016RX64 ldtr=%04x tr=%04x\n"
"dr[0]=%016RX64 dr[1]=%016RX64 dr[2]=%016RX64\n"
"dr[3]=%016RX64 dr[6]=%016RX64 dr[7]=%016RX64\n"
"gdtr=%016RX64:%04x idtr=%016RX64:%04x\n"
"SysEnter={cs=%04x eip=%08x esp=%08x}\n"
"FSbase=%016RX64 GSbase=%016RX64 efer=%08RX64\n"
,
}
#endif
}
/**
* Get L1 cache / TLS associativity.
*/
static const char *getCacheAss(unsigned u, char *pszBuf)
{
if (u == 0)
return "res0 ";
if (u == 1)
return "direct";
if (u == 255)
return "fully";
if (u >= 256)
return "???";
return pszBuf;
}
/**
* Get L2 cache associativity.
*/
const char *getL2CacheAss(unsigned u)
{
switch (u)
{
case 0: return "off ";
case 1: return "direct";
case 2: return "2 way ";
case 3: return "res3 ";
case 4: return "4 way ";
case 5: return "res5 ";
case 6: return "8 way ";
case 7: return "res7 ";
case 8: return "16 way";
case 9: return "res9 ";
case 10: return "res10 ";
case 11: return "res11 ";
case 12: return "res12 ";
case 13: return "res13 ";
case 14: return "res14 ";
case 15: return "fully ";
default: return "????";
}
}
/**
* Display the guest CpuId leaves.
*
* @param pVM VM Handle.
* @param pHlp The info helper functions.
* @param pszArgs "terse", "default" or "verbose".
*/
{
/*
* Parse the argument.
*/
unsigned iVerbosity = 1;
if (pszArgs)
{
iVerbosity--;
iVerbosity++;
}
/*
* Start cracking.
*/
" RAW Standard CPUIDs\n"
" Function eax ebx ecx edx\n");
{
"Gst: %08x %08x %08x %08x %08x%s\n"
"Hst: %08x %08x %08x %08x\n",
}
/*
* If verbose, decode it.
*/
if (iVerbosity)
{
"Name: %.04s%.04s%.04s\n"
"Supports: 0-%x\n",
}
/*
* Get Features.
*/
{
"Family: %d \tExtended: %d \tEffective: %d\n"
"Model: %d \tExtended: %d \tEffective: %d\n"
"Stepping: %d\n"
"Type: %d (%s)\n"
"APIC ID: %#04x\n"
"Logical CPUs: %d\n"
"CLFLUSH Size: %d\n"
"Brand ID: %#04x\n",
if (iVerbosity == 1)
{
}
else
{
pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", EdxGuest.u1VME, EdxHost.u1VME);
pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", EdxGuest.u1PAE, EdxHost.u1PAE);
pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", EdxGuest.u1MTRR, EdxHost.u1MTRR);
pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", EdxGuest.u1MCA, EdxHost.u1MCA);
pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", EdxGuest.u1CMOV, EdxHost.u1CMOV);
pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", EdxGuest.u1PSE36, EdxHost.u1PSE36);
pHlp->pfnPrintf(pHlp, "CLFSH - CLFLUSH Instruction. = %d (%d)\n", EdxGuest.u1CLFSH, EdxHost.u1CLFSH);
pHlp->pfnPrintf(pHlp, "ACPI - Thermal Mon. & Soft. Clock Ctrl.= %d (%d)\n", EdxGuest.u1ACPI, EdxHost.u1ACPI);
pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", EdxGuest.u1FXSR, EdxHost.u1FXSR);
pHlp->pfnPrintf(pHlp, "HTT - Hyper-Threading Technology = %d (%d)\n", EdxGuest.u1HTT, EdxHost.u1HTT);
pHlp->pfnPrintf(pHlp, "CPL-DS - CPL Qualified Debug Store = %d (%d)\n", EcxGuest.u1CPLDS, EcxHost.u1CPLDS);
pHlp->pfnPrintf(pHlp, "VMX - Virtual Machine Technology = %d (%d)\n", EcxGuest.u1VMX, EcxHost.u1VMX);
pHlp->pfnPrintf(pHlp, "Supplemental SSE3 instructions = %d (%d)\n", EcxGuest.u1SSSE3, EcxHost.u1SSSE3);
pHlp->pfnPrintf(pHlp, "xTPR Update Control = %d (%d)\n", EcxGuest.u1TPRUpdate, EcxHost.u1TPRUpdate);
pHlp->pfnPrintf(pHlp, "PCID - Process-context identifiers = %d (%d)\n", EcxGuest.u1PCID, EcxHost.u1PCID);
pHlp->pfnPrintf(pHlp, "SSE4.1 instruction extensions = %d (%d)\n", EcxGuest.u1SSE4_1, EcxHost.u1SSE4_1);
pHlp->pfnPrintf(pHlp, "SSE4.2 instruction extensions = %d (%d)\n", EcxGuest.u1SSE4_2, EcxHost.u1SSE4_2);
pHlp->pfnPrintf(pHlp, "Supports the x2APIC extensions = %d (%d)\n", EcxGuest.u1x2APIC, EcxHost.u1x2APIC);
pHlp->pfnPrintf(pHlp, "TSC-Deadline LAPIC timer mode = %d (%d)\n", EcxGuest.u1TSCDEADLINE,EcxHost.u1TSCDEADLINE);
pHlp->pfnPrintf(pHlp, "XSAVE/XRSTOR extended state feature = %d (%d)\n", EcxGuest.u1XSAVE, EcxHost.u1XSAVE);
pHlp->pfnPrintf(pHlp, "31 - Reserved (always 0) = %d (%d)\n", EcxGuest.u1Reserved4, EcxHost.u1Reserved4);
}
}
{
/** @todo */
}
/*
* Extended.
* Implemented after AMD specs.
*/
"\n"
" RAW Extended CPUIDs\n"
" Function eax ebx ecx edx\n");
{
"Gst: %08x %08x %08x %08x %08x%s\n"
"Hst: %08x %08x %08x %08x\n",
}
/*
* Understandable output
*/
if (iVerbosity)
{
"Ext Name: %.4s%.4s%.4s\n"
"Ext Supports: 0x80000000-%#010x\n",
}
{
"Family: %d \tExtended: %d \tEffective: %d\n"
"Model: %d \tExtended: %d \tEffective: %d\n"
"Stepping: %d\n"
"Brand ID: %#05x\n",
if (iVerbosity == 1)
{
}
else
{
pHlp->pfnPrintf(pHlp, "FPU - x87 FPU on Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
pHlp->pfnPrintf(pHlp, "DE - Debugging extensions = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
pHlp->pfnPrintf(pHlp, "PSE - Page Size Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
pHlp->pfnPrintf(pHlp, "TSC - Time Stamp Counter = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
pHlp->pfnPrintf(pHlp, "MSR - K86 Model Specific Registers = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
pHlp->pfnPrintf(pHlp, "MCE - Machine Check Exception = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
pHlp->pfnPrintf(pHlp, "CX8 - CMPXCHG8B instruction = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
pHlp->pfnPrintf(pHlp, "APIC - APIC On-Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
pHlp->pfnPrintf(pHlp, "10 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
pHlp->pfnPrintf(pHlp, "SEP - SYSCALL and SYSRET = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
pHlp->pfnPrintf(pHlp, "PGE - PTE Global Bit = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", !!(uEdxGst & RT_BIT(14)), !!(uEdxHst & RT_BIT(14)));
pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(15)), !!(uEdxHst & RT_BIT(15)));
pHlp->pfnPrintf(pHlp, "PAT - Page Attribute Table = %d (%d)\n", !!(uEdxGst & RT_BIT(16)), !!(uEdxHst & RT_BIT(16)));
pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", !!(uEdxGst & RT_BIT(17)), !!(uEdxHst & RT_BIT(17)));
pHlp->pfnPrintf(pHlp, "18 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(18)), !!(uEdxHst & RT_BIT(18)));
pHlp->pfnPrintf(pHlp, "19 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(19)), !!(uEdxHst & RT_BIT(19)));
pHlp->pfnPrintf(pHlp, "NX - No-Execute Page Protection = %d (%d)\n", !!(uEdxGst & RT_BIT(20)), !!(uEdxHst & RT_BIT(20)));
pHlp->pfnPrintf(pHlp, "DS - Debug Store = %d (%d)\n", !!(uEdxGst & RT_BIT(21)), !!(uEdxHst & RT_BIT(21)));
pHlp->pfnPrintf(pHlp, "AXMMX - AMD Extensions to MMX Instr. = %d (%d)\n", !!(uEdxGst & RT_BIT(22)), !!(uEdxHst & RT_BIT(22)));
pHlp->pfnPrintf(pHlp, "MMX - Intel MMX Technology = %d (%d)\n", !!(uEdxGst & RT_BIT(23)), !!(uEdxHst & RT_BIT(23)));
pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(24)), !!(uEdxHst & RT_BIT(24)));
pHlp->pfnPrintf(pHlp, "25 - AMD fast FXSAVE and FXRSTOR Instr.= %d (%d)\n", !!(uEdxGst & RT_BIT(25)), !!(uEdxHst & RT_BIT(25)));
pHlp->pfnPrintf(pHlp, "26 - 1 GB large page support = %d (%d)\n", !!(uEdxGst & RT_BIT(26)), !!(uEdxHst & RT_BIT(26)));
pHlp->pfnPrintf(pHlp, "27 - RDTSCP instruction = %d (%d)\n", !!(uEdxGst & RT_BIT(27)), !!(uEdxHst & RT_BIT(27)));
pHlp->pfnPrintf(pHlp, "28 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(28)), !!(uEdxHst & RT_BIT(28)));
pHlp->pfnPrintf(pHlp, "29 - AMD Long Mode = %d (%d)\n", !!(uEdxGst & RT_BIT(29)), !!(uEdxHst & RT_BIT(29)));
pHlp->pfnPrintf(pHlp, "30 - AMD Extensions to 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(30)), !!(uEdxHst & RT_BIT(30)));
pHlp->pfnPrintf(pHlp, "31 - AMD 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(31)), !!(uEdxHst & RT_BIT(31)));
pHlp->pfnPrintf(pHlp, "LahfSahf - LAHF/SAHF in 64-bit mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 0)), !!(uEcxHst & RT_BIT( 0)));
pHlp->pfnPrintf(pHlp, "CmpLegacy - Core MP legacy mode (depr) = %d (%d)\n", !!(uEcxGst & RT_BIT( 1)), !!(uEcxHst & RT_BIT( 1)));
pHlp->pfnPrintf(pHlp, "SVM - AMD VM Extensions = %d (%d)\n", !!(uEcxGst & RT_BIT( 2)), !!(uEcxHst & RT_BIT( 2)));
pHlp->pfnPrintf(pHlp, "APIC registers starting at 0x400 = %d (%d)\n", !!(uEcxGst & RT_BIT( 3)), !!(uEcxHst & RT_BIT( 3)));
pHlp->pfnPrintf(pHlp, "AltMovCR8 - LOCK MOV CR0 means MOV CR8 = %d (%d)\n", !!(uEcxGst & RT_BIT( 4)), !!(uEcxHst & RT_BIT( 4)));
pHlp->pfnPrintf(pHlp, "Advanced bit manipulation = %d (%d)\n", !!(uEcxGst & RT_BIT( 5)), !!(uEcxHst & RT_BIT( 5)));
pHlp->pfnPrintf(pHlp, "SSE4A instruction support = %d (%d)\n", !!(uEcxGst & RT_BIT( 6)), !!(uEcxHst & RT_BIT( 6)));
pHlp->pfnPrintf(pHlp, "Misaligned SSE mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 7)), !!(uEcxHst & RT_BIT( 7)));
pHlp->pfnPrintf(pHlp, "PREFETCH and PREFETCHW instruction = %d (%d)\n", !!(uEcxGst & RT_BIT( 8)), !!(uEcxHst & RT_BIT( 8)));
pHlp->pfnPrintf(pHlp, "OS visible workaround = %d (%d)\n", !!(uEcxGst & RT_BIT( 9)), !!(uEcxHst & RT_BIT( 9)));
pHlp->pfnPrintf(pHlp, "Instruction based sampling = %d (%d)\n", !!(uEcxGst & RT_BIT(10)), !!(uEcxHst & RT_BIT(10)));
pHlp->pfnPrintf(pHlp, "SSE5 support = %d (%d)\n", !!(uEcxGst & RT_BIT(11)), !!(uEcxHst & RT_BIT(11)));
pHlp->pfnPrintf(pHlp, "SKINIT, STGI, and DEV support = %d (%d)\n", !!(uEcxGst & RT_BIT(12)), !!(uEcxHst & RT_BIT(12)));
pHlp->pfnPrintf(pHlp, "Watchdog timer support. = %d (%d)\n", !!(uEcxGst & RT_BIT(13)), !!(uEcxHst & RT_BIT(13)));
}
}
{
if (cExtMax >= 3)
{
}
if (cExtMax >= 4)
{
}
}
{
char sz1[32];
char sz2[32];
"TLB 2/4M Data: %s %3d entries\n",
"TLB 4K Data: %s %3d entries\n",
"L1 Instr Cache Lines Per Tag: %d\n"
"L1 Instr Cache Associativity: %s\n"
"L1 Instr Cache Size: %d KB\n",
(uEDX >> 0) & 0xff,
"L1 Data Cache Line Size: %d bytes\n"
"L1 Data Cache Lines Per Tag: %d\n"
"L1 Data Cache Associativity: %s\n"
"L1 Data Cache Size: %d KB\n",
(uECX >> 0) & 0xff,
}
{
"L2 TLB 2/4M Data: %s %4d entries\n",
"L2 TLB 4K Data: %s %4d entries\n",
"L2 Cache Line Size: %d bytes\n"
"L2 Cache Lines Per Tag: %d\n"
"L2 Cache Associativity: %s\n"
"L2 Cache Size: %d KB\n",
(uEDX >> 0) & 0xff,
}
{
}
{
"Physical Address Width: %d bits\n"
"Virtual Address Width: %d bits\n"
"Guest Physical Address Width: %d bits\n",
(uEAX >> 0) & 0xff,
"Physical Core Count: %d\n",
(uECX >> 0) & 0xff);
}
/*
* Centaur.
*/
"\n"
" RAW Centaur CPUIDs\n"
" Function eax ebx ecx edx\n");
{
"Gst: %08x %08x %08x %08x %08x%s\n"
"Hst: %08x %08x %08x %08x\n",
}
/*
* Understandable output
*/
if (iVerbosity)
{
"Centaur Supports: 0xc0000000-%#010x\n",
}
{
if (iVerbosity == 1)
{
}
else
{
pHlp->pfnPrintf(pHlp, "AIS - Alternate Instruction Set = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
pHlp->pfnPrintf(pHlp, "AIS-E - AIS enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
pHlp->pfnPrintf(pHlp, "RNG - Random Number Generator = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
pHlp->pfnPrintf(pHlp, "RNG-E - RNG enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
pHlp->pfnPrintf(pHlp, "LH - LongHaul MSR 0000_110Ah = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
pHlp->pfnPrintf(pHlp, "FEMMS - FEMMS = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
pHlp->pfnPrintf(pHlp, "ACE - Advanced Cryptography Engine = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
pHlp->pfnPrintf(pHlp, "ACE-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
pHlp->pfnPrintf(pHlp, "ACE2 - Advanced Cryptography Engine 2 = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
pHlp->pfnPrintf(pHlp, "ACE2-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
pHlp->pfnPrintf(pHlp, "PHE - Hash Engine = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
pHlp->pfnPrintf(pHlp, "PHE-E - PHE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
pHlp->pfnPrintf(pHlp, "PMM - Montgomery Multiplier = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
pHlp->pfnPrintf(pHlp, "PMM-E - PMM enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
pHlp->pfnPrintf(pHlp, "Bit %d = %d (%d)\n", !!(uEdxGst & RT_BIT(iBit)), !!(uEdxHst & RT_BIT(iBit)));
}
}
}
/**
* Structure used when disassembling and instructions in DBGF.
* This is used so the reader function can get the stuff it needs.
*/
typedef struct CPUMDISASSTATE
{
/** Pointer to the CPU structure. */
/** The VM handle. */
/** The VMCPU handle. */
/** Pointer to the first byte in the segment. */
/** Pointer to the byte after the end of the segment. (might have wrapped!) */
/** The size of the segment minus 1. */
/** Pointer to the current page - R3 Ptr. */
void const *pvPageR3;
/** Pointer to the current page - GC Ptr. */
/** The lock information that PGMPhysReleasePageMappingLock needs. */
/** Whether the PageMapLock is valid or not. */
bool fLocked;
/** 64 bits mode or not. */
bool f64Bits;
/**
* Instruction reader.
*
* @returns VBox status code.
* @param PtrSrc Address to read from.
* In our case this is relative to the selector pointed to by the 2nd user argument of uDisCpu.
* @param pu8Dst Where to store the bytes.
* @param cbRead Number of bytes to read.
* @param uDisCpu Pointer to the disassembler cpu state.
* In this context it's always pointer to the Core of a DBGFDISASSTATE.
*/
static DECLCALLBACK(int) cpumR3DisasInstrRead(RTUINTPTR PtrSrc, uint8_t *pu8Dst, unsigned cbRead, void *uDisCpu)
{
for (;;)
{
/* Need to update the page translation? */
{
int rc = VINF_SUCCESS;
/* translate the address */
{
}
else
{
/* Release mapping lock previously acquired. */
rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVCpu, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
}
if (RT_FAILURE(rc))
{
return rc;
}
}
/* check the segment limit */
return VERR_OUT_OF_SELECTOR_BOUNDS;
/* calc how much we can read */
{
}
/* read and advance */
if (!cbRead)
return VINF_SUCCESS;
}
}
/**
* Disassemble an instruction and return the information in the provided structure.
*
* @returns VBox status code.
* @param pVM VM Handle
* @param pVCpu VMCPU Handle
* @param pCtx CPU context
* @param GCPtrPC Program counter (relative to CS) to disassemble from.
* @param pCpu Disassembly state
* @param pszPrefix String prefix for logging (debug only)
*
*/
VMMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu, const char *pszPrefix)
{
int rc;
/*
* Get selector information.
*/
{
{
}
else
{
if (RT_FAILURE(rc))
{
AssertMsgFailed(("SELMR3GetShadowSelectorInfo failed for %04X:%RGv rc=%d\n", pCtx->cs, GCPtrPC, rc));
return rc;
}
/*
* Validate the selector.
*/
if (RT_FAILURE(rc))
{
return rc;
}
}
}
else
{
/* real or V86 mode */
}
/*
* Disassemble the instruction.
*/
#ifndef LOG_ENABLED
if (RT_SUCCESS(rc))
{
#else
char szOutput[160];
if (RT_SUCCESS(rc))
{
/* log it */
if (pszPrefix)
else
#endif
rc = VINF_SUCCESS;
}
else
/* Release mapping lock acquired in cpumR3DisasInstrRead. */
return rc;
}
#ifdef DEBUG
/**
* Disassemble an instruction and dump it to the log
*
* @returns VBox status code.
* @param pVM VM Handle
* @param pVCpu VMCPU Handle
* @param pCtx CPU context
* @param pc GC instruction pointer
* @param pszPrefix String prefix for logging
*
* @deprecated Use DBGFR3DisasInstrCurrentLog().
*/
VMMR3DECL(void) CPUMR3DisasmInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR pc, const char *pszPrefix)
{
}
/**
* Debug helper - Saves guest context on raw mode entry (for fatal dump)
*
* @internal
*/
{
/** @todo SMP support!! */
}
#endif /* DEBUG */
/**
* API for controlling a few of the CPU features found in CR4.
*
* Currently only X86_CR4_TSD is accepted as input.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param fOr The CR4 OR mask.
* @param fAnd The CR4 AND mask.
*/
{
AssertMsgReturn((fAnd & ~(X86_CR4_TSD)) == ~(X86_CR4_TSD), ("%#x\n", fAnd), VERR_INVALID_PARAMETER);
return VINF_SUCCESS;
}
/**
* Gets a pointer to the array of standard CPUID leaves.
*
* CPUMR3GetGuestCpuIdStdMax() give the size of the array.
*
* @returns Pointer to the standard CPUID leaves (read-only).
* @param pVM The VM handle.
* @remark Intended for PATM.
*/
{
}
/**
* Gets a pointer to the array of extended CPUID leaves.
*
* CPUMGetGuestCpuIdExtMax() give the size of the array.
*
* @returns Pointer to the extended CPUID leaves (read-only).
* @param pVM The VM handle.
* @remark Intended for PATM.
*/
{
}
/**
* Gets a pointer to the array of centaur CPUID leaves.
*
* CPUMGetGuestCpuIdCentaurMax() give the size of the array.
*
* @returns Pointer to the centaur CPUID leaves (read-only).
* @param pVM The VM handle.
* @remark Intended for PATM.
*/
{
}
/**
* Gets a pointer to the default CPUID leaf.
*
* @returns Pointer to the default CPUID leaf (read-only).
* @param pVM The VM handle.
* @remark Intended for PATM.
*/
{
}
/**
* Transforms the guest CPU state to raw-ring mode.
*
* This function will change the any of the cs and ss register with DPL=0 to DPL=1.
*
* @returns VBox status. (recompiler failure)
* @param pVCpu The VMCPU handle.
* @param pCtxCore The context core (for trap usage).
* @see @ref pg_raw
*/
{
if (!pCtxCore)
/*
* Are we in Ring-0?
*/
{
/*
* Enter execution mode.
*/
/*
* Set CPL to Ring-1.
*/
}
else
{
("ring-1 code not supported\n"));
/*
* PATM takes care of IOPL and IF flags for Ring-3 and Ring-2 code as well.
*/
}
/*
* Invalidate the hidden registers.
*/
/*
* Assert sanity.
*/
Assert((pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PG | X86_CR0_WP | X86_CR0_PE)) == (X86_CR0_PG | X86_CR0_PE | X86_CR0_WP));
return VINF_SUCCESS;
}
/**
* Transforms the guest CPU state from raw-ring mode to correct values.
*
* This function will change any selector registers with DPL=1 to DPL=0.
*
* @returns Adjusted rc.
* @param pVCpu The VMCPU handle.
* @param rc Raw mode return code
* @param pCtxCore The context core (for trap usage).
* @see @ref pg_raw
*/
{
/*
* Don't leave if we've already left (in GC).
*/
return rc;
if (!pCtxCore)
AssertMsg(pCtxCore->eflags.Bits.u1VM || pCtxCore->eflags.Bits.u2IOPL < (unsigned)(pCtxCore->ss & X86_SEL_RPL),
/*
* Are we executing in raw ring-1?
*/
{
/*
* Leave execution mode.
*/
/* Not quite sure if this is really required, but shouldn't harm (too much anyways). */
/** @todo See what happens if we remove this. */
/*
* Ring-1 selector => Ring-0.
*/
}
else
{
/*
* PATM is taking care of the IOPL and IF flags for us.
*/
{
/** @todo See what happens if we remove this. */
}
}
return rc;
}
/**
* Enters REM, gets and resets the changed flags (CPUM_CHANGED_*).
*
* Only REM should ever call this function!
*
* @returns The changed flags.
* @param pVCpu The VMCPU handle.
* @param puCpl Where to return the current privilege level (CPL).
*/
{
/*
* Get the CPL first.
*/
/*
* Get and reset the flags, leaving CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID set.
*/
/** @todo change the switcher to use the fChanged flags. */
{
}
return fFlags;
}
/**
* Leaves REM and works the CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID flag.
*
* @param pVCpu The virtual CPU handle.
* @param fNoOutOfSyncSels This is @c false if there are out of sync
* registers.
*/
{
if (fNoOutOfSyncSels)
else
}