#include <Library/PeCoffLoaderLib.h>\r
#include <Library/CacheMaintenanceLib.h>\r
#include <Library/BaseMemoryLib.h>\r
+#include <Library/PeCoffLib.h>\r
\r
#include "DebugImageInfo.h"\r
#include "Library.h"\r
[LibraryClasses]\r
BaseMemoryLib\r
CacheMaintenanceLib\r
- PeCoffLoaderLib\r
UefiDecompressLib\r
CustomDecompressLib\r
PerformanceLib\r
UefiLib\r
DebugLib\r
DxeCoreEntryPoint\r
+ PeCoffLib\r
\r
[Guids]\r
gEfiEventLegacyBootGuid # ALWAYS_CONSUMED\r
// DXE Core Global Variables for Protocols from PEI\r
//\r
EFI_HANDLE mDecompressHandle = NULL;\r
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *gEfiPeiPeCoffLoader = NULL;\r
\r
//\r
// DXE Core globals for Architecture Protocols\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- gEfiPeiPeCoffLoader = GetPeCoffLoaderProtocol ();\r
- ASSERT (gEfiPeiPeCoffLoader != NULL);\r
-\r
//\r
// Register for the GUIDs of the Architectural Protocols, so the rest of the\r
// EFI Boot Services and EFI Runtime Services tables can be filled in.\r
//\r
// Get information about the image being loaded\r
//\r
- Status = gEfiPeiPeCoffLoader->GetImageInfo (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+ Status = PeCoffLoaderGetImageInfo (&Image->ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Load the image from the file into the allocated memory\r
//\r
- Status = gEfiPeiPeCoffLoader->LoadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+ Status = PeCoffLoaderLoadImage (&Image->ImageContext);\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
//\r
// Relocate the image in memory\r
//\r
- Status = gEfiPeiPeCoffLoader->RelocateImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+ Status = PeCoffLoaderRelocateImage (&Image->ImageContext);\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
//\r
// Unload image, free Image->ImageContext->ModHandle\r
//\r
- gEfiPeiPeCoffLoader->UnloadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+ PeCoffLoaderUnloadImage (&Image->ImageContext);\r
\r
//\r
// Free our references to the image handle\r
PeiServicesTablePointerLib\r
CustomDecompressLib\r
UefiDecompressLib\r
- PeCoffLoaderLib\r
CacheMaintenanceLib\r
ReportStatusCodeLib\r
PeiServicesLib\r
gEfiPeiSectionExtractionPpiGuid # PPI SOMETIMES_CONSUMED\r
gEfiEndOfPeiSignalPpiGuid # PPI SOMETIMES_PRODUCED\r
gEfiDxeIplPpiGuid # PPI SOMETIMES_PRODUCED\r
- gEfiPeiPeCoffLoaderGuid \r
gEfiPeiDecompressPpiGuid\r
gEfiPeiFirmwareVolumeInfoPpiGuid\r
\r
EFI_PHYSICAL_ADDRESS DxeCoreAddress;\r
UINT64 DxeCoreSize;\r
EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;\r
- EFI_PEI_PE_COFF_LOADER_PROTOCOL *PeiEfiPeiPeCoffLoader;\r
EFI_BOOT_MODE BootMode;\r
EFI_PEI_FV_HANDLE VolumeHandle;\r
EFI_PEI_FILE_HANDLE FileHandle;\r
// Now should have a HOB with the DXE core w/ the old HOB destroyed\r
//\r
}\r
-\r
- //\r
- // Install the PEI Protocols that are shared between PEI and DXE\r
- //\r
- PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *) GetPeCoffLoaderProtocol ();\r
- ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
\r
//\r
// If any FV contains an encapsulated FV extract that FV\r
);\r
\r
//\r
- // Add HOB for the PE/COFF Loader Protocol\r
- //\r
- BuildGuidDataHob (\r
- &gEfiPeiPeCoffLoaderGuid,\r
- (VOID *)&PeiEfiPeiPeCoffLoader,\r
- sizeof (VOID *)\r
- );\r
- //\r
// Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
//\r
REPORT_STATUS_CODE (\r
EFI_STATUS Status;\r
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
VOID *Pe32Data;\r
- EFI_PEI_PE_COFF_LOADER_PROTOCOL *PeiEfiPeiPeCoffLoader;\r
-\r
- PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
//\r
// First try to find the required section in this ffs file.\r
//\r
\r
ASSERT_EFI_ERROR (Status);\r
\r
- Status = PeiEfiPeiPeCoffLoader->GetImageInfo (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Load the image to our new buffer\r
//\r
- Status = PeiEfiPeiPeCoffLoader->LoadImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderLoadImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Relocate the image in our new buffer\r
//\r
- Status = PeiEfiPeiPeCoffLoader->RelocateImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderRelocateImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
STATIC\r
EFI_STATUS\r
LoadAndRelocatePeCoffImage (\r
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *PeiEfiPeiPeCoffLoader,\r
IN VOID *Pe32Data,\r
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,\r
OUT UINT64 *ImageSize,\r
\r
Arguments:\r
\r
- PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol\r
-\r
Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated\r
\r
ImageAddress - The base address of the relocated PE/COFF image\r
EFI_STATUS Status;\r
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;\r
\r
- ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
-\r
ZeroMem (&ImageContext, sizeof (ImageContext));\r
ImageContext.Handle = Pe32Data;\r
Status = GetImageReadFunction (&ImageContext);\r
\r
ASSERT_EFI_ERROR (Status);\r
\r
- Status = PeiEfiPeiPeCoffLoader->GetImageInfo (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Load the image to our new buffer\r
//\r
- Status = PeiEfiPeiPeCoffLoader->LoadImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderLoadImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Relocate the image in our new buffer\r
//\r
- Status = PeiEfiPeiPeCoffLoader->RelocateImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+ Status = PeCoffLoaderRelocateImage (&ImageContext);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
EFI_PHYSICAL_ADDRESS ImageAddress;\r
UINT64 ImageSize;\r
EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r
- EFI_TE_IMAGE_HEADER *TEImageHeader;\r
UINT16 Machine;\r
PEI_CORE_INSTANCE *Private;\r
VOID *EntryPointArg;\r
\r
- *EntryPoint = 0;\r
- TEImageHeader = NULL;\r
- ImageSize = 0;\r
+ *EntryPoint = 0;\r
+ ImageSize = 0;\r
*AuthenticationState = 0;\r
\r
//\r
FileHandle,\r
&Pe32Data\r
);\r
- if (!EFI_ERROR (Status)) {\r
- TEImageHeader = (EFI_TE_IMAGE_HEADER *)Pe32Data;\r
- }\r
//\r
- // If we didn't find a PE32 section, try to find a TE section.\r
+ // If we didn't find a TE section, try to find a PE32 section.\r
//\r
if (EFI_ERROR (Status)) {\r
Status = PeiServicesFfsFindSectionData (\r
\r
if (Private->PeiMemoryInstalled && \r
(Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
- {\r
- //\r
- // If memory is installed, perform the shadow operations\r
- //\r
- Status = LoadAndRelocatePeCoffImage (\r
- Private->PeCoffLoader,\r
- Pe32Data,\r
- &ImageAddress,\r
- &ImageSize,\r
- &ImageEntryPoint\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return EFI_NOT_FOUND;\r
- }\r
+ //\r
+ // If memory is installed, perform the shadow operations\r
+ //\r
+ Status = LoadAndRelocatePeCoffImage (\r
+ Pe32Data,\r
+ &ImageAddress,\r
+ &ImageSize,\r
+ &ImageEntryPoint\r
+ );\r
\r
- //\r
- // Got the entry point from ImageEntryPoint and ImageStartAddress\r
- //\r
- Pe32Data = (VOID *) ((UINTN) ImageAddress);\r
- *EntryPoint = ImageEntryPoint;\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
}\r
+\r
+ //\r
+ // Got the entry point from the loaded Pe32Data\r
+ //\r
+ Pe32Data = (VOID *) ((UINTN) ImageAddress);\r
+ *EntryPoint = ImageEntryPoint;\r
} else {\r
- if (TEImageHeader != NULL) {\r
- //\r
- // Retrieve the entry point from the TE image header\r
- //\r
- ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) TEImageHeader;\r
- ImageSize = 0;\r
- *EntryPoint = (EFI_PHYSICAL_ADDRESS)((UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) +\r
- TEImageHeader->AddressOfEntryPoint - TEImageHeader->StrippedSize);\r
- } else {\r
- //\r
- // Retrieve the entry point from the PE/COFF image header\r
- //\r
- ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;\r
- ImageSize = 0;\r
- Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);\r
- *EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;\r
- if (EFI_ERROR (Status)) {\r
- return EFI_NOT_FOUND;\r
- }\r
+ //\r
+ // Retrieve the entry point from the PE/COFF or TE image header\r
+ //\r
+ ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;\r
+ Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
}\r
+ *EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;\r
}\r
-\r
- if (((EFI_TE_IMAGE_HEADER *) (UINTN) ImageAddress)->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
- TEImageHeader = (EFI_TE_IMAGE_HEADER *) (UINTN) ImageAddress;\r
- Machine = TEImageHeader->Machine;\r
- } else {\r
- Machine = PeCoffLoaderGetMachineType (Pe32Data);\r
- } \r
+ \r
+ Machine = PeCoffLoaderGetMachineType (Pe32Data);\r
\r
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Machine)) {\r
return EFI_UNSUPPORTED; \r
//\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, *EntryPoint));\r
DEBUG_CODE_BEGIN ();\r
- EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;\r
- EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
- UINTN DirCount;\r
- UINTN Index;\r
- UINTN Index1;\r
- BOOLEAN FileNameFound;\r
- CHAR8 *AsciiString;\r
- CHAR8 AsciiBuffer[512];\r
- VOID *CodeViewEntryPointer;\r
- INTN TEImageAdjust;\r
- EFI_IMAGE_DOS_HEADER *DosHeader;\r
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
- UINT32 NumberOfRvaAndSizes;\r
-\r
- Hdr.Pe32 = NULL;\r
- if (TEImageHeader == NULL) {\r
- DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
- if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
- //\r
- // DOS image header is present, so read the PE header after the DOS image header\r
- //\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHeader->e_lfanew) & 0x0ffff));\r
- } else {\r
- //\r
- // DOS image header is not present, so PE header is at the image base\r
- //\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
- }\r
- }\r
-\r
- //\r
- // Find the codeview info in the image and display the file name\r
- // being loaded.\r
- //\r
- // Per the PE/COFF spec, you can't assume that a given data directory\r
- // is present in the image. You have to check the NumberOfRvaAndSizes in\r
- // the optional header to verify a desired directory entry is there.\r
- //\r
- DebugEntry = NULL;\r
- DirectoryEntry = NULL;\r
- NumberOfRvaAndSizes = 0;\r
- TEImageAdjust = 0;\r
+ CHAR8 *AsciiString;\r
+ CHAR8 AsciiBuffer[512];\r
+ INT32 Index;\r
+ INT32 Index1;\r
\r
- if (TEImageHeader == NULL) {\r
- if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
- // \r
- // Use PE32 offset get Debug Directory Entry\r
- //\r
- NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
- } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
- // \r
- // Use PE32+ offset get Debug Directory Entry\r
- //\r
- NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
- }\r
-\r
- if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
- DirectoryEntry = NULL;\r
- DebugEntry = NULL;\r
- }\r
- } else {\r
- if (TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
- DirectoryEntry = &TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
- TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize;\r
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) TEImageHeader +\r
- TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
- TEImageAdjust);\r
+ AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);\r
+ \r
+ if (AsciiString != NULL) {\r
+ for (Index = AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) {\r
+ if (AsciiString[Index] == '\\') {\r
+ break;\r
+ }\r
}\r
- }\r
\r
- if (DebugEntry != NULL && DirectoryEntry != NULL) {\r
- for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
- if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
- if (DebugEntry->SizeOfData > 0) {\r
- CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageAddress + (UINTN)TEImageAdjust);\r
- switch (* (UINT32 *) CodeViewEntryPointer) {\r
- case CODEVIEW_SIGNATURE_NB10:\r
- AsciiString = (CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);\r
- break;\r
-\r
- case CODEVIEW_SIGNATURE_RSDS:\r
- AsciiString = (CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
- break;\r
-\r
- default:\r
- AsciiString = NULL;\r
- break;\r
- }\r
- if (AsciiString != NULL) {\r
- FileNameFound = FALSE;\r
- for (Index = 0, Index1 = 0; AsciiString[Index] != '\0'; Index++) {\r
- if (AsciiString[Index] == '\\') {\r
- Index1 = Index;\r
- FileNameFound = TRUE;\r
- }\r
- }\r
-\r
- if (FileNameFound) {\r
- for (Index = Index1 + 1; AsciiString[Index] != '.'; Index++) {\r
- AsciiBuffer[Index - (Index1 + 1)] = AsciiString[Index];\r
- }\r
- AsciiBuffer[Index - (Index1 + 1)] = 0;\r
- DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));\r
- break;\r
- }\r
- }\r
- }\r
+ if (Index != 0) {\r
+ for (Index1 = 0; AsciiString[Index + 1 + Index1] != '.'; Index1 ++) {\r
+ AsciiBuffer [Index1] = AsciiString[Index + 1 + Index1];\r
}\r
+ AsciiBuffer [Index1] = '\0';\r
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));\r
}\r
}\r
+\r
DEBUG_CODE_END ();\r
\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
\r
--*/ \r
{\r
- //\r
- // Always update PeCoffLoader pointer as PEI core itself may get \r
- // shadowed into memory\r
- //\r
- PrivateData->PeCoffLoader = GetPeCoffLoaderProtocol ();\r
- \r
if (OldCoreData == NULL) {\r
//\r
// The first time we are XIP (running from FLASH). We need to remember the\r
#include <Library/MemoryAllocationLib.h>\r
#include <Guid/FirmwareFileSystem2.h>\r
#include <Guid/AprioriFileName.h>\r
-#include <Guid/PeiPeCoffLoader.h>\r
\r
#define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff\r
\r
UINTN SizeOfCacheAsRam;\r
VOID *MaxTopOfCarHeap;\r
EFI_PEI_PPI_DESCRIPTOR *XipLoadFile;\r
- EFI_PEI_PE_COFF_LOADER_PROTOCOL *PeCoffLoader; \r
} PEI_CORE_INSTANCE;\r
\r
//\r
DebugLib\r
MemoryAllocationLib\r
CacheMaintenanceLib\r
- PeCoffLoaderLib\r
PeCoffLib\r
\r
[Guids]\r
gPeiAprioriFileNameGuid\r
gEfiFirmwareFileSystem2Guid\r
-\r
+ gEfiPeiPeCoffLoaderGuid\r
\r
[Ppis]\r
gEfiPeiSecurityPpiGuid # PPI_NOTIFY SOMETIMES_CONSUMED\r
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
- PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
CustomDecompressLib|MdePkg/Library/BaseCustomDecompressLibNull/BaseCustomDecompressLibNull.inf\r
S3Lib|MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf\r
RecoveryLib|MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf\r
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
- PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
-\r
\r
[LibraryClasses.common.PEIM]\r
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
- PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
\r
[LibraryClasses.common.DXE_DRIVER]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
)\r
;\r
\r
+/**\r
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+ \r
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+ this function can simply return RETURN_SUCCESS.\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image to be unloaded.\r
\r
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+;\r
#endif\r
OUT VOID **EntryPoint\r
)\r
{\r
- EFI_IMAGE_DOS_HEADER *DosHeader;\r
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Header;\r
+ EFI_IMAGE_DOS_HEADER *DosHdr;\r
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
\r
ASSERT (Pe32Data != NULL);\r
ASSERT (EntryPoint != NULL);\r
\r
- DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
- if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+ if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
//\r
// DOS image header is present, so read the PE header after the DOS image header.\r
//\r
- Header.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
} else {\r
//\r
// DOS image header is not present, so PE header is at the image base.\r
//\r
- Header.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
}\r
\r
//\r
// Calculate the entry point relative to the start of the image.\r
// AddressOfEntryPoint is common for PE32 & PE32+\r
//\r
- *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Header.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
- return RETURN_SUCCESS;\r
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);\r
+ return RETURN_SUCCESS;\r
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
+ return RETURN_SUCCESS;\r
+ }\r
+\r
+ return RETURN_UNSUPPORTED;\r
}\r
\r
\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
EFI_IMAGE_DOS_HEADER *DosHdr;\r
\r
- DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+ ASSERT (Pe32Data != NULL);\r
+\r
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
+ //\r
+ // DOS image header is present, so read the PE header after the DOS image header.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
} else {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
+ //\r
+ // DOS image header is not present, so PE header is at the image base.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
}\r
\r
- if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+ return Hdr.Te->Machine;\r
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
return Hdr.Pe32->FileHeader.Machine;\r
}\r
\r
IN VOID *Pe32Data\r
)\r
{\r
- EFI_IMAGE_DOS_HEADER *DosHeader;\r
+ EFI_IMAGE_DOS_HEADER *DosHdr;\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;\r
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
DebugEntry = NULL;\r
NumberOfRvaAndSizes = 0;\r
\r
- DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
- if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+ if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
//\r
// DOS image header is present, so read the PE header after the DOS image header.\r
//\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
} else {\r
//\r
// DOS image header is not present, so PE header is at the image base.\r
return NULL;\r
}\r
\r
- for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount++, DebugEntry++) {\r
+ for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
if (DebugEntry->SizeOfData > 0) {\r
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
return RETURN_SUCCESS;\r
}\r
\r
+/**\r
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+ \r
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+ this function can simply return RETURN_SUCCESS.\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image to be unloaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return RETURN_SUCCESS;\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+ DxeNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+ Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+ to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiDxe.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+ The constructor function gets the pointer to PeCofferLoader guid structure\r
+ from the guid data hob.\r
+\r
+ It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeNt32PeCoffLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ \r
+ //\r
+ // Find guid data hob that contains PeCoffLoader guid structure.\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+ ASSERT (GuidHob != NULL);\r
+\r
+ //\r
+ // Get PeCofferLoader guid structure from guid hob data.\r
+ //\r
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrieves information about a PE/COFF image.\r
+\r
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+ ImageContext. \r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that needs to be examined by this function.\r
+\r
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r
+ of ImageContext as the relocation base address. The caller must allocate the relocation\r
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being relocated.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Loads a PE/COFF image into memory.\r
+\r
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being loaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r
+ the ImageAddress and ImageSize fields of ImageContext.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ ImageRead function that operates on a memory buffer whos base is passed into\r
+ FileHandle. \r
+\r
+ @param FileHandle Ponter to baes of the input stream\r
+ @param FileOffset Offset to the start of the buffer\r
+ @param ReadSize Number of bytes to copy into the buffer\r
+ @param Buffer Location to place results of read\r
+\r
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r
+ the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+ IN VOID *FileHandle,\r
+ IN UINTN FileOffset,\r
+ IN OUT UINTN *ReadSize,\r
+ OUT VOID *Buffer\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+ runtime. \r
+ \r
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+ the fixups with a virtual mapping.\r
+\r
+\r
+ @param ImageBase Base address of relocated image\r
+ @param VirtImageBase Virtual mapping for ImageBase\r
+ @param ImageSize Size of the image to relocate\r
+ @param RelocationData Location to place results of read\r
+ \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+ IN PHYSICAL_ADDRESS ImageBase,\r
+ IN PHYSICAL_ADDRESS VirtImageBase,\r
+ IN UINTN ImageSize,\r
+ IN VOID *RelocationData\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+ \r
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+ this function can simply return RETURN_SUCCESS.\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image to be unloaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
--- /dev/null
+#/** @file\r
+# PeCoff libary for Dxe modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = DxeNt32PeCoffLib\r
+ FILE_GUID = 624571b0-4b69-40e3-bd13-78fae0e84270\r
+ MODULE_TYPE = DXE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PeCoffLib|DXE_CORE DXE_DRIVER\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+ CONSTRUCTOR = DxeNt32PeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32\r
+#\r
+\r
+[Sources.common]\r
+ DxeNt32PeCoffLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+ DebugLib\r
+ HobLib\r
+\r
+[Guids]\r
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
+\r
#include <Ppi/NtPeiLoadFile.h>\r
#include <Library/PeCoffGetEntryPointLib.h>\r
#include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
\r
\r
RETURN_STATUS\r
UINT64 ImageSize;\r
EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r
\r
+ ASSERT (Pe32Data != NULL);\r
+ ASSERT (EntryPoint != NULL);\r
+\r
Status = PeiServicesLocatePpi (\r
&gNtPeiLoadFilePpiGuid,\r
0,\r
&PpiDescriptor,\r
&PeiNtService\r
);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
+ ASSERT_EFI_ERROR (Status);\r
\r
Status = PeiNtService->PeiLoadFileService (\r
Pe32Data,\r
&ImageSize,\r
&ImageEntryPoint\r
);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
*EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
return Status;\r
}\r
level debug.\r
\r
\r
- @param Image Pointer to a PE/COFF header\r
+ @param Pe32Data Pointer to a PE/COFF header\r
\r
- @return Machine type or zero if not a valid iamge\r
+ @return Machine type or zero if not a valid iamge\r
\r
**/\r
UINT16\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
EFI_IMAGE_DOS_HEADER *DosHdr;\r
\r
+ ASSERT (Pe32Data != NULL);\r
+\r
DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
+ //\r
+ // DOS image header is present, so read the PE header after the DOS image header.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
} else {\r
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
+ //\r
+ // DOS image header is not present, so PE header is at the image base.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
}\r
\r
- if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+ return Hdr.Te->Machine;\r
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
return Hdr.Pe32->FileHeader.Machine;\r
}\r
\r
return 0x0000;\r
}\r
\r
+/**\r
+ Returns a pointer to the PDB file name for a PE/COFF image that has been\r
+ loaded into system memory with the PE/COFF Loader Library functions.\r
+\r
+ Returns the PDB file name for the PE/COFF image specified by Pe32Data. If\r
+ the PE/COFF image specified by Pe32Data is not a valid, then NULL is\r
+ returned. If the PE/COFF image specified by Pe32Data does not contain a\r
+ debug directory entry, then NULL is returned. If the debug directory entry\r
+ in the PE/COFF image specified by Pe32Data does not contain a PDB file name,\r
+ then NULL is returned.\r
+ If Pe32Data is NULL, then ASSERT().\r
+\r
+ @param Pe32Data Pointer to the PE/COFF image that is loaded in system\r
+ memory.\r
+\r
+ @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
+ if it cannot be retrieved.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+PeCoffLoaderGetPdbPointer (\r
+ IN VOID *Pe32Data\r
+ )\r
+{\r
+ EFI_IMAGE_DOS_HEADER *DosHdr;\r
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
+ EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;\r
+ EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
+ UINTN DirCount;\r
+ VOID *CodeViewEntryPointer;\r
+ INTN TEImageAdjust;\r
+ UINT32 NumberOfRvaAndSizes;\r
+ UINT16 Magic;\r
+\r
+ ASSERT (Pe32Data != NULL);\r
+\r
+ TEImageAdjust = 0;\r
+ DirectoryEntry = NULL;\r
+ DebugEntry = NULL;\r
+ NumberOfRvaAndSizes = 0;\r
+\r
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+ if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+ //\r
+ // DOS image header is present, so read the PE header after the DOS image header.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+ } else {\r
+ //\r
+ // DOS image header is not present, so PE header is at the image base.\r
+ //\r
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+ }\r
+\r
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+ if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
+ DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+ TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+ Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+ TEImageAdjust);\r
+ }\r
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+ //\r
+ // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
+ // It is due to backward-compatibility, for some system might\r
+ // generate PE32+ image with PE32 Magic.\r
+ //\r
+ switch (Hdr.Pe32->FileHeader.Machine) {\r
+ case EFI_IMAGE_MACHINE_IA32:\r
+ //\r
+ // Assume PE32 image with IA32 Machine field.\r
+ //\r
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+ break;\r
+ case EFI_IMAGE_MACHINE_X64:\r
+ case EFI_IMAGE_MACHINE_IPF:\r
+ //\r
+ // Assume PE32+ image with X64 or IPF Machine field\r
+ //\r
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+ break;\r
+ default:\r
+ //\r
+ // For unknow Machine field, use Magic in optional Header\r
+ //\r
+ Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+ }\r
+\r
+ if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+ //\r
+ // Use PE32 offset get Debug Directory Entry\r
+ //\r
+ NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+ } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+ //\r
+ // Use PE32+ offset get Debug Directory Entry\r
+ //\r
+ NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+ }\r
+\r
+ if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+ DirectoryEntry = NULL;\r
+ DebugEntry = NULL;\r
+ }\r
+ } else {\r
+ return NULL;\r
+ }\r
+\r
+ if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
+ if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+ if (DebugEntry->SizeOfData > 0) {\r
+ CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+ switch (* (UINT32 *) CodeViewEntryPointer) {\r
+ case CODEVIEW_SIGNATURE_NB10:\r
+ return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+ case CODEVIEW_SIGNATURE_RSDS:\r
+ return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+ PeiCoreNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+ Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+ to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader = NULL;\r
+\r
+/**\r
+ The function caches the pointer of PeCofferLoader guid structure\r
+ into the guid data hob.\r
+\r
+ The funtion must be called after PeCofferLoader guid structure is installed.\r
+ It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+ @retval EFI_SUCCESS PeCofferLoader guid structure is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetPeCoffLoaderStucture (\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+\r
+ Status = EFI_NOT_FOUND;\r
+ \r
+ //\r
+ // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+ if (GuidHob == NULL) {\r
+ //\r
+ // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+ //\r
+ Status = PeiServicesLocatePpi (\r
+ &gEfiPeiPeCoffLoaderGuid,\r
+ 0,\r
+ NULL,\r
+ &mPeiEfiPeiPeCoffLoader\r
+ );\r
+ \r
+ //\r
+ // PeCofferLoader guid structure must be installed before this library runs.\r
+ //\r
+ ASSERT_EFI_ERROR (Status);\r
+ \r
+ //\r
+ // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+ //\r
+ BuildGuidDataHob (\r
+ &gEfiPeiPeCoffLoaderGuid,\r
+ (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+ sizeof (VOID *)\r
+ );\r
+ } else {\r
+ //\r
+ // Get PeCofferLoader guid structure directly from guid hob data.\r
+ //\r
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrieves information about a PE/COFF image.\r
+\r
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+ ImageContext. \r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that needs to be examined by this function.\r
+\r
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+ GetPeCoffLoaderStucture ();\r
+ }\r
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r
+ of ImageContext as the relocation base address. The caller must allocate the relocation\r
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being relocated.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+ GetPeCoffLoaderStucture ();\r
+ }\r
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Loads a PE/COFF image into memory.\r
+\r
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being loaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r
+ the ImageAddress and ImageSize fields of ImageContext.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+ GetPeCoffLoaderStucture ();\r
+ }\r
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ ImageRead function that operates on a memory buffer whos base is passed into\r
+ FileHandle. \r
+\r
+ @param FileHandle Ponter to baes of the input stream\r
+ @param FileOffset Offset to the start of the buffer\r
+ @param ReadSize Number of bytes to copy into the buffer\r
+ @param Buffer Location to place results of read\r
+\r
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r
+ the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+ IN VOID *FileHandle,\r
+ IN UINTN FileOffset,\r
+ IN OUT UINTN *ReadSize,\r
+ OUT VOID *Buffer\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+ runtime. \r
+ \r
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+ the fixups with a virtual mapping.\r
+\r
+\r
+ @param ImageBase Base address of relocated image\r
+ @param VirtImageBase Virtual mapping for ImageBase\r
+ @param ImageSize Size of the image to relocate\r
+ @param RelocationData Location to place results of read\r
+ \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+ IN PHYSICAL_ADDRESS ImageBase,\r
+ IN PHYSICAL_ADDRESS VirtImageBase,\r
+ IN UINTN ImageSize,\r
+ IN VOID *RelocationData\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+ \r
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+ this function can simply return RETURN_SUCCESS.\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image to be unloaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+ GetPeCoffLoaderStucture ();\r
+ }\r
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
--- /dev/null
+#/** @file\r
+# PeCoff libary for PeiCore modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = PeiCoreNt32PeCoffLib\r
+ FILE_GUID = ef9fd7ee-3181-4b16-adc1-8615f88b58b8\r
+ MODULE_TYPE = PEIM\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PeCoffLib|PEI_CORE\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32\r
+#\r
+\r
+[Sources.common]\r
+ PeiCoreNt32PeCoffLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+ PeiServicesLib\r
+ DebugLib\r
+ HobLib\r
+\r
+[Guids]\r
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
+\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+ PeiNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+ Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+ to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+ The constructor function caches the pointer of PeCofferLoader guid structure\r
+ into the guid data hob.\r
+\r
+ The constructor must be called after PeCofferLoader guid structure is installed.\r
+ It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+ @param FfsHeader Pointer to FFS header the loaded driver.\r
+ @param PeiServices Pointer to the PEI services.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiNt32PeCoffLibConstructor (\r
+ IN EFI_FFS_FILE_HEADER *FfsHeader,\r
+ IN EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+\r
+ Status = EFI_NOT_FOUND;\r
+ \r
+ //\r
+ // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+ if (GuidHob == NULL) {\r
+ //\r
+ // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+ //\r
+ Status = (*PeiServices)->LocatePpi (\r
+ PeiServices,\r
+ &gEfiPeiPeCoffLoaderGuid,\r
+ 0,\r
+ NULL,\r
+ &mPeiEfiPeiPeCoffLoader\r
+ );\r
+ \r
+ //\r
+ // PeCofferLoader guid structure must be installed before this library runs.\r
+ //\r
+ ASSERT_EFI_ERROR (Status);\r
+ \r
+ //\r
+ // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+ //\r
+ BuildGuidDataHob (\r
+ &gEfiPeiPeCoffLoaderGuid,\r
+ (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+ sizeof (VOID *)\r
+ );\r
+ } else {\r
+ //\r
+ // Get PeCofferLoader guid structure directly from guid hob data.\r
+ //\r
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrieves information about a PE/COFF image.\r
+\r
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+ ImageContext. \r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that needs to be examined by this function.\r
+\r
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r
+ of ImageContext as the relocation base address. The caller must allocate the relocation\r
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being relocated.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ Loads a PE/COFF image into memory.\r
+\r
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image that is being loaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r
+ the ImageAddress and ImageSize fields of ImageContext.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.\r
+ Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+ ImageRead function that operates on a memory buffer whos base is passed into\r
+ FileHandle. \r
+\r
+ @param FileHandle Ponter to baes of the input stream\r
+ @param FileOffset Offset to the start of the buffer\r
+ @param ReadSize Number of bytes to copy into the buffer\r
+ @param Buffer Location to place results of read\r
+\r
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r
+ the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+ IN VOID *FileHandle,\r
+ IN UINTN FileOffset,\r
+ IN OUT UINTN *ReadSize,\r
+ OUT VOID *Buffer\r
+ )\r
+{\r
+ return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+ runtime. \r
+ \r
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+ the fixups with a virtual mapping.\r
+\r
+\r
+ @param ImageBase Base address of relocated image\r
+ @param VirtImageBase Virtual mapping for ImageBase\r
+ @param ImageSize Size of the image to relocate\r
+ @param RelocationData Location to place results of read\r
+ \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+ IN PHYSICAL_ADDRESS ImageBase,\r
+ IN PHYSICAL_ADDRESS VirtImageBase,\r
+ IN UINTN ImageSize,\r
+ IN VOID *RelocationData\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+ \r
+ For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+ this function can simply return RETURN_SUCCESS.\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
+ image to be unloaded.\r
+\r
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
--- /dev/null
+#/** @file\r
+# PeCoff libary for PEIM modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = PeiNt32PeCoffLib\r
+ FILE_GUID = 91404129-c58a-40bb-8a2b-f05bc05a961c\r
+ MODULE_TYPE = PEIM\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PeCoffLib|PEIM\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+ CONSTRUCTOR = PeiNt32PeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32\r
+#\r
+\r
+[Sources.common]\r
+ PeiNt32PeCoffLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+ DebugLib\r
+ HobLib\r
+\r
+[Guids]\r
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
+\r
[LibraryClasses.common.SEC]\r
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf\r
+ PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
\r
[LibraryClasses.common.DXE_CORE]\r
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
- PeCoffLoaderLib|MdeModulePkg/Library/DxePeCoffLoaderFromHobLib/DxePeCoffLoaderFromHobLib.inf\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+ PeCoffLib|Nt32Pkg/Library/DxeNT32PeCoffLib/DxeNT32PeCoffLib.inf\r
\r
[LibraryClasses.common.DXE_SMM_DRIVER]\r
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
- PeCoffLoaderLib|Nt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.inf\r
PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
OemHookStatusCodeLib|Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/PeiNt32OemHookStatusCodeLib.inf\r
PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+ PeCoffLib|Nt32Pkg/Library/PeiNT32PeCoffLib/PeiNT32PeCoffLib.inf\r
\r
[LibraryClasses.common.PEI_CORE]\r
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf\r
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
- PeCoffLoaderLib|Nt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.inf\r
+ PeCoffLib|Nt32Pkg/Library/PeiCoreNT32PeCoffLib/PeiCoreNT32PeCoffLib.inf\r
\r
[LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r