PGMBth.h revision a04fd356c6a066fa94377352c941a49be7ab83b3
/* $Id$ */
/** @file
* VBox - Page Manager / Monitor, Shadow+Guest Paging Template.
*/
/*
* Copyright (C) 2006-2012 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.
*/
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
PGM_BTH_DECL(int, Trap0eHandler)(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, bool *pfLockTaken);
PGM_BTH_DECL(int, VerifyAccessSyncPage)(PVMCPU pVCpu, RTGCPTR Addr, unsigned fPage, unsigned uError);
PGM_BTH_DECL(unsigned, AssertCR3)(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr = 0, RTGCPTR cb = ~(RTGCPTR)0);
/**
* Initializes the both bit of the paging mode data.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
* This is used early in the init process to avoid trouble with PDM
* not being initialized yet.
*/
{
/* Ring 3 */
#ifdef VBOX_STRICT
#endif
if (fResolveGCAndR0)
{
int rc;
if (!HMIsEnabled(pVM))
{
#if PGM_SHW_TYPE != PGM_TYPE_AMD64 && PGM_SHW_TYPE != PGM_TYPE_NESTED && PGM_SHW_TYPE != PGM_TYPE_EPT /* No AMD64 for traditional virtualization, only VT-x and AMD-V. */
/* RC */
rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_BTH_NAME_RC_STR(Trap0eHandler), &pModeData->pfnRCBthTrap0eHandler);
rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_BTH_NAME_RC_STR(InvalidatePage), &pModeData->pfnRCBthInvalidatePage);
rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_BTH_NAME_RC_STR(PrefetchPage), &pModeData->pfnRCBthPrefetchPage);
rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_BTH_NAME_RC_STR(VerifyAccessSyncPage),&pModeData->pfnRCBthVerifyAccessSyncPage);
# ifdef VBOX_STRICT
# endif
#endif /* Not AMD64 shadow paging. */
}
/* Ring 0 */
rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_BTH_NAME_R0_STR(Trap0eHandler), &pModeData->pfnR0BthTrap0eHandler);
rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_BTH_NAME_R0_STR(InvalidatePage), &pModeData->pfnR0BthInvalidatePage);
rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_BTH_NAME_R0_STR(PrefetchPage), &pModeData->pfnR0BthPrefetchPage);
rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_BTH_NAME_R0_STR(VerifyAccessSyncPage),&pModeData->pfnR0BthVerifyAccessSyncPage);
#ifdef VBOX_STRICT
#endif
}
return VINF_SUCCESS;
}
/**
* Enters the shadow+guest mode.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param pVCpu Pointer to the VMCPU.
* @param GCPhysCR3 The physical address from the CR3 register.
*/
{
/* Here we deal with allocation of the root shadow page table for real and protected mode during mode switches;
*/
#if ( ( PGM_SHW_TYPE == PGM_TYPE_32BIT \
|| PGM_SHW_TYPE == PGM_TYPE_PAE \
|| PGM_SHW_TYPE == PGM_TYPE_AMD64) \
&& ( PGM_GST_TYPE == PGM_TYPE_REAL \
|| PGM_GST_TYPE == PGM_TYPE_PROT))
/* Note: we only really need shadow paging in real and protected mode for VT-x and AMD-V (excluding nested paging/EPT modes),
* but any calls to GC need a proper shadow page setup as well.
*/
/* Free the previous root mapping if still active. */
{
/* Mark the page as unlocked; allow flushing again. */
# ifndef PGM_WITHOUT_MAPPINGS
/* Remove the hypervisor mappings from the shadow page table. */
# endif
}
/* construct a fake address. */
int rc = pgmPoolAlloc(pVM, GCPhysCR3, BTH_PGMPOOLKIND_ROOT, PGMPOOLACCESS_DONTCARE, PGM_A20_IS_ENABLED(pVCpu),
if (rc == VERR_PGM_POOL_FLUSHED)
{
Log(("Bth-Enter: PGM pool flushed -> signal sync cr3\n"));
return VINF_PGM_SYNC_CR3;
}
/* Mark the page as locked; disallow flushing. */
/* Set the current hypervisor CR3. */
# ifndef PGM_WITHOUT_MAPPINGS
/* Apply all hypervisor mappings to the new CR3. */
# endif
return rc;
#else
return VINF_SUCCESS;
#endif
}
/**
* Relocate any GC pointers related to shadow mode paging.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param pVCpu Pointer to the VMCPU.
* @param offDelta The relocation offset.
*/
{
/* nothing special to do here - InitData does the job. */
return VINF_SUCCESS;
}