- Timestamp:
- Apr 17, 2007 8:40:33 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
r2078 r2120 54 54 PGM_BTH_DECL(int, Trap0eHandler)(PVM pVM, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault) 55 55 { 56 #if PGM_GST_TYPE == PGM_TYPE_32BIT 56 #if (PGM_GST_TYPE == PGM_TYPE_32BIT || PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT) && PGM_SHW_TYPE != PGM_TYPE_AMD64 57 57 58 # if PGM_SHW_TYPE != PGM_TYPE_32BIT && PGM_SHW_TYPE != PGM_TYPE_PAE 58 59 # error "32-bit guest mode is only implemented for 32-bit and PAE shadow modes." … … 75 76 */ 76 77 int rc; 78 # if PGM_WITH_PAGING(PGM_GST_TYPE) 77 79 PVBOXPD pPDSrc = CTXSUFF(pVM->pgm.s.pGuestPD); 78 const unsigned iPDSrc = (uintptr_t)pvFault >> GST_PD_SHIFT; 79 const unsigned iPDDst = (uintptr_t)pvFault >> SHW_PD_SHIFT; 80 const unsigned iPDSrc = (RTGCUINTPTR)pvFault >> GST_PD_SHIFT; 81 # else 82 PVBOXPD pPDSrc = NULL; 83 const unsigned iPDSrc = 0; 84 # endif 85 86 const unsigned iPDDst = (RTGCUINTPTR)pvFault >> SHW_PD_SHIFT; 80 87 # if PGM_SHW_TYPE == PGM_TYPE_32BIT 81 88 PX86PD pPDDst = pVM->pgm.s.CTXMID(p,32BitPD); … … 87 94 uint32_t cpl = CPUMGetGuestCPL(pVM, pRegFrame); 88 95 89 # ifdef PGM_SYNC_DIRTY_BIT 96 # if PGM_WITH_PAGING(PGM_GST_TYPE) 97 # ifdef PGM_SYNC_DIRTY_BIT 90 98 /* 91 99 * If we successfully correct the write protection fault due to dirty bit … … 103 111 return rc == VINF_PGM_HANDLED_DIRTY_BIT_FAULT ? VINF_SUCCESS : rc; 104 112 } 105 # endif 113 # endif 114 106 115 STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0ePD[iPDSrc]); 116 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 107 117 108 118 /* … … 117 127 * 118 128 */ 129 # if PGM_WITH_PAGING(PGM_GST_TYPE) 119 130 VBOXPDE PdeSrc = pPDSrc->a[iPDSrc]; 131 # else 132 VBOXPDE PdeSrc; 133 PdeSrc.au32[0] = 0; /* faked so we don't have to #ifdef everything */ 134 PdeSrc.n.u1Present = 1; 135 PdeSrc.n.u1Write = 1; 136 PdeSrc.n.u1Accessed = 1; 137 # endif 120 138 if ( !(uErr & X86_TRAP_PF_P) /* not set means page not present instead of page protection violation */ 121 139 && !pPDDst->a[iPDDst].n.u1Present 122 && PdeSrc.n.u1Present) 140 && PdeSrc.n.u1Present 141 ) 123 142 124 143 { … … 138 157 } 139 158 159 # if PGM_WITH_PAGING(PGM_GST_TYPE) 140 160 /* 141 161 * Check if this address is within any of our mappings. … … 151 171 for ( ; pMapping; pMapping = CTXSUFF(pMapping->pNext)) 152 172 { 153 if (( uintptr_t)pvFault < (uintptr_t)pMapping->GCPtr)173 if ((RTGCUINTPTR)pvFault < (RTGCUINTPTR)pMapping->GCPtr) 154 174 break; 155 if (( uintptr_t)pvFault - (uintptr_t)pMapping->GCPtr < pMapping->cb)175 if ((RTGCUINTPTR)pvFault - (RTGCUINTPTR)pMapping->GCPtr < pMapping->cb) 156 176 { 157 177 /* … … 178 198 if ( pCur 179 199 && pCur->enmType != PGMVIRTHANDLERTYPE_EIP 180 && ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr < pCur->cb200 && (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr < pCur->cb 181 201 && ( uErr & X86_TRAP_PF_RW 182 202 || ( pCur->enmType != PGMVIRTHANDLERTYPE_WRITE 183 203 && pCur->enmType != PGMVIRTHANDLERTYPE_HYPERVISOR) ) ) /** r=bird: <- this is probably wrong. */ 184 204 { 185 # ifdef IN_GC205 # ifdef IN_GC 186 206 STAM_PROFILE_START(&pCur->Stat, h); 187 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr);207 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr); 188 208 STAM_PROFILE_STOP(&pCur->Stat, h); 189 # else209 # else 190 210 AssertFailed(); 191 211 rc = VINF_EM_RAW_EMULATE_INSTR; /* can't happen with VMX */ 192 # endif212 # endif 193 213 STAM_COUNTER_INC(&pVM->pgm.s.StatTrap0eMapHandler); 194 214 STAM_PROFILE_STOP(&pVM->pgm.s.StatMapping, a); … … 208 228 if ( pCur 209 229 && pCur->enmType == PGMVIRTHANDLERTYPE_EIP 210 && ( uintptr_t)pvEIP - (uintptr_t)pCur->GCPtr < pCur->cb)230 && (RTGCUINTPTR)pvEIP - (RTGCUINTPTR)pCur->GCPtr < pCur->cb) 211 231 { 212 # ifdef IN_GC232 # ifdef IN_GC 213 233 STAM_PROFILE_START(&pCur->Stat, h); 214 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, ( uintptr_t)pvEIP - (uintptr_t)pCur->GCPtr);234 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, (RTGCUINTPTR)pvEIP - (RTGCUINTPTR)pCur->GCPtr); 215 235 STAM_PROFILE_STOP(&pCur->Stat, h); 216 # else236 # else 217 237 AssertFailed(); 218 238 rc = VINF_EM_RAW_EMULATE_INSTR; /* can't happen with VMX */ 219 # endif239 # endif 220 240 STAM_COUNTER_INC(&pVM->pgm.s.StatTrap0eMapHandler); 221 241 STAM_PROFILE_STOP(&pVM->pgm.s.StatMapping, a); … … 237 257 STAM_PROFILE_STOP(&pVM->pgm.s.StatMapping, a); 238 258 } /* pgmAreMappingsEnabled(&pVM->pgm.s) */ 259 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 239 260 240 261 /* … … 249 270 { 250 271 RTGCPHYS GCPhys = ~0U; 272 273 # if PGM_WITH_PAGING(PGM_GST_TYPE) 251 274 uint32_t cr4 = CPUMGetGuestCR4(pVM); 252 275 if ( PdeSrc.b.u1Size … … 257 280 { 258 281 PVBOXPT pPTSrc; 259 # ifdef IN_GC282 # ifdef IN_GC 260 283 rc = PGMGCDynMapGCPage(pVM, PdeSrc.u & X86_PDE_PG_MASK, (void **)&pPTSrc); 261 # else284 # else 262 285 pPTSrc = (PVBOXPT)MMPhysGCPhys2HCVirt(pVM, PdeSrc.u & X86_PDE_PG_MASK, sizeof(*pPTSrc)); 263 286 if (pPTSrc == 0) 264 287 rc = VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS; 265 # endif288 # endif 266 289 if (VBOX_SUCCESS(rc)) 267 290 { 268 unsigned iPTESrc = (( uintptr_t)pvFault >> PAGE_SHIFT) & PTE_MASK;291 unsigned iPTESrc = ((RTGCUINTPTR)pvFault >> PAGE_SHIFT) & PTE_MASK; 269 292 if (pPTSrc->a[iPTESrc].n.u1Present) 270 293 GCPhys = pPTSrc->a[iPTESrc].u & X86_PTE_PG_MASK; 271 294 } 272 295 } 296 # else 297 /* No paging so the fault address is the physical address */ 298 GCPhys = (RTGCPHYS)((RTGCUINTPTR)pvFault & ~PAGE_OFFSET_MASK); 299 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 273 300 274 301 /* … … 290 317 * Physical page access handler. 291 318 */ 292 const RTGCPHYS GCPhysFault = GCPhys | (( uintptr_t)pvFault & PAGE_OFFSET_MASK);319 const RTGCPHYS GCPhysFault = GCPhys | ((RTGCUINTPTR)pvFault & PAGE_OFFSET_MASK); 293 320 PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&CTXSUFF(pVM->pgm.s.pTrees)->PhysHandlers, GCPhysFault); 294 321 if (pCur) … … 346 373 } 347 374 } 375 # if PGM_WITH_PAGING(PGM_GST_TYPE) 348 376 else 349 377 { … … 383 411 if (pCur) 384 412 { 385 AssertMsg(!(( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr < pCur->cb)413 AssertMsg(!((RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr < pCur->cb) 386 414 || ( pCur->enmType != PGMVIRTHANDLERTYPE_WRITE 387 415 || !(uErr & X86_TRAP_PF_P) … … 390 418 391 419 if ( pCur->enmType != PGMVIRTHANDLERTYPE_EIP 392 && ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr < pCur->cb420 && (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr < pCur->cb 393 421 && ( uErr & X86_TRAP_PF_RW 394 422 || ( pCur->enmType != PGMVIRTHANDLERTYPE_WRITE 395 423 && pCur->enmType != PGMVIRTHANDLERTYPE_HYPERVISOR) ) ) /** @todo r=bird: _HYPERVISOR is impossible here because of mapping check. */ 396 424 { 397 # ifdef IN_GC425 # ifdef IN_GC 398 426 STAM_PROFILE_START(&pCur->Stat, h); 399 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr);427 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr); 400 428 STAM_PROFILE_STOP(&pCur->Stat, h); 401 # else429 # else 402 430 rc = VINF_EM_RAW_EMULATE_INSTR; /** @todo for VMX */ 403 # endif431 # endif 404 432 STAM_COUNTER_INC(&pVM->pgm.s.StatHandlersVirtual); 405 433 STAM_PROFILE_STOP(&pVM->pgm.s.StatHandlers, b); … … 414 442 PPGMVIRTHANDLER pCur; 415 443 unsigned iPage; 416 rc = pgmHandlerVirtualFindByPhysAddr(pVM, GCPhys + (( uintptr_t)pvFault & PAGE_OFFSET_MASK),444 rc = pgmHandlerVirtualFindByPhysAddr(pVM, GCPhys + ((RTGCUINTPTR)pvFault & PAGE_OFFSET_MASK), 417 445 &pCur, &iPage); 418 446 Assert(VBOX_SUCCESS(rc) || !pCur); … … 424 452 { 425 453 Assert((pCur->aPhysToVirt[iPage].Core.Key & X86_PTE_PAE_PG_MASK) == GCPhys); 426 # ifdef IN_GC427 uintptr_t off = (iPage << PAGE_SHIFT) + ((uintptr_t)pvFault & PAGE_OFFSET_MASK) - ((uintptr_t)pCur->GCPtr & PAGE_OFFSET_MASK);454 # ifdef IN_GC 455 RTGCUINTPTR off = (iPage << PAGE_SHIFT) + ((RTGCUINTPTR)pvFault & PAGE_OFFSET_MASK) - ((RTGCUINTPTR)pCur->GCPtr & PAGE_OFFSET_MASK); 428 456 Assert(off < pCur->cb); 429 457 STAM_PROFILE_START(&pCur->Stat, h); 430 458 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, off); 431 459 STAM_PROFILE_STOP(&pCur->Stat, h); 432 # else460 # else 433 461 rc = VINF_EM_RAW_EMULATE_INSTR; /** @todo for VMX */ 434 # endif462 # endif 435 463 STAM_COUNTER_INC(&pVM->pgm.s.StatHandlersVirtualByPhys); 436 464 STAM_PROFILE_STOP(&pVM->pgm.s.StatHandlers, b); … … 440 468 } 441 469 } 470 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 442 471 443 472 /* … … 479 508 } /* if any kind of handler */ 480 509 510 # if PGM_WITH_PAGING(PGM_GST_TYPE) 481 511 if (uErr & X86_TRAP_PF_P) 482 512 { … … 491 521 if (pCur) 492 522 { 493 AssertMsg( !(( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr < pCur->cb)523 AssertMsg( !((RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr < pCur->cb) 494 524 || ( pCur->enmType != PGMVIRTHANDLERTYPE_WRITE 495 525 || !(uErr & X86_TRAP_PF_P) … … 498 528 499 529 if ( pCur->enmType != PGMVIRTHANDLERTYPE_EIP 500 && ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr < pCur->cb530 && (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr < pCur->cb 501 531 && ( uErr & X86_TRAP_PF_RW 502 532 || ( pCur->enmType != PGMVIRTHANDLERTYPE_WRITE 503 533 && pCur->enmType != PGMVIRTHANDLERTYPE_HYPERVISOR) ) ) /** @todo r=bird: _HYPERVISOR is impossible here because of mapping check. */ 504 534 { 505 # ifdef IN_GC535 # ifdef IN_GC 506 536 STAM_PROFILE_START(&pCur->Stat, h); 507 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, ( uintptr_t)pvFault - (uintptr_t)pCur->GCPtr);537 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, (RTGCUINTPTR)pvFault - (RTGCUINTPTR)pCur->GCPtr); 508 538 STAM_PROFILE_STOP(&pCur->Stat, h); 509 # else539 # else 510 540 rc = VINF_EM_RAW_EMULATE_INSTR; /** @todo for VMX */ 511 # endif541 # endif 512 542 STAM_COUNTER_INC(&pVM->pgm.s.StatHandlersVirtualUnmarked); 513 543 STAM_PROFILE_STOP(&pVM->pgm.s.StatHandlers, b); … … 517 547 } 518 548 } 549 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 519 550 } 520 551 STAM_PROFILE_STOP(&pVM->pgm.s.StatHandlers, b); … … 547 578 pvFault, pRegFrame->eip, PdeSrc.n.u1User, fPageGst, GCPhys, CSAMDoesPageNeedScanning(pVM, (RTGCPTR)pRegFrame->eip))); 548 579 # endif /* LOG_ENABLED */ 549 550 # if ndef IN_RING0580 581 # if PGM_WITH_PAGING(PGM_GST_TYPE) && !defined(IN_RING0) 551 582 if (cpl == 0) 552 583 { … … 559 590 if ( pvFault == (RTGCPTR)pRegFrame->eip 560 591 || (RTGCUINTPTR)pvFault - pRegFrame->eip < 8 /* instruction crossing a page boundary */ 561 # ifdef CSAM_DETECT_NEW_CODE_PAGES592 # ifdef CSAM_DETECT_NEW_CODE_PAGES 562 593 || ( !PATMIsPatchGCAddr(pVM, (RTGCPTR)pRegFrame->eip) 563 594 && CSAMDoesPageNeedScanning(pVM, (RTGCPTR)pRegFrame->eip)) /* any new code we encounter here */ 564 # endif /* CSAM_DETECT_NEW_CODE_PAGES */595 # endif /* CSAM_DETECT_NEW_CODE_PAGES */ 565 596 ) 566 597 { … … 584 615 } 585 616 } 586 # ifdef CSAM_DETECT_NEW_CODE_PAGES617 # ifdef CSAM_DETECT_NEW_CODE_PAGES 587 618 else 588 619 if ( uErr == X86_TRAP_PF_RW … … 615 646 } 616 647 } 617 # endif /* CSAM_DETECT_NEW_CODE_PAGES */648 # endif /* CSAM_DETECT_NEW_CODE_PAGES */ 618 649 619 650 /* … … 625 656 } 626 657 } 627 # endif 658 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 628 659 rc = PGM_BTH_NAME(SyncPage)(pVM, PdeSrc, (RTGCUINTPTR)pvFault, PGM_SYNC_NR_PAGES, uErr); 629 660 if (VBOX_SUCCESS(rc)) … … 728 759 729 760 761 # if PGM_WITH_PAGING(PGM_GST_TYPE) 730 762 /* 731 763 * Check if it's in a EIP based virtual page access handler range. … … 744 776 if ( pCur 745 777 && pCur->enmType == PGMVIRTHANDLERTYPE_EIP 746 && ( uintptr_t)pvEIP - (uintptr_t)pCur->GCPtr < pCur->cb)778 && (RTGCUINTPTR)pvEIP - (RTGCUINTPTR)pCur->GCPtr < pCur->cb) 747 779 { 748 780 LogFlow(("EIP handler\n")); 749 # ifdef IN_GC781 # ifdef IN_GC 750 782 STAM_PROFILE_START(&pCur->Stat, h); 751 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, ( uintptr_t)pvEIP - (uintptr_t)pCur->GCPtr);783 rc = CTXSUFF(pCur->pfnHandler)(pVM, uErr, pRegFrame, pvFault, pCur->GCPtr, (RTGCUINTPTR)pvEIP - (RTGCUINTPTR)pCur->GCPtr); 752 784 STAM_PROFILE_STOP(&pCur->Stat, h); 753 # else785 # else 754 786 rc = VINF_EM_RAW_EMULATE_INSTR; /** @todo for VMX */ 755 # endif787 # endif 756 788 STAM_PROFILE_STOP(&pVM->pgm.s.StatEIPHandlers, d); 757 789 return rc; … … 767 799 STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUnhandled); 768 800 return VINF_EM_RAW_GUEST_TRAP; 801 # else 802 /* present, but not a monitored page; perhaps the guest is probing physical memory */ 803 return VINF_EM_RAW_EMULATE_INSTR; 804 # endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 805 769 806 770 807 #else /* PGM_GST_TYPE != PGM_TYPE_32BIT */ … … 1021 1058 1022 1059 #else /* guest real and protected mode */ 1023 1060 /* There's no such thing when paging is disabled. */ 1024 1061 return VINF_SUCCESS; 1025 1062 #endif … … 1506 1543 return VINF_PGM_SYNCPAGE_MODIFIED_PDE; 1507 1544 1545 #elif PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT 1546 1547 # ifdef PGM_SYNC_N_PAGES 1548 /* 1549 * Get the shadow PDE, find the shadow page table in the pool. 1550 */ 1551 const unsigned iPDDst = GCPtrPage >> SHW_PD_SHIFT; 1552 # if PGM_SHW_TYPE == PGM_TYPE_32BIT 1553 X86PDE PdeDst = pVM->pgm.s.CTXMID(p,32BitPD)->a[iPDDst]; 1554 # else /* PAE */ 1555 X86PDEPAE PdeDst = pVM->pgm.s.CTXMID(ap,PaePDs)[0]->a[iPDDst]; 1556 # endif 1557 Assert(PdeDst.n.u1Present); 1558 PPGMPOOLPAGE pShwPage = pgmPoolGetPageByHCPhys(pVM, PdeDst.u & SHW_PDE_PG_MASK); 1559 PSHWPT pPTDst = (PSHWPT)PGMPOOL_PAGE_2_PTR(pVM, pShwPage); 1560 1561 # if PGM_SHW_TYPE == PGM_TYPE_32BIT 1562 const unsigned offPTSrc = 0; 1563 # else 1564 const unsigned offPTSrc = ((GCPtrPage >> SHW_PD_SHIFT) & 1) * 512; 1565 # endif 1566 1567 Assert(cPages == 1 || !(uErr & X86_TRAP_PF_P)); 1568 if (cPages > 1 && !(uErr & X86_TRAP_PF_P)) 1569 { 1570 /* 1571 * This code path is currently only taken when the caller is PGMTrap0eHandler 1572 * for non-present pages! 1573 * 1574 * We're setting PGM_SYNC_NR_PAGES pages around the faulting page to sync it and 1575 * deal with locality. 1576 */ 1577 unsigned iPTDst = (GCPtrPage >> SHW_PT_SHIFT) & SHW_PT_MASK; 1578 const unsigned iPTDstEnd = RT_MIN(iPTDst + PGM_SYNC_NR_PAGES / 2, ELEMENTS(pPTDst->a)); 1579 if (iPTDst < PGM_SYNC_NR_PAGES / 2) 1580 iPTDst = 0; 1581 else 1582 iPTDst -= PGM_SYNC_NR_PAGES / 2; 1583 for (; iPTDst < iPTDstEnd; iPTDst++) 1584 { 1585 if (!pPTDst->a[iPTDst].n.u1Present) 1586 { 1587 VBOXPTE PteSrc; 1588 1589 RTGCUINTPTR GCPtrCurPage = ((RTGCUINTPTR)GCPtrPage & ~(RTGCUINTPTR)(X86_PT_MASK << X86_PT_SHIFT)) | ((offPTSrc + iPTDst) << PAGE_SHIFT); 1590 1591 /* Fake the page table entry */ 1592 PteSrc.u = GCPtrCurPage; 1593 PteSrc.n.u1Present = 1; 1594 PteSrc.n.u1Dirty = 1; 1595 PteSrc.n.u1Accessed = 1; 1596 PteSrc.n.u1Write = 1; 1597 1598 PGM_BTH_NAME(SyncPageWorker)(pVM, &pPTDst->a[iPTDst], PdeSrc, PteSrc, pShwPage, iPTDst); 1599 1600 Log2(("SyncPage: 4K+ %VGv PteSrc:{P=%d RW=%d U=%d raw=%08llx} PteDst=%08llx%s\n", 1601 GCPtrCurPage, PteSrc.n.u1Present, 1602 PteSrc.n.u1Write & PdeSrc.n.u1Write, 1603 PteSrc.n.u1User & PdeSrc.n.u1User, 1604 (uint64_t)PteSrc.u, 1605 (uint64_t)pPTDst->a[iPTDst].u, 1606 pPTDst->a[iPTDst].u & PGM_PTFLAGS_TRACK_DIRTY ? " Track-Dirty" : "")); 1607 } 1608 } 1609 } 1610 else 1611 # endif /* PGM_SYNC_N_PAGES */ 1612 { 1613 VBOXPTE PteSrc; 1614 const unsigned iPTDst = (GCPtrPage >> SHW_PT_SHIFT) & SHW_PT_MASK; 1615 RTGCUINTPTR GCPtrCurPage = ((RTGCUINTPTR)GCPtrPage & ~(RTGCUINTPTR)(X86_PT_MASK << X86_PT_SHIFT)) | ((offPTSrc + iPTDst) << PAGE_SHIFT); 1616 1617 /* Fake the page table entry */ 1618 PteSrc.u = GCPtrCurPage; 1619 PteSrc.n.u1Present = 1; 1620 PteSrc.n.u1Dirty = 1; 1621 PteSrc.n.u1Accessed = 1; 1622 PteSrc.n.u1Write = 1; 1623 PGM_BTH_NAME(SyncPageWorker)(pVM, &pPTDst->a[iPTDst], PdeSrc, PteSrc, pShwPage, iPTDst); 1624 1625 Log2(("SyncPage: 4K %VGv PteSrc:{P=%d RW=%d U=%d raw=%08llx}%s\n", 1626 GCPtrPage, PteSrc.n.u1Present, 1627 PteSrc.n.u1Write & PdeSrc.n.u1Write, 1628 PteSrc.n.u1User & PdeSrc.n.u1User, 1629 (uint64_t)PteSrc.u, 1630 pPTDst->a[iPTDst].u & PGM_PTFLAGS_TRACK_DIRTY ? " Track-Dirty" : "")); 1631 } 1632 return VINF_SUCCESS; 1633 1508 1634 #else /* PGM_GST_TYPE != PGM_TYPE_32BIT */ 1509 1510 1635 AssertReleaseMsgFailed(("Shw=%d Gst=%d is not implemented!\n", PGM_GST_TYPE, PGM_SHW_TYPE)); 1511 1636 return VERR_INTERNAL_ERROR; … … 1515 1640 1516 1641 1517 #ifdef PGM_SYNC_DIRTY_BIT 1642 #if PGM_WITH_PAGING(PGM_GST_TYPE) 1643 1644 # ifdef PGM_SYNC_DIRTY_BIT 1518 1645 1519 1646 /** … … 1541 1668 || ((uErr & X86_TRAP_PF_US) && !pPdeSrc->n.u1User) ) 1542 1669 { 1543 # ifdef IN_GC1670 # ifdef IN_GC 1544 1671 STAM_COUNTER_INC(&pVM->pgm.s.StatGCDirtyTrackRealPF); 1545 # endif1672 # endif 1546 1673 STAM_PROFILE_STOP(&pVM->pgm.s.CTXMID(Stat, DirtyBitTracking), a); 1547 1674 LogFlow(("CheckPageFault: real page fault at %VGv (1)\n", GCPtrPage)); … … 1629 1756 ) 1630 1757 { 1631 # ifdef IN_GC1758 # ifdef IN_GC 1632 1759 STAM_COUNTER_INC(&pVM->pgm.s.StatGCDirtyTrackRealPF); 1633 # endif1760 # endif 1634 1761 STAM_PROFILE_STOP(&pVM->pgm.s.CTXMID(Stat,DirtyBitTracking), a); 1635 1762 LogFlow(("CheckPageFault: real page fault at %VGv PteSrc.u=%08x (2)\n", GCPtrPage, PteSrc.u)); … … 1658 1785 { 1659 1786 /* Write access, so mark guest entry as dirty. */ 1660 # if defined(IN_GC) && defined(VBOX_WITH_STATISTICS)1787 # if defined(IN_GC) && defined(VBOX_WITH_STATISTICS) 1661 1788 if (!pPteSrc->n.u1Dirty) 1662 1789 STAM_COUNTER_INC(&pVM->pgm.s.StatGCDirtiedPage); 1663 1790 else 1664 1791 STAM_COUNTER_INC(&pVM->pgm.s.StatGCPageAlreadyDirty); 1665 # endif1792 # endif 1666 1793 pPteSrc->n.u1Dirty = 1; 1667 1794 … … 1690 1817 { 1691 1818 LogFlow(("DIRTY page trap addr=%VGv\n", GCPtrPage)); 1692 # ifdef VBOX_STRICT1819 # ifdef VBOX_STRICT 1693 1820 RTHCPHYS HCPhys; 1694 1821 rc = PGMRamGCPhys2HCPhysWithFlags(&pVM->pgm.s, pPteSrc->u & X86_PTE_PG_MASK, &HCPhys); … … 1696 1823 AssertMsg(!(HCPhys & (MM_RAM_FLAGS_PHYSICAL_ALL | MM_RAM_FLAGS_VIRTUAL_ALL | MM_RAM_FLAGS_PHYSICAL_WRITE | MM_RAM_FLAGS_VIRTUAL_WRITE)), 1697 1824 ("Unexpected dirty bit tracking on monitored page %VGv (phys %VGp)!!!!!!\n", GCPtrPage, pPteSrc->u & X86_PTE_PAE_PG_MASK)); 1698 # endif1825 # endif 1699 1826 STAM_COUNTER_INC(&pVM->pgm.s.CTXMID(Stat,DirtyPageTrap)); 1700 1827 … … 1716 1843 } 1717 1844 /** @todo Optimize accessed bit emulation? */ 1718 # ifdef VBOX_STRICT1845 # ifdef VBOX_STRICT 1719 1846 /* 1720 1847 * Sanity check. … … 1731 1858 LogFlow(("Writable present page %VGv not marked for dirty bit tracking!!!\n", GCPtrPage)); 1732 1859 } 1733 # endif /* VBOX_STRICT */1860 # endif /* VBOX_STRICT */ 1734 1861 STAM_PROFILE_STOP(&pVM->pgm.s.CTXMID(Stat,DirtyBitTracking), a); 1735 1862 return VINF_PGM_NO_DIRTY_BIT_TRACKING; … … 1740 1867 } 1741 1868 1742 #endif 1869 # endif 1870 1871 #endif /* PGM_WITH_PAGING(PGM_GST_TYPE) */ 1743 1872 1744 1873 … … 1876 2005 pPDSrc->a[iPDSrc].n.u1Accessed = 1; 1877 2006 # endif 1878 1879 2007 if (fPageTable) 1880 2008 { … … 2033 2161 if (RT_UNLIKELY(!(pRam->aHCPhys[iHCPage] & X86_PTE_PAE_PG_MASK))) 2034 2162 { 2035 # ifdef IN_RING32163 # ifdef IN_RING3 2036 2164 int rc = pgmr3PhysGrowRange(pVM, GCPhys); 2037 # else2165 # else 2038 2166 int rc = CTXALLMID(VMM, CallHost)(pVM, VMMCALLHOST_PGM_RAM_GROW_RANGE, GCPhys); 2039 # endif2167 # endif 2040 2168 if (rc != VINF_SUCCESS) 2041 2169 return rc; … … 2055 2183 PteDst.u = 0; 2056 2184 } 2057 # ifndef IN_RING02185 # ifndef IN_RING0 2058 2186 /* 2059 2187 * Assuming kernel code will be marked as supervisor and not as user level and executed … … 2064 2192 && CSAMDoesPageNeedScanning(pVM, (RTGCPTR)(GCPtr | (iPTDst << SHW_PT_SHIFT)))) 2065 2193 PteDst.u = 0; 2066 # endif2194 # endif 2067 2195 else 2068 2196 PteDst.u = (HCPhys & X86_PTE_PAE_PG_MASK) | PteDstBase.u; … … 2110 2238 # ifdef IN_GC 2111 2239 if (VBOX_FAILURE(rc)) 2112 STAM_COUNTER_INC(&pVM->pgm.s.CTXMID(Stat,SyncPTFailed)); 2113 # endif 2240 STAM_COUNTER_INC(&pVM->pgm.s.CTXMID(Stat,SyncPTFailed)); 2241 # endif 2242 return rc; 2243 2244 #elif PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT 2245 2246 int rc = VINF_SUCCESS; 2247 2248 /* 2249 * Validate input a little bit. 2250 */ 2251 # if PGM_SHW_TYPE == PGM_TYPE_32BIT 2252 PX86PD pPDDst = pVM->pgm.s.CTXMID(p,32BitPD); 2253 # else 2254 PX86PDPAE pPDDst = pVM->pgm.s.CTXMID(ap,PaePDs)[0]; 2255 # endif 2256 const unsigned iPDDst = GCPtrPage >> SHW_PD_SHIFT; 2257 PSHWPDE pPdeDst = &pPDDst->a[iPDDst]; 2258 SHWPDE PdeDst = *pPdeDst; 2259 2260 Assert(!(PdeDst.u & PGM_PDFLAGS_MAPPING)); 2261 Assert(!PdeDst.n.u1Present); /* We're only supposed to call SyncPT on PDE!P and conflicts.*/ 2262 2263 VBOXPDE PdeSrc; 2264 PdeSrc.au32[0] = 0; /* faked so we don't have to #ifdef everything */ 2265 PdeSrc.n.u1Present = 1; 2266 PdeSrc.n.u1Write = 1; 2267 PdeSrc.n.u1Accessed = 1; 2268 2269 /* 2270 * Allocate & map the page table. 2271 */ 2272 PSHWPT pPTDst; 2273 PPGMPOOLPAGE pShwPage; 2274 RTGCPHYS GCPhys; 2275 2276 /* Virtual address = physical address */ 2277 GCPhys = GCPtrPage & X86_PAGE_4K_BASE_MASK_32; 2278 rc = pgmPoolAlloc(pVM, GCPhys, BTH_PGMPOOLKIND_PT_FOR_PT, SHW_POOL_ROOT_IDX, iPDDst, &pShwPage); 2279 2280 if ( rc == VINF_SUCCESS 2281 || rc == VINF_PGM_CACHED_PAGE) 2282 pPTDst = (PSHWPT)PGMPOOL_PAGE_2_PTR(pVM, pShwPage); 2283 else 2284 AssertMsgFailedReturn(("rc=%Vrc\n", rc), VERR_INTERNAL_ERROR); 2285 2286 PdeDst.u &= X86_PDE_AVL_MASK; 2287 PdeDst.u |= pShwPage->Core.Key; 2288 PdeDst.n.u1Present = 1; 2289 *pPdeDst = PdeDst; 2290 2291 rc = PGM_BTH_NAME(SyncPage)(pVM, PdeSrc, (RTGCUINTPTR)GCPtrPage, PGM_SYNC_NR_PAGES, 0 /* page not present */); 2292 STAM_PROFILE_STOP(&pVM->pgm.s.CTXMID(Stat,SyncPT), a); 2114 2293 return rc; 2115 2294 … … 2136 2315 PGM_BTH_DECL(int, PrefetchPage)(PVM pVM, RTGCUINTPTR GCPtrPage) 2137 2316 { 2138 #if PGM_GST_TYPE == PGM_TYPE_32BIT2317 #if (PGM_GST_TYPE == PGM_TYPE_32BIT || PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT) && PGM_SHW_TYPE != PGM_TYPE_AMD64 2139 2318 2140 2319 # if PGM_SHW_TYPE != PGM_TYPE_32BIT && PGM_SHW_TYPE != PGM_TYPE_PAE … … 2147 2326 */ 2148 2327 int rc = VINF_SUCCESS; 2149 PVBOXPD pPDSrc = CTXSUFF(pVM->pgm.s.pGuestPD); 2150 const unsigned iPDSrc = GCPtrPage >> GST_PD_SHIFT; 2151 const VBOXPDE PdeSrc = pPDSrc->a[iPDSrc]; 2328 # if PGM_WITH_PAGING(PGM_GST_TYPE) 2329 PVBOXPD pPDSrc = CTXSUFF(pVM->pgm.s.pGuestPD); 2330 const unsigned iPDSrc = (RTGCUINTPTR)GCPtrPage >> GST_PD_SHIFT; 2331 # else 2332 PVBOXPD pPDSrc = NULL; 2333 const unsigned iPDSrc = 0; 2334 # endif 2335 2336 # if PGM_WITH_PAGING(PGM_GST_TYPE) 2337 const VBOXPDE PdeSrc = pPDSrc->a[iPDSrc]; 2338 # else 2339 VBOXPDE PdeSrc; 2340 PdeSrc.au32[0] = 0; /* faked so we don't have to #ifdef everything */ 2341 PdeSrc.n.u1Present = 1; 2342 PdeSrc.n.u1Write = 1; 2343 PdeSrc.n.u1Accessed = 1; 2344 # endif 2345 2152 2346 # ifdef PGM_SYNC_ACCESSED_BIT 2153 2347 if (PdeSrc.n.u1Present && PdeSrc.n.u1Accessed) … … 2261 2455 } 2262 2456 return rc; 2457 2458 #elif PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT 2459 /* Everything is allowed */ 2460 return VINF_SUCCESS; 2263 2461 2264 2462 #else /* PGM_GST_TYPE != PGM_TYPE_32BIT */
Note:
See TracChangeset
for help on using the changeset viewer.