PGMGst.h revision 9f1e0743f565b1975bb4efd7311b30cfa0d3e384
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync/* $Id$ */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/** @file
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VBox - Page Manager / Monitor, Guest Paging Template.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * available from http://www.virtualbox.org. This file is free software;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * you can redistribute it and/or modify it under the terms of the GNU
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * General Public License (GPL) as published by the Free Software
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * additional information or have any questions.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*******************************************************************************
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync* Defined Constants And Macros *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync*******************************************************************************/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GSTPT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef PGSTPT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GSTPTE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef PGSTPTE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GSTPD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef PGSTPD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GSTPDE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef PGSTPDE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_BIG_PAGE_SIZE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_BIG_PAGE_OFFSET_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PDE_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PDE_BIG_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PD_SHIFT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PD_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PTE_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PT_SHIFT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PT_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_TOTAL_PD_ENTRIES
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_CR3_PAGE_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_PDPE_ENTRIES
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#undef GST_GET_PDE_BIG_PG_GCPHYS
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#if PGM_GST_TYPE == PGM_TYPE_32BIT \
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || PGM_GST_TYPE == PGM_TYPE_REAL \
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync || PGM_GST_TYPE == PGM_TYPE_PROT
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPT X86PT
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPT PX86PT
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPTE X86PTE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPTE PX86PTE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPD X86PD
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPD PX86PD
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPDE X86PDE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPDE PX86PDE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_BIG_PAGE_SIZE X86_PAGE_4M_SIZE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_BIG_PAGE_OFFSET_MASK X86_PAGE_4M_OFFSET_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PDE_PG_MASK X86_PDE_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PDE_BIG_PG_MASK X86_PDE4M_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_GET_PDE_BIG_PG_GCPHYS(PdeGst) pgmGstGet4MBPhysPage(&pVM->pgm.s, PdeGst)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PD_SHIFT X86_PD_SHIFT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PD_MASK X86_PD_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_TOTAL_PD_ENTRIES X86_PG_ENTRIES
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_PTE_PG_MASK X86_PTE_PG_MASK
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_PT_SHIFT X86_PT_SHIFT
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_PT_MASK X86_PT_MASK
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GST_CR3_PAGE_MASK X86_CR3_PAGE_MASK
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#elif PGM_GST_TYPE == PGM_TYPE_PAE \
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync || PGM_GST_TYPE == PGM_TYPE_AMD64
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GSTPT X86PTPAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPT PX86PTPAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPTE X86PTEPAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPTE PX86PTEPAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define GSTPD X86PDPAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# define PGSTPD PX86PDPAE
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync# define GSTPDE X86PDEPAE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define PGSTPDE PX86PDEPAE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_BIG_PAGE_SIZE X86_PAGE_2M_SIZE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_BIG_PAGE_OFFSET_MASK X86_PAGE_2M_OFFSET_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PDE_PG_MASK X86_PDE_PAE_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PDE_BIG_PG_MASK X86_PDE2M_PAE_PG_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_GET_PDE_BIG_PG_GCPHYS(PdeGst) (PdeGst.u & GST_PDE_BIG_PG_MASK)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PD_SHIFT X86_PD_PAE_SHIFT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# define GST_PD_MASK X86_PD_PAE_MASK
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# if PGM_GST_TYPE == PGM_TYPE_PAE
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# define GST_TOTAL_PD_ENTRIES (X86_PG_PAE_ENTRIES * X86_PG_PAE_PDPE_ENTRIES)
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync# define GST_PDPE_ENTRIES X86_PG_PAE_PDPE_ENTRIES
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# else
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync# define GST_TOTAL_PD_ENTRIES (X86_PG_AMD64_ENTRIES * X86_PG_AMD64_PDPE_ENTRIES)
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync# define GST_PDPE_ENTRIES X86_PG_AMD64_PDPE_ENTRIES
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync# endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# define GST_PT_SHIFT X86_PT_PAE_SHIFT
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# define GST_PT_MASK X86_PT_PAE_MASK
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# define GST_CR3_PAGE_MASK X86_CR3_PAE_PAGE_MASK
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#endif
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync/*******************************************************************************
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync* Internal Functions *
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync*******************************************************************************/
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync__BEGIN_DECLS
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync/* r3 */
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsyncPGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsyncPGM_GST_DECL(int, Enter)(PVM pVM, RTGCPHYS GCPhysCR3);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsyncPGM_GST_DECL(int, Relocate)(PVM pVM, RTGCPTR offDelta);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsyncPGM_GST_DECL(int, Exit)(PVM pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncstatic DECLCALLBACK(int) pgmR3Gst32BitWriteHandlerCR3(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncstatic DECLCALLBACK(int) pgmR3GstPAEWriteHandlerCR3(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync/* all */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncPGM_GST_DECL(int, GetPage)(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsyncPGM_GST_DECL(int, ModifyPage)(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsyncPGM_GST_DECL(int, GetPDE)(PVM pVM, RTGCPTR GCPtr, PX86PDEPAE pPDE);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncPGM_GST_DECL(int, MapCR3)(PVM pVM, RTGCPHYS GCPhysCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncPGM_GST_DECL(int, UnmapCR3)(PVM pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsyncPGM_GST_DECL(int, MonitorCR3)(PVM pVM, RTGCPHYS GCPhysCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncPGM_GST_DECL(int, UnmonitorCR3)(PVM pVM);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync__END_DECLS
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Initializes the guest bit of the paging mode data.
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This is used early in the init process to avoid trouble with PDM
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * not being initialized yet.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pModeData->uGstType == PGM_GST_TYPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Ring-3 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstRelocate = PGM_GST_NAME(Relocate);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstExit = PGM_GST_NAME(Exit);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pModeData->pfnR3GstGetPDE = PGM_GST_NAME(GetPDE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstGetPage = PGM_GST_NAME(GetPage);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pModeData->pfnR3GstModifyPage = PGM_GST_NAME(ModifyPage);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pModeData->pfnR3GstMapCR3 = PGM_GST_NAME(MapCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pModeData->pfnR3GstUnmapCR3 = PGM_GST_NAME(UnmapCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pModeData->pfnR3GstMonitorCR3 = PGM_GST_NAME(MonitorCR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstUnmonitorCR3 = PGM_GST_NAME(UnmonitorCR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# if PGM_GST_TYPE == PGM_TYPE_32BIT || PGM_GST_TYPE == PGM_TYPE_PAE
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pModeData->pfnR3GstWriteHandlerCR3 = PGM_GST_NAME(WriteHandlerCR3);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pModeData->pszR3GstWriteHandlerCR3 = "Guest CR3 Write access handler";
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pModeData->pfnR3GstPAEWriteHandlerCR3 = PGM_GST_NAME(WriteHandlerCR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pszR3GstPAEWriteHandlerCR3 = "Guest CR3 Write access handler (PAE)";
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstWriteHandlerCR3 = NULL;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pModeData->pszR3GstWriteHandlerCR3 = NULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pModeData->pfnR3GstPAEWriteHandlerCR3 = NULL;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pModeData->pszR3GstPAEWriteHandlerCR3 = NULL;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fResolveGCAndR0)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#if PGM_SHW_TYPE != PGM_TYPE_AMD64 /* No AMD64 for traditional virtualization, only VT-x and AMD-V. */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync /* GC */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPage), &pModeData->pfnRCGstGetPage);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPage), rc), rc);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(ModifyPage), &pModeData->pfnRCGstModifyPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(ModifyPage), rc), rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPDE), &pModeData->pfnRCGstGetPDE);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPDE), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(MonitorCR3), &pModeData->pfnRCGstMonitorCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(MonitorCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(UnmonitorCR3), &pModeData->pfnRCGstUnmonitorCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(UnmonitorCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(MapCR3), &pModeData->pfnRCGstMapCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(MapCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(UnmapCR3), &pModeData->pfnRCGstUnmapCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(UnmapCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# if PGM_GST_TYPE == PGM_TYPE_32BIT || PGM_GST_TYPE == PGM_TYPE_PAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(WriteHandlerCR3), &pModeData->pfnRCGstWriteHandlerCR3);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(WriteHandlerCR3), rc), rc);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(WriteHandlerCR3), &pModeData->pfnRCGstPAEWriteHandlerCR3);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(WriteHandlerCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#endif /* Not AMD64 shadow paging. */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Ring-0 */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPage), &pModeData->pfnR0GstGetPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPage), rc), rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(ModifyPage), &pModeData->pfnR0GstModifyPage);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(ModifyPage), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPDE), &pModeData->pfnR0GstGetPDE);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPDE), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(MonitorCR3), &pModeData->pfnR0GstMonitorCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(MonitorCR3), rc), rc);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(UnmonitorCR3), &pModeData->pfnR0GstUnmonitorCR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(UnmonitorCR3), rc), rc);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(MapCR3), &pModeData->pfnR0GstMapCR3);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(MapCR3), rc), rc);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(UnmapCR3), &pModeData->pfnR0GstUnmapCR3);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(UnmapCR3), rc), rc);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# if PGM_GST_TYPE == PGM_TYPE_32BIT || PGM_GST_TYPE == PGM_TYPE_PAE
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(WriteHandlerCR3), &pModeData->pfnR0GstWriteHandlerCR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(WriteHandlerCR3), rc), rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(WriteHandlerCR3), &pModeData->pfnR0GstPAEWriteHandlerCR3);
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(WriteHandlerCR3), rc), rc);
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync# endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync }
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return VINF_SUCCESS;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync}
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync/**
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Enters the guest mode.
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync *
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * @returns VBox status code.
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync * @param pVM VM handle.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param GCPhysCR3 The physical address from the CR3 register.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncPGM_GST_DECL(int, Enter)(PVM pVM, RTGCPHYS GCPhysCR3)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Map and monitor CR3
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync int rc = PGM_GST_NAME(MapCR3)(pVM, GCPhysCR3);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (RT_SUCCESS(rc) && !pVM->pgm.s.fMappingsFixed)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync rc = PGM_GST_NAME(MonitorCR3)(pVM, GCPhysCR3);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync}
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Relocate any GC pointers related to guest mode paging.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @returns VBox status code.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pVM The VM handle.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param offDelta The reloation offset.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncPGM_GST_DECL(int, Relocate)(PVM pVM, RTGCPTR offDelta)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* nothing special to do here - InitData does the job. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return VINF_SUCCESS;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync/**
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * Exits the guest mode.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPGM_GST_DECL(int, Exit)(PVM pVM)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PGM_GST_NAME(UnmonitorCR3)(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_SUCCESS(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PGM_GST_NAME(UnmapCR3)(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if PGM_GST_TYPE == PGM_TYPE_32BIT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Physical write access for the Guest CR3 in 32-bit mode.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VINF_SUCCESS if the handler have carried out the operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys The physical address the guest is writing to.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvPhys The HC mapping of that address.
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * @param pvBuf What the guest is reading/writing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param cbBuf How much it's reading/writing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmAccessType The access type.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvUser User argument.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic DECLCALLBACK(int) pgmR3Gst32BitWriteHandlerCR3(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(!pVM->pgm.s.fMappingsFixed, ("Shouldn't be registered when mappings are fixed!\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(enmAccessType == PGMACCESSTYPE_WRITE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmR3Gst32BitWriteHandlerCR3: ff=%#x GCPhys=%RGp pvPhys=%p cbBuf=%d pvBuf={%.*Rhxs}\n", pVM->fForcedActions, GCPhys, pvPhys, cbBuf, cbBuf, pvBuf));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * Do the write operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync memcpy(pvPhys, pvBuf, cbBuf);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( !pVM->pgm.s.fMappingsFixed
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && !VM_FF_ISPENDING(pVM, VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Check for conflicts.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const RTGCPTR offPD = GCPhys & PAGE_OFFSET_MASK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iPD1 = offPD / sizeof(X86PDE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iPD2 = (unsigned)(offPD + cbBuf - 1) / sizeof(X86PDE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iPD1 - iPD2 <= 1);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( ( pVM->pgm.s.pGst32BitPdR3->a[iPD1].n.u1Present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pgmGetMapping(pVM, iPD1 << X86_PD_SHIFT) )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || ( iPD1 != iPD2
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pVM->pgm.s.pGst32BitPdR3->a[iPD2].n.u1Present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pgmGetMapping(pVM, iPD2 << X86_PD_SHIFT) )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmR3Gst32BitWriteHandlerCR3: detected conflict. iPD1=%#x iPD2=%#x GCPhys=%RGp\n", iPD1, iPD2, GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatR3GuestPDWriteConflict);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatR3GuestPDWrite);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* 32BIT */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if PGM_GST_TYPE == PGM_TYPE_PAE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Physical write access handler for the Guest CR3 in PAE mode.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VINF_SUCCESS if the handler have carried out the operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys The physical address the guest is writing to.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvPhys The HC mapping of that address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvBuf What the guest is reading/writing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param cbBuf How much it's reading/writing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmAccessType The access type.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvUser User argument.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic DECLCALLBACK(int) pgmR3GstPAEWriteHandlerCR3(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(!pVM->pgm.s.fMappingsFixed, ("Shouldn't be registered when mappings are fixed!\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(enmAccessType == PGMACCESSTYPE_WRITE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmR3GstPAEWriteHandlerCR3: ff=%#x GCPhys=%RGp pvPhys=%p cbBuf=%d pvBuf={%.*Rhxs}\n", pVM->fForcedActions, GCPhys, pvPhys, cbBuf, cbBuf, pvBuf));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Do the write operation.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync memcpy(pvPhys, pvBuf, cbBuf);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( !pVM->pgm.s.fMappingsFixed
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && !VM_FF_ISPENDING(pVM, VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Check if any of the PDs have changed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * We'll simply check all of them instead of figuring out which one/two to check.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < 4; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pVM->pgm.s.pGstPaePdptR3->a[i].n.u1Present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (pVM->pgm.s.pGstPaePdptR3->a[i].u & X86_PDPE_PG_MASK) != pVM->pgm.s.aGCPhysGstPaePDsMonitored[i])
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmR3GstPAEWriteHandlerCR3: detected updated PDPE; [%d] = %#llx, Old GCPhys=%RGp\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, pVM->pgm.s.pGstPaePdptR3->a[i].u, pVM->pgm.s.aGCPhysGstPaePDsMonitored[i]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * The PD has changed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * We will schedule a monitoring update for the next TLB Flush,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * InvalidatePage or SyncCR3.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This isn't perfect, because a lazy page sync might be dealing with an half
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * updated PDPE. However, we assume that the guest OS is disabling interrupts
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * and being extremely careful (cmpxchg8b) when updating a PDPE where it's
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * executing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pVM->pgm.s.fSyncFlags |= PGM_SYNC_MONITOR_CR3;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flag a updating of the monitor at the next crossroad so we don't monitor the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * wrong pages for soo long that they can be reused as code pages and freak out
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * the recompiler or something.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pVM->pgm.s.fSyncFlags |= PGM_SYNC_MONITOR_CR3;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatR3GuestPDWrite);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* PAE */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* !VBOX_WITH_PGMPOOL_PAGING_ONLY */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync