CPUMAllRegs.cpp revision d23ef84f5789f32a04282733f27a7d802cfb535f
/* $Id$ */
/** @file
* CPUM - CPU Monitor(/Manager) - Getters and Setters.
*/
/*
* Copyright (C) 2006-2015 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_CPUM
#if defined(VBOX_WITH_RAW_MODE) && !defined(IN_RING0)
#endif
#include "CPUMInternal.h"
#include <iprt/asm-amd64-x86.h>
#ifdef IN_RING3
#endif
/** Disable stack frame pointer generation here. */
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/**
* Converts a CPUMCPU::Guest pointer into a VMCPU pointer.
*
* @returns Pointer to the Virtual CPU.
* @param a_pGuestCtx Pointer to the guest context.
*/
/**
* Lazily loads the hidden parts of a selector register when using raw-mode.
*/
#if defined(VBOX_WITH_RAW_MODE) && !defined(IN_RING0)
do \
{ \
} while (0)
#else
#endif
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
/**
* Does the lazy hidden selector register loading.
*
* @param pVCpu The current Virtual CPU.
* @param pSReg The selector register to lazily load hidden parts of.
*/
{
{
/* V8086 mode - Tightly controlled environment, no question about the limit or flags. */
pSReg->Attr.n.u4Type = pSReg == &pVCpu->cpum.s.Guest.cs ? X86_SEL_TYPE_ER_ACC : X86_SEL_TYPE_RW_ACC;
/** @todo Check what the accessed bit should be (VT-x and AMD-V). */
}
{
/* Real mode - leave the limit and flags alone here, at least for now. */
}
else
{
/* Protected mode - get it from the selector descriptor tables. */
{
/** @todo see todo in iemHlpLoadNullDataSelectorProt. */
}
else
}
}
/**
* Makes sure the hidden CS and SS selector registers are valid, loading them if
* necessary.
*
* @param pVCpu The current virtual CPU.
*/
{
}
/**
* Loads a the hidden parts of a selector register.
*
* @param pVCpu The current virtual CPU.
*/
{
}
#endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
/**
* Obsolete.
*
* We don't support nested hypervisor context interrupts or traps. Life is much
* simpler when we don't. It's also slightly faster at times.
*
* @param pVM Handle to the virtual machine.
*/
{
}
/**
* Gets the pointer to the hypervisor CPU context structure of a virtual CPU.
*
* @param pVCpu Pointer to the VMCPU.
*/
{
}
{
}
{
}
{
#ifdef IN_RC
/* Update the current CR3. */
#endif
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
return VINF_SUCCESS;
}
{
}
/**
* Used by VMMR3RawRunGC to reinitialize the general raw-mode context registers,
* EFLAGS and EIP prior to resuming guest execution.
*
* All general register not given as a parameter will be set to 0. The EFLAGS
* register will be set to sane values for C/C++ code execution with interrupts
* disabled and IOPL 0.
*
* @param pVCpu The current virtual CPU.
* @param u32EIP The EIP value.
* @param u32ESP The ESP value.
* @param u32EAX The EAX value.
* @param u32EDX The EDX value.
*/
VMM_INT_DECL(void) CPUMSetHyperState(PVMCPU pVCpu, uint32_t u32EIP, uint32_t u32ESP, uint32_t u32EAX, uint32_t u32EDX)
{
}
{
}
{
}
/** @MAYBE_LOAD_DRx
* Macro for updating DRx values in raw-mode and ring-0 contexts.
*/
#ifdef IN_RING0
# ifndef VBOX_WITH_HYBRID_32BIT_KERNEL
do { \
else \
} while (0)
# else
do { \
/** @todo we're not loading the correct guest value here! */ \
} while (0)
# endif
# else
do { \
} while (0)
# endif
do { \
} while (0)
#else
#endif
{
}
{
}
{
}
{
}
{
}
{
#ifdef IN_RC
#endif
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
if (pcbLimit)
}
{
if (pcbLimit)
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
/**
* Gets the pointer to the internal CPUMCTXCORE structure.
* This is only for reading in order to save a few calls.
*
* @param pVCpu Handle to the virtual cpu.
*/
{
}
/**
* Queries the pointer to the internal CPUMCTX structure.
*
* @returns The CPUMCTX pointer.
* @param pVCpu Handle to the virtual cpu.
*/
{
}
{
#ifdef VBOX_WITH_IEM
# ifdef VBOX_WITH_RAW_MODE_NOT_R0
# endif
#endif
return VINF_SUCCESS; /* formality, consider it void. */
}
{
#ifdef VBOX_WITH_IEM
# ifdef VBOX_WITH_RAW_MODE_NOT_R0
# endif
#endif
return VINF_SUCCESS; /* formality, consider it void. */
}
{
#ifdef VBOX_WITH_IEM
# ifdef VBOX_WITH_RAW_MODE_NOT_R0
# endif
#endif
return VINF_SUCCESS; /* formality, consider it void. */
}
{
#ifdef VBOX_WITH_IEM
# ifdef VBOX_WITH_RAW_MODE_NOT_R0
if ( ( ldtr != 0
# endif
#endif
/* The caller will set more hidden bits if it has them. */
return VINF_SUCCESS; /* formality, consider it void. */
}
/**
* Set the guest CR0.
*
* When called in GC, the hyper CR0 may be updated if that is
* required. The caller only has to take special action if AM,
* WP, PG or PE changes.
*
* @returns VINF_SUCCESS (consider it void).
* @param pVCpu Handle to the virtual cpu.
* @param cr0 The new CR0 value.
*/
{
#ifdef IN_RC
/*
* Check if we need to change hypervisor CR0 because
* of math stuff.
*/
{
{
/*
* We haven't saved the host FPU state yet, so TS and MT are both set
* and EM should be reflecting the guest EM (it always does this).
*/
{
AssertMsg((HyperCR0 & (X86_CR0_TS | X86_CR0_MP)) == (X86_CR0_TS | X86_CR0_MP), ("%#x\n", HyperCR0));
HyperCR0 &= ~X86_CR0_EM;
}
# ifdef VBOX_STRICT
else
{
AssertMsg((HyperCR0 & (X86_CR0_TS | X86_CR0_MP)) == (X86_CR0_TS | X86_CR0_MP), ("%#x\n", HyperCR0));
}
# endif
}
else
{
/*
* Already saved the state, so we're just mirroring
* the guest flags.
*/
}
}
#endif /* IN_RC */
/*
* Check for changes causing TLB flushes (for REM).
* The caller is responsible for calling PGM when appropriate.
*/
/*
* Let PGM know if the WP goes from 0 to 1 (netware WP0+RO+US hack)
*/
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
/*
* The CR4.OSXSAVE bit is reflected in CPUID(1).ECX[27].
*/
if ( (cr4 & X86_CR4_OSXSAVE)
{
if (cr4 & X86_CR4_OSXSAVE)
else
}
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
{
}
{
if (pcbLimit)
}
{
if (pHidden)
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
if (RT_FAILURE(rc))
u64 = 0;
return u64;
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
switch (iReg)
{
case DISCREG_CR0:
break;
case DISCREG_CR2:
break;
case DISCREG_CR3:
break;
case DISCREG_CR4:
break;
case DISCREG_CR8:
{
if (RT_FAILURE(rc))
{
*pValue = 0;
return rc;
}
break;
}
default:
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
{
}
{
}
{
}
{
}
{
}
{
}
{
/* DR4 is an alias for DR6, and DR5 is an alias for DR7. */
iReg += 2;
return VINF_SUCCESS;
}
{
}
/**
* Looks up a CPUID leaf in the CPUID leaf array, no subleaf.
*
* @returns Pointer to the leaf if found, NULL if not.
*
* @param pVM Pointer to the cross context VM structure.
* @param uLeaf The leaf to get.
*/
{
if (iEnd)
{
unsigned iStart = 0;
for (;;)
{
{
if (i <= iStart)
return NULL;
iEnd = i;
}
{
i += 1;
if (i >= iEnd)
return NULL;
iStart = i;
}
else
{
return &paLeaves[i];
/* This shouldn't normally happen. But in case the it does due
to user configuration overrids or something, just return the
first sub-leaf. */
AssertMsgFailed(("uLeaf=%#x fSubLeafMask=%#x uSubLeaf=%#x\n",
&& i > 0
i--;
return &paLeaves[i];
}
}
}
return NULL;
}
/**
* Looks up a CPUID leaf in the CPUID leaf array.
*
* @returns Pointer to the leaf if found, NULL if not.
*
* @param pVM Pointer to the cross context VM structure.
* @param uLeaf The leaf to get.
* @param uSubLeaf The subleaf, if applicable. Just pass 0 if it
* isn't.
* @param pfExactSubLeafHit Whether we've got an exact subleaf hit or not.
*/
PCPUMCPUIDLEAF cpumCpuIdGetLeafEx(PVM pVM, uint32_t uLeaf, uint32_t uSubLeaf, bool *pfExactSubLeafHit)
{
if (iEnd)
{
unsigned iStart = 0;
for (;;)
{
{
if (i <= iStart)
return NULL;
iEnd = i;
}
{
i += 1;
if (i >= iEnd)
return NULL;
iStart = i;
}
else
{
*pfExactSubLeafHit = true;
else
{
/* Find the right subleaf. We return the last one before
uSubLeaf if we don't find an exact match. */
while ( i > 0
i--;
else
i++;
}
return &paLeaves[i];
}
}
}
*pfExactSubLeafHit = false;
return NULL;
}
/**
* Gets a CPUID leaf.
*
* @param pVCpu Pointer to the VMCPU.
* @param uLeaf The CPUID leaf to get.
* @param uSubLeaf The CPUID sub-leaf to get, if applicable.
* @param pEax Where to store the EAX value.
* @param pEbx Where to store the EBX value.
* @param pEcx Where to store the ECX value.
* @param pEdx Where to store the EDX value.
*/
{
bool fExactSubLeafHit;
if (pLeaf)
{
if (fExactSubLeafHit)
{
/*
* Deal with CPU specific information (currently only APIC ID).
*/
{
if (uLeaf == 1)
{
/* EBX: Bits 31-24: Initial APIC ID. */
/* ECX: Bit 27: CR4.OSXSAVE mirror. */
}
else if (uLeaf == 0xb)
{
/* EDX: Initial extended APIC ID. */
}
{
/* EAX: Initial extended APIC ID. */
}
else
}
}
/*
* Out of range sub-leaves aren't quite as easy and pretty as we emulate
* them here, but we do the best we can here...
*/
else
{
{
}
}
}
else
{
/*
* Different CPUs have different ways of dealing with unknown CPUID leaves.
*/
{
default:
AssertFailed();
case CPUMUNKNOWNCPUID_LAST_STD_LEAF: /* ASSUME this is executed */
case CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX: /** @todo Implement CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX */
break;
*pEbx = 0;
*pEdx = 0;
break;
}
}
Log2(("CPUMGetGuestCpuId: uLeaf=%#010x/%#010x %RX32 %RX32 %RX32 %RX32\n", uLeaf, uSubLeaf, *pEax, *pEbx, *pEcx, *pEdx));
}
/**
* Sets a CPUID feature bit.
*
* @param pVM Pointer to the VM.
* @param enmFeature The feature to set.
*/
{
switch (enmFeature)
{
/*
* Set the APIC bit in both feature masks.
*/
case CPUMCPUIDFEATURE_APIC:
if (pLeaf)
if ( pLeaf
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled APIC\n"));
break;
/*
* Set the x2APIC bit in the standard feature mask.
*/
case CPUMCPUIDFEATURE_X2APIC:
if (pLeaf)
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled x2APIC\n"));
break;
/*
* Assumes the caller knows what it's doing! (host must support these)
*/
case CPUMCPUIDFEATURE_SEP:
{
AssertMsgFailed(("ERROR: Can't turn on SEP when the host doesn't support it!!\n"));
return;
}
if (pLeaf)
break;
/*
* Assumes the caller knows what it's doing! (host must support these)
*/
case CPUMCPUIDFEATURE_SYSCALL:
if ( !pLeaf
{
#if HC_ARCH_BITS == 32
/* X86_CPUID_EXT_FEATURE_EDX_SYSCALL not set it seems in 32-bit
mode by Intel, even when the cpu is capable of doing so in
64-bit mode. Long mode requires syscall support. */
#endif
{
return;
}
}
/* Valid for both Intel and AMD CPUs, although only in 64 bits mode for Intel. */
break;
/*
* Set the PAE bit in both feature masks.
* Assumes the caller knows what it's doing! (host must support these)
*/
case CPUMCPUIDFEATURE_PAE:
{
LogRel(("CPUM: WARNING! Can't turn on PAE when the host doesn't support it!\n"));
return;
}
if (pLeaf)
if ( pLeaf
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled PAE\n"));
break;
/*
* Set the LONG MODE bit in the extended feature mask.
* Assumes the caller knows what it's doing! (host must support these)
*/
if ( !pLeaf
{
LogRel(("CPUM: WARNING! Can't turn on LONG MODE when the host doesn't support it!\n"));
return;
}
/* Valid for both Intel and AMD. */
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled LONG MODE\n"));
break;
/*
* Assumes the caller knows what it's doing! (host must support these)
*/
case CPUMCPUIDFEATURE_NX:
if ( !pLeaf
{
return;
}
/* Valid for both Intel and AMD. */
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled NX\n"));
break;
/*
* Assumes the caller knows what it's doing! (host must support this)
*/
case CPUMCPUIDFEATURE_LAHF:
if ( !pLeaf
{
return;
}
/* Valid for both Intel and AMD. */
break;
/*
* Set the page attribute table bit. This is alternative page level
* cache control that doesn't much matter when everything is
* virtualized, though it may when passing thru device memory.
*/
case CPUMCPUIDFEATURE_PAT:
if (pLeaf)
if ( pLeaf
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled PAT\n"));
break;
/*
* Set the RDTSCP support bit.
* Assumes the caller knows what it's doing! (host must support this)
*/
case CPUMCPUIDFEATURE_RDTSCP:
if ( !pLeaf
{
LogRel(("CPUM: WARNING! Can't turn on RDTSCP when the host doesn't support it!\n"));
return;
}
/* Valid for both Intel and AMD. */
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled RDTSCP.\n"));
break;
/*
* Set the Hypervisor Present bit in the standard feature mask.
*/
case CPUMCPUIDFEATURE_HVP:
if (pLeaf)
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled Hypervisor Present bit\n"));
break;
/*
* This currently includes the Present bit and MWAITBREAK bit as well.
*/
if ( !pLeaf
{
LogRel(("CPUM: WARNING! Can't turn on MWAIT Extensions when the host doesn't support it!\n"));
return;
}
/* Valid for both Intel and AMD. */
pVM->cpum.s.aGuestCpuIdPatmStd[5].uEcx = pLeaf->uEcx |= X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0;
LogRel(("CPUM: SetGuestCpuIdFeature: Enabled MWAIT Extensions.\n"));
break;
/*
* OSXSAVE - only used from CPUMSetGuestCR4.
*/
case CPUMCPUIDFEATURE_OSXSAVE:
AssertLogRelReturnVoid(pVM->cpum.s.HostFeatures.fXSaveRstor && pVM->cpum.s.HostFeatures.fOpSysXSaveRstor);
/* UNI: Special case for single CPU to make life simple for CPUMPatchHlpCpuId. */
/* SMP: Set flag indicating OSXSAVE updating (superfluous because of the APIC ID, but that's fine). */
else
break;
default:
break;
}
{
}
}
/**
* Queries a CPUID feature bit.
*
* @returns boolean for feature presence
* @param pVM Pointer to the VM.
* @param enmFeature The feature to query.
*/
{
switch (enmFeature)
{
case CPUMCPUIDFEATURE_OSXSAVE:
case CPUMCPUIDFEATURE_INVALID:
break;
}
AssertFailed();
return false;
}
/**
* Clears a CPUID feature bit.
*
* @param pVM Pointer to the VM.
* @param enmFeature The feature to clear.
*/
{
switch (enmFeature)
{
case CPUMCPUIDFEATURE_APIC:
if (pLeaf)
if ( pLeaf
Log(("CPUM: ClearGuestCpuIdFeature: Disabled APIC\n"));
break;
case CPUMCPUIDFEATURE_X2APIC:
if (pLeaf)
Log(("CPUM: ClearGuestCpuIdFeature: Disabled x2APIC\n"));
break;
case CPUMCPUIDFEATURE_PAE:
if (pLeaf)
if ( pLeaf
Log(("CPUM: ClearGuestCpuIdFeature: Disabled PAE!\n"));
break;
case CPUMCPUIDFEATURE_PAT:
if (pLeaf)
if ( pLeaf
Log(("CPUM: ClearGuestCpuIdFeature: Disabled PAT!\n"));
break;
if (pLeaf)
break;
case CPUMCPUIDFEATURE_LAHF:
if (pLeaf)
break;
case CPUMCPUIDFEATURE_RDTSCP:
if (pLeaf)
Log(("CPUM: ClearGuestCpuIdFeature: Disabled RDTSCP!\n"));
break;
case CPUMCPUIDFEATURE_HVP:
if (pLeaf)
break;
if (pLeaf)
pVM->cpum.s.aGuestCpuIdPatmStd[5].uEcx = pLeaf->uEcx &= ~(X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0);
Log(("CPUM: ClearGuestCpuIdFeature: Disabled MWAIT Extensions!\n"));
break;
/*
* OSXSAVE - only used from CPUMSetGuestCR4.
*/
case CPUMCPUIDFEATURE_OSXSAVE:
AssertLogRelReturnVoid(pVM->cpum.s.HostFeatures.fXSaveRstor && pVM->cpum.s.HostFeatures.fOpSysXSaveRstor);
/* UNI: Special case for single CPU to make life easy for CPUMPatchHlpCpuId. */
/* else: SMP: We never set the OSXSAVE bit and leaving the CONTAINS_OSXSAVE flag is fine. */
break;
default:
break;
}
{
}
}
/**
* Gets the host CPU vendor.
*
* @returns CPU vendor.
* @param pVM Pointer to the VM.
*/
{
}
/**
* Gets the CPU vendor.
*
* @returns CPU vendor.
* @param pVM Pointer to the VM.
*/
{
}
{
return CPUMRecalcHyperDRx(pVCpu, 0, false);
}
{
}
{
}
{
}
{
return VINF_SUCCESS; /* No need to recalc. */
}
{
}
{
/* DR4 is an alias for DR6, and DR5 is an alias for DR7. */
iReg += 2;
}
/**
* Recalculates the hypervisor DRx register values based on current guest
* registers and DBGF breakpoints, updating changed registers depending on the
* context.
*
* This is called whenever a guest DRx register is modified (any context) and
* when DBGF sets a hardware breakpoint (ring-3 only, rendezvous).
*
* In raw-mode context this function will reload any (hyper) DRx registers which
* comes out with a different value. It may also have to save the host debug
* registers if that haven't been done already. In this context though, we'll
* be intercepting and emulating all DRx accesses, so the hypervisor DRx values
* are only important when breakpoints are actually enabled.
*
* In ring-0 (HM) context DR0-3 will be relocated by us, while DR7 will be
* reloaded by the HM code if it changes. Further more, we will only use the
* combined register set when the VBox debugger is actually using hardware BPs,
* when it isn't we'll keep the guest DR0-3 + (maybe) DR6 loaded (DR6 doesn't
* concern us here).
*
* In ring-3 we won't be loading anything, so well calculate hypervisor values
* all the time.
*
* @returns VINF_SUCCESS.
* @param pVCpu Pointer to the VMCPU.
* @param iGstReg The guest debug register number that was modified.
* UINT8_MAX if not guest register.
* @param fForceHyper Used in HM to force hyper registers because of single
* stepping.
*/
{
/*
* Compare the DR7s first.
*
* We only care about the enabled flags. GD is virtualized when we
* dispatch the #DB, we never enable it. The DBGF DR7 value is will
* always have the LE and GE bits set, so no need to check and disable
* stuff if they're cleared like we have to for the guest DR7.
*/
uGstDr7 = 0;
else if (!(uGstDr7 & X86_DR7_LE))
uGstDr7 &= ~X86_DR7_LE_ALL;
else if (!(uGstDr7 & X86_DR7_GE))
uGstDr7 &= ~X86_DR7_GE_ALL;
#ifdef IN_RING0
fForceHyper = true;
#endif
if (( HMIsEnabled(pVCpu->CTX_SUFF(pVM)) && !fForceHyper ? uDbgfDr7 : (uGstDr7 | uDbgfDr7)) & X86_DR7_ENABLED_MASK)
{
#ifdef IN_RC
bool const fHmEnabled = false;
#endif
/*
* Ok, something is enabled. Recalc each of the breakpoints, taking
* the VM debugger ones of the guest ones. In raw-mode context we will
* not allow breakpoints with values inside the hypervisor area.
*/
/* bp 0 */
{
}
{
#ifndef IN_RING0
uNewDr0 = 0;
else
#endif
}
else
uNewDr0 = 0;
/* bp 1 */
{
}
{
#ifndef IN_RING0
uNewDr1 = 0;
else
#endif
}
else
uNewDr1 = 0;
/* bp 2 */
{
}
{
#ifndef IN_RING0
uNewDr2 = 0;
else
#endif
}
else
uNewDr2 = 0;
/* bp 3 */
{
}
{
#ifndef IN_RING0
uNewDr3 = 0;
else
#endif
}
else
uNewDr3 = 0;
/*
* Apply the updates.
*/
#ifdef IN_RC
/* Make sure to save host registers first. */
{
{
}
pVCpu->cpum.s.fUseFlags |= CPUM_USED_DEBUG_REGS_HOST | CPUM_USE_DEBUG_REGS_HYPER | CPUM_USED_DEBUG_REGS_HYPER;
/* We haven't loaded any hyper DRxes yet, so we'll have to load them all now. */
}
else
#endif
{
}
}
#ifdef IN_RING0
else if (CPUMIsGuestDebugStateActive(pVCpu))
{
/*
* Reload the register that was modified. Normally this won't happen
* as we won't intercept DRx writes when not having the hyper debug
* state loaded, but in case we do for some reason we'll simply deal
* with it.
*/
switch (iGstReg)
{
default:
}
}
#endif
else
{
/*
* No active debug state any more. In raw-mode this means we have to
* make sure DR7 has everything disabled now, if we armed it already.
* In ring-0 we might end up here when just single stepping.
*/
{
# ifdef IN_RC
# endif
ASMSetDR0(0);
ASMSetDR1(0);
ASMSetDR2(0);
ASMSetDR3(0);
}
#endif
/* Clear all the registers. */
}
Log2(("CPUMRecalcHyperDRx: fUseFlags=%#x %RGr %RGr %RGr %RGr %RGr %RGr\n",
return VINF_SUCCESS;
}
/**
* Tests if the guest has No-Execute Page Protection Enabled (NXE).
*
* @returns true if in real mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest has the Page Size Extension enabled (PSE).
*
* @returns true if in real mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
/* PAE or AMD64 implies support for big pages regardless of CR4.PSE */
}
/**
* Tests if the guest has the paging enabled (PG).
*
* @returns true if in real mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest has the paging enabled (PG).
*
* @returns true if in real mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in real mode or not.
*
* @returns true if in real mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in real or virtual 8086 mode.
*
* @returns @c true if it is, @c false if not.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in protected or not.
*
* @returns true if in protected mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in paged protected or not.
*
* @returns true if in paged protected mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in long mode or not.
*
* @returns true if in long mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* Tests if the guest is running in PAE mode or not.
*
* @returns true if in PAE mode, otherwise false.
* @param pVCpu Pointer to the VMCPU.
*/
{
/* Intel mentions EFER.LMA and EFER.LME in different parts of their spec. We shall use EFER.LMA rather
than EFER.LME as it reflects if the CPU has entered paging with EFER.LME set. */
}
/**
* Tests if the guest is running in 64 bits mode or not.
*
* @returns true if in 64 bits protected mode, otherwise false.
* @param pVCpu The current virtual CPU.
*/
{
if (!CPUMIsGuestInLongMode(pVCpu))
return false;
}
/**
* Helper for CPUMIsGuestIn64BitCodeEx that handles lazy resolving of hidden CS
* registers.
*
* @returns true if in 64 bits protected mode, otherwise false.
* @param pCtx Pointer to the current guest CPU context.
*/
{
}
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
/**
*
* @returns @c true if we've entered raw-mode and selectors with RPL=1 are
* really RPL=0, @c false if we've not (RPL=1 really is RPL=1).
* @param pVCpu The current virtual CPU.
*/
{
}
/**
* 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 Pointer to the VMCPU.
* @see @ref pg_raw
*/
{
/*
* Are we in Ring-0?
*/
{
/*
* Enter execution mode.
*/
/*
* Set CPL to Ring-1.
*/
}
else
{
# ifdef VBOX_WITH_RAW_RING1
if ( EMIsRawRing1Enabled(pVM)
{
/* Set CPL to Ring-2. */
}
# else
("ring-1 code not supported\n"));
# endif
/*
* PATM takes care of IOPL and IF flags for Ring-3 and Ring-2 code as well.
*/
}
/*
* 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 Pointer to the VMCPU.
* @param rc Raw mode return code
* @see @ref pg_raw
*/
{
/*
* Don't leave if we've already left (in RC).
*/
return rc;
AssertMsg(pCtx->eflags.Bits.u1VM || pCtx->eflags.Bits.u2IOPL < (unsigned)(pCtx->ss.Sel & 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.
*/
{
# ifdef VBOX_WITH_RAW_RING1
if ( EMIsRawRing1Enabled(pVM)
{
/* Not quite sure if this is really required, but shouldn't harm (too much anyways). */
/** @todo See what happens if we remove this. */
/*
* Ring-2 selector => Ring-1.
*/
}
else
{
# endif
/** @todo See what happens if we remove this. */
# ifdef VBOX_WITH_RAW_RING1
}
# endif
}
}
return rc;
}
#endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
/**
* Updates the EFLAGS while we're in raw-mode.
*
* @param pVCpu Pointer to the VMCPU.
* @param fEfl The new EFLAGS value.
*/
{
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
else
#endif
}
/**
* Gets the EFLAGS while we're in raw-mode.
*
* @returns The eflags.
* @param pVCpu Pointer to the current virtual CPU.
*/
{
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
#endif
}
/**
* Sets the specified changed flags (CPUM_CHANGED_*).
*
* @param pVCpu Pointer to the current virtual CPU.
*/
{
}
/**
* Checks if the CPU supports the XSAVE and XRSTOR instruction.
*
* @returns true if supported.
* @returns false if not supported.
* @param pVM Pointer to the VM.
*/
{
}
/**
* Checks if the host OS uses the SYSENTER / SYSEXIT instructions.
* @returns true if used.
* @returns false if not used.
* @param pVM Pointer to the VM.
*/
{
}
/**
* Checks if the host OS uses the SYSCALL / SYSRET instructions.
* @returns true if used.
* @returns false if not used.
* @param pVM Pointer to the VM.
*/
{
}
#ifdef IN_RC
/**
*
* @returns VBox status code.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
#endif /* !IN_RC */
/**
* @returns true if we did.
* @returns false if not.
* @param pVCpu Pointer to the VMCPU.
*/
{
}
/**
* @param pVCpu Pointer to the VMCPU.
*
* @todo r=bird: Why is this needed? Looks like a workaround for mishandled
* FPU state management.
*/
{
}
/**
* Checks if the guest debug state is active.
*
* @returns boolean
* @param pVM Pointer to the VMCPU.
*/
{
}
/**
* Checks if the guest debug state is to be made active during the world-switch
* (currently only used for the 32->64 switcher case).
*
* @returns boolean
* @param pVM Pointer to the VMCPU.
*/
{
}
/**
* Checks if the hyper debug state is active.
*
* @returns boolean
* @param pVM Pointer to the VM.
*/
{
}
/**
* Checks if the hyper debug state is to be made active during the world-switch
* (currently only used for the 32->64 switcher case).
*
* @returns boolean
* @param pVM Pointer to the VMCPU.
*/
{
}
/**
* Mark the guest's debug state as inactive.
*
* @returns boolean
* @param pVM Pointer to the VM.
* @todo This API doesn't make sense any more.
*/
{
Assert(!(pVCpu->cpum.s.fUseFlags & (CPUM_USED_DEBUG_REGS_GUEST | CPUM_USED_DEBUG_REGS_HYPER | CPUM_USED_DEBUG_REGS_HOST)));
}
/**
* Get the current privilege level of the guest.
*
* @returns CPL
* @param pVCpu Pointer to the current virtual CPU.
*/
{
/*
* CPL can reliably be found in SS.DPL (hidden regs valid) or SS if not.
*
* Note! We used to check CS.DPL here, assuming it was always equal to
* CPL even if a conforming segment was loaded. But this truned out to
* only apply to older AMD-V. With VT-x we had an ACP2 regression
* during install after a far call to ring 2 with VT-x. Then on newer
* AMD-V CPUs we have to move the VMCB.guest.u8CPL into cs.Attr.n.u2Dpl
* as well as ss.Attr.n.u2Dpl to make this (and other) code work right.
*
* So, forget CS.DPL, always use SS.DPL.
*
* Note! The SS RPL is always equal to the CPL, while the CS RPL
* isn't necessarily equal if the segment is conforming.
* See section 4.11.1 in the AMD manual.
*
* Update: Where the heck does it say CS.RPL can differ from CPL other than
* right after real->prot mode switch and when in V8086 mode? That
* section says the RPL specified in a direct transfere (call, jmp,
* ret) is not the one loaded into CS. Besides, if CS.RPL != CPL
* it would be impossible for an exception handle or the iret
* instruction to figure out whether SS:ESP are part of the frame
* or not. VBox or qemu bug must've lead to this misconception.
*
* Update2: On an AMD bulldozer system here, I've no trouble loading a null
* selector into SS with an RPL other than the CPL when CPL != 3 and
* we're in 64-bit mode. The intel dev box doesn't allow this, on
* RPL = CPL. Weird.
*/
{
{
else
{
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
# ifdef VBOX_WITH_RAW_RING1
{
if ( uCpl == 2
uCpl = 1;
else if (uCpl == 1)
uCpl = 0;
}
# else
if (uCpl == 1)
uCpl = 0;
# endif
#endif
}
}
else
}
else
uCpl = 0; /* Real mode is zero; CPL set to 3 for VT-x real-mode emulation. */
return uCpl;
}
/**
* Gets the current guest CPU mode.
*
* If paging mode is what you need, check out PGMGetGuestMode().
*
* @returns The CPU mode.
* @param pVCpu Pointer to the VMCPU.
*/
{
else
return enmMode;
}
/**
* Figure whether the CPU is currently executing 16, 32 or 64 bit code.
*
* @returns 16, 32 or 64.
* @param pVCpu The current virtual CPU.
*/
{
return 16;
{
return 16;
}
return 64;
return 32;
return 16;
}
{
return DISCPUMODE_16BIT;
{
return DISCPUMODE_16BIT;
}
return DISCPUMODE_64BIT;
return DISCPUMODE_32BIT;
return DISCPUMODE_16BIT;
}