]> git.proxmox.com Git - qemu.git/blob - elf.h
avoid pt_regs clash
[qemu.git] / elf.h
1 /*
2 * ELF register definitions..
3 */
4
5 #include <inttypes.h>
6
7 typedef uint32_t elf_greg_t;
8
9 #define ELF_NGREG (sizeof (struct target_pt_regs) / sizeof(elf_greg_t))
10 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
11
12 typedef struct user_i387_struct elf_fpregset_t;
13
14 /*
15 * This is used to ensure we don't load something for the wrong architecture.
16 */
17 #define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
18
19 /*
20 * These are used to set parameters in the core dumps.
21 */
22 #define ELF_CLASS ELFCLASS32
23 #define ELF_DATA ELFDATA2LSB;
24 #define ELF_ARCH EM_386
25
26 /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
27 starts %edx contains a pointer to a function which might be
28 registered using `atexit'. This provides a mean for the
29 dynamic linker to call DT_FINI functions for shared libraries
30 that have been loaded before the code runs.
31
32 A value of 0 tells we have no such handler. */
33 #define ELF_PLAT_INIT(_r) _r->edx = 0
34
35 #define USE_ELF_CORE_DUMP
36 #define ELF_EXEC_PAGESIZE 4096
37
38
39 typedef uint32_t Elf32_Addr;
40 typedef uint16_t Elf32_Half;
41 typedef uint32_t Elf32_Off;
42 typedef int32_t Elf32_Sword;
43 typedef uint32_t Elf32_Word;
44
45 /* These constants are for the segment types stored in the image headers */
46 #define PT_NULL 0
47 #define PT_LOAD 1
48 #define PT_DYNAMIC 2
49 #define PT_INTERP 3
50 #define PT_NOTE 4
51 #define PT_SHLIB 5
52 #define PT_PHDR 6
53 #define PT_LOPROC 0x70000000
54 #define PT_HIPROC 0x7fffffff
55
56 /* These constants define the different elf file types */
57 #define ET_NONE 0
58 #define ET_REL 1
59 #define ET_EXEC 2
60 #define ET_DYN 3
61 #define ET_CORE 4
62 #define ET_LOPROC 5
63 #define ET_HIPROC 6
64
65 /* These constants define the various ELF target machines */
66 #define EM_NONE 0
67 #define EM_M32 1
68 #define EM_SPARC 2
69 #define EM_386 3
70 #define EM_68K 4
71 #define EM_88K 5
72 #define EM_486 6 /* Perhaps disused */
73 #define EM_860 7
74
75 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
76
77 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
78
79 #define EM_SPARC64 11 /* SPARC v9 (not official) 64-bit */
80
81 #define EM_PARISC 15 /* HPPA */
82
83 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
84
85 #define EM_PPC 20 /* PowerPC */
86
87 /*
88 * This is an interim value that we will use until the committee comes
89 * up with a final number.
90 */
91 #define EM_ALPHA 0x9026
92
93
94 /* This is the info that is needed to parse the dynamic section of the file */
95 #define DT_NULL 0
96 #define DT_NEEDED 1
97 #define DT_PLTRELSZ 2
98 #define DT_PLTGOT 3
99 #define DT_HASH 4
100 #define DT_STRTAB 5
101 #define DT_SYMTAB 6
102 #define DT_RELA 7
103 #define DT_RELASZ 8
104 #define DT_RELAENT 9
105 #define DT_STRSZ 10
106 #define DT_SYMENT 11
107 #define DT_INIT 12
108 #define DT_FINI 13
109 #define DT_SONAME 14
110 #define DT_RPATH 15
111 #define DT_SYMBOLIC 16
112 #define DT_REL 17
113 #define DT_RELSZ 18
114 #define DT_RELENT 19
115 #define DT_PLTREL 20
116 #define DT_DEBUG 21
117 #define DT_TEXTREL 22
118 #define DT_JMPREL 23
119 #define DT_LOPROC 0x70000000
120 #define DT_HIPROC 0x7fffffff
121
122 /* This info is needed when parsing the symbol table */
123 #define STB_LOCAL 0
124 #define STB_GLOBAL 1
125 #define STB_WEAK 2
126
127 #define STT_NOTYPE 0
128 #define STT_OBJECT 1
129 #define STT_FUNC 2
130 #define STT_SECTION 3
131 #define STT_FILE 4
132
133 #define ELF32_ST_BIND(x) ((x) >> 4)
134 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
135
136 /* Symbolic values for the entries in the auxiliary table
137 put on the initial stack */
138 #define AT_NULL 0 /* end of vector */
139 #define AT_IGNORE 1 /* entry should be ignored */
140 #define AT_EXECFD 2 /* file descriptor of program */
141 #define AT_PHDR 3 /* program headers for program */
142 #define AT_PHENT 4 /* size of program header entry */
143 #define AT_PHNUM 5 /* number of program headers */
144 #define AT_PAGESZ 6 /* system page size */
145 #define AT_BASE 7 /* base address of interpreter */
146 #define AT_FLAGS 8 /* flags */
147 #define AT_ENTRY 9 /* entry point of program */
148 #define AT_NOTELF 10 /* program is not ELF */
149 #define AT_UID 11 /* real uid */
150 #define AT_EUID 12 /* effective uid */
151 #define AT_GID 13 /* real gid */
152 #define AT_EGID 14 /* effective gid */
153
154
155 typedef struct dynamic{
156 Elf32_Sword d_tag;
157 union{
158 Elf32_Sword d_val;
159 Elf32_Addr d_ptr;
160 } d_un;
161 } Elf32_Dyn;
162
163 typedef struct {
164 unsigned long long d_tag; /* entry tag value */
165 union {
166 unsigned long long d_val;
167 unsigned long long d_ptr;
168 } d_un;
169 } Elf64_Dyn;
170
171 /* The following are used with relocations */
172 #define ELF32_R_SYM(x) ((x) >> 8)
173 #define ELF32_R_TYPE(x) ((x) & 0xff)
174
175 #define R_386_NONE 0
176 #define R_386_32 1
177 #define R_386_PC32 2
178 #define R_386_GOT32 3
179 #define R_386_PLT32 4
180 #define R_386_COPY 5
181 #define R_386_GLOB_DAT 6
182 #define R_386_JMP_SLOT 7
183 #define R_386_RELATIVE 8
184 #define R_386_GOTOFF 9
185 #define R_386_GOTPC 10
186 #define R_386_NUM 11
187
188 typedef struct elf32_rel {
189 Elf32_Addr r_offset;
190 Elf32_Word r_info;
191 } Elf32_Rel;
192
193 typedef struct elf64_rel {
194 unsigned long long r_offset; /* Location at which to apply the action */
195 unsigned long long r_info; /* index and type of relocation */
196 } Elf64_Rel;
197
198 typedef struct elf32_rela{
199 Elf32_Addr r_offset;
200 Elf32_Word r_info;
201 Elf32_Sword r_addend;
202 } Elf32_Rela;
203
204 typedef struct elf64_rela {
205 unsigned long long r_offset; /* Location at which to apply the action */
206 unsigned long long r_info; /* index and type of relocation */
207 unsigned long long r_addend; /* Constant addend used to compute value */
208 } Elf64_Rela;
209
210 typedef struct elf32_sym{
211 Elf32_Word st_name;
212 Elf32_Addr st_value;
213 Elf32_Word st_size;
214 unsigned char st_info;
215 unsigned char st_other;
216 Elf32_Half st_shndx;
217 } Elf32_Sym;
218
219 typedef struct elf64_sym {
220 unsigned int st_name; /* Symbol name, index in string tbl */
221 unsigned char st_info; /* Type and binding attributes */
222 unsigned char st_other; /* No defined meaning, 0 */
223 unsigned short st_shndx; /* Associated section index */
224 unsigned long long st_value; /* Value of the symbol */
225 unsigned long long st_size; /* Associated symbol size */
226 } Elf64_Sym;
227
228
229 #define EI_NIDENT 16
230
231 typedef struct elf32_hdr{
232 unsigned char e_ident[EI_NIDENT];
233 Elf32_Half e_type;
234 Elf32_Half e_machine;
235 Elf32_Word e_version;
236 Elf32_Addr e_entry; /* Entry point */
237 Elf32_Off e_phoff;
238 Elf32_Off e_shoff;
239 Elf32_Word e_flags;
240 Elf32_Half e_ehsize;
241 Elf32_Half e_phentsize;
242 Elf32_Half e_phnum;
243 Elf32_Half e_shentsize;
244 Elf32_Half e_shnum;
245 Elf32_Half e_shstrndx;
246 } Elf32_Ehdr;
247
248 typedef struct elf64_hdr {
249 unsigned char e_ident[16]; /* ELF "magic number" */
250 short int e_type;
251 short unsigned int e_machine;
252 int e_version;
253 unsigned long long e_entry; /* Entry point virtual address */
254 unsigned long long e_phoff; /* Program header table file offset */
255 unsigned long long e_shoff; /* Section header table file offset */
256 int e_flags;
257 short int e_ehsize;
258 short int e_phentsize;
259 short int e_phnum;
260 short int e_shentsize;
261 short int e_shnum;
262 short int e_shstrndx;
263 } Elf64_Ehdr;
264
265 /* These constants define the permissions on sections in the program
266 header, p_flags. */
267 #define PF_R 0x4
268 #define PF_W 0x2
269 #define PF_X 0x1
270
271 typedef struct elf32_phdr{
272 Elf32_Word p_type;
273 Elf32_Off p_offset;
274 Elf32_Addr p_vaddr;
275 Elf32_Addr p_paddr;
276 Elf32_Word p_filesz;
277 Elf32_Word p_memsz;
278 Elf32_Word p_flags;
279 Elf32_Word p_align;
280 } Elf32_Phdr;
281
282 typedef struct elf64_phdr {
283 int p_type;
284 int p_flags;
285 unsigned long long p_offset; /* Segment file offset */
286 unsigned long long p_vaddr; /* Segment virtual address */
287 unsigned long long p_paddr; /* Segment physical address */
288 unsigned long long p_filesz; /* Segment size in file */
289 unsigned long long p_memsz; /* Segment size in memory */
290 unsigned long long p_align; /* Segment alignment, file & memory */
291 } Elf64_Phdr;
292
293 /* sh_type */
294 #define SHT_NULL 0
295 #define SHT_PROGBITS 1
296 #define SHT_SYMTAB 2
297 #define SHT_STRTAB 3
298 #define SHT_RELA 4
299 #define SHT_HASH 5
300 #define SHT_DYNAMIC 6
301 #define SHT_NOTE 7
302 #define SHT_NOBITS 8
303 #define SHT_REL 9
304 #define SHT_SHLIB 10
305 #define SHT_DYNSYM 11
306 #define SHT_NUM 12
307 #define SHT_LOPROC 0x70000000
308 #define SHT_HIPROC 0x7fffffff
309 #define SHT_LOUSER 0x80000000
310 #define SHT_HIUSER 0xffffffff
311
312 /* sh_flags */
313 #define SHF_WRITE 0x1
314 #define SHF_ALLOC 0x2
315 #define SHF_EXECINSTR 0x4
316 #define SHF_MASKPROC 0xf0000000
317
318 /* special section indexes */
319 #define SHN_UNDEF 0
320 #define SHN_LORESERVE 0xff00
321 #define SHN_LOPROC 0xff00
322 #define SHN_HIPROC 0xff1f
323 #define SHN_ABS 0xfff1
324 #define SHN_COMMON 0xfff2
325 #define SHN_HIRESERVE 0xffff
326
327 typedef struct {
328 Elf32_Word sh_name;
329 Elf32_Word sh_type;
330 Elf32_Word sh_flags;
331 Elf32_Addr sh_addr;
332 Elf32_Off sh_offset;
333 Elf32_Word sh_size;
334 Elf32_Word sh_link;
335 Elf32_Word sh_info;
336 Elf32_Word sh_addralign;
337 Elf32_Word sh_entsize;
338 } Elf32_Shdr;
339
340 typedef struct elf64_shdr {
341 unsigned int sh_name; /* Section name, index in string tbl */
342 unsigned int sh_type; /* Type of section */
343 unsigned long long sh_flags; /* Miscellaneous section attributes */
344 unsigned long long sh_addr; /* Section virtual addr at execution */
345 unsigned long long sh_offset; /* Section file offset */
346 unsigned long long sh_size; /* Size of section in bytes */
347 unsigned int sh_link; /* Index of another section */
348 unsigned int sh_info; /* Additional section information */
349 unsigned long long sh_addralign; /* Section alignment */
350 unsigned long long sh_entsize; /* Entry size if section holds table */
351 } Elf64_Shdr;
352
353 #define EI_MAG0 0 /* e_ident[] indexes */
354 #define EI_MAG1 1
355 #define EI_MAG2 2
356 #define EI_MAG3 3
357 #define EI_CLASS 4
358 #define EI_DATA 5
359 #define EI_VERSION 6
360 #define EI_PAD 7
361
362 #define ELFMAG0 0x7f /* EI_MAG */
363 #define ELFMAG1 'E'
364 #define ELFMAG2 'L'
365 #define ELFMAG3 'F'
366 #define ELFMAG "\177ELF"
367 #define SELFMAG 4
368
369 #define ELFCLASSNONE 0 /* EI_CLASS */
370 #define ELFCLASS32 1
371 #define ELFCLASS64 2
372 #define ELFCLASSNUM 3
373
374 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
375 #define ELFDATA2LSB 1
376 #define ELFDATA2MSB 2
377
378 #define EV_NONE 0 /* e_version, EI_VERSION */
379 #define EV_CURRENT 1
380 #define EV_NUM 2
381
382 /* Notes used in ET_CORE */
383 #define NT_PRSTATUS 1
384 #define NT_PRFPREG 2
385 #define NT_PRPSINFO 3
386 #define NT_TASKSTRUCT 4
387
388 /* Note header in a PT_NOTE section */
389 typedef struct elf32_note {
390 Elf32_Word n_namesz; /* Name size */
391 Elf32_Word n_descsz; /* Content size */
392 Elf32_Word n_type; /* Content type */
393 } Elf32_Nhdr;
394
395 /* Note header in a PT_NOTE section */
396 /*
397 * For now we use the 32 bit version of the structure until we figure
398 * out whether we need anything better. Note - on the Alpha, "unsigned int"
399 * is only 32 bits.
400 */
401 typedef struct elf64_note {
402 unsigned int n_namesz; /* Name size */
403 unsigned int n_descsz; /* Content size */
404 unsigned int n_type; /* Content type */
405 } Elf64_Nhdr;
406
407 #define ELF_START_MMAP 0x80000000
408
409 #if ELF_CLASS == ELFCLASS32
410
411 extern Elf32_Dyn _DYNAMIC [];
412 #define elfhdr elf32_hdr
413 #define elf_phdr elf32_phdr
414 #define elf_note elf32_note
415
416 #else
417
418 extern Elf64_Dyn _DYNAMIC [];
419 #define elfhdr elf64_hdr
420 #define elf_phdr elf64_phdr
421 #define elf_note elf64_note
422
423 #endif
424
425