/[gxemul]/trunk/src/include/exec_elf.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/src/include/exec_elf.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations)
Mon Oct 8 16:22:56 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 23402 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1632 2007/09/11 21:46:35 debug Exp $
20070616	Implementing the MIPS32/64 revision 2 "ror" instruction.
20070617	Adding a struct for each physpage which keeps track of which
		ranges within that page (base offset, length) that are
		continuously translatable. When running with native code
		generation enabled (-b), a range is added after each read-
		ahead loop.
		Experimenting with using the physical program counter sample
		data (implemented 20070608) together with the "translatable
		range" information, to figure out which physical address ranges
		would be worth translating to native code (if the number of
		samples falling within a range is above a certain threshold).
20070618	Adding automagic building of .index comment files for
		src/file/, src/promemul/, src src/useremul/ as well.
		Adding a "has been translated" bit to the ranges, so that only
		not-yet-translated ranges will be sampled.
20070619	Moving src/cpu.c and src/memory_rw.c into src/cpus/,
		src/device.c into src/devices/, and src/machine.c into
		src/machines/.
		Creating a skeleton cc/ld native backend module; beginning on
		the function which will detect cc command line, etc.
20070620	Continuing on the native code generation infrastructure.
20070621	Moving src/x11.c and src/console.c into a new src/console/
		subdir (for everything that is console or framebuffer related).
		Moving src/symbol*.c into a new src/symbol/, which should
		contain anything that is symbol handling related.
20070624	Making the program counter sampling threshold a "settings
		variable" (sampling_threshold), i.e. it can now be changed
		during runtime.
		Switching the RELEASE notes format from plain text to HTML.
		If the TMPDIR environment variable is set, it is used instead
		of "/tmp" for temporary files.
		Continuing on the cc/ld backend: simple .c code is generated,
		the compiler and linker are called, etc.
		Adding detection of host architecture to the configure script
		(again), and adding icache invalidation support (only
		implemented for Alpha hosts so far).
20070625	Simplifying the program counter sampling mechanism.
20070626	Removing the cc/ld native code generation stuff, program
		counter sampling, etc; it would not have worked well in the
		general case.
20070627	Removing everything related to native code generation.
20070629	Removing the (practically unusable) support for multiple
		emulations. (The single emulation allowed now still supports
		multiple simultaneous machines, as before.)
		Beginning on PCCTWO and M88K interrupts.
20070723	Adding a dummy skeleton for emulation of M32R processors.
20070901	Fixing a warning found by "gcc version 4.3.0 20070817
		(experimental)" on amd64.
20070905	Removing some more traces of the old "multiple emulations"
		code.
		Also looking in /usr/local/include and /usr/local/lib for
		X11 libs, when running configure.
20070909	Minor updates to the guest OS install instructions, in
		preparation for the NetBSD 4.0 release.
20070918	More testing of NetBSD 4.0 RC1.

1 /* gxemul: $Id: exec_elf.h,v 1.7 2007/07/20 09:03:33 debug Exp $ */
2
3 #ifndef __EXEC_ELF_H
4 #define __EXEC_ELF_H
5
6 #include <inttypes.h>
7
8 /* $NetBSD: exec_elf.h,v 1.37.4.2 2001/05/01 12:05:43 he Exp $ */
9
10 /*-
11 * Copyright (c) 1994 The NetBSD Foundation, Inc.
12 * All rights reserved.
13 *
14 * This code is derived from software contributed to The NetBSD Foundation
15 * by Christos Zoulas.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. All advertising materials mentioning features or use of this software
26 * must display the following acknowledgement:
27 * This product includes software developed by the NetBSD
28 * Foundation, Inc. and its contributors.
29 * 4. Neither the name of The NetBSD Foundation nor the names of its
30 * contributors may be used to endorse or promote products derived
31 * from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
34 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
37 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
44 */
45
46
47 typedef uint8_t Elf_Byte;
48
49 typedef uint32_t Elf32_Addr;
50 #define ELF32_FSZ_ADDR 4
51 typedef uint32_t Elf32_Off;
52 #define ELF32_FSZ_OFF 4
53 typedef int32_t Elf32_Sword;
54 #define ELF32_FSZ_SWORD 4
55 typedef uint32_t Elf32_Word;
56 #define ELF32_FSZ_WORD 4
57 typedef uint16_t Elf32_Half;
58 #define ELF32_FSZ_HALF 2
59
60 typedef uint64_t Elf64_Addr;
61 #define ELF64_FSZ_ADDR 8
62 typedef uint64_t Elf64_Off;
63 #define ELF64_FSZ_OFF 8
64 typedef int32_t Elf64_Shalf;
65 #define ELF64_FSZ_SHALF 4
66 #ifdef __sparc_v9__
67 /* #error weird */
68 typedef int32_t Elf64_Sword;
69 #define ELF64_FSZ_SWORD 4
70 typedef uint32_t Elf64_Word;
71 #define ELF64_FSZ_WORD 4
72 #else
73 typedef int64_t Elf64_Sword;
74 #define ELF64_FSZ_SWORD 8
75 typedef uint64_t Elf64_Word;
76 #define ELF64_FSZ_WORD 8
77 #endif
78 typedef int64_t Elf64_Sxword;
79 #define ELF64_FSZ_XWORD 8
80 typedef uint64_t Elf64_Xword;
81 #define ELF64_FSZ_XWORD 8
82 typedef uint32_t Elf64_Half;
83 #define ELF64_FSZ_HALF 4
84 typedef uint16_t Elf64_Quarter;
85 #define ELF64_FSZ_QUARTER 2
86
87 /*
88 * ELF Header
89 */
90 #define ELF_NIDENT 16
91
92 typedef struct {
93 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
94 Elf32_Half e_type; /* file type */
95 Elf32_Half e_machine; /* machine type */
96 Elf32_Word e_version; /* version number */
97 Elf32_Addr e_entry; /* entry point */
98 Elf32_Off e_phoff; /* Program hdr offset */
99 Elf32_Off e_shoff; /* Section hdr offset */
100 Elf32_Word e_flags; /* Processor flags */
101 Elf32_Half e_ehsize; /* sizeof ehdr */
102 Elf32_Half e_phentsize; /* Program header entry size */
103 Elf32_Half e_phnum; /* Number of program headers */
104 Elf32_Half e_shentsize; /* Section header entry size */
105 Elf32_Half e_shnum; /* Number of section headers */
106 Elf32_Half e_shstrndx; /* String table index */
107 } Elf32_Ehdr;
108
109 typedef struct {
110 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
111 Elf64_Quarter e_type; /* file type */
112 Elf64_Quarter e_machine; /* machine type */
113 Elf64_Half e_version; /* version number */
114 Elf64_Addr e_entry; /* entry point */
115 Elf64_Off e_phoff; /* Program hdr offset */
116 Elf64_Off e_shoff; /* Section hdr offset */
117 Elf64_Half e_flags; /* Processor flags */
118 Elf64_Quarter e_ehsize; /* sizeof ehdr */
119 Elf64_Quarter e_phentsize; /* Program header entry size */
120 Elf64_Quarter e_phnum; /* Number of program headers */
121 Elf64_Quarter e_shentsize; /* Section header entry size */
122 Elf64_Quarter e_shnum; /* Number of section headers */
123 Elf64_Quarter e_shstrndx; /* String table index */
124 } Elf64_Ehdr;
125
126 /* e_ident offsets */
127 #define EI_MAG0 0 /* '\177' */
128 #define EI_MAG1 1 /* 'E' */
129 #define EI_MAG2 2 /* 'L' */
130 #define EI_MAG3 3 /* 'F' */
131 #define EI_CLASS 4 /* File class */
132 #define EI_DATA 5 /* Data encoding */
133 #define EI_VERSION 6 /* File version */
134 #define EI_OSABI 7 /* Operating system/ABI identification */
135 #define EI_ABIVERSION 8 /* ABI version */
136 #define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
137
138 /* e_ident[ELFMAG0,ELFMAG3] */
139 #define ELFMAG0 0x7f
140 #define ELFMAG1 'E'
141 #define ELFMAG2 'L'
142 #define ELFMAG3 'F'
143 #define ELFMAG "\177ELF"
144 #define SELFMAG 4
145
146 /* e_ident[EI_CLASS] */
147 #define ELFCLASSNONE 0 /* Invalid class */
148 #define ELFCLASS32 1 /* 32-bit objects */
149 #define ELFCLASS64 2 /* 64-bit objects */
150 #define ELFCLASSNUM 3
151
152 /* e_ident[EI_DATA] */
153 #define ELFDATANONE 0 /* Invalid data encoding */
154 #define ELFDATA2LSB 1 /* 2's complement values, LSB first */
155 #define ELFDATA2MSB 2 /* 2's complement values, MSB first */
156
157 /* e_ident[EI_VERSION] */
158 #define EV_NONE 0 /* Invalid version */
159 #define EV_CURRENT 1 /* Current version */
160 #define EV_NUM 2
161
162 /* e_ident[EI_OSABI] */
163 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
164 #define ELFOSABI_HPUX 1 /* HP-UX operating system */
165 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
166
167 /* e_type */
168 #define ET_NONE 0 /* No file type */
169 #define ET_REL 1 /* Relocatable file */
170 #define ET_EXEC 2 /* Executable file */
171 #define ET_DYN 3 /* Shared object file */
172 #define ET_CORE 4 /* Core file */
173 #define ET_NUM 5
174
175 #define ET_LOOS 0xfe00 /* Operating system specific range */
176 #define ET_HIOS 0xfeff
177 #define ET_LOPROC 0xff00 /* Processor-specific range */
178 #define ET_HIPROC 0xffff
179
180 /* e_machine */
181 #define EM_NONE 0 /* No machine */
182 #define EM_M32 1 /* AT&T WE 32100 */
183 #define EM_SPARC 2 /* SPARC */
184 #define EM_386 3 /* Intel 80386 */
185 #define EM_68K 4 /* Motorola 68000 */
186 #define EM_88K 5 /* Motorola 88000 */
187 #define EM_486 6 /* Intel 80486 */
188 #define EM_860 7 /* Intel 80860 */
189 #define EM_MIPS 8 /* MIPS I Architecture */
190 #define EM_S370 9 /* Amdahl UTS on System/370 */
191 #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
192 #define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
193 #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
194 #define EM_NCUBE 16 /* NCube XXX reserved */
195 #define EM_VPP500 17 /* Fujitsu VPP500 */
196 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
197 #define EM_960 19 /* Intel 80960 */
198 #define EM_PPC 20 /* PowerPC */
199 #define EM_PPC64 21 /* PowerPC 64-bit (GXemul addition) */
200 #define EM_V800 36 /* NEC V800 */
201 #define EM_FR20 37 /* Fujitsu FR20 */
202 #define EM_RH32 38 /* TRW RH-32 */
203 #define EM_RCE 39 /* Motorola RCE */
204 #define EM_ARM 40 /* Advanced RISC Machines ARM */
205 #define EM_ALPHA 41 /* DIGITAL Alpha */
206 #define EM_SH 42 /* Hitachi Super-H */
207 #define EM_SPARCV9 43 /* SPARC Version 9 */
208 #define EM_TRICORE 44 /* Siemens Tricore */
209 #define EM_ARC 45 /* Argonaut RISC Core */
210 #define EM_H8_300 46 /* Hitachi H8/300 */
211 #define EM_H8_300H 47 /* Hitachi H8/300H */
212 #define EM_H8S 48 /* Hitachi H8S */
213 #define EM_H8_500 49 /* Hitachi H8/500 */
214 #define EM_IA_64 50 /* Intel Merced Processor */
215 #define EM_MIPS_X 51 /* Stanford MIPS-X */
216 #define EM_COLDFIRE 52 /* Motorola Coldfire */
217 #define EM_68HC12 53 /* Motorola MC68HC12 */
218 #define EM_AMD64 62 /* AMD64 (GXemul addition) */
219 #define EM_VAX 75 /* DIGITAL VAX */
220 #define EM_AVR 83 /* Atmel AVR (GXemul addition) */
221 #define EM_M32R 88 /* Renesas M32R (GXemul addition) */
222 #define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
223 #define EM_NUM 36903
224
225 /*
226 * Program Header
227 */
228 typedef struct {
229 Elf32_Word p_type; /* entry type */
230 Elf32_Off p_offset; /* offset */
231 Elf32_Addr p_vaddr; /* virtual address */
232 Elf32_Addr p_paddr; /* physical address */
233 Elf32_Word p_filesz; /* file size */
234 Elf32_Word p_memsz; /* memory size */
235 Elf32_Word p_flags; /* flags */
236 Elf32_Word p_align; /* memory & file alignment */
237 } Elf32_Phdr;
238
239 typedef struct {
240 Elf64_Half p_type; /* entry type */
241 Elf64_Half p_flags; /* flags */
242 Elf64_Off p_offset; /* offset */
243 Elf64_Addr p_vaddr; /* virtual address */
244 Elf64_Addr p_paddr; /* physical address */
245 Elf64_Xword p_filesz; /* file size */
246 Elf64_Xword p_memsz; /* memory size */
247 Elf64_Xword p_align; /* memory & file alignment */
248 } Elf64_Phdr;
249
250 /* p_type */
251 #define PT_NULL 0 /* Program header table entry unused */
252 #define PT_LOAD 1 /* Loadable program segment */
253 #define PT_DYNAMIC 2 /* Dynamic linking information */
254 #define PT_INTERP 3 /* Program interpreter */
255 #define PT_NOTE 4 /* Auxiliary information */
256 #define PT_SHLIB 5 /* Reserved, unspecified semantics */
257 #define PT_PHDR 6 /* Entry for header table itself */
258 #define PT_NUM 7
259
260 /* p_flags */
261 #define PF_R 0x4 /* Segment is readable */
262 #define PF_W 0x2 /* Segment is writable */
263 #define PF_X 0x1 /* Segment is executable */
264
265 #define PF_MASKOS 0x0ff00000 /* Opersting system specific values */
266 #define PF_MASKPROC 0xf0000000 /* Processor-specific values */
267
268 #define PT_LOPROC 0x70000000 /* Processor-specific range */
269 #define PT_HIPROC 0x7fffffff
270
271 #define PT_MIPS_REGINFO 0x70000000
272
273 /*
274 * Section Headers
275 */
276 typedef struct {
277 Elf32_Word sh_name; /* section name (.shstrtab index) */
278 Elf32_Word sh_type; /* section type */
279 Elf32_Word sh_flags; /* section flags */
280 Elf32_Addr sh_addr; /* virtual address */
281 Elf32_Off sh_offset; /* file offset */
282 Elf32_Word sh_size; /* section size */
283 Elf32_Word sh_link; /* link to another */
284 Elf32_Word sh_info; /* misc info */
285 Elf32_Word sh_addralign; /* memory alignment */
286 Elf32_Word sh_entsize; /* table entry size */
287 } Elf32_Shdr;
288
289 typedef struct {
290 Elf64_Half sh_name; /* section name (.shstrtab index) */
291 Elf64_Half sh_type; /* section type */
292 Elf64_Xword sh_flags; /* section flags */
293 Elf64_Addr sh_addr; /* virtual address */
294 Elf64_Off sh_offset; /* file offset */
295 Elf64_Xword sh_size; /* section size */
296 Elf64_Half sh_link; /* link to another */
297 Elf64_Half sh_info; /* misc info */
298 Elf64_Xword sh_addralign; /* memory alignment */
299 Elf64_Xword sh_entsize; /* table entry size */
300 } Elf64_Shdr;
301
302 /* sh_type */
303 #define SHT_NULL 0
304 #define SHT_PROGBITS 1
305 #define SHT_SYMTAB 2
306 #define SHT_STRTAB 3
307 #define SHT_RELA 4
308 #define SHT_HASH 5
309 #define SHT_DYNAMIC 6
310 #define SHT_NOTE 7
311 #define SHT_NOBITS 8
312 #define SHT_REL 9
313 #define SHT_SHLIB 10
314 #define SHT_DYNSYM 11
315 #define SHT_NUM 12
316
317 #define SHT_LOOS 0x60000000 /* Operating system specific range */
318 #define SHT_HIOS 0x6fffffff
319 #define SHT_LOPROC 0x70000000 /* Processor-specific range */
320 #define SHT_HIPROC 0x7fffffff
321 #define SHT_LOUSER 0x80000000 /* Application-specific range */
322 #define SHT_HIUSER 0xffffffff
323
324 /* sh_flags */
325 #define SHF_WRITE 0x1 /* Section contains writable data */
326 #define SHF_ALLOC 0x2 /* Section occupies memory */
327 #define SHF_EXECINSTR 0x4 /* Section contains executable insns */
328
329 #define SHF_MASKOS 0x0f000000 /* Operating system specific values */
330 #define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
331
332 /*
333 * Symbol Table
334 */
335 typedef struct {
336 Elf32_Word st_name; /* Symbol name (.symtab index) */
337 Elf32_Word st_value; /* value of symbol */
338 Elf32_Word st_size; /* size of symbol */
339 Elf_Byte st_info; /* type / binding attrs */
340 Elf_Byte st_other; /* unused */
341 Elf32_Half st_shndx; /* section index of symbol */
342 } Elf32_Sym;
343
344 typedef struct {
345 Elf64_Half st_name; /* Symbol name (.symtab index) */
346 Elf_Byte st_info; /* type / binding attrs */
347 Elf_Byte st_other; /* unused */
348 Elf64_Quarter st_shndx; /* section index of symbol */
349 Elf64_Addr st_value; /* value of symbol */
350 Elf64_Xword st_size; /* size of symbol */
351 } Elf64_Sym;
352
353 /* Symbol Table index of the undefined symbol */
354 #define ELF_SYM_UNDEFINED 0
355
356 /* st_info: Symbol Bindings */
357 #define STB_LOCAL 0 /* local symbol */
358 #define STB_GLOBAL 1 /* global symbol */
359 #define STB_WEAK 2 /* weakly defined global symbol */
360 #define STB_NUM 3
361
362 #define STB_LOOS 10 /* Operating system specific range */
363 #define STB_HIOS 12
364 #define STB_LOPROC 13 /* Processor-specific range */
365 #define STB_HIPROC 15
366
367 /* st_info: Symbol Types */
368 #define STT_NOTYPE 0 /* Type not specified */
369 #define STT_OBJECT 1 /* Associated with a data object */
370 #define STT_FUNC 2 /* Associated with a function */
371 #define STT_SECTION 3 /* Associated with a section */
372 #define STT_FILE 4 /* Associated with a file name */
373 #define STT_NUM 5
374
375 #define STT_LOOS 10 /* Operating system specific range */
376 #define STT_HIOS 12
377 #define STT_LOPROC 13 /* Processor-specific range */
378 #define STT_HIPROC 15
379
380 /* st_info utility macros */
381 #define ELF32_ST_BIND(info) ((Elf32_Word)(info) >> 4)
382 #define ELF32_ST_TYPE(info) ((Elf32_Word)(info) & 0xf)
383 #define ELF32_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | ((type) & 0xf)))
384
385 #define ELF64_ST_BIND(info) ((Elf64_Xword)(info) >> 4)
386 #define ELF64_ST_TYPE(info) ((Elf64_Xword)(info) & 0xf)
387 #define ELF64_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | ((type) & 0xf)))
388
389 /*
390 * Special section indexes
391 */
392 #define SHN_UNDEF 0 /* Undefined section */
393
394 #define SHN_LORESERVE 0xff00 /* Reserved range */
395 #define SHN_ABS 0xfff1 /* Absolute symbols */
396 #define SHN_COMMON 0xfff2 /* Common symbols */
397 #define SHN_HIRESERVE 0xffff
398
399 #define SHN_LOPROC 0xff00 /* Processor-specific range */
400 #define SHN_HIPROC 0xff1f
401 #define SHN_LOOS 0xff20 /* Operating system specific range */
402 #define SHN_HIOS 0xff3f
403
404 #define SHN_MIPS_ACOMMON 0xff00
405 #define SHN_MIPS_TEXT 0xff01
406 #define SHN_MIPS_DATA 0xff02
407 #define SHN_MIPS_SCOMMON 0xff03
408
409 /*
410 * Relocation Entries
411 */
412 typedef struct {
413 Elf32_Word r_offset; /* where to do it */
414 Elf32_Word r_info; /* index & type of relocation */
415 } Elf32_Rel;
416
417 typedef struct {
418 Elf32_Word r_offset; /* where to do it */
419 Elf32_Word r_info; /* index & type of relocation */
420 Elf32_Sword r_addend; /* adjustment value */
421 } Elf32_Rela;
422
423 /* r_info utility macros */
424 #define ELF32_R_SYM(info) ((info) >> 8)
425 #define ELF32_R_TYPE(info) ((info) & 0xff)
426 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
427
428 typedef struct {
429 Elf64_Addr r_offset; /* where to do it */
430 Elf64_Xword r_info; /* index & type of relocation */
431 } Elf64_Rel;
432
433 typedef struct {
434 Elf64_Addr r_offset; /* where to do it */
435 Elf64_Xword r_info; /* index & type of relocation */
436 Elf64_Sxword r_addend; /* adjustment value */
437 } Elf64_Rela;
438
439 /* r_info utility macros */
440 #define ELF64_R_SYM(info) ((info) >> 32)
441 #define ELF64_R_TYPE(info) ((info) & 0xffffffff)
442 #define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
443
444 /*
445 * Dynamic Section structure array
446 */
447 typedef struct {
448 Elf32_Word d_tag; /* entry tag value */
449 union {
450 Elf32_Addr d_ptr;
451 Elf32_Word d_val;
452 } d_un;
453 } Elf32_Dyn;
454
455 typedef struct {
456 Elf64_Xword d_tag; /* entry tag value */
457 union {
458 Elf64_Addr d_ptr;
459 Elf64_Xword d_val;
460 } d_un;
461 } Elf64_Dyn;
462
463 /* d_tag */
464 #define DT_NULL 0 /* Marks end of dynamic array */
465 #define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
466 #define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
467 #define DT_PLTGOT 3 /* Address of PLT and/or GOT */
468 #define DT_HASH 4 /* Address of symbol hash table */
469 #define DT_STRTAB 5 /* Address of string table */
470 #define DT_SYMTAB 6 /* Address of symbol table */
471 #define DT_RELA 7 /* Address of Rela relocation table */
472 #define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
473 #define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
474 #define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
475 #define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
476 #define DT_INIT 12 /* Address of initialization function */
477 #define DT_FINI 13 /* Address of termination function */
478 #define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
479 #define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
480 #define DT_SYMBOLIC 16 /* Start symbol search within local object */
481 #define DT_REL 17 /* Address of Rel relocation table */
482 #define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
483 #define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
484 #define DT_PLTREL 20 /* Type of PLT relocation entries */
485 #define DT_DEBUG 21 /* Used for debugging; unspecified */
486 #define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
487 #define DT_JMPREL 23 /* Address of relocations associated with PLT */
488 #define DT_BIND_NOW 24 /* Process all relocations at load-time */
489 #define DT_INIT_ARRAY 25 /* Address of initialization function array */
490 #define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
491 #define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
492 #define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
493 #define DT_NUM 29
494
495 #define DT_LOOS 0x60000000 /* Operating system specific range */
496 #define DT_HIOS 0x6fffffff
497 #define DT_LOPROC 0x70000000 /* Processor-specific range */
498 #define DT_HIPROC 0x7fffffff
499
500 /*
501 * Auxiliary Vectors
502 */
503 typedef struct {
504 Elf32_Word a_type; /* 32-bit id */
505 Elf32_Word a_v; /* 32-bit id */
506 } Aux32Info;
507
508 typedef struct {
509 Elf64_Half a_type; /* 32-bit id */
510 Elf64_Xword a_v; /* 64-bit id */
511 } Aux64Info;
512
513 /* a_type */
514 #define AT_NULL 0 /* Marks end of array */
515 #define AT_IGNORE 1 /* No meaning, a_un is undefined */
516 #define AT_EXECFD 2 /* Open file descriptor of object file */
517 #define AT_PHDR 3 /* &phdr[0] */
518 #define AT_PHENT 4 /* sizeof(phdr[0]) */
519 #define AT_PHNUM 5 /* # phdr entries */
520 #define AT_PAGESZ 6 /* PAGESIZE */
521 #define AT_BASE 7 /* Interpreter base addr */
522 #define AT_FLAGS 8 /* Processor flags */
523 #define AT_ENTRY 9 /* Entry address of executable */
524 #define AT_DCACHEBSIZE 10 /* Data cache block size */
525 #define AT_ICACHEBSIZE 11 /* Instruction cache block size */
526 #define AT_UCACHEBSIZE 12 /* Unified cache block size */
527
528 /* Vendor specific */
529 #define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
530
531 #define AT_SUN_UID 2000 /* euid */
532 #define AT_SUN_RUID 2001 /* ruid */
533 #define AT_SUN_GID 2002 /* egid */
534 #define AT_SUN_RGID 2003 /* rgid */
535
536 /* Solaris kernel specific */
537 #define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
538 #define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
539 #define AT_SUN_LDNAME 2006 /* dynamic linker's name */
540 #define AT_SUN_LPGSIZE 2007 /* large pagesize */
541
542 /* Other information */
543 #define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
544 #define AT_SUN_HWCAP 2009 /* process hardware capabilities */
545 #define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
546 #define AT_SUN_CPU 2011 /* cpu name */
547 /* ibcs2 emulation band aid */
548 #define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
549 #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
550 /* Executable's fully resolved name */
551 #define AT_SUN_EXECNAME 2014
552
553 /*
554 * Note Headers
555 */
556 typedef struct {
557 Elf32_Word n_namesz;
558 Elf32_Word n_descsz;
559 Elf32_Word n_type;
560 } Elf32_Nhdr;
561
562 typedef struct {
563 Elf64_Half n_namesz;
564 Elf64_Half n_descsz;
565 Elf64_Half n_type;
566 } Elf64_Nhdr;
567
568 #define ELF_NOTE_TYPE_OSVERSION 1
569
570 /* NetBSD-specific note type: OS Version. desc is 4-byte NetBSD integer. */
571 #define ELF_NOTE_NETBSD_TYPE_OSVERSION ELF_NOTE_TYPE_OSVERSION
572
573 /* NetBSD-specific note type: Emulation name. desc is emul name string. */
574 #define ELF_NOTE_NETBSD_TYPE_EMULNAME 2
575
576 /* NetBSD-specific note name and description sizes */
577 #define ELF_NOTE_NETBSD_NAMESZ 7
578 #define ELF_NOTE_NETBSD_DESCSZ 4
579 /* NetBSD-specific note name */
580 #define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
581
582 /* GNU-specific note name and description sizes */
583 #define ELF_NOTE_GNU_NAMESZ 4
584 #define ELF_NOTE_GNU_DESCSZ 4
585 /* GNU-specific note name */
586 #define ELF_NOTE_GNU_NAME "GNU\0"
587
588 /* GNU-specific OS/version value stuff */
589 #define ELF_NOTE_GNU_OSMASK (u_int32_t)0xff000000
590 #define ELF_NOTE_GNU_OSLINUX (u_int32_t)0x01000000
591 #define ELF_NOTE_GNU_OSMACH (u_int32_t)0x00000000
592
593 #if defined(ELFSIZE)
594 #define CONCAT(x,y) __CONCAT(x,y)
595 #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
596 #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
597 #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
598 #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
599 #endif
600
601 /* #include <machine/elf_machdep.h> */
602
603 #if defined(ELFSIZE) && (ELFSIZE == 32)
604 #define Elf_Ehdr Elf32_Ehdr
605 #define Elf_Phdr Elf32_Phdr
606 #define Elf_Shdr Elf32_Shdr
607 #define Elf_Sym Elf32_Sym
608 #define Elf_Rel Elf32_Rel
609 #define Elf_Rela Elf32_Rela
610 #define Elf_Dyn Elf32_Dyn
611 #define Elf_Word Elf32_Word
612 #define Elf_Sword Elf32_Sword
613 #define Elf_Addr Elf32_Addr
614 #define Elf_Off Elf32_Off
615 #define Elf_Nhdr Elf32_Nhdr
616
617 #define ELF_R_SYM ELF32_R_SYM
618 #define ELF_R_TYPE ELF32_R_TYPE
619 #define ELFCLASS ELFCLASS32
620
621 #define ELF_ST_BIND ELF32_ST_BIND
622 #define ELF_ST_TYPE ELF32_ST_TYPE
623 #define ELF_ST_INFO ELF32_ST_INFO
624
625 #define AuxInfo Aux32Info
626 #elif defined(ELFSIZE) && (ELFSIZE == 64)
627 #define Elf_Ehdr Elf64_Ehdr
628 #define Elf_Phdr Elf64_Phdr
629 #define Elf_Shdr Elf64_Shdr
630 #define Elf_Sym Elf64_Sym
631 #define Elf_Rel Elf64_Rel
632 #define Elf_Rela Elf64_Rela
633 #define Elf_Dyn Elf64_Dyn
634 #define Elf_Word Elf64_Word
635 #define Elf_Sword Elf64_Sword
636 #define Elf_Addr Elf64_Addr
637 #define Elf_Off Elf64_Off
638 #define Elf_Nhdr Elf64_Nhdr
639
640 #define ELF_R_SYM ELF64_R_SYM
641 #define ELF_R_TYPE ELF64_R_TYPE
642 #define ELFCLASS ELFCLASS64
643
644 #define ELF_ST_BIND ELF64_ST_BIND
645 #define ELF_ST_TYPE ELF64_ST_TYPE
646 #define ELF_ST_INFO ELF64_ST_INFO
647
648 #define AuxInfo Aux64Info
649 #endif
650
651 #ifdef _KERNEL
652
653 #define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */
654 #define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
655 #define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
656
657 #if defined(ELFSIZE) && (ELFSIZE == 64)
658 #define ELF_NO_ADDR ELF64_NO_ADDR
659 #elif defined(ELFSIZE) && (ELFSIZE == 32)
660 #define ELF_NO_ADDR ELF32_NO_ADDR
661 #endif
662
663 #if defined(ELFSIZE)
664 struct elf_args {
665 Elf_Addr arg_entry; /* program entry point */
666 Elf_Addr arg_interp; /* Interpreter load address */
667 Elf_Addr arg_phaddr; /* program header address */
668 Elf_Addr arg_phentsize; /* Size of program header */
669 Elf_Addr arg_phnum; /* Number of program headers */
670 };
671 #endif
672
673 #ifndef _LKM
674 #include "opt_execfmt.h"
675 #endif
676
677 #ifdef EXEC_ELF32
678 int exec_elf32_makecmds __P((struct proc *, struct exec_package *));
679 int elf32_read_from __P((struct proc *, struct vnode *, u_long,
680 caddr_t, int));
681 void *elf32_copyargs __P((struct exec_package *, struct ps_strings *,
682 void *, void *));
683 #endif
684
685 #ifdef EXEC_ELF64
686 int exec_elf64_makecmds __P((struct proc *, struct exec_package *));
687 int elf64_read_from __P((struct proc *, struct vnode *, u_long,
688 caddr_t, int));
689 void *elf64_copyargs __P((struct exec_package *, struct ps_strings *,
690 void *, void *));
691 #endif
692
693 /* common */
694 int exec_elf_setup_stack __P((struct proc *, struct exec_package *));
695
696 #endif /* _KERNEL */
697
698 #endif /* __EXEC_ELF_H */
699

  ViewVC Help
Powered by ViewVC 1.1.26