]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c
Fix capitalization
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / Ia32 / ImageRead.c
diff --git a/EdkModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c b/EdkModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c
new file mode 100644 (file)
index 0000000..fe07608
--- /dev/null
@@ -0,0 +1,112 @@
+/*++\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
+  ImageRead.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include <DxeIpl.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeiImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
+\r
+Arguments:\r
+\r
+  FileHandle - The handle to the PE/COFF file\r
+\r
+  FileOffset - The offset, in bytes, into the file to read\r
+\r
+  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
+\r
+  Buffer     - A pointer to the buffer to read the data into.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
+\r
+--*/\r
+{\r
+  UINT8 *Destination32;\r
+  UINT8 *Source32;\r
+  UINTN  Length;\r
+\r
\r
+  Destination32 = Buffer;\r
+  Source32      = (UINT8 *) ((UINTN) FileHandle + FileOffset);\r
+\r
+  //\r
+  // This function assumes 32-bit alignment to increase performance\r
+  //\r
+//  ASSERT (ALIGN_POINTER (Destination32, sizeof (UINT32)) == Destination32);\r
+//  ASSERT (ALIGN_POINTER (Source32, sizeof (UINT32)) == Source32);\r
+\r
+  Length = *ReadSize;\r
+  while (Length--) {\r
+    *(Destination32++) = *(Source32++);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Support routine to return the PE32 Image Reader.\r
+  If the PeiImageRead() function is less than a page\r
+  in legnth. If the function is more than a page the DXE IPL will crash!!!!\r
+\r
+Arguments:\r
+  ImageContext  - The context of the image being loaded\r
+\r
+Returns:\r
+  EFI_SUCCESS - If Image function location is found\r
+\r
+--*/\r
+{\r
+  VOID        *MemoryBuffer;\r
+\r
+  if (gInMemory) {\r
+    ImageContext->ImageRead = PeiImageRead;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // BugBug; This code assumes PeiImageRead() is less than a page in size!\r
+  //  Allocate a page so we can shaddow the read function from FLASH into \r
+  //  memory to increase performance. \r
+  //\r
+  \r
+  MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);\r
+  ASSERT (MemoryBuffer != NULL);\r
+\r
+  ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
+\r
+  return EFI_SUCCESS;\r
+}\r