Changeset 41162 in vbox for trunk/src/VBox/Devices
- Timestamp:
- May 4, 2012 12:09:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/DevEFI.cpp
r40280 r41162 571 571 { 572 572 *pcbFile = FFS_SIZE(pFfsFile); 573 LogFunc(("Found %RTuuid of type:%d\n", &pFfsFile->Name, FileType)); 573 574 return pFfsFile; 574 575 } … … 578 579 } 579 580 580 static int efiFind EntryPoint(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage)581 static int efiFindRelativeAddressOfEPAndBaseAddressOfModule(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage) 581 582 { 582 583 /* … … 637 638 ("%x / %x\n", pHdr->Nt32.FileHeader.Machine, pHdr->Nt32.FileHeader.SizeOfOptionalHeader), 638 639 VERR_LDR_ARCH_MISMATCH); 640 EFI_IMAGE_SECTION_HEADER *pSectionsHeaders = NULL; 641 int cSectionsHeaders = 0; 639 642 if (pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386) 640 643 { … … 645 648 ImageBase = pHdr->Nt32.OptionalHeader.ImageBase; 646 649 EpRVA = pHdr->Nt32.OptionalHeader.AddressOfEntryPoint; 650 EpRVA -= pHdr->Nt32.OptionalHeader.BaseOfCode; 647 651 AssertLogRelMsgReturn(EpRVA < pHdr->Nt32.OptionalHeader.SizeOfImage, 648 652 ("%#RGp / %#x\n", EpRVA, pHdr->Nt32.OptionalHeader.SizeOfImage), 649 653 VERR_BAD_EXE_FORMAT); 654 pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt32.OptionalHeader + pHdr->Nt32.FileHeader.SizeOfOptionalHeader); 655 cSectionsHeaders = pHdr->Nt32.FileHeader.NumberOfSections; 650 656 } 651 657 else 652 658 { 653 Log2(("EFI: PE+/AMD64 \n"));659 Log2(("EFI: PE+/AMD64 %RX16\n", pHdr->Nt32.FileHeader.Machine)); 654 660 AssertLogRelMsgReturn(pHdr->Nt64.OptionalHeader.SizeOfImage < cbFfsFile, 655 661 ("%#x / %#x\n", pHdr->Nt64.OptionalHeader.SizeOfImage, cbFfsFile), … … 657 663 ImageBase = pHdr->Nt64.OptionalHeader.ImageBase; 658 664 EpRVA = pHdr->Nt64.OptionalHeader.AddressOfEntryPoint; 665 EpRVA -= pHdr->Nt64.OptionalHeader.BaseOfCode; 659 666 AssertLogRelMsgReturn(EpRVA < pHdr->Nt64.OptionalHeader.SizeOfImage, 660 667 ("%#RGp / %#x\n", EpRVA, pHdr->Nt64.OptionalHeader.SizeOfImage), 661 668 VERR_BAD_EXE_FORMAT); 669 pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt64.OptionalHeader + pHdr->Nt64.FileHeader.SizeOfOptionalHeader); 670 cSectionsHeaders = pHdr->Nt64.FileHeader.NumberOfSections; 671 } 672 AssertPtrReturn(pSectionsHeaders, VERR_BAD_EXE_FORMAT); 673 int idxSection = 0; 674 for (; idxSection < cSectionsHeaders; ++idxSection) 675 { 676 EFI_IMAGE_SECTION_HEADER *pSection = &pSectionsHeaders[idxSection]; 677 if (!RTStrCmp((const char *)&pSection->Name[0], ".text")) 678 { 679 EpRVA += pSection->PointerToRawData; 680 break; 681 } 662 682 } 663 683 } … … 684 704 if (ppbImage != NULL) 685 705 *ppbImage = (uint8_t *)pbImage; 686 return ImageBase + EpRVA;706 return (EpRVA); 687 707 } 688 708 … … 728 748 AssertLogRelMsgReturn(pFfsFile, ("No SECURITY_CORE found in the firmware volume\n"), VERR_FILE_NOT_FOUND); 729 749 730 RTGCPHYS ImageBase; 731 uint8_t *pbImage; 732 pThis->GCEntryPoint0 = efiFindEntryPoint(pFfsFile, cbFfsFile, &ImageBase, &pbImage); 733 750 RTGCPHYS ImageBase = NULL; 751 uint8_t *pbImage = NULL; 752 pThis->GCEntryPoint0 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, &ImageBase, &pbImage); 753 pThis->GCEntryPoint0 += pbImage - pThis->pu8EfiRom; 754 Assert(pThis->pu8EfiRom <= pbImage); 755 Assert(pbImage < pThis->pu8EfiRom + pThis->cbEfiRom); 734 756 /* 735 757 * Calc the firmware load address from the image base and validate it. 736 758 */ 737 759 pThis->GCLoadAddress = ImageBase - (pbImage - pThis->pu8EfiRom); 760 pThis->GCEntryPoint0 += pThis->GCLoadAddress; 738 761 AssertLogRelMsgReturn(~(pThis->GCLoadAddress & PAGE_OFFSET_MASK), 739 762 ("%RGp\n", pThis->GCLoadAddress), … … 751 774 752 775 pFfsFile = efiFwVolFindFileByType(pFfsFile, pbFwVolEnd, EFI_FV_FILETYPE_PEI_CORE, &cbFfsFile); 753 pThis->GCEntryPoint1 = efiFindEntryPoint(pFfsFile, cbFfsFile, NULL, NULL); 776 pThis->GCEntryPoint1 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, NULL, &pbImage); 777 pThis->GCEntryPoint1 += pThis->GCLoadAddress; 778 pThis->GCEntryPoint1 += pbImage - pThis->pu8EfiRom; 754 779 LogRel(("EFI: Firmware volume loading at %RGp, PEI CORE at with EP at %RGp\n", 755 780 pThis->GCLoadAddress, pThis->GCEntryPoint1)); … … 805 830 PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, 806 831 "EFI Firmware Volume"); 807 if (RT_FAILURE(rc)) 808 return rc; 832 AssertRCReturn(rc, rc); 833 rc = PDMDevHlpROMProtectShadow(pThis->pDevIns, pThis->GCLoadAddress, (uint32_t)cbQuart, PGMROMPROT_READ_RAM_WRITE_IGNORE); 834 AssertRCReturn(rc, rc); 809 835 rc = PDMDevHlpROMRegister(pThis->pDevIns, 810 836 pThis->GCLoadAddress + cbQuart,
Note:
See TracChangeset
for help on using the changeset viewer.