]>
Commit | Line | Data |
---|---|---|
96226baa | 1 | /** @file\r |
2 | This module loads an image to memory for IA32 Cpu architecture.\r | |
95276127 | 3 | \r |
96226baa | 4 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
95276127 | 9 | \r |
96226baa | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
95276127 | 12 | \r |
96226baa | 13 | **/\r |
95276127 | 14 | \r |
95276127 | 15 | #include "DxeIpl.h"\r |
16 | \r | |
91d92e25 | 17 | /**\r |
18 | Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r | |
19 | \r | |
20 | @param FileHandle The handle to the PE/COFF file \r | |
21 | @param FileOffset The offset, in bytes, into the file to read \r | |
22 | @param ReadSize The number of bytes to read from the file starting at \r | |
23 | FileOffset \r | |
24 | @param Buffer A pointer to the buffer to read the data into. \r | |
25 | \r | |
26 | @retval EFI_SUCCESS ReadSize bytes of data were read into Buffer from the \r | |
27 | PE/COFF file starting at FileOffset\r | |
28 | \r | |
29 | **/\r | |
95276127 | 30 | EFI_STATUS\r |
95276127 | 31 | PeiImageRead (\r |
32 | IN VOID *FileHandle,\r | |
33 | IN UINTN FileOffset,\r | |
34 | IN OUT UINTN *ReadSize,\r | |
35 | OUT VOID *Buffer\r | |
36 | )\r | |
95276127 | 37 | {\r |
38 | UINT8 *Destination32;\r | |
39 | UINT8 *Source32;\r | |
40 | UINTN Length;\r | |
41 | \r | |
42 | \r | |
43 | Destination32 = Buffer;\r | |
44 | Source32 = (UINT8 *) ((UINTN) FileHandle + FileOffset);\r | |
45 | \r | |
46 | //\r | |
47 | // This function assumes 32-bit alignment to increase performance\r | |
48 | //\r | |
95276127 | 49 | \r |
50 | Length = *ReadSize;\r | |
708919be | 51 | while (Length-- != 0) {\r |
95276127 | 52 | *(Destination32++) = *(Source32++);\r |
53 | }\r | |
54 | \r | |
55 | return EFI_SUCCESS;\r | |
56 | }\r | |
57 | \r | |
95276127 | 58 | \r |
95276127 | 59 | \r |
95276127 | 60 | \r |
95276127 | 61 | \r |
91d92e25 | 62 | /**\r |
63 | This function simply retrieves the function pointer of ImageRead in\r | |
64 | ImageContext structure.\r | |
65 | \r | |
66 | @param ImageContext A pointer to the structure of \r | |
67 | PE_COFF_LOADER_IMAGE_CONTEXT\r | |
68 | \r | |
b98da1b1 | 69 | @retval EFI_SUCCESS This function always returns EFI_SUCCESS.\r |
91d92e25 | 70 | \r |
71 | **/\r | |
72 | EFI_STATUS\r | |
73 | GetImageReadFunction (\r | |
74 | IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
75 | )\r | |
95276127 | 76 | {\r |
77 | VOID *MemoryBuffer;\r | |
78 | \r | |
79 | if (gInMemory) {\r | |
80 | ImageContext->ImageRead = PeiImageRead;\r | |
81 | return EFI_SUCCESS;\r | |
82 | }\r | |
83 | \r | |
84 | //\r | |
85 | // BugBug; This code assumes PeiImageRead() is less than a page in size!\r | |
86 | // Allocate a page so we can shaddow the read function from FLASH into \r | |
87 | // memory to increase performance. \r | |
88 | //\r | |
89 | \r | |
90 | MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);\r | |
91 | ASSERT (MemoryBuffer != NULL);\r | |
92 | \r | |
93 | ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r | |
94 | \r | |
95 | return EFI_SUCCESS;\r | |
96 | }\r |