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