Update PEI Core LoadImage() service to always call LoadAndRelocatePeCoffImage() even for XIP PEIMs. This will guarantee that the PE/COFF Extra Action Lib will be called for all PE/COFF images, even XIP PEIMs.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9327 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
mdkinney 2009-10-01 23:49:36 +00:00
parent 5cfafa075a
commit 43ada17c28

View File

@ -54,10 +54,12 @@ PeiImageRead (
Destination8 = Buffer; Destination8 = Buffer;
Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset); Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
if (Destination8 != Source8) {
Length = *ReadSize; Length = *ReadSize;
while ((Length--) > 0) { while ((Length--) > 0) {
*(Destination8++) = *(Source8++); *(Destination8++) = *(Source8++);
} }
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -76,14 +78,21 @@ GetImageReadFunction (
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
) )
{ {
PEI_CORE_INSTANCE *Private;
VOID* MemoryBuffer; VOID* MemoryBuffer;
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
if (!Private->PeiMemoryInstalled) {
ImageContext->ImageRead = PeiImageRead;
} else {
MemoryBuffer = AllocatePages (0x400 / EFI_PAGE_SIZE + 1); MemoryBuffer = AllocatePages (0x400 / EFI_PAGE_SIZE + 1);
ASSERT (MemoryBuffer != NULL); ASSERT (MemoryBuffer != NULL);
CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) PeiImageRead, 0x400); CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) PeiImageRead, 0x400);
ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer; ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -113,6 +122,9 @@ LoadAndRelocatePeCoffImage (
{ {
EFI_STATUS Status; EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
PEI_CORE_INSTANCE *Private;
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
ZeroMem (&ImageContext, sizeof (ImageContext)); ZeroMem (&ImageContext, sizeof (ImageContext));
ImageContext.Handle = Pe32Data; ImageContext.Handle = Pe32Data;
@ -129,11 +141,11 @@ LoadAndRelocatePeCoffImage (
// //
if (ImageContext.RelocationsStripped) { if (ImageContext.RelocationsStripped) {
DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data)); DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));
return EFI_INVALID_PARAMETER;
} }
// //
// Allocate Memory for the image // Allocate Memory for the image
// //
if (Private->PeiMemoryInstalled) {
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize)); ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));
ASSERT (ImageContext.ImageAddress != 0); ASSERT (ImageContext.ImageAddress != 0);
@ -145,6 +157,9 @@ LoadAndRelocatePeCoffImage (
((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize - ((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize -
sizeof (EFI_TE_IMAGE_HEADER); sizeof (EFI_TE_IMAGE_HEADER);
} }
} else {
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;
}
// //
// Load the image to our new buffer // Load the image to our new buffer
@ -164,7 +179,9 @@ LoadAndRelocatePeCoffImage (
// //
// Flush the instruction cache so the image data is written before we execute it // Flush the instruction cache so the image data is written before we execute it
// //
if (Private->PeiMemoryInstalled) {
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize); InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
}
*ImageAddress = ImageContext.ImageAddress; *ImageAddress = ImageContext.ImageAddress;
*ImageSize = ImageContext.ImageSize; *ImageSize = ImageContext.ImageSize;
@ -207,7 +224,6 @@ PeiLoadImageLoadImage (
EFI_PHYSICAL_ADDRESS ImageEntryPoint; EFI_PHYSICAL_ADDRESS ImageEntryPoint;
UINT16 Machine; UINT16 Machine;
PEI_CORE_INSTANCE *Private; PEI_CORE_INSTANCE *Private;
VOID *EntryPointArg;
EFI_SECTION_TYPE SearchType1; EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2; EFI_SECTION_TYPE SearchType2;
@ -251,8 +267,6 @@ PeiLoadImageLoadImage (
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
if (Private->PeiMemoryInstalled &&
(Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
// //
// If memory is installed, perform the shadow operations // If memory is installed, perform the shadow operations
// //
@ -263,6 +277,9 @@ PeiLoadImageLoadImage (
&ImageEntryPoint &ImageEntryPoint
); );
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -272,17 +289,6 @@ PeiLoadImageLoadImage (
// //
Pe32Data = (VOID *) ((UINTN) ImageAddress); Pe32Data = (VOID *) ((UINTN) ImageAddress);
*EntryPoint = ImageEntryPoint; *EntryPoint = ImageEntryPoint;
} else {
//
// Retrieve the entry point from the PE/COFF or TE image header
//
ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;
Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);
if (EFI_ERROR (Status)) {
return Status;
}
*EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;
}
Machine = PeCoffLoaderGetMachineType (Pe32Data); Machine = PeCoffLoaderGetMachineType (Pe32Data);