PGMAllPhys.cpp revision 6d9de847ae1685acb4967293c198a3448b1a797e
/* $Id$ */
/** @file
* PGM - Page Manager and Monitor, Physical Memory Addressing.
*/
/*
* 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 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.
*/
/** @def PGM_IGNORE_RAM_FLAGS_RESERVED
* Don't respect the MM_RAM_FLAGS_RESERVED flag when converting to HC addresses.
*
* Since this flag is currently incorrectly kept set for ROM regions we will
* have to ignore it for now so we don't break stuff.
*
* @todo this has been fixed now I believe, remove this hack.
*/
#define PGM_IGNORE_RAM_FLAGS_RESERVED
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM_PHYS
#include "PGMInternal.h"
#ifdef IN_RING3
#endif
/**
* Checks if Address Gate 20 is enabled or not.
*
* @returns true if enabled.
* @returns false if disabled.
* @param pVM VM handle.
*/
{
}
/**
* Validates a GC physical address.
*
* @returns true if valid.
* @returns false if invalid.
* @param pVM The VM handle.
* @param GCPhys The physical address to validate.
*/
{
}
/**
* Checks if a GC physical address is a normal page,
* i.e. not ROM, MMIO or reserved.
*
* @returns true if normal.
* @returns false if invalid, ROM, MMIO or reserved page.
* @param pVM The VM handle.
* @param GCPhys The physical address to check.
*/
{
return pPage
&& !(pPage->HCPhys & (MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO2));
}
/**
* Converts a GC physical address to a HC physical address.
*
* @returns VINF_SUCCESS on success.
* @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
* page but has no physical backing.
* @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
* GC physical address.
*
* @param pVM The VM handle.
* @param GCPhys The GC physical address to convert.
* @param pHCPhys Where to store the HC physical address on success.
*/
{
if (VBOX_FAILURE(rc))
return rc;
#ifndef PGM_IGNORE_RAM_FLAGS_RESERVED
return VERR_PGM_PHYS_PAGE_RESERVED;
#endif
return VINF_SUCCESS;
}
#ifdef NEW_PHYS_CODE
/**
* Replace a zero or shared page with new page that we can write to.
*
* @returns VBox status.
* @todo Define the return values and propagate them up the call tree..
*
* @param pVM The VM address.
* @param pPage The physical page tracking structure.
* @param GCPhys The address of the page.
*
* @remarks Called from within the PGM critical section.
*/
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Deal with pages that are not writable, i.e. not in the ALLOCATED state.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
*
* @param pVM The VM address.
* @param pPage The physical page tracking structure.
* @param GCPhys The address of the page.
*
* @remarks Called from within the PGM critical section.
*/
{
{
pPage->fWrittenTo = true;
/* fall thru */
case PGM_PAGE_STATE_ALLOCATED:
return VINF_SUCCESS;
/*
* Zero pages can be dummy pages for MMIO or reserved memory,
* so we need to check the flags before joining cause with
* shared page replacement.
*/
case PGM_PAGE_STATE_ZERO:
if ( PGM_PAGE_IS_MMIO(pPage)
return VERR_PGM_PHYS_PAGE_RESERVED;
/* fall thru */
case PGM_PAGE_STATE_SHARED:
}
}
#ifdef IN_RING3
/**
* Tree enumeration callback for dealing with age rollover.
* It will perform a simple compression of the current age.
*/
{
/* ASSMES iNow = 4 */
return 0;
}
/**
* Tree enumeration callback that updates the chunks that have
* been used since the last
*/
{
{
}
return 0;
}
/**
* Performs ageing of the ring-3 chunk mappings.
*
* @param pVM The VM handle.
*/
{
{
RTAvlU32DoWithAll(&pVM->pgm.s.R3ChunkMap.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingRolloverCallback, NULL);
}
RTAvlU32DoWithAll(&pVM->pgm.s.R3ChunkMap.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingCallback, pVM);
}
/**
* The structure passed in the pvUser argument of pgmR3PhysChunkUnmapCandidateCallback().
*/
typedef struct PGMR3PHYSCHUNKUNMAPCB
{
/**
* Callback used to find the mapping that's been unused for
* the longest time.
*/
{
do
{
{
/*
* Check that it's not in any of the TLBs.
*/
{
break;
}
if (pChunk)
{
break;
}
if (pChunk)
{
return 1; /* done */
}
}
/* next with the same age - this version of the AVL API doesn't enumerate the list, so we have to do it. */
} while (pNode);
return 0;
}
/**
* Finds a good candidate for unmapping when the ring-3 mapping cache is full.
*
* The candidate will not be part of any TLBs, so no need to flush
* anything afterwards.
*
* @returns Chunk id.
* @param pVM The VM handle.
*/
{
/*
* Do tree ageing first?
*/
/*
* Enumerate the age tree starting with the left most node.
*/
if (RTAvlU32DoWithAll(&pVM->pgm.s.R3ChunkMap.pAgeTree, true /*fFromLeft*/, pgmR3PhysChunkUnmapCandidateCallback, pVM))
return INT32_MAX;
}
/**
* Maps the given chunk into the ring-3 mapping cache.
*
* This will call ring-0.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param idChunk The chunk in question.
* @param ppChunk Where to store the chunk tracking structure.
*
* @remarks Called from within the PGM critical section.
*/
{
/*
* Allocate a new tracking structure first.
*/
#if 0 /* for later when we've got a separate mapping method for ring-0. */
PPGMCHUNKR3MAPPING pChunk = (PPGMCHUNKR3MAPPING)MMR3HeapAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk));
#else
PPGMCHUNKR3MAPPING pChunk = (PPGMCHUNKR3MAPPING)MMHyperAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk));
#endif
/*
* Request the ring-0 part to map the chunk in question and if
* necessary unmap another one to make space in the mapping cache.
*/
/** @todo SUPCallVMMR0Ex needs to support in+out or similar. */
if (VBOX_SUCCESS(rc))
{
/*
* Update the tree.
*/
/* insert the new one. */
/* remove the unmapped one. */
{
PPGMCHUNKR3MAPPING pUnmappedChunk = (PPGMCHUNKR3MAPPING)RTAvlU32Remove(&pVM->pgm.s.R3ChunkMap.Tree, Req.idChunkUnmap);
#if 0 /* for later when we've got a separate mapping method for ring-0. */
#else
#endif
}
}
else
{
#if 0 /* for later when we've got a separate mapping method for ring-0. */
#else
#endif
}
return rc;
}
#endif /* IN_RING3 */
/**
* Maps a page into the current virtual address space so it can be accessed.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
*
* @param pVM The VM address.
* @param pPage The physical page tracking structure.
* @param GCPhys The address of the page.
* @param ppMap Where to store the address of the mapping tracking structure.
* @param ppv Where to store the mapping address of the page. The page
* offset is masked off!
*
* @remarks Called from within the PGM critical section.
*/
{
#ifdef IN_GC
/*
* Just some sketchy GC code.
*/
#else /* IN_RING3 || IN_RING0 */
/**
* Calculates the index of a guest page in the Ring-3 Chunk TLB.
* @returns Chunk TLB index.
* @param idChunk The Chunk ID.
*/
/*
*/
{
}
else
{
/*
* Find the chunk, map it if necessary.
*/
if (!pChunk)
{
#ifdef IN_RING0
#else
if (VBOX_FAILURE(rc))
return rc;
#endif
}
/*
* Enter it into the Chunk TLB.
*/
}
return VINF_SUCCESS;
#endif /* IN_RING3 */
}
/**
* Calculates the index of a guest page in the Physical TLB.
* @returns Physical TLB index.
* @param GCPhys The guest physical address.
*/
# define PGMPHYSTLBE PGMR3PHYSTLBE
#else /* IN_GC */
# define PGMPHYSTLBE PGMGCPHYSTLBE
#endif
/**
* Load a guest page into the ring-3 physical TLB.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success
* @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
* @param pPGM The PGM instance pointer.
* @param GCPhys The guest physical address in question.
*/
{
/*
* Find the ram range.
* 99.8% of requests are expected to be in the first range.
*/
{
do
{
if (!pRam)
}
/*
* Map the page.
* Make a special case for the zero page as it is kind of special.
*/
{
void *pv;
if (VBOX_FAILURE(rc))
return rc;
}
else
{
}
return VINF_SUCCESS;
}
/**
* Queries the Physical TLB entry for a physical guest page,
* attemting to load the TLB entry if necessary.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success
* @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
* @param pPgm The PGM instance handle.
* @param GCPhys The address of the guest page.
* @param ppTlbe Where to store the pointer to the TLB entry.
*/
{
int rc;
{
rc = VINF_SUCCESS;
}
else
return rc;
}
#endif /* NEW_PHYS_CODE */
/**
* Requests the mapping of a guest page into the current context.
*
* This API should only be used for very short term, as it will consume
* scarse resources (R0 and GC) in the mapping cache. When you're done
* with the page, call PGMPhysGCPhys2CCPtrRelease() ASAP to release it.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
* @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
*
* @param pVM The VM handle.
* @param GCPhys The guest physical address of the page that should be mapped.
* @param ppv Where to store the address corresponding to GCPhys.
*
* @remark Avoid calling this API from within critical sections (other than
* the PGM one) because of the deadlock risk.
*/
{
# ifdef NEW_PHYS_CODE
#ifdef IN_GC
/* Until a physical TLB is implemented for GC, let PGMGCDynMapGCPageEx handle it. */
#else
/*
* Query the Physical TLB entry for the page (may fail).
*/
if (RT_SUCCESS(rc))
{
/*
* If the page is shared, the zero page, or being write monitored
* it must be converted to an page that's writable if possible.
*/
if (RT_SUCCESS(rc))
{
/*
* Now, just perform the locking and calculate the return address.
*/
{
}
}
}
return rc;
#endif /* IN_RING3 || IN_RING0 */
#else
/*
* Temporary fallback code.
*/
# ifdef IN_GC
# else
# endif
#endif
}
/**
* Release the mapping of a guest page.
*
* This is the counterpart to the PGMPhysGCPhys2CCPtr.
*
* @param pVM The VM handle.
* @param GCPhys The address that was mapped using PGMPhysGCPhys2CCPtr.
* @param pv The address that PGMPhysGCPhys2CCPtr returned.
*/
{
#ifdef NEW_PHYS_CODE
#ifdef IN_GC
/* currently nothing to do here. */
/* --- postponed
#elif defined(IN_RING0)
*/
#else /* IN_RING3 */
/*
* Try the Physical TLB cache.
* There's a high likely hood that this will work out since it's a short-term lock.
*/
{
}
else
{
/*
* Find the page and unlock it.
*/
{
do
{
}
/*
* Now find the chunk mapping and unlock it.
*/
else
{
}
}
#endif /* IN_RING3 */
#else
#endif
}
/**
* Converts a GC physical address to a HC pointer.
*
* @returns VINF_SUCCESS on success.
* @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
* page but has no physical backing.
* @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
* GC physical address.
* @returns VERR_PGM_GCPHYS_RANGE_CROSSES_BOUNDARY if the range crosses
* a dynamic ram chunk boundary
* @param pVM The VM handle.
* @param GCPhys The GC physical address to convert.
* @param cbRange Physical range
* @param pHCPtr Where to store the HC pointer on success.
*/
{
#ifdef PGM_DYNAMIC_RAM_ALLOC
{
}
#endif
if (VBOX_FAILURE(rc))
return rc;
#ifndef PGM_IGNORE_RAM_FLAGS_RESERVED
return VERR_PGM_PHYS_PAGE_RESERVED;
#endif
{
}
{
*pHCPtr = (RTHCPTR)((RTHCUINTPTR)CTXSUFF(pRam->pavHCChunk)[iChunk] + (off & PGM_DYNAMIC_CHUNK_OFFSET_MASK));
}
else
return VERR_PGM_PHYS_PAGE_RESERVED;
return VINF_SUCCESS;
}
/**
* Converts a guest pointer to a GC physical address.
*
*
* @returns VBox status code.
* @param pVM The VM Handle
* @param GCPtr The guest pointer to convert.
* @param pGCPhys Where to store the GC physical address.
*/
{
return rc;
}
/**
* Converts a guest pointer to a HC physical address.
*
*
* @returns VBox status code.
* @param pVM The VM Handle
* @param GCPtr The guest pointer to convert.
* @param pHCPhys Where to store the HC physical address.
*/
{
if (VBOX_SUCCESS(rc))
return rc;
}
/**
* Converts a guest pointer to a HC pointer.
*
*
* @returns VBox status code.
* @param pVM The VM Handle
* @param GCPtr The guest pointer to convert.
* @param pHCPtr Where to store the HC virtual address.
*/
{
if (VBOX_SUCCESS(rc))
rc = PGMPhysGCPhys2HCPtr(pVM, GCPhys | ((RTGCUINTPTR)GCPtr & PAGE_OFFSET_MASK), 1 /* we always stay within one page */, pHCPtr);
return rc;
}
/**
* Converts a guest virtual address to a HC pointer by specfied CR3 and flags.
*
* @returns VBox status code.
* @param pVM The VM Handle
* @param GCPtr The guest pointer to convert.
* @param cr3 The guest CR3.
* @param fFlags Flags used for interpreting the PD correctly: X86_CR4_PSE and X86_CR4_PAE
* @param pHCPtr Where to store the HC pointer.
*
* @remark This function is used by the REM at a time where PGM could
* potentially not be in sync. It could also be used by a
* future DBGF API to cpu state independent conversions.
*/
PGMDECL(int) PGMPhysGCPtr2HCPtrByGstCR3(PVM pVM, RTGCPTR GCPtr, uint32_t cr3, unsigned fFlags, PRTHCPTR pHCPtr)
{
/*
* PAE or 32-bit?
*/
int rc;
if (!(fFlags & X86_CR4_PAE))
{
if (VBOX_SUCCESS(rc))
{
{
{ /* (big page) */
rc = PGMPhysGCPhys2HCPtr(pVM, (Pde.u & X86_PDE4M_PG_MASK) | ((RTGCUINTPTR)GCPtr & X86_PAGE_4M_OFFSET_MASK), 1 /* we always stay within one page */, pHCPtr);
}
else
{ /* (normal page) */
if (VBOX_SUCCESS(rc))
{
return PGMPhysGCPhys2HCPtr(pVM, (Pte.u & X86_PTE_PG_MASK) | ((RTGCUINTPTR)GCPtr & PAGE_OFFSET_MASK), 1 /* we always stay within one page */, pHCPtr);
}
}
}
else
}
}
else
{
/** @todo long mode! */
if (VBOX_SUCCESS(rc))
{
{
if (VBOX_SUCCESS(rc))
{
{
{ /* (big page) */
rc = PGMPhysGCPhys2HCPtr(pVM, (Pde.u & X86_PDE4M_PAE_PG_MASK) | ((RTGCUINTPTR)GCPtr & X86_PAGE_4M_OFFSET_MASK), 1 /* we always stay within one page */, pHCPtr);
}
else
{ /* (normal page) */
if (VBOX_SUCCESS(rc))
{
return PGMPhysGCPhys2HCPtr(pVM, (Pte.u & X86_PTE_PAE_PG_MASK) | ((RTGCUINTPTR)GCPtr & PAGE_OFFSET_MASK), 1 /* we always stay within one page */, pHCPtr);
}
}
}
else
}
}
else
}
}
return rc;
}
#define LOG_GROUP LOG_GROUP_PGM_PHYS_ACCESS
#ifdef IN_RING3
/**
* Cache PGMPhys memory access
*
* @param pVM VM Handle.
* @param pCache Cache structure pointer
* @param GCPhys GC physical address
* @param pbHC HC pointer corresponding to physical page
*
* @thread EMT.
*/
{
}
#endif
/**
* Read physical memory.
*
* This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
* want to ignore those.
*
* @param pVM VM Handle.
* @param GCPhys Physical address start reading from.
* @param pvBuf Where to put the read bits.
* @param cbRead How many bytes to read.
*/
{
#ifdef IN_RING3
bool fGrabbedLock = false;
#endif
if (cbRead == 0)
return;
#ifdef IN_RING3
{
fGrabbedLock = true;
}
#endif
/*
* Copy loop on ram ranges.
*/
for (;;)
{
/* Find range. */
/* Inside range or not? */
{
/*
* Must work our way thru this page by page.
*/
{
/* Physical chunk in dynamically allocated range not present? */
{
/* Treat it as reserved; return zeros */
{
goto end;
}
}
else
{
switch (pPage->HCPhys & (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_VIRTUAL_ALL | MM_RAM_FLAGS_PHYSICAL_ALL | MM_RAM_FLAGS_ROM)) /** @todo PAGE FLAGS */
{
/*
* Normal memory or ROM.
*/
case 0:
case MM_RAM_FLAGS_ROM:
//case MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO2: /* = shadow */ - //MMIO2 isn't in the mask.
{
#ifdef IN_GC
#else
#endif
{
#if defined(IN_RING3) && defined(PGM_PHYSMEMACCESS_CACHING)
#endif /* IN_RING3 && PGM_PHYSMEMACCESS_CACHING */
goto end;
}
break;
}
/*
* All reserved, nothing there.
*/
case MM_RAM_FLAGS_RESERVED:
{
goto end;
}
break;
/*
* Physical handler.
*/
{
int rc = VINF_PGM_HANDLER_DO_DEFAULT;
#ifdef IN_RING3 /** @todo deal with this in GC and R0! */
/* find and call the handler */
PPGMPHYSHANDLER pNode = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pVM->pgm.s.pTreesHC->PhysHandlers, GCPhys);
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
}
#endif /* IN_RING3 */
if (rc == VINF_PGM_HANDLER_DO_DEFAULT)
{
#ifdef IN_GC
#else
#endif
{
goto end;
}
}
goto end;
break;
}
case MM_RAM_FLAGS_VIRTUAL_ALL:
{
int rc = VINF_PGM_HANDLER_DO_DEFAULT;
#ifdef IN_RING3 /** @todo deal with this in GC and R0! */
/* Search the whole tree for matching physical addresses (rather expensive!) */
unsigned iPage;
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
}
#endif /* IN_RING3 */
if (rc == VINF_PGM_HANDLER_DO_DEFAULT)
{
#ifdef IN_GC
#else
#endif
{
goto end;
}
}
goto end;
break;
}
/*
* The rest needs to be taken more carefully.
*/
default:
#if 1 /** @todo r=bird: Can you do this properly please. */
/** @todo Try MMIO; quick hack */
goto end;
#endif
/** @todo fix me later. */
AssertReleaseMsgFailed(("Unknown read at %VGp size %d implement the complex physical reading case %x\n",
pPage->HCPhys & (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_VIRTUAL_ALL | MM_RAM_FLAGS_PHYSICAL_ALL | MM_RAM_FLAGS_ROM))); /** @todo PAGE FLAGS */
break;
}
}
}
}
else
{
/*
* Unassigned address space.
*/
if ( !pCur
{
goto end;
}
}
}
end:
#ifdef IN_RING3
if (fGrabbedLock)
#endif
return;
}
/**
* Write to physical memory.
*
* This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
* want to ignore those.
*
* @param pVM VM Handle.
* @param GCPhys Physical address to write to.
* @param pvBuf What to write.
* @param cbWrite How many bytes to write.
*/
{
#ifdef IN_RING3
bool fGrabbedLock = false;
#endif
if (cbWrite == 0)
return;
#ifdef IN_RING3
{
fGrabbedLock = true;
}
#endif
/*
* Copy loop on ram ranges.
*/
for (;;)
{
/* Find range. */
/* Inside range or not? */
{
/*
* Must work our way thru this page by page.
*/
{
/* Physical chunk in dynamically allocated range not present? */
{
int rc;
#ifdef IN_RING3
if (fGrabbedLock)
{
if (rc == VINF_SUCCESS)
PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite); /* try again; can't assume pCur is still valid (paranoia) */
return;
}
#else
#endif
if (rc != VINF_SUCCESS)
goto end;
}
/** @todo r=bird: missing MM_RAM_FLAGS_ROM here, we shall not allow anyone to overwrite the ROM! */
switch (pPage->HCPhys & (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2 | MM_RAM_FLAGS_VIRTUAL_ALL | MM_RAM_FLAGS_VIRTUAL_WRITE | MM_RAM_FLAGS_PHYSICAL_ALL | MM_RAM_FLAGS_PHYSICAL_WRITE)) /** @todo PAGE FLAGS */
{
/*
* Normal memory, MMIO2 or writable shadow ROM.
*/
case 0:
case MM_RAM_FLAGS_MMIO2:
{
#ifdef IN_GC
#else
#endif
{
#if defined(IN_RING3) && defined(PGM_PHYSMEMACCESS_CACHING)
#endif /* IN_RING3 && PGM_PHYSMEMACCESS_CACHING */
goto end;
}
break;
}
/*
* All reserved, nothing there.
*/
case MM_RAM_FLAGS_RESERVED:
goto end;
break;
/*
* Physical handler.
*/
{
int rc = VINF_PGM_HANDLER_DO_DEFAULT;
#ifdef IN_RING3 /** @todo deal with this in GC and R0! */
/* find and call the handler */
PPGMPHYSHANDLER pNode = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pVM->pgm.s.pTreesHC->PhysHandlers, GCPhys);
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
rc = pNode->pfnHandlerR3(pVM, GCPhys, pvDst, (void *)pvBuf, cb, PGMACCESSTYPE_WRITE, pNode->pvUserR3);
}
#endif /* IN_RING3 */
if (rc == VINF_PGM_HANDLER_DO_DEFAULT)
{
#ifdef IN_GC
#else
#endif
{
goto end;
}
}
goto end;
break;
}
case MM_RAM_FLAGS_VIRTUAL_ALL:
{
int rc = VINF_PGM_HANDLER_DO_DEFAULT;
#ifdef IN_RING3
/** @todo deal with this in GC and R0! */
/* Search the whole tree for matching physical addresses (rather expensive!) */
unsigned iPage;
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
}
#endif /* IN_RING3 */
if (rc == VINF_PGM_HANDLER_DO_DEFAULT)
{
#ifdef IN_GC
#else
#endif
{
goto end;
}
}
goto end;
break;
}
/*
* Physical write handler + virtual write handler.
* Consider this a quick workaround for the CSAM + shadow caching problem.
*
* We hand it to the shadow caching first since it requires the unchanged
* data. CSAM will have to put up with it already being changed.
*/
{
int rc = VINF_PGM_HANDLER_DO_DEFAULT;
#ifdef IN_RING3 /** @todo deal with this in GC and R0! */
/* 1. The physical handler */
PPGMPHYSHANDLER pPhysNode = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pVM->pgm.s.pTreesHC->PhysHandlers, GCPhys);
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
rc = pPhysNode->pfnHandlerR3(pVM, GCPhys, pvDst, (void *)pvBuf, cb, PGMACCESSTYPE_WRITE, pPhysNode->pvUserR3);
}
/* 2. The virtual handler (will see incorrect data) */
unsigned iPage;
{
/** @note Dangerous assumption that HC handlers don't do anything that really requires an EMT lock! */
rc2 = pVirtNode->pfnHandlerHC(pVM, (RTGCPTR)GCPtr, pvDst, (void *)pvBuf, cb, PGMACCESSTYPE_WRITE, 0);
if ( ( rc2 != VINF_PGM_HANDLER_DO_DEFAULT
&& rc == VINF_PGM_HANDLER_DO_DEFAULT)
|| ( VBOX_FAILURE(rc2)
&& VBOX_SUCCESS(rc)))
}
#endif /* IN_RING3 */
if (rc == VINF_PGM_HANDLER_DO_DEFAULT)
{
#ifdef IN_GC
#else
#endif
{
goto end;
}
}
goto end;
break;
}
/*
* The rest needs to be taken more carefully.
*/
default:
#if 1 /** @todo r=bird: Can you do this properly please. */
/** @todo Try MMIO; quick hack */
goto end;
#endif
/** @todo fix me later. */
AssertReleaseMsgFailed(("Unknown write at %VGp size %d implement the complex physical writing case %x\n",
(pPage->HCPhys & (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2 | MM_RAM_FLAGS_VIRTUAL_ALL | MM_RAM_FLAGS_VIRTUAL_WRITE | MM_RAM_FLAGS_PHYSICAL_ALL | MM_RAM_FLAGS_PHYSICAL_WRITE)))); /** @todo PAGE FLAGS */
/* skip the write */
break;
}
}
}
else
{
/*
* Unassigned address space.
*/
if ( !pCur
goto end;
}
}
end:
#ifdef IN_RING3
if (fGrabbedLock)
#endif
return;
}
#ifndef IN_GC /* Ring 0 & 3 only */
/**
* Read from guest physical memory by GC physical address, bypassing
* MMIO and access handlers.
*
* @returns VBox status.
* @param pVM VM handle.
* @param pvDst The destination address.
* @param GCPhysSrc The source address (GC physical address).
* @param cb The number of bytes to read.
*/
{
/*
* Anything to be done?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Loop ram ranges.
*/
pRam;
{
{
{
/* Copy page by page as we're not dealing with a linear HC range. */
for (;;)
{
/* convert */
void *pvSrc;
if (VBOX_FAILURE(rc))
return rc;
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
{
/* read */
{
return VINF_SUCCESS;
}
/* next */
}
else
return VERR_PGM_PHYS_PAGE_RESERVED;
}
break;
}
}
/**
* Write to guest physical memory referenced by GC pointer.
* Write memory to GC physical address in guest physical memory.
*
* This will bypass MMIO and access handlers.
*
* @returns VBox status.
* @param pVM VM handle.
* @param GCPhysDst The GC physical address of the destination.
* @param pvSrc The source buffer.
* @param cb The number of bytes to write.
*/
{
/*
* Anything to be done?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Loop ram ranges.
*/
pRam;
{
{
#ifdef NEW_PHYS_CODE
/** @todo PGMRamGCPhys2HCPtrWithRange. */
#endif
{
/* Copy page by page as we're not dealing with a linear HC range. */
for (;;)
{
/* convert */
void *pvDst;
if (VBOX_FAILURE(rc))
return rc;
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
{
/* write */
{
return VINF_SUCCESS;
}
/* next */
}
else
return VERR_PGM_PHYS_PAGE_RESERVED;
}
break;
}
}
/**
* Read from guest physical memory referenced by GC pointer.
*
* bypass access handlers and not set any accessed bits.
*
* @returns VBox status.
* @param pVM VM handle.
* @param pvDst The destination address.
* @param GCPtrSrc The source address (GC pointer).
* @param cb The number of bytes to read.
*/
{
/*
* Anything to do?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Optimize reads within a single page.
*/
{
void *pvSrc;
if (VBOX_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/*
* Page by page.
*/
for (;;)
{
/* convert */
void *pvSrc;
if (VBOX_FAILURE(rc))
return rc;
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
/**
* Write to guest physical memory referenced by GC pointer.
*
* bypass access handlers and not set dirty or accessed bits.
*
* @returns VBox status.
* @param pVM VM handle.
* @param GCPtrDst The destination address (GC pointer).
* @param pvSrc The source address.
* @param cb The number of bytes to write.
*/
{
/*
* Anything to do?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Optimize writes within a single page.
*/
{
void *pvDst;
if (VBOX_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/*
* Page by page.
*/
for (;;)
{
/* convert */
void *pvDst;
if (VBOX_FAILURE(rc))
return rc;
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
/**
* Read from guest physical memory referenced by GC pointer.
*
* respect access handlers and set accessed bits.
*
* @returns VBox status.
* @param pVM VM handle.
* @param pvDst The destination address.
* @param GCPtrSrc The source address (GC pointer).
* @param cb The number of bytes to read.
*/
/** @todo use the PGMPhysReadGCPtr name and rename the unsafe one to something appropriate */
{
int rc;
/*
* Anything to do?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Optimize reads within a single page.
*/
{
/* Convert virtual to physical address */
/* mark the guest page as accessed. */
return VINF_SUCCESS;
}
/*
* Page by page.
*/
for (;;)
{
/* Convert virtual to physical address */
/* mark the guest page as accessed. */
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
/**
* Write to guest physical memory referenced by GC pointer.
*
* respect access handlers and set dirty and accessed bits.
*
* @returns VBox status.
* @param pVM VM handle.
* @param GCPtrDst The destination address (GC pointer).
* @param pvSrc The source address.
* @param cb The number of bytes to write.
*/
/** @todo use the PGMPhysWriteGCPtr name and rename the unsafe one to something appropriate */
{
int rc;
/*
* Anything to do?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Optimize writes within a single page.
*/
{
/* Convert virtual to physical address */
/* mark the guest page as accessed and dirty. */
return VINF_SUCCESS;
}
/*
* Page by page.
*/
for (;;)
{
/* Convert virtual to physical address */
/* mark the guest page as accessed and dirty. */
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
/**
* Write to guest physical memory referenced by GC pointer and update the PTE.
*
* bypass access handlers and set any dirty and accessed bits in the PTE.
*
* If you don't want to set the dirty bit, use PGMPhysWriteGCPtr().
*
* @returns VBox status.
* @param pVM VM handle.
* @param GCPtrDst The destination address (GC pointer).
* @param pvSrc The source address.
* @param cb The number of bytes to write.
*/
{
/*
* Anything to do?
*/
if (!cb)
return VINF_SUCCESS;
/*
* Optimize writes within a single page.
*/
{
void *pvDst;
if (VBOX_FAILURE(rc))
return rc;
rc = PGMGstModifyPage(pVM, GCPtrDst, cb, X86_PTE_A | X86_PTE_D, ~(uint64_t)(X86_PTE_A | X86_PTE_D));
return VINF_SUCCESS;
}
/*
* Page by page.
*/
for (;;)
{
/* convert */
void *pvDst;
if (VBOX_FAILURE(rc))
return rc;
/* mark the guest page as accessed and dirty. */
/* copy */
{
return VINF_SUCCESS;
}
/* next */
}
}
#endif /* !IN_GC */
/**
* Performs a read of guest virtual memory for instruction emulation.
*
* This will check permissions, raise exceptions and update the access bits.
*
* The current implementation will bypass all access handlers. It may later be
* changed to at least respect MMIO.
*
*
* @returns VBox status code suitable to scheduling.
* @retval VINF_SUCCESS if the read was performed successfully.
* @retval VINF_EM_RAW_GUEST_TRAP if an exception was raised but not dispatched yet.
* @retval VINF_TRPM_XCPT_DISPATCHED if an exception was raised and dispatched.
*
* @param pVM The VM handle.
* @param pCtxCore The context core.
* @param pvDst Where to put the bytes we've read.
* @param GCPtrSrc The source address.
* @param cb The number of bytes to read. Not more than a page.
*
* @remark This function will dynamically map physical pages in GC. This may unmap
* mappings done by the caller. Be careful!
*/
PGMDECL(int) PGMPhysInterpretedRead(PVM pVM, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb)
{
/** @todo r=bird: This isn't perfect!
* -# It's not checking for reserved bits being 1.
* -# It's not correctly dealing with the access bit.
* -# It's not respecting MMIO memory or any other access handlers.
*/
/*
* 1. Translate virtual to physical. This may fault.
* 2. Map the physical address.
* 3. Do the read operation.
* 4. Set access bits if required.
*/
int rc;
{
/*
* Not crossing pages.
*/
if (VBOX_SUCCESS(rc))
{
/** @todo we should check reserved bits ... */
void *pvSrc;
switch (rc)
{
case VINF_SUCCESS:
Log(("PGMPhysInterpretedRead: pvDst=%p pvSrc=%p cb=%d\n", pvDst, (uint8_t *)pvSrc + (GCPtrSrc & PAGE_OFFSET_MASK), cb));
break;
break;
default:
return rc;
}
/** @todo access bit emulation isn't 100% correct. */
{
}
return VINF_SUCCESS;
}
}
else
{
/*
* Crosses pages.
*/
if (VBOX_SUCCESS(rc))
if (VBOX_SUCCESS(rc))
{
/** @todo we should check reserved bits ... */
void *pvSrc1;
switch (rc)
{
case VINF_SUCCESS:
break;
break;
default:
return rc;
}
void *pvSrc2;
switch (rc)
{
case VINF_SUCCESS:
break;
break;
default:
return rc;
}
{
}
{
}
return VINF_SUCCESS;
}
}
/*
* Raise a #PF.
*/
/* Get the current privilege level. */
switch (rc)
{
case VINF_SUCCESS:
break;
case VERR_PAGE_NOT_PRESENT:
break;
default:
return rc;
}
}
/// @todo PGMDECL(int) PGMPhysInterpretedWrite(PVM pVM, PCPUMCTXCORE pCtxCore, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb)