-/**\r
-\r
- Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file.\r
- The function is implemented as PIC so as to support shadowing.\r
-\r
- @param FileHandle - The handle to the PE/COFF file\r
- @param FileOffset - The offset, in bytes, into the file to read\r
- @param ReadSize - The number of bytes to read from the file starting at FileOffset\r
- @param Buffer - A pointer to the buffer to read the data into.\r
-\r
- @return EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PeiImageReadForShadow (\r
- IN VOID *FileHandle,\r
- IN UINTN FileOffset,\r
- IN UINTN *ReadSize,\r
- OUT VOID *Buffer\r
- )\r
-{\r
- volatile CHAR8 *Destination8;\r
- CHAR8 *Source8;\r
- UINTN Length;\r
-\r
- Destination8 = Buffer;\r
- Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);\r
- if (Destination8 != Source8) {\r
- Length = *ReadSize;\r
- while ((Length--) > 0) {\r
- *(Destination8++) = *(Source8++);\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-\r
- Support routine to get the Image read file function.\r
-\r
- @param ImageContext - The context of the image being loaded\r
-\r
- @retval EFI_SUCCESS - If Image function location is found\r
-\r
-**/\r
-EFI_STATUS\r
-GetImageReadFunction (\r
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-{\r
-#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
- PEI_CORE_INSTANCE *Private;\r
- EFI_PHYSICAL_ADDRESS MemoryBuffer;\r
-\r
- Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
- MemoryBuffer = 0;\r
-\r
- if (Private->PeiMemoryInstalled && (((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)) ||\r
- ((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
- //\r
- // Shadow algorithm makes lots of non ANSI C assumptions and only works for IA32 and X64\r
- // compilers that have been tested\r
- //\r
- if (Private->ShadowedImageRead == NULL) {\r
- PeiServicesAllocatePages (EfiBootServicesCode, 0x400 / EFI_PAGE_SIZE + 1, &MemoryBuffer);\r
- ASSERT (MemoryBuffer != 0);\r
- CopyMem ((VOID *)(UINTN)MemoryBuffer, (CONST VOID *) (UINTN) PeiImageReadForShadow, 0x400);\r
- Private->ShadowedImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
- }\r
-\r
- ImageContext->ImageRead = Private->ShadowedImageRead;\r
- } else {\r
- ImageContext->ImageRead = PeiImageRead;\r
- }\r
-#else\r
- ImageContext->ImageRead = PeiImageRead;\r
-#endif\r
- return EFI_SUCCESS;\r
-}\r