Index: /trunk/src/VBox/VMM/Makefile.kmk
===================================================================
--- /trunk/src/VBox/VMM/Makefile.kmk	(revision 17293)
+++ /trunk/src/VBox/VMM/Makefile.kmk	(revision 17294)
@@ -500,4 +500,5 @@
 
 # Alias the PGM templates to the object in which they are defined.
+PGMInternal.o \
 PGMBth.o   PGMGst.o   PGMShw.o \
 PGMBth.obj PGMGst.obj PGMShw.obj: PGM.o
Index: /trunk/src/VBox/VMM/PGMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/PGMInternal.h	(revision 17293)
+++ /trunk/src/VBox/VMM/PGMInternal.h	(revision 17294)
@@ -579,4 +579,5 @@
     /** The physical address and a whole lot of other stuff. All bits are used! */
     RTHCPHYS    HCPhys;
+#define HCPhysX HCPhys /**< Temporary while in the process of eliminating direct access to PGMPAGE::HCPhys. */
     /** The page state. */
     uint32_t    u2StateX : 2;
@@ -586,6 +587,6 @@
     uint32_t    fSomethingElse : 1;
     /** The Page ID.
-     * @todo  Merge with HCPhys once we've liberated HCPhys of its stuff.
-     *        The HCPhys will be 100% static. */
+     * @todo  Merge with HCPhysX once we've liberated HCPhysX of its stuff.
+     *        The HCPhysX will then be 100% static. */
     uint32_t    idPageX : 28;
     /** The page type (PGMPAGETYPE). */
@@ -612,5 +613,5 @@
 #define PGM_PAGE_CLEAR(pPage) \
     do { \
-        (pPage)->HCPhys         = 0; \
+        (pPage)->HCPhysX        = 0; \
         (pPage)->u2StateX       = 0; \
         (pPage)->fWrittenToX    = 0; \
@@ -627,5 +628,5 @@
 #define PGM_PAGE_INIT(pPage, _HCPhys, _idPage, _uType, _uState) \
     do { \
-        (pPage)->HCPhys         = (_HCPhys); \
+        (pPage)->HCPhysX        = (_HCPhys); \
         (pPage)->u2StateX       = (_uState); \
         (pPage)->fWrittenToX    = 0; \
@@ -695,5 +696,5 @@
  * @param   pPage       Pointer to the physical guest page tracking structure.
  */
-#define PGM_PAGE_GET_HCPHYS(pPage)      ( (pPage)->HCPhys & UINT64_C(0x0000fffffffff000) )
+#define PGM_PAGE_GET_HCPHYS(pPage)      ( (pPage)->HCPhysX & UINT64_C(0x0000fffffffff000) )
 
 /**
@@ -703,6 +704,6 @@
  */
 #define PGM_PAGE_SET_HCPHYS(pPage, _HCPhys) \
-                                        do { (pPage)->HCPhys = (((pPage)->HCPhys) & UINT64_C(0xffff000000000fff)) \
-                                                             | ((_HCPhys) & UINT64_C(0x0000fffffffff000)); } while (0)
+                                        do { (pPage)->HCPhysX = (((pPage)->HCPhys) & UINT64_C(0xffff000000000fff)) \
+                                                              | ((_HCPhys) & UINT64_C(0x0000fffffffff000)); } while (0)
 
 /**
@@ -713,6 +714,6 @@
 #define PGM_PAGE_GET_PAGEID(pPage)      ( (pPage)->idPageX )
 /* later:
-#define PGM_PAGE_GET_PAGEID(pPage)      (   ((uint32_t)(pPage)->HCPhys >> (48 - 12))
-                                         |  ((uint32_t)(pPage)->HCPhys & 0xfff) )
+#define PGM_PAGE_GET_PAGEID(pPage)      (   ((uint32_t)(pPage)->HCPhysX >> (48 - 12))
+                                         |  ((uint32_t)(pPage)->HCPhysX & 0xfff) )
 */
 /**
@@ -722,7 +723,7 @@
 #define PGM_PAGE_SET_PAGEID(pPage, _idPage)  do { (pPage)->idPageX = (_idPage); } while (0)
 /* later:
-#define PGM_PAGE_SET_PAGEID(pPage, _idPage)  do { (pPage)->HCPhys = (((pPage)->HCPhys) & UINT64_C(0x0000fffffffff000)) \
-                                                                  | ((_idPage) & 0xfff) \
-                                                                  | (((_idPage) & 0x0ffff000) << (48-12)); } while (0)
+#define PGM_PAGE_SET_PAGEID(pPage, _idPage)  do { (pPage)->HCPhysX = (((pPage)->HCPhysX) & UINT64_C(0x0000fffffffff000)) \
+                                                                   | ((_idPage) & 0xfff) \
+                                                                   | (((_idPage) & 0x0ffff000) << (48-12)); } while (0)
 */
 
@@ -735,10 +736,10 @@
 /* later:
 #if GMM_CHUNKID_SHIFT == 12
-# define PGM_PAGE_GET_CHUNKID(pPage)    ( (uint32_t)((pPage)->HCPhys >> 48) )
+# define PGM_PAGE_GET_CHUNKID(pPage)    ( (uint32_t)((pPage)->HCPhysX >> 48) )
 #elif GMM_CHUNKID_SHIFT > 12
-# define PGM_PAGE_GET_CHUNKID(pPage)    ( (uint32_t)((pPage)->HCPhys >> (48 + (GMM_CHUNKID_SHIFT - 12)) )
+# define PGM_PAGE_GET_CHUNKID(pPage)    ( (uint32_t)((pPage)->HCPhysX >> (48 + (GMM_CHUNKID_SHIFT - 12)) )
 #elif GMM_CHUNKID_SHIFT < 12
-# define PGM_PAGE_GET_CHUNKID(pPage)    (   ( (uint32_t)((pPage)->HCPhys >> 48)   << (12 - GMM_CHUNKID_SHIFT) ) \
-                                         |  ( (uint32_t)((pPage)->HCPhys & 0xfff) >> GMM_CHUNKID_SHIFT ) )
+# define PGM_PAGE_GET_CHUNKID(pPage)    (   ( (uint32_t)((pPage)->HCPhysX >> 48)   << (12 - GMM_CHUNKID_SHIFT) ) \
+                                         |  ( (uint32_t)((pPage)->HCPhysX & 0xfff) >> GMM_CHUNKID_SHIFT ) )
 #else
 # error "GMM_CHUNKID_SHIFT isn't defined or something."
@@ -754,8 +755,8 @@
 /* later:
 #if GMM_CHUNKID_SHIFT <= 12
-# define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage)  ( (uint32_t)((pPage)->HCPhys & GMM_PAGEID_IDX_MASK) )
+# define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage)  ( (uint32_t)((pPage)->HCPhysX & GMM_PAGEID_IDX_MASK) )
 #else
-# define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage)  (   (uint32_t)((pPage)->HCPhys & 0xfff) \
-                                             |  ( (uint32_t)((pPage)->HCPhys >> 48) & (RT_BIT_32(GMM_CHUNKID_SHIFT - 12) - 1) ) )
+# define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage)  (   (uint32_t)((pPage)->HCPhysX & 0xfff) \
+                                             |  ( (uint32_t)((pPage)->HCPhysX >> 48) & (RT_BIT_32(GMM_CHUNKID_SHIFT - 12) - 1) ) )
 #endif
 */
@@ -782,9 +783,9 @@
         (pPage)->u3Type = (_enmType); \
         if ((_enmType) == PGMPAGETYPE_ROM) \
-            (pPage)->HCPhys |= MM_RAM_FLAGS_ROM; \
+            (pPage)->HCPhysX |= MM_RAM_FLAGS_ROM; \
         else if ((_enmType) == PGMPAGETYPE_ROM_SHADOW) \
-            (pPage)->HCPhys |= MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO2; \
+            (pPage)->HCPhysX |= MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO2; \
         else if ((_enmType) == PGMPAGETYPE_MMIO2) \
-            (pPage)->HCPhys |= MM_RAM_FLAGS_MMIO2; \
+            (pPage)->HCPhysX |= MM_RAM_FLAGS_MMIO2; \
     } while (0)
 #endif
@@ -796,5 +797,5 @@
  * @param   pPage       Pointer to the physical guest page tracking structure.
  */
-#define PGM_PAGE_IS_RESERVED(pPage)     ( !!((pPage)->HCPhys & MM_RAM_FLAGS_RESERVED) )
+#define PGM_PAGE_IS_RESERVED(pPage)     ( !!((pPage)->HCPhysX & MM_RAM_FLAGS_RESERVED) )
 
 /**
@@ -803,5 +804,5 @@
  * @param   pPage       Pointer to the physical guest page tracking structure.
  */
-#define PGM_PAGE_IS_MMIO(pPage)         ( !!((pPage)->HCPhys & MM_RAM_FLAGS_MMIO) )
+#define PGM_PAGE_IS_MMIO(pPage)         ( !!((pPage)->HCPhysX & MM_RAM_FLAGS_MMIO) )
 
 /**
@@ -967,5 +968,5 @@
  */
 #define PGM_PAGE_GET_TRACKING(pPage) \
-    ( *((uint16_t *)&(pPage)->HCPhys + 3) )
+    ( *((uint16_t *)&(pPage)->HCPhysX + 3) )
 
 /** @def PGM_PAGE_SET_TRACKING
@@ -975,5 +976,5 @@
  */
 #define PGM_PAGE_SET_TRACKING(pPage, u16TrackingData) \
-    do { *((uint16_t *)&(pPage)->HCPhys + 3) = (u16TrackingData); } while (0)
+    do { *((uint16_t *)&(pPage)->HCPhysX + 3) = (u16TrackingData); } while (0)
 
 /** @def PGM_PAGE_GET_TD_CREFS
@@ -3481,6 +3482,6 @@
 
 #endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
-
 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+
 /**
  * Maps the page into current context (RC and maybe R0).
@@ -3528,6 +3529,6 @@
     return pv;
 }
+
 #endif /*  VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 || IN_RC */
-
 
 #ifndef IN_RC
@@ -3560,46 +3561,4 @@
 #endif /* !IN_RC */
 
-#if !defined(IN_RC) && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
-
-# ifndef VBOX_WITH_NEW_PHYS_CODE
-/**
- * Convert GC Phys to HC Virt.
- *
- * @returns VBox status.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      The GC physical address.
- * @param   pHCPtr      Where to store the corresponding HC virtual address.
- *
- * @deprecated  This will be eliminated by PGMPhysGCPhys2CCPtr. Only user is
- *              pgmPoolMonitorGCPtr2CCPtr.
- */
-DECLINLINE(int) pgmRamGCPhys2HCPtr(PPGM pPGM, RTGCPHYS GCPhys, PRTHCPTR pHCPtr)
-{
-    PPGMRAMRANGE pRam;
-    PPGMPAGE pPage;
-    int rc = pgmPhysGetPageAndRangeEx(pPGM, GCPhys, &pPage, &pRam);
-    if (RT_FAILURE(rc))
-    {
-        *pHCPtr = 0; /* Shut up silly GCC warnings. */
-        return rc;
-    }
-    RTGCPHYS off = GCPhys - pRam->GCPhys;
-
-    if (pRam->fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC)
-    {
-        unsigned iChunk = off >> PGM_DYNAMIC_CHUNK_SHIFT;
-        *pHCPtr = (RTHCPTR)(pRam->paChunkR3Ptrs[iChunk] + (off & PGM_DYNAMIC_CHUNK_OFFSET_MASK));
-        return VINF_SUCCESS;
-    }
-    if (pRam->pvR3)
-    {
-        *pHCPtr = (RTHCPTR)((RTHCUINTPTR)pRam->pvR3 + off);
-        return VINF_SUCCESS;
-    }
-    *pHCPtr = 0; /* Shut up silly GCC warnings. */
-    return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
-}
-# endif /* !VBOX_WITH_NEW_PHYS_CODE */
-#endif /* !IN_RC && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) */
 
 /**
@@ -3614,6 +3573,7 @@
  * @deprecated  Will go away or be changed. Only user is MapCR3. MapCR3 will have to do ring-3
  *              and ring-0 locking of the CR3 in a lazy fashion I'm fear... or perhaps not. we'll see.
- */
-DECLINLINE(int) pgmRamGCPhys2HCPtrAndHCPhysWithFlags(PPGM pPGM, RTGCPHYS GCPhys, PRTHCPTR pHCPtr, PRTHCPHYS pHCPhys)
+ *              Either way, we have to make sure the page is writable in MapCR3.
+ */
+DECLINLINE(int) pgmRamGCPhys2HCPtrAndHCPhys(PPGM pPGM, RTGCPHYS GCPhys, PRTHCPTR pHCPtr, PRTHCPHYS pHCPhys)
 {
     PPGMRAMRANGE pRam;
@@ -3628,5 +3588,5 @@
     RTGCPHYS off = GCPhys - pRam->GCPhys;
 
-    *pHCPhys = pPage->HCPhys; /** @todo PAGE FLAGS */
+    *pHCPhys = PGM_PAGE_GET_HCPHYS(pPage);
     if (pRam->fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC)
     {
@@ -3647,92 +3607,4 @@
     *pHCPtr = 0;
     return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
-}
-
-
-/**
- * Clears flags associated with a RAM address.
- *
- * @returns VBox status code.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      Guest context physical address.
- * @param   fFlags      fFlags to clear. (Bits 0-11.)
- */
-DECLINLINE(int) pgmRamFlagsClearByGCPhys(PPGM pPGM, RTGCPHYS GCPhys, unsigned fFlags)
-{
-    PPGMPAGE pPage;
-    int rc = pgmPhysGetPageEx(pPGM, GCPhys, &pPage);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    fFlags &= ~X86_PTE_PAE_PG_MASK;
-    pPage->HCPhys &= ~(RTHCPHYS)fFlags; /** @todo PAGE FLAGS */
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Clears flags associated with a RAM address.
- *
- * @returns VBox status code.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      Guest context physical address.
- * @param   fFlags      fFlags to clear. (Bits 0-11.)
- * @param   ppRamHint   Where to read and store the ram list hint.
- *                      The caller initializes this to NULL before the call.
- */
-DECLINLINE(int) pgmRamFlagsClearByGCPhysWithHint(PPGM pPGM, RTGCPHYS GCPhys, unsigned fFlags, PPGMRAMRANGE *ppRamHint)
-{
-    PPGMPAGE pPage;
-    int rc = pgmPhysGetPageWithHintEx(pPGM, GCPhys, &pPage, ppRamHint);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    fFlags &= ~X86_PTE_PAE_PG_MASK;
-    pPage->HCPhys &= ~(RTHCPHYS)fFlags; /** @todo PAGE FLAGS */
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Sets (bitwise OR) flags associated with a RAM address.
- *
- * @returns VBox status code.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      Guest context physical address.
- * @param   fFlags      fFlags to set clear. (Bits 0-11.)
- */
-DECLINLINE(int) pgmRamFlagsSetByGCPhys(PPGM pPGM, RTGCPHYS GCPhys, unsigned fFlags)
-{
-    PPGMPAGE pPage;
-    int rc = pgmPhysGetPageEx(pPGM, GCPhys, &pPage);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    fFlags &= ~X86_PTE_PAE_PG_MASK;
-    pPage->HCPhys |= fFlags; /** @todo PAGE FLAGS */
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Sets (bitwise OR) flags associated with a RAM address.
- *
- * @returns VBox status code.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      Guest context physical address.
- * @param   fFlags      fFlags to set clear. (Bits 0-11.)
- * @param   ppRamHint   Where to read and store the ram list hint.
- *                      The caller initializes this to NULL before the call.
- */
-DECLINLINE(int) pgmRamFlagsSetByGCPhysWithHint(PPGM pPGM, RTGCPHYS GCPhys, unsigned fFlags, PPGMRAMRANGE *ppRamHint)
-{
-    PPGMPAGE pPage;
-    int rc = pgmPhysGetPageWithHintEx(pPGM, GCPhys, &pPage, ppRamHint);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    fFlags &= ~X86_PTE_PAE_PG_MASK;
-    pPage->HCPhys |= fFlags; /** @todo PAGE FLAGS */
-    return VINF_SUCCESS;
 }
 
@@ -4267,5 +4139,4 @@
 
 #endif /* !IN_RC */
-
 
 /**
@@ -4392,4 +4263,5 @@
 }
 
+
 /**
  * Gets the shadow page directory for the specified address, PAE.
@@ -4417,4 +4289,5 @@
 #endif
 }
+
 
 /**
@@ -4456,4 +4329,5 @@
 
 #ifndef IN_RC
+
 /**
  * Gets the shadow page map level-4 pointer.
@@ -4552,21 +4426,4 @@
 
 #endif /* !IN_RC */
-
-/**
- * Checks if any of the specified page flags are set for the given page.
- *
- * @returns true if any of the flags are set.
- * @returns false if all the flags are clear.
- * @param   pPGM        PGM handle.
- * @param   GCPhys      The GC physical address.
- * @param   fFlags      The flags to check for.
- */
-DECLINLINE(bool) pgmRamTestFlags(PPGM pPGM, RTGCPHYS GCPhys, uint64_t fFlags)
-{
-    PPGMPAGE pPage = pgmPhysGetPage(pPGM, GCPhys);
-    return pPage
-        && (pPage->HCPhys & fFlags) != 0; /** @todo PAGE FLAGS */
-}
-
 
 /**
@@ -4815,4 +4672,5 @@
 
 #ifdef VBOX_WITH_PGMPOOL_PAGING_ONLY
+
 /**
  * Locks a page to prevent flushing (important for cr3 root pages or shadow pae pd pages).
@@ -4829,4 +4687,5 @@
 }
 
+
 /**
  * Unlocks a page to allow flushing again
@@ -4842,4 +4701,5 @@
     return VINF_SUCCESS;
 }
+
 
 /**
@@ -4860,5 +4720,6 @@
     return false;
 }
-#endif
+
+#endif /* VBOX_WITH_PGMPOOL_PAGING_ONLY */
 
 /**
@@ -4868,5 +4729,4 @@
  * @param   pVM         VM handle.
  */
-
 DECLINLINE(bool) pgmMapAreMappingsEnabled(PPGM pPGM)
 {
Index: /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 17293)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 17294)
@@ -4495,5 +4495,5 @@
     RTHCPHYS    HCPhysGuestCR3;
     RTHCPTR     HCPtrGuestCR3;
-    int rc = pgmRamGCPhys2HCPtrAndHCPhysWithFlags(&pVM->pgm.s, GCPhysCR3 & GST_CR3_PAGE_MASK, &HCPtrGuestCR3, &HCPhysGuestCR3);
+    int rc = pgmRamGCPhys2HCPtrAndHCPhys(&pVM->pgm.s, GCPhysCR3 & GST_CR3_PAGE_MASK, &HCPtrGuestCR3, &HCPhysGuestCR3);
     if (RT_SUCCESS(rc))
     {
@@ -4532,8 +4532,8 @@
                     RTHCPHYS    HCPhys;
                     RTGCPHYS    GCPhys = pGuestPDPT->a[i].u & X86_PDPE_PG_MASK;
-                    int rc2 = pgmRamGCPhys2HCPtrAndHCPhysWithFlags(&pVM->pgm.s, GCPhys, &HCPtr, &HCPhys);
+                    int rc2 = pgmRamGCPhys2HCPtrAndHCPhys(&pVM->pgm.s, GCPhys, &HCPtr, &HCPhys);
                     if (RT_SUCCESS(rc2))
                     {
-                        rc = PGMMap(pVM, GCPtr, HCPhys & X86_PTE_PAE_PG_MASK, PAGE_SIZE, 0);
+                        rc = PGMMap(pVM, GCPtr, HCPhys, PAGE_SIZE, 0);
                         AssertRCReturn(rc, rc);
 
