- Timestamp:
- Jul 25, 2012 3:22:05 PM (12 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/DevOVMF.cpp
r41470 r42397 53 53 #include <Common/PiFirmwareVolume.h> 54 54 #include <Common/PiFirmwareFile.h> 55 #include <IndustryStandard/PeImage.h>56 55 57 56 /******************************************************************************* … … 359 358 { 360 359 case EFI_PANIC_CMD_BAD_ORG: 360 #if 0 361 361 LogRel(("EFI Panic: You have to fix ORG offset in EfiThunk.asm! Must be 0x%x\n", 362 362 g_cbEfiThunkBinary)); … … 364 364 g_cbEfiThunkBinary); 365 365 break; 366 #endif 366 367 367 368 case EFI_PANIC_CMD_THUNK_TRAP: … … 579 580 } 580 581 581 static int efiFindRelativeAddressOfEPAndBaseAddressOfModule(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage)582 {583 /*584 * Sections headers are lays at the beginning of block it describes,585 * the first section header is located immediately after FFS header.586 */587 EFI_FILE_SECTION_POINTER uSecHdrPtr;588 uint8_t const * const pbFfsFileEnd = (uint8_t *)pFfsFile + cbFfsFile;589 uint8_t const *pbImage = NULL;590 uint8_t const *pbSecHdr = (uint8_t const *)&pFfsFile[1]; /* FFS header has fixed size */591 for (; (uintptr_t)pbSecHdr < (uintptr_t)pbFfsFileEnd;592 pbSecHdr += SECTION_SIZE(uSecHdrPtr.CommonHeader))593 {594 uSecHdrPtr.CommonHeader = (EFI_COMMON_SECTION_HEADER *)pbSecHdr;595 if ( uSecHdrPtr.CommonHeader->Type == EFI_SECTION_PE32596 || uSecHdrPtr.CommonHeader->Type == EFI_SECTION_TE)597 {598 /*Here should be other code containing sections*/599 pbImage = (uint8_t const *)&uSecHdrPtr.Pe32Section[1]; /* the PE/PE+/TE headers begins just after the Section Header */600 break;601 }602 Log2(("EFI: Section of type:%d has been detected\n", uSecHdrPtr.CommonHeader->Type));603 }604 AssertLogRelMsgReturn(pbImage, ("Failed to find PE32 or TE section for the SECURITY_CORE FFS\n"), VERR_INVALID_PARAMETER);605 606 /*607 * Parse the image extracting the ImageBase and the EntryPoint.608 */609 int rc = VINF_SUCCESS;610 union EfiHdrUnion611 {612 EFI_IMAGE_DOS_HEADER Dos;613 EFI_IMAGE_NT_HEADERS32 Nt32;614 EFI_IMAGE_NT_HEADERS64 Nt64;615 EFI_TE_IMAGE_HEADER Te;616 };617 EfiHdrUnion const *pHdr = (EfiHdrUnion const *)pbImage;618 619 /* Skip MZ if found. */620 if (pHdr->Dos.e_magic == RT_MAKE_U16('M', 'Z'))621 {622 uint8_t const *pbNewHdr = (uint8_t const *)pHdr + pHdr->Dos.e_lfanew;623 AssertLogRelMsgReturn( (uintptr_t)pbNewHdr < (uintptr_t)pbFfsFileEnd624 && (uintptr_t)pbNewHdr >= (uintptr_t)&pHdr->Dos.e_lfanew + sizeof(pHdr->Dos.e_lfanew),625 ("%x\n", pHdr->Dos.e_lfanew),626 VERR_BAD_EXE_FORMAT);627 pHdr = (EfiHdrUnion const *)pbNewHdr;628 }629 630 RTGCPHYS ImageBase;631 RTGCPHYS EpRVA;632 if (pHdr->Nt32.Signature == RT_MAKE_U32_FROM_U8('P', 'E', 0, 0))633 {634 AssertLogRelMsgReturn( ( pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386635 && pHdr->Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pHdr->Nt32.OptionalHeader))636 || ( pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_MACHINE_X64637 && pHdr->Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pHdr->Nt64.OptionalHeader)),638 ("%x / %x\n", pHdr->Nt32.FileHeader.Machine, pHdr->Nt32.FileHeader.SizeOfOptionalHeader),639 VERR_LDR_ARCH_MISMATCH);640 EFI_IMAGE_SECTION_HEADER *pSectionsHeaders = NULL;641 int cSectionsHeaders = 0;642 if (pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386)643 {644 Log2(("EFI: PE32/i386\n"));645 AssertLogRelMsgReturn(pHdr->Nt32.OptionalHeader.SizeOfImage < cbFfsFile,646 ("%#x / %#x\n", pHdr->Nt32.OptionalHeader.SizeOfImage, cbFfsFile),647 VERR_BAD_EXE_FORMAT);648 ImageBase = pHdr->Nt32.OptionalHeader.ImageBase;649 EpRVA = pHdr->Nt32.OptionalHeader.AddressOfEntryPoint;650 EpRVA -= pHdr->Nt32.OptionalHeader.BaseOfCode;651 AssertLogRelMsgReturn(EpRVA < pHdr->Nt32.OptionalHeader.SizeOfImage,652 ("%#RGp / %#x\n", EpRVA, pHdr->Nt32.OptionalHeader.SizeOfImage),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;656 }657 else658 {659 Log2(("EFI: PE+/AMD64 %RX16\n", pHdr->Nt32.FileHeader.Machine));660 AssertLogRelMsgReturn(pHdr->Nt64.OptionalHeader.SizeOfImage < cbFfsFile,661 ("%#x / %#x\n", pHdr->Nt64.OptionalHeader.SizeOfImage, cbFfsFile),662 VERR_BAD_EXE_FORMAT);663 ImageBase = pHdr->Nt64.OptionalHeader.ImageBase;664 EpRVA = pHdr->Nt64.OptionalHeader.AddressOfEntryPoint;665 EpRVA -= pHdr->Nt64.OptionalHeader.BaseOfCode;666 AssertLogRelMsgReturn(EpRVA < pHdr->Nt64.OptionalHeader.SizeOfImage,667 ("%#RGp / %#x\n", EpRVA, pHdr->Nt64.OptionalHeader.SizeOfImage),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 }682 }683 }684 else if (pHdr->Te.Signature == RT_MAKE_U16('V', 'Z'))685 {686 /* TE header */687 Log2(("EFI: TE header\n"));688 AssertLogRelMsgReturn( pHdr->Te.Machine == EFI_IMAGE_FILE_MACHINE_I386689 || pHdr->Te.Machine == EFI_IMAGE_MACHINE_X64,690 ("%x\n", pHdr->Te.Machine),691 VERR_LDR_ARCH_MISMATCH);692 ImageBase = pHdr->Te.ImageBase;693 EpRVA = pHdr->Te.AddressOfEntryPoint;694 AssertLogRelMsgReturn(EpRVA < cbFfsFile,695 ("%#RGp / %#x\n", EpRVA, cbFfsFile),696 VERR_BAD_EXE_FORMAT);697 }698 else699 AssertLogRelMsgFailedReturn(("%#x\n", pHdr->Nt32.Signature), VERR_INVALID_EXE_SIGNATURE);700 701 Log2(("EFI: EpRVA=%RGp ImageBase=%RGp EntryPoint=%RGp\n", EpRVA, ImageBase, EpRVA + ImageBase));702 if (pImageBase != NULL)703 *pImageBase = ImageBase;704 if (ppbImage != NULL)705 *ppbImage = (uint8_t *)pbImage;706 return (EpRVA);707 }708 582 709 583 /** … … 738 612 739 613 uint8_t const * const pbFwVolEnd = pThis->pu8EfiRom + pFwVolHdr->FvLength; 740 614 pThis->GCLoadAddress = UINT32_C(0xfffff000) - pThis->cbEfiRom + PAGE_SIZE; 615 616 #if 0 741 617 /* 742 618 * Ffs files are stored one by one, so to find SECURITY_CORE we've to … … 779 655 LogRel(("EFI: Firmware volume loading at %RGp, PEI CORE at with EP at %RGp\n", 780 656 pThis->GCLoadAddress, pThis->GCEntryPoint1)); 657 #endif 781 658 return VINF_SUCCESS; 782 659 } … … 863 740 } 864 741 742 #if 0 865 743 /** 866 744 * Patches and loads the EfiThunk ROM image. … … 941 819 return rc; 942 820 } 821 #endif 943 822 944 823 … … 1210 1089 return rc; 1211 1090 1091 #if 0 1212 1092 rc = efiLoadThunk(pThis, pCfg); 1213 1093 if (RT_FAILURE(rc)) 1214 1094 return rc; 1095 #endif 1215 1096 1216 1097 /* -
trunk/src/VBox/Devices/Makefile.kmk
r42310 r42397 44 44 include $(PATH_SUB_CURRENT)/Graphics/BIOS/Makefile.kmk 45 45 endif 46 if def VBOX_WITH_EFI46 if defined(VBOX_WITH_EFI) && !defined(VBOX_WITH_OVMF) 47 47 include $(PATH_SUB_CURRENT)/EFI/Thunk/Makefile.kmk 48 48 endif … … 469 469 470 470 ifdef VBOX_WITH_EFI 471 VBoxDD_DEFS += VBOX_WITH_EFI 472 VBoxDD_LIBS += $(PATH_STAGE_LIB)/EfiThunkBin$(VBOX_SUFF_LIB) 473 ifdef VBOX_WITH_ALT_EFITHUNK 474 VBoxDD_DEFS += VBOX_WITH_ALT_EFITHUNK 475 endif 476 VBoxDD_SOURCES += EFI/DevEFI.cpp 477 EFI/DevEFI.cpp_INCS += EFI/tools/include 478 EFI/DevEFI.cpp_INCS.x86 += EFI/tools/include/Ia32 479 EFI/DevEFI.cpp_INCS.amd64 += EFI/tools/include/X64 471 ifndef VBOX_WITH_OVMF 472 VBoxDD_DEFS += VBOX_WITH_EFI 473 VBoxDD_LIBS += $(PATH_STAGE_LIB)/EfiThunkBin$(VBOX_SUFF_LIB) 474 ifdef VBOX_WITH_ALT_EFITHUNK 475 VBoxDD_DEFS += VBOX_WITH_ALT_EFITHUNK 476 endif 477 VBoxDD_SOURCES += EFI/DevEFI.cpp 478 EFI/DevEFI.cpp_INCS += EFI/tools/include 479 EFI/DevEFI.cpp_INCS.x86 += EFI/tools/include/Ia32 480 EFI/DevEFI.cpp_INCS.amd64 += EFI/tools/include/X64 481 else 482 VBoxDD_DEFS += VBOX_WITH_EFI 483 VBoxDD_SOURCES += EFI/DevOVMF.cpp 484 EFI/DevOVMF.cpp_INCS += EFI/tools/include 485 EFI/DevOVMF.cpp_INCS.x86 += EFI/tools/include/Ia32 486 EFI/DevOVMF.cpp_INCS.amd64 += EFI/tools/include/X64 487 build/VBoxDD.cpp_DEFS += VBOX_WITH_OVMF 488 endif 480 489 endif 481 490 -
trunk/src/VBox/Devices/build/VBoxDD.cpp
r40652 r42397 37 37 const void *g_apvVBoxDDDependencies[] = 38 38 { 39 #if def VBOX_WITH_EFI39 #if defined(VBOX_WITH_EFI) && !defined(VBOX_WITH_OVMF) 40 40 &g_abEfiThunkBinary[0], 41 41 #endif
Note:
See TracChangeset
for help on using the changeset viewer.