]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/GenFw/elf32.h
BaseTools: Roll back GenFw Change to keep unknown field in RSDS debug entry
[mirror_edk2.git] / BaseTools / Source / C / GenFw / elf32.h
CommitLineData
f51461c8
LG
1/** @file\r
2Ported ELF include files from FreeBSD\r
3\r
4Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14**/\r
15/*-\r
16 * Copyright (c) 1996-1998 John D. Polstra.\r
17 * All rights reserved.\r
18 *\r
19 * Redistribution and use in source and binary forms, with or without\r
20 * modification, are permitted provided that the following conditions\r
21 * are met:\r
22 * 1. Redistributions of source code must retain the above copyright\r
23 * notice, this list of conditions and the following disclaimer.\r
24 * 2. Redistributions in binary form must reproduce the above copyright\r
25 * notice, this list of conditions and the following disclaimer in the\r
26 * documentation and/or other materials provided with the distribution.\r
27 *\r
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
38 * SUCH DAMAGE.\r
39 *\r
40 * $FreeBSD: src/sys/sys/elf32.h,v 1.8.14.2 2007/12/03 21:30:36 marius Exp $\r
41 */\r
42\r
43#ifndef _SYS_ELF32_H_\r
44#define _SYS_ELF32_H_ 1\r
45\r
46\r
47/*\r
48 * ELF definitions common to all 32-bit architectures.\r
49 */\r
50\r
51typedef UINT32 Elf32_Addr;\r
52typedef UINT16 Elf32_Half;\r
53typedef UINT32 Elf32_Off;\r
54typedef INT32 Elf32_Sword;\r
55typedef UINT32 Elf32_Word;\r
56typedef UINT64 Elf32_Lword;\r
57\r
58typedef Elf32_Word Elf32_Hashelt;\r
59\r
60/* Non-standard class-dependent datatype used for abstraction. */\r
61typedef Elf32_Word Elf32_Size;\r
62typedef Elf32_Sword Elf32_Ssize;\r
63\r
64/*\r
65 * ELF header.\r
66 */\r
67\r
68typedef struct {\r
69 unsigned char e_ident[EI_NIDENT]; /* File identification. */\r
70 Elf32_Half e_type; /* File type. */\r
71 Elf32_Half e_machine; /* Machine architecture. */\r
72 Elf32_Word e_version; /* ELF format version. */\r
73 Elf32_Addr e_entry; /* Entry point. */\r
74 Elf32_Off e_phoff; /* Program header file offset. */\r
75 Elf32_Off e_shoff; /* Section header file offset. */\r
76 Elf32_Word e_flags; /* Architecture-specific flags. */\r
77 Elf32_Half e_ehsize; /* Size of ELF header in bytes. */\r
78 Elf32_Half e_phentsize; /* Size of program header entry. */\r
79 Elf32_Half e_phnum; /* Number of program header entries. */\r
80 Elf32_Half e_shentsize; /* Size of section header entry. */\r
81 Elf32_Half e_shnum; /* Number of section header entries. */\r
82 Elf32_Half e_shstrndx; /* Section name strings section. */\r
83} Elf32_Ehdr;\r
84\r
85/*\r
86 * Section header.\r
87 */\r
88\r
89typedef struct {\r
90 Elf32_Word sh_name; /* Section name (index into the\r
91 section header string table). */\r
92 Elf32_Word sh_type; /* Section type. */\r
93 Elf32_Word sh_flags; /* Section flags. */\r
94 Elf32_Addr sh_addr; /* Address in memory image. */\r
95 Elf32_Off sh_offset; /* Offset in file. */\r
96 Elf32_Word sh_size; /* Size in bytes. */\r
97 Elf32_Word sh_link; /* Index of a related section. */\r
98 Elf32_Word sh_info; /* Depends on section type. */\r
99 Elf32_Word sh_addralign; /* Alignment in bytes. */\r
100 Elf32_Word sh_entsize; /* Size of each entry in section. */\r
101} Elf32_Shdr;\r
102\r
103/*\r
104 * Program header.\r
105 */\r
106\r
107typedef struct {\r
108 Elf32_Word p_type; /* Entry type. */\r
109 Elf32_Off p_offset; /* File offset of contents. */\r
110 Elf32_Addr p_vaddr; /* Virtual address in memory image. */\r
111 Elf32_Addr p_paddr; /* Physical address (not used). */\r
112 Elf32_Word p_filesz; /* Size of contents in file. */\r
113 Elf32_Word p_memsz; /* Size of contents in memory. */\r
114 Elf32_Word p_flags; /* Access permission flags. */\r
115 Elf32_Word p_align; /* Alignment in memory and file. */\r
116} Elf32_Phdr;\r
117\r
118/*\r
119 * Dynamic structure. The ".dynamic" section contains an array of them.\r
120 */\r
121\r
122typedef struct {\r
123 Elf32_Sword d_tag; /* Entry type. */\r
124 union {\r
125 Elf32_Word d_val; /* Integer value. */\r
126 Elf32_Addr d_ptr; /* Address value. */\r
127 } d_un;\r
128} Elf32_Dyn;\r
129\r
130/*\r
131 * Relocation entries.\r
132 */\r
133\r
134/* Relocations that don't need an addend field. */\r
135typedef struct {\r
136 Elf32_Addr r_offset; /* Location to be relocated. */\r
137 Elf32_Word r_info; /* Relocation type and symbol index. */\r
138} Elf32_Rel;\r
139\r
140/* Relocations that need an addend field. */\r
141typedef struct {\r
142 Elf32_Addr r_offset; /* Location to be relocated. */\r
143 Elf32_Word r_info; /* Relocation type and symbol index. */\r
144 Elf32_Sword r_addend; /* Addend. */\r
145} Elf32_Rela;\r
146\r
147/* Macros for accessing the fields of r_info. */\r
148#define ELF32_R_SYM(info) ((info) >> 8)\r
149#define ELF32_R_TYPE(info) ((unsigned char)(info))\r
150\r
151/* Macro for constructing r_info from field values. */\r
152#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))\r
153\r
154/*\r
155 * Note entry header\r
156 */\r
157typedef Elf_Note Elf32_Nhdr;\r
158\r
159/*\r
160 * Move entry\r
161 */\r
162typedef struct {\r
163 Elf32_Lword m_value; /* symbol value */\r
164 Elf32_Word m_info; /* size + index */\r
165 Elf32_Word m_poffset; /* symbol offset */\r
166 Elf32_Half m_repeat; /* repeat count */\r
167 Elf32_Half m_stride; /* stride info */\r
168} Elf32_Move;\r
169\r
170/*\r
171 * The macros compose and decompose values for Move.r_info\r
172 *\r
173 * sym = ELF32_M_SYM(M.m_info)\r
174 * size = ELF32_M_SIZE(M.m_info)\r
175 * M.m_info = ELF32_M_INFO(sym, size)\r
176 */\r
177#define ELF32_M_SYM(info) ((info)>>8)\r
178#define ELF32_M_SIZE(info) ((unsigned char)(info))\r
179#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))\r
180\r
181/*\r
182 * Hardware/Software capabilities entry\r
183 */\r
184typedef struct {\r
185 Elf32_Word c_tag; /* how to interpret value */\r
186 union {\r
187 Elf32_Word c_val;\r
188 Elf32_Addr c_ptr;\r
189 } c_un;\r
190} Elf32_Cap;\r
191\r
192/*\r
193 * Symbol table entries.\r
194 */\r
195\r
196typedef struct {\r
197 Elf32_Word st_name; /* String table index of name. */\r
198 Elf32_Addr st_value; /* Symbol value. */\r
199 Elf32_Word st_size; /* Size of associated object. */\r
200 unsigned char st_info; /* Type and binding information. */\r
201 unsigned char st_other; /* Reserved (not used). */\r
202 Elf32_Half st_shndx; /* Section index of symbol. */\r
203} Elf32_Sym;\r
204\r
205/* Macros for accessing the fields of st_info. */\r
206#define ELF32_ST_BIND(info) ((info) >> 4)\r
207#define ELF32_ST_TYPE(info) ((info) & 0xf)\r
208\r
209/* Macro for constructing st_info from field values. */\r
210#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))\r
211\r
212/* Macro for accessing the fields of st_other. */\r
213#define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3)\r
214\r
215/* Structures used by Sun & GNU symbol versioning. */\r
216typedef struct\r
217{\r
218 Elf32_Half vd_version;\r
219 Elf32_Half vd_flags;\r
220 Elf32_Half vd_ndx;\r
221 Elf32_Half vd_cnt;\r
222 Elf32_Word vd_hash;\r
223 Elf32_Word vd_aux;\r
224 Elf32_Word vd_next;\r
225} Elf32_Verdef;\r
226\r
227typedef struct\r
228{\r
229 Elf32_Word vda_name;\r
230 Elf32_Word vda_next;\r
231} Elf32_Verdaux;\r
232\r
233typedef struct\r
234{\r
235 Elf32_Half vn_version;\r
236 Elf32_Half vn_cnt;\r
237 Elf32_Word vn_file;\r
238 Elf32_Word vn_aux;\r
239 Elf32_Word vn_next;\r
240} Elf32_Verneed;\r
241\r
242typedef struct\r
243{\r
244 Elf32_Word vna_hash;\r
245 Elf32_Half vna_flags;\r
246 Elf32_Half vna_other;\r
247 Elf32_Word vna_name;\r
248 Elf32_Word vna_next;\r
249} Elf32_Vernaux;\r
250\r
251typedef Elf32_Half Elf32_Versym;\r
252\r
253typedef struct {\r
254 Elf32_Half si_boundto; /* direct bindings - symbol bound to */\r
255 Elf32_Half si_flags; /* per symbol flags */\r
256} Elf32_Syminfo;\r
257\r
258#endif /* !_SYS_ELF32_H_ */\r