]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c
b6278154d1451b793e7bc00e0634efa6dc045b60
[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 EFI_STATUS
18 EFIAPI
19 PeiImageRead (
20 IN VOID *FileHandle,
21 IN UINTN FileOffset,
22 IN OUT UINTN *ReadSize,
23 OUT VOID *Buffer
24 )
25 /*++
26
27 Routine Description:
28
29 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
30
31 Arguments:
32
33 FileHandle - The handle to the PE/COFF file
34
35 FileOffset - The offset, in bytes, into the file to read
36
37 ReadSize - The number of bytes to read from the file starting at FileOffset
38
39 Buffer - A pointer to the buffer to read the data into.
40
41 Returns:
42
43 EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
44
45 --*/
46 {
47 UINT8 *Destination32;
48 UINT8 *Source32;
49 UINTN Length;
50
51
52 Destination32 = Buffer;
53 Source32 = (UINT8 *) ((UINTN) FileHandle + FileOffset);
54
55 //
56 // This function assumes 32-bit alignment to increase performance
57 //
58 // ASSERT (ALIGN_POINTER (Destination32, sizeof (UINT32)) == Destination32);
59 // ASSERT (ALIGN_POINTER (Source32, sizeof (UINT32)) == Source32);
60
61 Length = *ReadSize;
62 while (Length--) {
63 *(Destination32++) = *(Source32++);
64 }
65
66 return EFI_SUCCESS;
67 }
68
69 EFI_STATUS
70 GetImageReadFunction (
71 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
72 )
73 /*++
74
75 Routine Description:
76 Support routine to return the PE32 Image Reader.
77 If the PeiImageRead() function is less than a page
78 in legnth. If the function is more than a page the DXE IPL will crash!!!!
79
80 Arguments:
81 ImageContext - The context of the image being loaded
82
83 Returns:
84 EFI_SUCCESS - If Image function location is found
85
86 --*/
87 {
88 VOID *MemoryBuffer;
89
90 if (gInMemory) {
91 ImageContext->ImageRead = PeiImageRead;
92 return EFI_SUCCESS;
93 }
94
95 //
96 // BugBug; This code assumes PeiImageRead() is less than a page in size!
97 // Allocate a page so we can shaddow the read function from FLASH into
98 // memory to increase performance.
99 //
100
101 MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);
102 ASSERT (MemoryBuffer != NULL);
103
104 ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;
105
106 return EFI_SUCCESS;
107 }