]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/DxeIplPeim/Ia32/ImageRead.c
Code Scrub DxeIpl module.
[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 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
19
20 @param FileHandle The handle to the PE/COFF file
21 @param FileOffset The offset, in bytes, into the file to read
22 @param ReadSize The number of bytes to read from the file starting at
23 FileOffset
24 @param Buffer A pointer to the buffer to read the data into.
25
26 @retval EFI_SUCCESS ReadSize bytes of data were read into Buffer from the
27 PE/COFF file starting at FileOffset
28
29 **/
30 EFI_STATUS
31 PeiImageRead (
32 IN VOID *FileHandle,
33 IN UINTN FileOffset,
34 IN OUT UINTN *ReadSize,
35 OUT VOID *Buffer
36 )
37 {
38 UINT8 *Destination32;
39 UINT8 *Source32;
40 UINTN Length;
41
42
43 Destination32 = Buffer;
44 Source32 = (UINT8 *) ((UINTN) FileHandle + FileOffset);
45
46 //
47 // This function assumes 32-bit alignment to increase performance
48 //
49
50 Length = *ReadSize;
51 while (Length-- != 0) {
52 *(Destination32++) = *(Source32++);
53 }
54
55 return EFI_SUCCESS;
56 }
57
58
59
60
61
62 /**
63 This function simply retrieves the function pointer of ImageRead in
64 ImageContext structure.
65
66 @param ImageContext A pointer to the structure of
67 PE_COFF_LOADER_IMAGE_CONTEXT
68
69 @retval EFI_SUCCESS This function always returns EFI_SUCCESS.
70
71 **/
72 EFI_STATUS
73 GetImageReadFunction (
74 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
75 )
76 {
77 VOID *MemoryBuffer;
78
79 if (gInMemory) {
80 ImageContext->ImageRead = PeiImageRead;
81 return EFI_SUCCESS;
82 }
83
84 //
85 // BugBug; This code assumes PeiImageRead() is less than a page in size!
86 // Allocate a page so we can shaddow the read function from FLASH into
87 // memory to increase performance.
88 //
89
90 MemoryBuffer = AllocateCopyPool (0x400, (VOID *)(UINTN) PeiImageRead);
91 ASSERT (MemoryBuffer != NULL);
92
93 ImageContext->ImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;
94
95 return EFI_SUCCESS;
96 }