PGMGCGst.h revision a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fc
/* $Id$ */
/** @file
* VBox - Page Manager, Guest Paging Template - Guest Context.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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.
*/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#if PGM_GST_TYPE == PGM_TYPE_32BIT
# define GST_BIG_PAGE_SIZE X86_PAGE_4M_SIZE
# define GST_PDE_PG_MASK X86_PDE_PG_MASK
# define GST_PDE4M_PG_MASK X86_PDE4M_PG_MASK
# define GST_PD_SHIFT X86_PD_SHIFT
# define GST_PD_MASK X86_PD_MASK
# define GST_PTE_PG_MASK X86_PTE_PG_MASK
# define GST_PT_SHIFT X86_PT_SHIFT
# define GST_PT_MASK X86_PT_MASK
#else
# define PGSTPTE PX86PTEPAE
# define PGSTPDE PX86PDEPAE
# define GST_BIG_PAGE_SIZE X86_PAGE_2M_SIZE
# define GST_PDE_PG_MASK X86_PDE_PAE_PG_MASK
# define GST_PDE4M_PG_MASK X86_PDE4M_PAE_PG_MASK
# define GST_PD_SHIFT X86_PD_PAE_SHIFT
# define GST_PD_MASK X86_PD_PAE_MASK
# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
# define GST_PT_SHIFT X86_PT_PAE_SHIFT
# define GST_PT_MASK X86_PT_PAE_MASK
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
PGMGCDECL(int) pgmGCGst32BitWriteHandlerCR3(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser);
PGMGCDECL(int) pgmGCGstPAEWriteHandlerCR3(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser);
PGMGCDECL(int) pgmGCGstPAEWriteHandlerPD(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser);
#if PGM_GST_TYPE == PGM_TYPE_32BIT
/**
* Write access handler for the Guest CR3 page in 32-bit mode.
*
* This will try interpret the instruction, if failure fail back to the recompiler.
* Check if the changed PDEs are marked present and conflicts with our
* mappings. If conflict, we'll switch to the host context and resolve it there
*
* @returns VBox status code (appropritate for trap handling and GC return).
* @param pVM VM Handle.
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param pvFault The fault address (cr2).
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pvUser User argument.
*/
PGMGCDECL(int) pgmGCGst32BitWriteHandlerCR3(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser)
{
/*
* Try interpret the instruction.
*/
{
/*
* Check if the modified PDEs are present and mappings.
*/
#ifdef DEBUG
Log(("pgmGCGst32BitWriteHandlerCR3: emulated change to PD %#x addr=%VGv\n", iPD1, iPD1 << X86_PD_SHIFT));
Log(("pgmGCGst32BitWriteHandlerCR3: emulated change to PD %#x addr=%VGv\n", iPD2, iPD2 << X86_PD_SHIFT));
#endif
{
)
{
if (rc == VINF_SUCCESS)
Log(("pgmGCGst32BitWriteHandlerCR3: detected conflict iPD1=%#x iPD2=%#x - returns %Rrc\n", iPD1, iPD2, rc));
return rc;
}
}
}
else
{
if (rc == VERR_EM_INTERPRETER)
}
return rc;
}
#endif /* PGM_TYPE_32BIT */
#if PGM_GST_TYPE == PGM_TYPE_PAE
/**
* Write access handler for the Guest CR3 page in PAE mode.
*
* This will try interpret the instruction, if failure fail back to the recompiler.
* Check if the changed PDEs are marked present and conflicts with our
* mappings. If conflict, we'll switch to the host context and resolve it there
*
* @returns VBox status code (appropritate for trap handling and GC return).
* @param pVM VM Handle.
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param pvFault The fault address (cr2).
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pvUser User argument.
*/
PGMGCDECL(int) pgmGCGstPAEWriteHandlerCR3(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser)
{
/*
* Try interpret the instruction.
*/
{
/*
* Check if any of the PDs have changed.
*/
for (unsigned i = 0; i < 4; i++)
{
{
/*
* The PDPE has changed.
* We will schedule a monitoring update for the next TLB Flush,
* InvalidatePage or SyncCR3.
*
* This isn't perfect, because a lazy page sync might be dealing with an half
* updated PDPE. However, we assume that the guest OS is disabling interrupts
* and being extremely careful (cmpxchg8b) when updating a PDPE where it's
* executing.
*/
Log(("pgmGCGstPaeWriteHandlerCR3: detected updated PDPE; [%d] = %#llx, Old GCPhys=%VGp\n",
}
}
}
else
{
if (rc == VERR_EM_INTERPRETER)
}
return rc;
}
/**
* Write access handler for the Guest PDs in PAE mode.
*
* This will try interpret the instruction, if failure fail back to the recompiler.
* Check if the changed PDEs are marked present and conflicts with our
* mappings. If conflict, we'll switch to the host context and resolve it there
*
* @returns VBox status code (appropritate for trap handling and GC return).
* @param pVM VM Handle.
* @param uErrorCode CPU Error code.
* @param pRegFrame Trap register frame.
* @param pvFault The fault address (cr2).
* @param GCPhysFault The GC physical address corresponding to pvFault.
* @param pvUser User argument.
*/
PGMGCDECL(int) pgmGCGstPAEWriteHandlerPD(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, RTGCPHYS GCPhysFault, void *pvUser)
{
/*
* Try interpret the instruction.
*/
{
/*
* Figure out which of the 4 PDs this is.
*/
RTGCUINTPTR i;
for (i = 0; i < 4; i++)
{
#ifdef DEBUG
Log(("pgmGCGstPaeWriteHandlerPD: emulated change to i=%d iPD1=%#05x (%VGv)\n",
Log(("pgmGCGstPaeWriteHandlerPD: emulated change to i=%d iPD2=%#05x (%VGv)\n",
#endif
{
)
{
return VINF_PGM_SYNC_CR3;
}
}
break; /* ASSUMES no duplicate entries... */
}
Assert(i < 4);
}
else
{
if (rc == VERR_EM_INTERPRETER)
else
}
return rc;
}
#endif /* PGM_TYPE_PAE */