]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/GenFw/elf64.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / C / GenFw / elf64.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
2e351cbe 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
f51461c8
LG
6\r
7**/\r
8/*-\r
9 * Copyright (c) 1996-1998 John D. Polstra.\r
10 * All rights reserved.\r
11 *\r
12 * Redistribution and use in source and binary forms, with or without\r
13 * modification, are permitted provided that the following conditions\r
14 * are met:\r
15 * 1. Redistributions of source code must retain the above copyright\r
16 * notice, this list of conditions and the following disclaimer.\r
17 * 2. Redistributions in binary form must reproduce the above copyright\r
18 * notice, this list of conditions and the following disclaimer in the\r
19 * documentation and/or other materials provided with the distribution.\r
20 *\r
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
31 * SUCH DAMAGE.\r
32 *\r
33 * $FreeBSD: src/sys/sys/elf64.h,v 1.10.14.2 2007/12/03 21:30:36 marius Exp $\r
34 */\r
35\r
36#ifndef _SYS_ELF64_H_\r
37#define _SYS_ELF64_H_ 1\r
38\r
39\r
40/*\r
41 * ELF definitions common to all 64-bit architectures.\r
42 */\r
43\r
f7496d71
LG
44typedef UINT64 Elf64_Addr;\r
45typedef UINT16 Elf64_Half;\r
46typedef UINT64 Elf64_Off;\r
47typedef INT32 Elf64_Sword;\r
48typedef INT64 Elf64_Sxword;\r
49typedef UINT32 Elf64_Word;\r
50typedef UINT64 Elf64_Lword;\r
51typedef UINT64 Elf64_Xword;\r
f51461c8
LG
52\r
53/*\r
54 * Types of dynamic symbol hash table bucket and chain elements.\r
55 *\r
56 * This is inconsistent among 64 bit architectures, so a machine dependent\r
57 * typedef is required.\r
58 */\r
59\r
f7496d71 60typedef Elf64_Word Elf64_Hashelt;\r
f51461c8
LG
61\r
62/* Non-standard class-dependent datatype used for abstraction. */\r
f7496d71
LG
63typedef Elf64_Xword Elf64_Size;\r
64typedef Elf64_Sxword Elf64_Ssize;\r
f51461c8
LG
65\r
66/*\r
67 * ELF header.\r
68 */\r
69\r
70typedef struct {\r
f7496d71
LG
71 unsigned char e_ident[EI_NIDENT]; /* File identification. */\r
72 Elf64_Half e_type; /* File type. */\r
73 Elf64_Half e_machine; /* Machine architecture. */\r
74 Elf64_Word e_version; /* ELF format version. */\r
75 Elf64_Addr e_entry; /* Entry point. */\r
76 Elf64_Off e_phoff; /* Program header file offset. */\r
77 Elf64_Off e_shoff; /* Section header file offset. */\r
78 Elf64_Word e_flags; /* Architecture-specific flags. */\r
79 Elf64_Half e_ehsize; /* Size of ELF header in bytes. */\r
80 Elf64_Half e_phentsize; /* Size of program header entry. */\r
81 Elf64_Half e_phnum; /* Number of program header entries. */\r
82 Elf64_Half e_shentsize; /* Size of section header entry. */\r
83 Elf64_Half e_shnum; /* Number of section header entries. */\r
84 Elf64_Half e_shstrndx; /* Section name strings section. */\r
f51461c8
LG
85} Elf64_Ehdr;\r
86\r
87/*\r
88 * Section header.\r
89 */\r
90\r
91typedef struct {\r
f7496d71
LG
92 Elf64_Word sh_name; /* Section name (index into the\r
93 section header string table). */\r
94 Elf64_Word sh_type; /* Section type. */\r
95 Elf64_Xword sh_flags; /* Section flags. */\r
96 Elf64_Addr sh_addr; /* Address in memory image. */\r
97 Elf64_Off sh_offset; /* Offset in file. */\r
98 Elf64_Xword sh_size; /* Size in bytes. */\r
99 Elf64_Word sh_link; /* Index of a related section. */\r
100 Elf64_Word sh_info; /* Depends on section type. */\r
101 Elf64_Xword sh_addralign; /* Alignment in bytes. */\r
102 Elf64_Xword sh_entsize; /* Size of each entry in section. */\r
f51461c8
LG
103} Elf64_Shdr;\r
104\r
105/*\r
106 * Program header.\r
107 */\r
108\r
109typedef struct {\r
f7496d71
LG
110 Elf64_Word p_type; /* Entry type. */\r
111 Elf64_Word p_flags; /* Access permission flags. */\r
112 Elf64_Off p_offset; /* File offset of contents. */\r
113 Elf64_Addr p_vaddr; /* Virtual address in memory image. */\r
114 Elf64_Addr p_paddr; /* Physical address (not used). */\r
115 Elf64_Xword p_filesz; /* Size of contents in file. */\r
116 Elf64_Xword p_memsz; /* Size of contents in memory. */\r
117 Elf64_Xword p_align; /* Alignment in memory and file. */\r
f51461c8
LG
118} Elf64_Phdr;\r
119\r
120/*\r
121 * Dynamic structure. The ".dynamic" section contains an array of them.\r
122 */\r
123\r
124typedef struct {\r
f7496d71
LG
125 Elf64_Sxword d_tag; /* Entry type. */\r
126 union {\r
127 Elf64_Xword d_val; /* Integer value. */\r
128 Elf64_Addr d_ptr; /* Address value. */\r
129 } d_un;\r
f51461c8
LG
130} Elf64_Dyn;\r
131\r
132/*\r
133 * Relocation entries.\r
134 */\r
135\r
136/* Relocations that don't need an addend field. */\r
137typedef struct {\r
f7496d71
LG
138 Elf64_Addr r_offset; /* Location to be relocated. */\r
139 Elf64_Xword r_info; /* Relocation type and symbol index. */\r
f51461c8
LG
140} Elf64_Rel;\r
141\r
142/* Relocations that need an addend field. */\r
143typedef struct {\r
f7496d71
LG
144 Elf64_Addr r_offset; /* Location to be relocated. */\r
145 Elf64_Xword r_info; /* Relocation type and symbol index. */\r
146 Elf64_Sxword r_addend; /* Addend. */\r
f51461c8
LG
147} Elf64_Rela;\r
148\r
149/* Macros for accessing the fields of r_info. */\r
f7496d71
LG
150#define ELF64_R_SYM(info) ((info) >> 32)\r
151#define ELF64_R_TYPE(info) ((info) & 0xffffffffL)\r
f51461c8
LG
152\r
153/* Macro for constructing r_info from field values. */\r
f7496d71 154#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))\r
f51461c8 155\r
f7496d71
LG
156#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40)\r
157#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56)\r
158#define ELF64_R_TYPE_INFO(data, type) \\r
159 (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))\r
f51461c8
LG
160\r
161/*\r
f7496d71 162 * Note entry header\r
f51461c8
LG
163 */\r
164typedef Elf_Note Elf64_Nhdr;\r
165\r
166/*\r
f7496d71 167 * Move entry\r
f51461c8
LG
168 */\r
169typedef struct {\r
f7496d71
LG
170 Elf64_Lword m_value; /* symbol value */\r
171 Elf64_Xword m_info; /* size + index */\r
172 Elf64_Xword m_poffset; /* symbol offset */\r
173 Elf64_Half m_repeat; /* repeat count */\r
174 Elf64_Half m_stride; /* stride info */\r
f51461c8
LG
175} Elf64_Move;\r
176\r
f7496d71
LG
177#define ELF64_M_SYM(info) ((info)>>8)\r
178#define ELF64_M_SIZE(info) ((unsigned char)(info))\r
179#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))\r
f51461c8
LG
180\r
181/*\r
f7496d71 182 * Hardware/Software capabilities entry\r
f51461c8
LG
183 */\r
184typedef struct {\r
f7496d71
LG
185 Elf64_Xword c_tag; /* how to interpret value */\r
186 union {\r
187 Elf64_Xword c_val;\r
188 Elf64_Addr c_ptr;\r
189 } c_un;\r
f51461c8
LG
190} Elf64_Cap;\r
191\r
192/*\r
193 * Symbol table entries.\r
194 */\r
195\r
196typedef struct {\r
f7496d71
LG
197 Elf64_Word st_name; /* String table index of name. */\r
198 unsigned char st_info; /* Type and binding information. */\r
199 unsigned char st_other; /* Reserved (not used). */\r
200 Elf64_Half st_shndx; /* Section index of symbol. */\r
201 Elf64_Addr st_value; /* Symbol value. */\r
202 Elf64_Xword st_size; /* Size of associated object. */\r
f51461c8
LG
203} Elf64_Sym;\r
204\r
205/* Macros for accessing the fields of st_info. */\r
f7496d71
LG
206#define ELF64_ST_BIND(info) ((info) >> 4)\r
207#define ELF64_ST_TYPE(info) ((info) & 0xf)\r
f51461c8
LG
208\r
209/* Macro for constructing st_info from field values. */\r
f7496d71 210#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))\r
f51461c8
LG
211\r
212/* Macro for accessing the fields of st_other. */\r
f7496d71 213#define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3)\r
f51461c8
LG
214\r
215/* Structures used by Sun & GNU-style symbol versioning. */\r
216typedef struct {\r
f7496d71
LG
217 Elf64_Half vd_version;\r
218 Elf64_Half vd_flags;\r
219 Elf64_Half vd_ndx;\r
220 Elf64_Half vd_cnt;\r
221 Elf64_Word vd_hash;\r
222 Elf64_Word vd_aux;\r
223 Elf64_Word vd_next;\r
f51461c8
LG
224} Elf64_Verdef;\r
225\r
226typedef struct {\r
f7496d71
LG
227 Elf64_Word vda_name;\r
228 Elf64_Word vda_next;\r
f51461c8
LG
229} Elf64_Verdaux;\r
230\r
231typedef struct {\r
f7496d71
LG
232 Elf64_Half vn_version;\r
233 Elf64_Half vn_cnt;\r
234 Elf64_Word vn_file;\r
235 Elf64_Word vn_aux;\r
236 Elf64_Word vn_next;\r
f51461c8
LG
237} Elf64_Verneed;\r
238\r
239typedef struct {\r
f7496d71
LG
240 Elf64_Word vna_hash;\r
241 Elf64_Half vna_flags;\r
242 Elf64_Half vna_other;\r
243 Elf64_Word vna_name;\r
244 Elf64_Word vna_next;\r
f51461c8
LG
245} Elf64_Vernaux;\r
246\r
247typedef Elf64_Half Elf64_Versym;\r
248\r
249typedef struct {\r
f7496d71
LG
250 Elf64_Half si_boundto; /* direct bindings - symbol bound to */\r
251 Elf64_Half si_flags; /* per symbol flags */\r
f51461c8
LG
252} Elf64_Syminfo;\r
253\r
254#endif /* !_SYS_ELF64_H_ */\r