Changeset 81195 in vbox for trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg
- Timestamp:
- Oct 9, 2019 8:04:51 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 133846
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/CpuDxe/CpuPageTable.c
r81193 r81195 18 18 #include <Register/Intel/Cpuid.h> 19 19 #include <Register/Intel/Msr.h> 20 #ifdef VBOX 21 # define IN_RING0 22 # include <iprt/asm.h> 23 #endif 20 24 21 25 #include "CpuDxe.h" … … 97 101 UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT]; 98 102 103 #ifdef VBOX 104 /** 105 Safe page table entry write function, make 104% sure the compiler won't 106 split up the access (fatal if modifying entries for current code or data). 107 108 @param[in] PageEntry The page table entry to modify.* 109 @param[in] CurrentPageEntry The old page table value (for cmpxchg8b). 110 @param[in] NewPageEntry What to write. 111 **/ 112 static VOID SafePageTableEntryWrite64 (UINT64 volatile *PageEntry, UINT64 CurrentPageEntry, UINT64 NewPageEntry) 113 { 114 # ifdef VBOX 115 ASMAtomicWriteU64(PageEntry, NewPageEntry); RT_NOREF(CurrentPageEntry); 116 # else 117 for (;;) { 118 UINT64 CurValue = InterlockedCompareExchange64(PageEntry, CurrentPageEntry, NewPageEntry); 119 if (CurValue == CurrentPageEntry) 120 return; 121 CurrentPageEntry = CurValue; 122 } 123 # endif 124 } 125 #endif 126 99 127 /** 100 128 Check if current execution environment is in SMM mode or not, via … … 388 416 ConvertPageEntryAttribute ( 389 417 IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext, 418 #ifdef VBOX 419 IN UINT64 volatile *PageEntry, 420 #else 390 421 IN UINT64 *PageEntry, 422 #endif 391 423 IN UINT64 Attributes, 392 424 IN PAGE_ACTION PageAction, … … 461 493 } 462 494 } 495 #ifndef VBOX 463 496 *PageEntry = NewPageEntry; 497 #endif 464 498 if (CurrentPageEntry != NewPageEntry) { 499 #ifdef VBOX 500 SafePageTableEntryWrite64 (PageEntry, CurrentPageEntry, NewPageEntry); 501 #endif 465 502 *IsModified = TRUE; 466 503 DEBUG ((DEBUG_VERBOSE, "ConvertPageEntryAttribute 0x%lx", CurrentPageEntry)); … … 519 556 SplitPage ( 520 557 #ifdef VBOX 521 IN volatile UINT64*PageEntry,558 IN UINT64 volatile *PageEntry, 522 559 #else 523 560 IN UINT64 *PageEntry, … … 529 566 { 530 567 UINT64 BaseAddress; 568 #ifdef VBOX 569 UINT64 CurrentPageEntry; 570 #endif 531 571 UINT64 *NewPageEntry; 532 572 UINTN Index; … … 552 592 return RETURN_OUT_OF_RESOURCES; 553 593 } 594 #ifdef VBOX 595 CurrentPageEntry = *PageEntry; 596 BaseAddress = CurrentPageEntry & ~AddressEncMask & PAGING_2M_ADDRESS_MASK_64; 597 #else 554 598 BaseAddress = *PageEntry & ~AddressEncMask & PAGING_2M_ADDRESS_MASK_64; 599 #endif 555 600 for (Index = 0; Index < SIZE_4KB / sizeof(UINT64); Index++) { 601 #ifdef VBOX 602 NewPageEntry[Index] = (BaseAddress + SIZE_4KB * Index) | AddressEncMask | (CurrentPageEntry & PAGE_PROGATE_BITS); 603 #else 556 604 NewPageEntry[Index] = (BaseAddress + SIZE_4KB * Index) | AddressEncMask | ((*PageEntry) & PAGE_PROGATE_BITS); 557 } 605 #endif 606 } 607 #ifdef VBOX 608 SafePageTableEntryWrite64 (PageEntry, CurrentPageEntry, 609 (UINT64)(UINTN)NewPageEntry | AddressEncMask | (CurrentPageEntry & PAGE_ATTRIBUTE_BITS)); 610 #else 558 611 (*PageEntry) = (UINT64)(UINTN)NewPageEntry | AddressEncMask | ((*PageEntry) & PAGE_ATTRIBUTE_BITS); 612 #endif 559 613 return RETURN_SUCCESS; 560 614 } else { … … 573 627 return RETURN_OUT_OF_RESOURCES; 574 628 } 629 #ifdef VBOX 630 CurrentPageEntry = *PageEntry; 631 BaseAddress = CurrentPageEntry & ~AddressEncMask & PAGING_1G_ADDRESS_MASK_64; 632 #else 575 633 BaseAddress = *PageEntry & ~AddressEncMask & PAGING_1G_ADDRESS_MASK_64; 634 #endif 576 635 for (Index = 0; Index < SIZE_4KB / sizeof(UINT64); Index++) { 636 #ifdef VBOX 637 NewPageEntry[Index] = (BaseAddress + SIZE_2MB * Index) | AddressEncMask | IA32_PG_PS | (CurrentPageEntry & PAGE_PROGATE_BITS); 638 #else 577 639 NewPageEntry[Index] = (BaseAddress + SIZE_2MB * Index) | AddressEncMask | IA32_PG_PS | ((*PageEntry) & PAGE_PROGATE_BITS); 578 } 640 #endif 641 } 642 #ifdef VBOX 643 SafePageTableEntryWrite64 (PageEntry, CurrentPageEntry, 644 (UINT64)(UINTN)NewPageEntry | AddressEncMask | (CurrentPageEntry & PAGE_ATTRIBUTE_BITS)); 645 #else 579 646 (*PageEntry) = (UINT64)(UINTN)NewPageEntry | AddressEncMask | ((*PageEntry) & PAGE_ATTRIBUTE_BITS); 647 #endif 580 648 return RETURN_SUCCESS; 581 649 } else {
Note:
See TracChangeset
for help on using the changeset viewer.