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