VirtualBox

Changeset 7715 in vbox for trunk/src/VBox/VMM/PGM.cpp


Ignore:
Timestamp:
Apr 3, 2008 9:03:01 AM (17 years ago)
Author:
vboxsync
Message:

Renamed PDPTR to PDPT.
Added preliminary code for executing code with X86_CR0_WP cleared (disabled).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PGM.cpp

    r7700 r7715  
    5454 *  [..]
    5555 *
    56  * Because of guest context mappings requires PDPTR and PML4 entries to allow
     56 * Because of guest context mappings requires PDPT and PML4 entries to allow
    5757 * writing on AMD64, the two upper levels will have fixed flags whatever the
    5858 * guest is thinking of using there. So, when shadowing the PD level we will
     
    888888    pVM->pgm.s.GCPhysGstCR3Monitored = NIL_RTGCPHYS;
    889889    pVM->pgm.s.fA20Enabled      = true;
    890     pVM->pgm.s.pGstPaePDPTRHC   = NULL;
    891     pVM->pgm.s.pGstPaePDPTRGC   = 0;
     890    pVM->pgm.s.pGstPaePDPTHC    = NULL;
     891    pVM->pgm.s.pGstPaePDPTGC    = 0;
    892892    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.apGstPaePDsHC); i++)
    893893    {
     
    10731073    pVM->pgm.s.apInterPaePDs[2] = (PX86PDPAE)MMR3PageAlloc(pVM);
    10741074    pVM->pgm.s.apInterPaePDs[3] = (PX86PDPAE)MMR3PageAlloc(pVM);
    1075     pVM->pgm.s.pInterPaePDPTR   = (PX86PDPTR)MMR3PageAllocLow(pVM);
    1076     pVM->pgm.s.pInterPaePDPTR64 = (PX86PDPTR)MMR3PageAllocLow(pVM);
     1075    pVM->pgm.s.pInterPaePDPT    = (PX86PDPT)MMR3PageAllocLow(pVM);
     1076    pVM->pgm.s.pInterPaePDPT64  = (PX86PDPT)MMR3PageAllocLow(pVM);
    10771077    pVM->pgm.s.pInterPaePML4    = (PX86PML4)MMR3PageAllocLow(pVM);
    10781078    if (    !pVM->pgm.s.pInterPD
     
    10851085        ||  !pVM->pgm.s.apInterPaePDs[2]
    10861086        ||  !pVM->pgm.s.apInterPaePDs[3]
    1087         ||  !pVM->pgm.s.pInterPaePDPTR
    1088         ||  !pVM->pgm.s.pInterPaePDPTR64
     1087        ||  !pVM->pgm.s.pInterPaePDPT
     1088        ||  !pVM->pgm.s.pInterPaePDPT64
    10891089        ||  !pVM->pgm.s.pInterPaePML4)
    10901090    {
     
    10951095    pVM->pgm.s.HCPhysInterPD = MMPage2Phys(pVM, pVM->pgm.s.pInterPD);
    10961096    AssertRelease(pVM->pgm.s.HCPhysInterPD != NIL_RTHCPHYS && !(pVM->pgm.s.HCPhysInterPD & PAGE_OFFSET_MASK));
    1097     pVM->pgm.s.HCPhysInterPaePDPTR = MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPTR);
    1098     AssertRelease(pVM->pgm.s.HCPhysInterPaePDPTR != NIL_RTHCPHYS && !(pVM->pgm.s.HCPhysInterPaePDPTR & PAGE_OFFSET_MASK));
     1097    pVM->pgm.s.HCPhysInterPaePDPT = MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPT);
     1098    AssertRelease(pVM->pgm.s.HCPhysInterPaePDPT != NIL_RTHCPHYS && !(pVM->pgm.s.HCPhysInterPaePDPT & PAGE_OFFSET_MASK));
    10991099    pVM->pgm.s.HCPhysInterPaePML4 = MMPage2Phys(pVM, pVM->pgm.s.pInterPaePML4);
    11001100    AssertRelease(pVM->pgm.s.HCPhysInterPaePML4 != NIL_RTHCPHYS && !(pVM->pgm.s.HCPhysInterPaePML4 & PAGE_OFFSET_MASK));
    11011101
    11021102    /*
    1103      * Initialize the pages, setting up the PML4 and PDPTR for repetitive 4GB action.
     1103     * Initialize the pages, setting up the PML4 and PDPT for repetitive 4GB action.
    11041104     */
    11051105    ASMMemZeroPage(pVM->pgm.s.pInterPD);
     
    11101110    ASMMemZeroPage(pVM->pgm.s.apInterPaePTs[1]);
    11111111
    1112     ASMMemZeroPage(pVM->pgm.s.pInterPaePDPTR);
     1112    ASMMemZeroPage(pVM->pgm.s.pInterPaePDPT);
    11131113    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.apInterPaePDs); i++)
    11141114    {
    11151115        ASMMemZeroPage(pVM->pgm.s.apInterPaePDs[i]);
    1116         pVM->pgm.s.pInterPaePDPTR->a[i].u = X86_PDPE_P | PGM_PLXFLAGS_PERMANENT
     1116        pVM->pgm.s.pInterPaePDPT->a[i].u = X86_PDPE_P | PGM_PLXFLAGS_PERMANENT
    11171117                                          | MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[i]);
    11181118    }
    11191119
    1120     for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.pInterPaePDPTR64->a); i++)
     1120    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.pInterPaePDPT64->a); i++)
    11211121    {
    11221122        const unsigned iPD = i % ELEMENTS(pVM->pgm.s.apInterPaePDs);
    1123         pVM->pgm.s.pInterPaePDPTR64->a[i].u = X86_PDPE_P | X86_PDPE_RW | X86_PDPE_US | X86_PDPE_A | PGM_PLXFLAGS_PERMANENT
     1123        pVM->pgm.s.pInterPaePDPT64->a[i].u = X86_PDPE_P | X86_PDPE_RW | X86_PDPE_US | X86_PDPE_A | PGM_PLXFLAGS_PERMANENT
    11241124                                            | MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[iPD]);
    11251125    }
    11261126
    1127     RTHCPHYS HCPhysInterPaePDPTR64 = MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPTR64);
     1127    RTHCPHYS HCPhysInterPaePDPT64 = MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPT64);
    11281128    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.pInterPaePML4->a); i++)
    11291129        pVM->pgm.s.pInterPaePML4->a[i].u = X86_PML4E_P | X86_PML4E_RW | X86_PML4E_US | X86_PML4E_A | PGM_PLXFLAGS_PERMANENT
    1130                                          | HCPhysInterPaePDPTR64;
     1130                                         | HCPhysInterPaePDPT64;
    11311131
    11321132    /*
     
    11351135     * avoid resource failure during mode switches. So, we need to cover all levels of the
    11361136     * of the first 4GB down to PD level.
    1137      * As with the intermediate context, AMD64 uses the PAE PDPTR and PDs.
     1137     * As with the intermediate context, AMD64 uses the PAE PDPT and PDs.
    11381138     */
    11391139    pVM->pgm.s.pHC32BitPD    = (PX86PD)MMR3PageAllocLow(pVM);
     
    11451145    pVM->pgm.s.apHCPaePDs[3] = (PX86PDPAE)MMR3PageAlloc(pVM);
    11461146    AssertRelease((uintptr_t)pVM->pgm.s.apHCPaePDs[2] + PAGE_SIZE == (uintptr_t)pVM->pgm.s.apHCPaePDs[3]);
    1147     pVM->pgm.s.pHCPaePDPTR   = (PX86PDPTR)MMR3PageAllocLow(pVM);
     1147    pVM->pgm.s.pHCPaePDPT    = (PX86PDPT)MMR3PageAllocLow(pVM);
    11481148    pVM->pgm.s.pHCPaePML4    = (PX86PML4)MMR3PageAllocLow(pVM);
    11491149    if (    !pVM->pgm.s.pHC32BitPD
     
    11521152        ||  !pVM->pgm.s.apHCPaePDs[2]
    11531153        ||  !pVM->pgm.s.apHCPaePDs[3]
    1154         ||  !pVM->pgm.s.pHCPaePDPTR
     1154        ||  !pVM->pgm.s.pHCPaePDPT
    11551155        ||  !pVM->pgm.s.pHCPaePML4)
    11561156    {
     
    11661166    pVM->pgm.s.aHCPhysPaePDs[2] = MMPage2Phys(pVM, pVM->pgm.s.apHCPaePDs[2]);
    11671167    pVM->pgm.s.aHCPhysPaePDs[3] = MMPage2Phys(pVM, pVM->pgm.s.apHCPaePDs[3]);
    1168     pVM->pgm.s.HCPhysPaePDPTR   = MMPage2Phys(pVM, pVM->pgm.s.pHCPaePDPTR);
     1168    pVM->pgm.s.HCPhysPaePDPT    = MMPage2Phys(pVM, pVM->pgm.s.pHCPaePDPT);
    11691169    pVM->pgm.s.HCPhysPaePML4    = MMPage2Phys(pVM, pVM->pgm.s.pHCPaePML4);
    11701170
    11711171    /*
    1172      * Initialize the pages, setting up the PML4 and PDPTR for action below 4GB.
     1172     * Initialize the pages, setting up the PML4 and PDPT for action below 4GB.
    11731173     */
    11741174    ASMMemZero32(pVM->pgm.s.pHC32BitPD, PAGE_SIZE);
    11751175
    1176     ASMMemZero32(pVM->pgm.s.pHCPaePDPTR, PAGE_SIZE);
     1176    ASMMemZero32(pVM->pgm.s.pHCPaePDPT, PAGE_SIZE);
    11771177    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.apHCPaePDs); i++)
    11781178    {
    11791179        ASMMemZero32(pVM->pgm.s.apHCPaePDs[i], PAGE_SIZE);
    1180         pVM->pgm.s.pHCPaePDPTR->a[i].u = X86_PDPE_P | PGM_PLXFLAGS_PERMANENT | pVM->pgm.s.aHCPhysPaePDs[i];
     1180        pVM->pgm.s.pHCPaePDPT->a[i].u = X86_PDPE_P | PGM_PLXFLAGS_PERMANENT | pVM->pgm.s.aHCPhysPaePDs[i];
    11811181        /* The flags will be corrected when entering and leaving long mode. */
    11821182    }
     
    11841184    ASMMemZero32(pVM->pgm.s.pHCPaePML4, PAGE_SIZE);
    11851185    pVM->pgm.s.pHCPaePML4->a[0].u = X86_PML4E_P | X86_PML4E_RW | X86_PML4E_A
    1186                                   | PGM_PLXFLAGS_PERMANENT | pVM->pgm.s.HCPhysPaePDPTR;
     1186                                  | PGM_PLXFLAGS_PERMANENT | pVM->pgm.s.HCPhysPaePDPT;
    11871187
    11881188    CPUMSetHyperCR3(pVM, (uint32_t)pVM->pgm.s.HCPhys32BitPD);
     
    12271227        LogFlow(("pgmR3InitPaging: returns successfully\n"));
    12281228#if HC_ARCH_BITS == 64
    1229 LogRel(("Debug: HCPhys32BitPD=%VHp aHCPhysPaePDs={%VHp,%VHp,%VHp,%VHp} HCPhysPaePDPTR=%VHp HCPhysPaePML4=%VHp\n",
     1229LogRel(("Debug: HCPhys32BitPD=%VHp aHCPhysPaePDs={%VHp,%VHp,%VHp,%VHp} HCPhysPaePDPT=%VHp HCPhysPaePML4=%VHp\n",
    12301230        pVM->pgm.s.HCPhys32BitPD, pVM->pgm.s.aHCPhysPaePDs[0], pVM->pgm.s.aHCPhysPaePDs[1], pVM->pgm.s.aHCPhysPaePDs[2], pVM->pgm.s.aHCPhysPaePDs[3],
    1231         pVM->pgm.s.HCPhysPaePDPTR, pVM->pgm.s.HCPhysPaePML4));
    1232 LogRel(("Debug: HCPhysInterPD=%VHp HCPhysInterPaePDPTR=%VHp HCPhysInterPaePML4=%VHp\n",
    1233         pVM->pgm.s.HCPhysInterPD, pVM->pgm.s.HCPhysInterPaePDPTR, pVM->pgm.s.HCPhysInterPaePML4));
    1234 LogRel(("Debug: apInterPTs={%VHp,%VHp} apInterPaePTs={%VHp,%VHp} apInterPaePDs={%VHp,%VHp,%VHp,%VHp} pInterPaePDPTR64=%VHp\n",
     1231        pVM->pgm.s.HCPhysPaePDPT, pVM->pgm.s.HCPhysPaePML4));
     1232LogRel(("Debug: HCPhysInterPD=%VHp HCPhysInterPaePDPT=%VHp HCPhysInterPaePML4=%VHp\n",
     1233        pVM->pgm.s.HCPhysInterPD, pVM->pgm.s.HCPhysInterPaePDPT, pVM->pgm.s.HCPhysInterPaePML4));
     1234LogRel(("Debug: apInterPTs={%VHp,%VHp} apInterPaePTs={%VHp,%VHp} apInterPaePDs={%VHp,%VHp,%VHp,%VHp} pInterPaePDPT64=%VHp\n",
    12351235        MMPage2Phys(pVM, pVM->pgm.s.apInterPTs[0]), MMPage2Phys(pVM, pVM->pgm.s.apInterPTs[1]),
    12361236        MMPage2Phys(pVM, pVM->pgm.s.apInterPaePTs[0]), MMPage2Phys(pVM, pVM->pgm.s.apInterPaePTs[1]),
    12371237        MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[0]), MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[1]), MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[2]), MMPage2Phys(pVM, pVM->pgm.s.apInterPaePDs[3]),
    1238         MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPTR64)));
     1238        MMPage2Phys(pVM, pVM->pgm.s.pInterPaePDPT64)));
    12391239#endif
    12401240
     
    13211321    STAM_REG(pVM, &pPGM->StatGCTrap0eMap,                   STAMTYPE_COUNTER, "/PGM/GC/Trap0e/GuestPF/Map",         STAMUNIT_OCCURENCES,     "Number of guest page faults due to map accesses.");
    13221322
     1323    STAM_REG(pVM, &pPGM->StatTrap0eWPEmulGC,                STAMTYPE_COUNTER, "/PGM/GC/Trap0e/WP/InGC",             STAMUNIT_OCCURENCES,     "Number of guest page faults due to X86_CR0_WP emulation.");
     1324    STAM_REG(pVM, &pPGM->StatTrap0eWPEmulR3,                STAMTYPE_COUNTER, "/PGM/GC/Trap0e/WP/ToR3",             STAMUNIT_OCCURENCES,     "Number of guest page faults due to X86_CR0_WP emulation (forward to R3 for emulation).");
    13231325
    13241326    STAM_REG(pVM, &pPGM->StatGCGuestCR3WriteHandled,        STAMTYPE_COUNTER, "/PGM/GC/CR3WriteInt",                STAMUNIT_OCCURENCES,     "The number of times the Guest CR3 change was successfully handled.");
     
    15241526    GCPtr += PAGE_SIZE; /* reserved page */
    15251527
    1526     rc = PGMMap(pVM, GCPtr, pVM->pgm.s.HCPhysPaePDPTR, PAGE_SIZE, 0);
     1528    rc = PGMMap(pVM, GCPtr, pVM->pgm.s.HCPhysPaePDPT, PAGE_SIZE, 0);
    15271529    AssertRCReturn(rc, rc);
    1528     pVM->pgm.s.pGCPaePDPTR = GCPtr;
     1530    pVM->pgm.s.pGCPaePDPT = GCPtr;
    15291531    GCPtr += PAGE_SIZE;
    15301532    GCPtr += PAGE_SIZE; /* reserved page */
     
    15871589    for (unsigned i = 0; i < ELEMENTS(pVM->pgm.s.apGCPaePDs); i++)
    15881590        pVM->pgm.s.apGCPaePDs[i] += offDelta;
    1589     pVM->pgm.s.pGCPaePDPTR += offDelta;
     1591    pVM->pgm.s.pGCPaePDPT += offDelta;
    15901592    pVM->pgm.s.pGCPaePML4 += offDelta;
    15911593
     
    31523154 * @param   pHlp        Pointer to the output functions.
    31533155 */
    3154 static int  pgmR3DumpHierarchyHCPaePDPTR(PVM pVM, RTHCPHYS HCPhys, uint64_t u64Address, uint32_t cr4, bool fLongMode, unsigned cMaxDepth, PCDBGFINFOHLP pHlp)
    3155 {
    3156     PX86PDPTR pPDPTR = (PX86PDPTR)MMPagePhys2Page(pVM, HCPhys);
    3157     if (!pPDPTR)
     3156static int  pgmR3DumpHierarchyHCPaePDPT(PVM pVM, RTHCPHYS HCPhys, uint64_t u64Address, uint32_t cr4, bool fLongMode, unsigned cMaxDepth, PCDBGFINFOHLP pHlp)
     3157{
     3158    PX86PDPT pPDPT = (PX86PDPT)MMPagePhys2Page(pVM, HCPhys);
     3159    if (!pPDPT)
    31583160    {
    31593161        pHlp->pfnPrintf(pHlp, "%0*llx error! Page directory pointer table at HCPhys=%#VHp was not found in the page pool!\n",
     
    31633165
    31643166    int rc = VINF_SUCCESS;
    3165     const unsigned c = fLongMode ? ELEMENTS(pPDPTR->a) : X86_PG_PAE_PDPE_ENTRIES;
     3167    const unsigned c = fLongMode ? ELEMENTS(pPDPT->a) : X86_PG_PAE_PDPE_ENTRIES;
    31663168    for (unsigned i = 0; i < c; i++)
    31673169    {
    3168         X86PDPE Pdpe = pPDPTR->a[i];
     3170        X86PDPE Pdpe = pPDPT->a[i];
    31693171        if (Pdpe.n.u1Present)
    31703172        {
     
    31723174                pHlp->pfnPrintf(pHlp,         /*P R  S  A  D  G  WT CD AT NX 4M a p ?  */
    31733175                                "%016llx 1  |   P %c %c %c %c %c %s %s %s %s .. %c%c%c  %016llx\n",
    3174                                 u64Address + ((uint64_t)i << X86_PDPTR_SHIFT),
     3176                                u64Address + ((uint64_t)i << X86_PDPT_SHIFT),
    31753177                                Pdpe.n.u1Write       ? 'W'  : 'R',
    31763178                                Pdpe.n.u1User        ? 'U'  : 'S',
     
    31893191                pHlp->pfnPrintf(pHlp,      /*P R  S  A  D  G  WT CD AT NX 4M a p ?  */
    31903192                                "%08x 0 |    P %c %c %c %c %c %s %s %s %s .. %c%c%c  %016llx\n",
    3191                                 i << X86_PDPTR_SHIFT,
     3193                                i << X86_PDPT_SHIFT,
    31923194                                Pdpe.n.u1Write       ? '!'  : '.', /* mbz */
    31933195                                Pdpe.n.u1User        ? '!'  : '.', /* mbz */
     
    32053207            if (cMaxDepth >= 1)
    32063208            {
    3207                 int rc2 = pgmR3DumpHierarchyHCPaePD(pVM, Pdpe.u & X86_PDPE_PG_MASK, u64Address + ((uint64_t)i << X86_PDPTR_SHIFT),
     3209                int rc2 = pgmR3DumpHierarchyHCPaePD(pVM, Pdpe.u & X86_PDPE_PG_MASK, u64Address + ((uint64_t)i << X86_PDPT_SHIFT),
    32083210                                                    cr4, fLongMode, cMaxDepth - 1, pHlp);
    32093211                if (rc2 < rc && VBOX_SUCCESS(rc))
     
    32413243        if (Pml4e.n.u1Present)
    32423244        {
    3243             uint64_t u64Address = ((uint64_t)i << X86_PML4_SHIFT) | (((uint64_t)i >> (X86_PML4_SHIFT - X86_PDPTR_SHIFT - 1)) * 0xffff000000000000ULL);
     3245            uint64_t u64Address = ((uint64_t)i << X86_PML4_SHIFT) | (((uint64_t)i >> (X86_PML4_SHIFT - X86_PDPT_SHIFT - 1)) * 0xffff000000000000ULL);
    32443246            pHlp->pfnPrintf(pHlp,         /*P R  S  A  D  G  WT CD AT NX 4M a p ?  */
    32453247                            "%016llx 0 |    P %c %c %c %c %c %s %s %s %s .. %c%c%c  %016llx\n",
     
    32613263            if (cMaxDepth >= 1)
    32623264            {
    3263                 int rc2 = pgmR3DumpHierarchyHCPaePDPTR(pVM, Pml4e.u & X86_PML4E_PG_MASK, u64Address, cr4, true, cMaxDepth - 1, pHlp);
     3265                int rc2 = pgmR3DumpHierarchyHCPaePDPT(pVM, Pml4e.u & X86_PML4E_PG_MASK, u64Address, cr4, true, cMaxDepth - 1, pHlp);
    32643266                if (rc2 < rc && VBOX_SUCCESS(rc))
    32653267                    rc = rc2;
     
    35973599        if (fLongMode)
    35983600            return pgmR3DumpHierarchyHcPaePML4(pVM, cr3 & X86_CR3_PAGE_MASK, cr4, cMaxDepth, pHlp);
    3599         return pgmR3DumpHierarchyHCPaePDPTR(pVM, cr3 & X86_CR3_PAE_PAGE_MASK, 0, cr4, false, cMaxDepth, pHlp);
     3601        return pgmR3DumpHierarchyHCPaePDPT(pVM, cr3 & X86_CR3_PAE_PAGE_MASK, 0, cr4, false, cMaxDepth, pHlp);
    36003602    }
    36013603    return pgmR3DumpHierarchyHC32BitPD(pVM, cr3 & X86_CR3_PAGE_MASK, cr4, cMaxDepth, pHlp);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette