\r
EFI_STATUS\r
CoreLoadPeImage (\r
+ IN BOOLEAN BootPolicy, \r
IN VOID *Pe32Handle,\r
IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
Loads, relocates, and invokes a PE/COFF image\r
\r
Arguments:\r
-\r
+ BootPolicy - If TRUE, indicates that the request originates from the boot manager,\r
+ and that the boot manager is attempting to load FilePath as a boot selection.\r
Pe32Handle - The handle of PE32 image\r
Image - PE image to be loaded\r
DstBuffer - The buffer to store the image\r
\r
--*/\r
{\r
- EFI_STATUS Status;\r
- BOOLEAN DstBufAlocated;\r
- UINTN Size;\r
+ EFI_STATUS Status;\r
+ BOOLEAN DstBufAlocated;\r
+ UINTN Size;\r
+ UINTN LinkTimeBase;\r
+ EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
\r
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));\r
\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
return EFI_UNSUPPORTED;\r
}\r
-\r
+ \r
+ //\r
+ // Set EFI memory type based on ImageType\r
+ //\r
+ switch (Image->ImageContext.ImageType) {\r
+ case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:\r
+ Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;\r
+ Image->ImageContext.ImageDataMemoryType = EfiLoaderData;\r
+ break;\r
+ case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:\r
+ Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;\r
+ Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;\r
+ break;\r
+ case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:\r
+ case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:\r
+ Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;\r
+ Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;\r
+ break;\r
+ default:\r
+ Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ //\r
+ // Get the image base address in the original PeImage.\r
+ //\r
+ LinkTimeBase = (UINTN) Image->ImageContext.ImageAddress;\r
\r
//\r
// Allocate memory of the correct memory type aligned on the required image boundry\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
}\r
\r
+ //\r
+ // Measure the image before applying fixup\r
+ //\r
+ Status = CoreLocateProtocol (\r
+ &gEfiTcgPlatformProtocolGuid,\r
+ NULL,\r
+ (VOID **) &TcgPlatformProtocol\r
+ );\r
+ if (!EFI_ERROR (Status)) { \r
+ Status = TcgPlatformProtocol->MeasurePeImage (\r
+ BootPolicy,\r
+ Image->ImageContext.ImageAddress,\r
+ (UINTN) Image->ImageContext.ImageSize,\r
+ LinkTimeBase,\r
+ Image->ImageContext.ImageType,\r
+ Image->Info.DeviceHandle,\r
+ Image->Info.FilePath\r
+ );\r
+ \r
+ ASSERT_EFI_ERROR (Status);\r
+ }\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
UINTN Index;\r
UINTN StartIndex;\r
CHAR8 EfiFileName[256];\r
-\r
- DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading driver at 0x%10p EntryPoint=0x%10p ", (VOID *)(UINTN)Image->ImageContext.ImageAddress, (VOID *)(UINTN)Image->ImageContext.EntryPoint));\r
+ \r
+ if (Image->ImageContext.Machine != IMAGE_FILE_MACHINE_IA64) {\r
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
+ "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
+ (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
+ (VOID *)(UINTN)Image->ImageContext.EntryPoint));\r
+ } else {\r
+ //\r
+ // For IPF Image, the real entry point should be print.\r
+ // \r
+ DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
+ "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
+ (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
+ (VOID *)(UINTN)(*(UINT64 *)(UINTN)Image->ImageContext.EntryPoint)));\r
+ }\r
+ \r
+ //\r
+ // Print Module Name by Pdb file path\r
+ //\r
if (Image->ImageContext.PdbPointer != NULL) {\r
StartIndex = 0;\r
for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {\r
BootPolicy,\r
SourceBuffer,\r
SourceSize,\r
- FilePath,\r
+ &FilePath,\r
&DeviceHandle,\r
&FHand,\r
&AuthenticationStatus\r
//\r
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath\r
//\r
+ FilePath = OriginalFilePath;\r
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
if (!EFI_ERROR (Status)) {\r
FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
//\r
// Load the image. If EntryPoint is Null, it will not be set.\r
//\r
- Status = CoreLoadPeImage (&FHand, Image, DstBuffer, EntryPoint, Attribute);\r
+ Status = CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryPoint, Attribute);\r
if (EFI_ERROR (Status)) {\r
if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_OUT_OF_RESOURCES)) {\r
if (NumberOfPages != NULL) {\r
);\r
}\r
\r
-\r
-\r
-\r
EFI_STATUS\r
EFIAPI\r
CoreStartImage (\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