]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/DxeIplX64Peim/x64/ImageRead.c
Enable global optimizations for IPF builds
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplX64Peim / x64 / 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 CHAR8 *Destination8;\r
53 CHAR8 *Source8;\r
54 UINTN Length;\r
55\r
56 Destination8 = Buffer;\r
57 Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);\r
58 Length = *ReadSize;\r
59 while (Length--) {\r
60 *(Destination8++) = *(Source8++);\r
61 }\r
62\r
63 return EFI_SUCCESS;\r
64}\r
65\r
66EFI_STATUS\r
67GetImageReadFunction (\r
68 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
69 )\r
70/*++\r
71\r
72Routine Description:\r
73\r
74 Support routine to return the PE32 Image Reader.\r
75 If the PeiImageRead() function is less than a page\r
76 in legnth. If the function is more than a page the DXE IPL will crash!!!!\r
77\r
78Arguments:\r
79 ImageContext - The context of the image being loaded\r
80\r
81Returns:\r
82\r
83 EFI_SUCCESS - If Image function location is found\r
84\r
85--*/\r
86{\r
87 VOID *MemoryBuffer;\r
88\r
89 if (gInMemory) {\r
90 ImageContext->ImageRead = PeiImageRead;\r
91 return EFI_SUCCESS;\r
92 }\r
93\r
94 //\r
95 // BugBug; This code assumes PeiImageRead() is less than a page in size!\r
96 // Allocate a page so we can shaddow the read function from FLASH into \r
97 // memory to increase performance. \r
98 //\r
99 \r
100 MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);\r
101 ASSERT (MemoryBuffer != NULL);\r
102\r
103 ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
104\r
105 return EFI_SUCCESS;\r
106}\r