2 Function prototypes and defines on Memory Only PE COFF loader
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __BASE_PE_COFF_LIB_H__
10 #define __BASE_PE_COFF_LIB_H__
13 // Return status codes from the PE/COFF Loader services
14 // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes
16 #define IMAGE_ERROR_SUCCESS 0
17 #define IMAGE_ERROR_IMAGE_READ 1
18 #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
19 #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3
20 #define IMAGE_ERROR_INVALID_SUBSYSTEM 4
21 #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5
22 #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6
23 #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7
24 #define IMAGE_ERROR_SECTION_NOT_LOADED 8
25 #define IMAGE_ERROR_FAILED_RELOCATION 9
26 #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10
30 // PE/COFF Loader Read Function passed in by caller
34 (EFIAPI
*PE_COFF_LOADER_READ_FILE
) (
37 IN OUT UINTN
*ReadSize
,
42 // Context structure used while PE/COFF image is being loaded and relocated
45 PHYSICAL_ADDRESS ImageAddress
;
47 PHYSICAL_ADDRESS DestinationAddress
;
48 PHYSICAL_ADDRESS EntryPoint
;
49 PE_COFF_LOADER_READ_FILE ImageRead
;
52 UINT32 SectionAlignment
;
53 UINT32 PeCoffHeaderOffset
;
54 UINT32 DebugDirectoryEntryRva
;
58 UINT32 ImageCodeMemoryType
;
59 UINT32 ImageDataMemoryType
;
64 BOOLEAN RelocationsStripped
;
66 } PE_COFF_LOADER_IMAGE_CONTEXT
;
70 Retrieves information on a PE/COFF image
72 @param ImageContext The context of the image being loaded
74 @retval EFI_SUCCESS The information on the PE/COFF image was collected.
75 @retval EFI_INVALID_PARAMETER ImageContext is NULL.
76 @retval EFI_UNSUPPORTED The PE/COFF image is not supported.
77 @retval Otherwise The error status from reading the PE/COFF image using the
78 ImageContext->ImageRead() function
83 PeCoffLoaderGetImageInfo (
84 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
89 Relocates a PE/COFF image in memory
91 @param ImageContext Contains information on the loaded image to relocate
93 @retval EFI_SUCCESS if the PE/COFF image was relocated
94 @retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image
95 @retval EFI_UNSUPPORTED not support
100 PeCoffLoaderRelocateImage (
101 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
106 Loads a PE/COFF image into memory
108 @param ImageContext Contains information on image to load into memory
110 @retval EFI_SUCCESS if the PE/COFF image was loaded
111 @retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer
112 @retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations
113 @retval EFI_INVALID_PARAMETER if the image address is invalid
118 PeCoffLoaderLoadImage (
119 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
125 PeCoffLoaderGetPdbPointer (
132 PeCoffLoaderGetEntryPoint (
134 OUT VOID
**EntryPoint
,
135 OUT VOID
**BaseOfImage
140 // These functions are used by the ARM PE/COFF relocation code and by
141 // the ELF to PE/COFF converter so that is why they are public
145 Pass in a pointer to an ARM MOVT or MOVW immediate instruction and
146 return the immediate data encoded in the instruction
148 @param Instruction Pointer to ARM MOVT or MOVW immediate instruction
150 @return Immediate address encoded in the instruction
155 ThumbMovtImmediateAddress (
156 IN UINT16
*Instruction
160 Update an ARM MOVT or MOVW immediate instruction immediate data.
162 @param Instruction Pointer to ARM MOVT or MOVW immediate instruction
163 @param Address New address to patch into the instruction
168 ThumbMovtImmediatePatch (
169 IN OUT UINT16
*Instruction
,
175 Pass in a pointer to an ARM MOVW/MOVT instruction pair and
176 return the immediate data encoded in the two` instruction
178 @param Instructions Pointer to ARM MOVW/MOVT instruction pair
180 @return Immediate address encoded in the instructions
185 ThumbMovwMovtImmediateAddress (
186 IN UINT16
*Instructions
190 Update an ARM MOVW/MOVT immediate instruction instruction pair.
192 @param Instructions Pointer to ARM MOVW/MOVT instruction pair
193 @param Address New address to patch into the instructions
197 ThumbMovwMovtImmediatePatch (
198 IN OUT UINT16
*Instructions
,