]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/Include/Library/PeCoffLib.h
Remove the dependence to MdePkg
[mirror_edk2.git] / Tools / Source / TianoTools / Include / Library / PeCoffLib.h
1 /** @file
2 Memory Only PE COFF loader
3
4 Copyright (c) 2006, Intel Corporation
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 Module Name: PeCoffLib.h
14
15 **/
16
17 #ifndef __BASE_PE_COFF_LIB_H__
18 #define __BASE_PE_COFF_LIB_H__
19
20 //
21 // Return status codes from the PE/COFF Loader services
22 // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes
23 //
24 #define IMAGE_ERROR_SUCCESS 0
25 #define IMAGE_ERROR_IMAGE_READ 1
26 #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
27 #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3
28 #define IMAGE_ERROR_INVALID_SUBSYSTEM 4
29 #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5
30 #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6
31 #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7
32 #define IMAGE_ERROR_SECTION_NOT_LOADED 8
33 #define IMAGE_ERROR_FAILED_RELOCATION 9
34 #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10
35
36
37 //
38 // PE/COFF Loader Read Function passed in by caller
39 //
40 typedef
41 RETURN_STATUS
42 (EFIAPI *PE_COFF_LOADER_READ_FILE) (
43 IN VOID *FileHandle,
44 IN UINTN FileOffset,
45 IN OUT UINTN *ReadSize,
46 OUT VOID *Buffer
47 );
48
49 //
50 // Context structure used while PE/COFF image is being loaded and relocated
51 //
52 typedef struct {
53 PHYSICAL_ADDRESS ImageAddress;
54 UINT64 ImageSize;
55 PHYSICAL_ADDRESS DestinationAddress;
56 PHYSICAL_ADDRESS EntryPoint;
57 PE_COFF_LOADER_READ_FILE ImageRead;
58 VOID *Handle;
59 VOID *FixupData;
60 UINT32 SectionAlignment;
61 UINT32 PeCoffHeaderOffset;
62 UINT32 DebugDirectoryEntryRva;
63 VOID *CodeView;
64 CHAR8 *PdbPointer;
65 UINTN SizeOfHeaders;
66 UINT32 ImageCodeMemoryType;
67 UINT32 ImageDataMemoryType;
68 UINT32 ImageError;
69 UINTN FixupDataSize;
70 UINT16 Machine;
71 UINT16 ImageType;
72 BOOLEAN RelocationsStripped;
73 BOOLEAN IsTeImage;
74 } PE_COFF_LOADER_IMAGE_CONTEXT;
75
76
77 /**
78 Retrieves information on a PE/COFF image
79
80 @param ImageContext The context of the image being loaded
81
82 @retval EFI_SUCCESS The information on the PE/COFF image was collected.
83 @retval EFI_INVALID_PARAMETER ImageContext is NULL.
84 @retval EFI_UNSUPPORTED The PE/COFF image is not supported.
85 @retval Otherwise The error status from reading the PE/COFF image using the
86 ImageContext->ImageRead() function
87
88 **/
89 RETURN_STATUS
90 EFIAPI
91 PeCoffLoaderGetImageInfo (
92 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
93 )
94 ;
95
96 /**
97 Relocates a PE/COFF image in memory
98
99 @param ImageContext Contains information on the loaded image to relocate
100
101 @retval EFI_SUCCESS if the PE/COFF image was relocated
102 @retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image
103 @retval EFI_UNSUPPORTED not support
104
105 **/
106 RETURN_STATUS
107 EFIAPI
108 PeCoffLoaderRelocateImage (
109 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
110 )
111 ;
112
113 /**
114 Loads a PE/COFF image into memory
115
116 @param ImageContext Contains information on image to load into memory
117
118 @retval EFI_SUCCESS if the PE/COFF image was loaded
119 @retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer
120 @retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations
121 @retval EFI_INVALID_PARAMETER if the image address is invalid
122
123 **/
124 RETURN_STATUS
125 EFIAPI
126 PeCoffLoaderLoadImage (
127 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
128 )
129 ;
130
131 #endif