]>
Commit | Line | Data |
---|---|---|
fe471d4a RN |
1 | /** @file\r |
2 | ELF library\r | |
3 | \r | |
4 | Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #ifndef ELF_LIB_H_\r | |
10 | #define ELF_LIB_H_\r | |
11 | \r | |
12 | #include <PiPei.h>\r | |
13 | \r | |
e5efcf8b MK |
14 | #define ELF_CLASS32 1\r |
15 | #define ELF_CLASS64 2\r | |
fe471d4a | 16 | \r |
e5efcf8b | 17 | #define ELF_PT_LOAD 1\r |
fe471d4a RN |
18 | \r |
19 | typedef struct {\r | |
e5efcf8b MK |
20 | RETURN_STATUS ParseStatus; ///< Return the status after ParseElfImage().\r |
21 | UINT8 *FileBase; ///< The source location in memory.\r | |
22 | UINTN FileSize; ///< The size including sections that don't require loading.\r | |
23 | UINT8 *PreferredImageAddress; ///< The preferred image to be loaded. No relocation is needed if loaded to this address.\r | |
24 | BOOLEAN ReloadRequired; ///< The image needs a new memory location for running.\r | |
25 | UINT8 *ImageAddress; ///< The destination memory address set by caller.\r | |
26 | UINTN ImageSize; ///< The memory size for loading and execution.\r | |
27 | UINT32 EiClass;\r | |
28 | UINT32 ShNum;\r | |
29 | UINT32 PhNum;\r | |
30 | UINTN ShStrOff;\r | |
31 | UINTN ShStrLen;\r | |
32 | UINTN EntryPoint; ///< Return the actual entry point after LoadElfImage().\r | |
fe471d4a RN |
33 | } ELF_IMAGE_CONTEXT;\r |
34 | \r | |
fe471d4a | 35 | typedef struct {\r |
e5efcf8b MK |
36 | UINT32 PtType;\r |
37 | UINTN Offset;\r | |
38 | UINTN Length;\r | |
39 | UINTN MemLen;\r | |
40 | UINTN MemAddr;\r | |
41 | UINTN Alignment;\r | |
fe471d4a RN |
42 | } SEGMENT_INFO;\r |
43 | \r | |
44 | /**\r | |
45 | Parse the ELF image info.\r | |
46 | \r | |
47 | @param[in] ImageBase Memory address of an image.\r | |
48 | @param[out] ElfCt The EFL image context pointer.\r | |
49 | \r | |
50 | @retval EFI_INVALID_PARAMETER Input parameters are not valid.\r | |
51 | @retval EFI_UNSUPPORTED Unsupported binary type.\r | |
52 | @retval EFI_LOAD_ERROR ELF binary loading error.\r | |
53 | @retval EFI_SUCCESS ELF binary is loaded successfully.\r | |
54 | **/\r | |
55 | EFI_STATUS\r | |
56 | EFIAPI\r | |
57 | ParseElfImage (\r | |
e5efcf8b MK |
58 | IN VOID *ImageBase,\r |
59 | OUT ELF_IMAGE_CONTEXT *ElfCt\r | |
fe471d4a RN |
60 | );\r |
61 | \r | |
62 | /**\r | |
63 | Load the ELF segments to specified address in ELF header.\r | |
64 | \r | |
65 | This function loads ELF image segments into memory address specified\r | |
66 | in ELF program header.\r | |
67 | \r | |
68 | @param[in] ElfCt ELF image context pointer.\r | |
69 | \r | |
70 | @retval EFI_INVALID_PARAMETER Input parameters are not valid.\r | |
71 | @retval EFI_UNSUPPORTED Unsupported binary type.\r | |
72 | @retval EFI_LOAD_ERROR ELF binary loading error.\r | |
73 | @retval EFI_SUCCESS ELF binary is loaded successfully.\r | |
74 | **/\r | |
75 | EFI_STATUS\r | |
76 | EFIAPI\r | |
77 | LoadElfImage (\r | |
e5efcf8b | 78 | IN ELF_IMAGE_CONTEXT *ElfCt\r |
fe471d4a RN |
79 | );\r |
80 | \r | |
81 | /**\r | |
82 | Get a ELF section name from its index.\r | |
83 | \r | |
84 | @param[in] ElfCt ELF image context pointer.\r | |
85 | @param[in] SectionIndex ELF section index.\r | |
86 | @param[out] SectionName The pointer to the section name.\r | |
87 | \r | |
88 | @retval EFI_INVALID_PARAMETER ElfCt or SecName is NULL.\r | |
89 | @retval EFI_NOT_FOUND Could not find the section.\r | |
90 | @retval EFI_SUCCESS Section name was filled successfully.\r | |
91 | **/\r | |
92 | EFI_STATUS\r | |
93 | EFIAPI\r | |
94 | GetElfSectionName (\r | |
e5efcf8b MK |
95 | IN ELF_IMAGE_CONTEXT *ElfCt,\r |
96 | IN UINT32 SectionIndex,\r | |
97 | OUT CHAR8 **SectionName\r | |
fe471d4a RN |
98 | );\r |
99 | \r | |
100 | /**\r | |
101 | Get the offset and size of x-th ELF section.\r | |
102 | \r | |
103 | @param[in] ElfCt ELF image context pointer.\r | |
104 | @param[in] Index ELF section index.\r | |
105 | @param[out] Offset Return the offset of the specific section.\r | |
106 | @param[out] Size Return the size of the specific section.\r | |
107 | \r | |
108 | @retval EFI_INVALID_PARAMETER ImageBase, Offset or Size is NULL.\r | |
109 | @retval EFI_INVALID_PARAMETER EiClass doesn't equal to ELFCLASS32 or ELFCLASS64.\r | |
110 | @retval EFI_NOT_FOUND Could not find the section.\r | |
111 | @retval EFI_SUCCESS Offset and Size are returned.\r | |
112 | **/\r | |
113 | EFI_STATUS\r | |
114 | EFIAPI\r | |
115 | GetElfSectionPos (\r | |
e5efcf8b MK |
116 | IN ELF_IMAGE_CONTEXT *ElfCt,\r |
117 | IN UINT32 Index,\r | |
118 | OUT UINTN *Offset,\r | |
119 | OUT UINTN *Size\r | |
fe471d4a | 120 | );\r |
e5efcf8b | 121 | \r |
fe471d4a | 122 | #endif /* ELF_LIB_H_ */\r |