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