Fix capitalization
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / ia32 / ImageRead.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 ImageRead.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19\r
20#include <DxeIpl.h>\r
21\r
22EFI_STATUS\r
23EFIAPI\r
24PeiImageRead (\r
25 IN VOID *FileHandle,\r
26 IN UINTN FileOffset,\r
27 IN OUT UINTN *ReadSize,\r
28 OUT VOID *Buffer\r
29 )\r
30/*++\r
31\r
32Routine Description:\r
33\r
34 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
35\r
36Arguments:\r
37\r
38 FileHandle - The handle to the PE/COFF file\r
39\r
40 FileOffset - The offset, in bytes, into the file to read\r
41\r
42 ReadSize - The number of bytes to read from the file starting at FileOffset\r
43\r
44 Buffer - A pointer to the buffer to read the data into.\r
45\r
46Returns:\r
47\r
48 EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
49\r
50--*/\r
51{\r
52 UINT8 *Destination32;\r
53 UINT8 *Source32;\r
54 UINTN Length;\r
55\r
56 \r
57 Destination32 = Buffer;\r
58 Source32 = (UINT8 *) ((UINTN) FileHandle + FileOffset);\r
59\r
60 //\r
61 // This function assumes 32-bit alignment to increase performance\r
62 //\r
63// ASSERT (ALIGN_POINTER (Destination32, sizeof (UINT32)) == Destination32);\r
64// ASSERT (ALIGN_POINTER (Source32, sizeof (UINT32)) == Source32);\r
65\r
66 Length = *ReadSize;\r
67 while (Length--) {\r
68 *(Destination32++) = *(Source32++);\r
69 }\r
70\r
71 return EFI_SUCCESS;\r
72}\r
73\r
74EFI_STATUS\r
75GetImageReadFunction (\r
76 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
77 )\r
78/*++\r
79\r
80Routine Description:\r
81 Support routine to return the PE32 Image Reader.\r
82 If the PeiImageRead() function is less than a page\r
83 in legnth. If the function is more than a page the DXE IPL will crash!!!!\r
84\r
85Arguments:\r
86 ImageContext - The context of the image being loaded\r
87\r
88Returns:\r
89 EFI_SUCCESS - If Image function location is found\r
90\r
91--*/\r
92{\r
93 VOID *MemoryBuffer;\r
94\r
95 if (gInMemory) {\r
96 ImageContext->ImageRead = PeiImageRead;\r
97 return EFI_SUCCESS;\r
98 }\r
99\r
100 //\r
101 // BugBug; This code assumes PeiImageRead() is less than a page in size!\r
102 // Allocate a page so we can shaddow the read function from FLASH into \r
103 // memory to increase performance. \r
104 //\r
105 \r
106 MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);\r
107 ASSERT (MemoryBuffer != NULL);\r
108\r
109 ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
110\r
111 return EFI_SUCCESS;\r
112}\r