root/ar5315_microredboot/microredboot/boot/src/lib/elf.h

Revision 12429, 32.5 kB (checked in by BrainSlayer, 5 months ago)

compressed ELF support is required for ubnt images

Line 
1 #ifndef CYGONCE_REDBOOT_ELF_H
2 #define CYGONCE_REDBOOT_ELF_H
3
4 //==========================================================================
5 //
6 //      elf.h
7 //
8 //      ELF file format definitions
9 //
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):           nickg
47 // Contributors:        nickg
48 // Date:                2000-11-15
49 // Purpose:             Define ELF file format
50 // Description:         The types defined here describe the ELF file format.
51 //             
52 // Usage:       #include <cyg/loader/elf.h>
53 //
54 //####DESCRIPTIONEND####
55 //
56 //==========================================================================
57 //
58 // Quite a lot of this file was taken from the BSD exec_elf.h header file.
59 // Hence we should show you this...
60 //
61 /*      $OpenBSD: exec_elf.h,v 1.20 1999/09/19 16:16:49 kstailey Exp $  */
62 /*
63  * Copyright (c) 1995, 1996 Erik Theisen.  All rights reserved.
64  *
65  * Redistribution and use in source and binary forms, with or without
66  * modification, are permitted provided that the following conditions
67  * are met:
68  * 1. Redistributions of source code must retain the above copyright
69  *    notice, this list of conditions and the following disclaimer.
70  * 2. Redistributions in binary form must reproduce the above copyright
71  *    notice, this list of conditions and the following disclaimer in the
72  *    documentation and/or other materials provided with the distribution.
73  * 3. The name of the author may not be used to endorse or promote products
74  *    derived from this software without specific prior written permission
75  *
76  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
77  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
78  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
79  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
80  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
81  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
85  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86  */
87 //==========================================================================
88
89
90 // -------------------------------------------------------------------------
91 // Basic types:
92
93 typedef unsigned int cyg_uint32;
94 typedef unsigned long long cyg_uint64;
95 typedef long long cyg_int64;
96 typedef unsigned short cyg_uint16;
97 typedef short cyg_int16;
98 typedef int cyg_int32;
99
100 typedef cyg_uint32 Elf32_Addr;
101 typedef cyg_uint32 Elf32_Off;
102 typedef cyg_uint16 Elf32_Half;
103 typedef cyg_uint32 Elf32_Word;
104 typedef cyg_int32  Elf32_Sword;
105
106 typedef cyg_uint64 Elf64_Addr;
107 typedef cyg_uint64 Elf64_Off;
108 typedef cyg_uint16 Elf64_Half;
109 typedef cyg_uint32 Elf64_Word;
110 typedef cyg_int32  Elf64_Sword;
111 typedef cyg_uint64 Elf64_Xword;
112 typedef cyg_int64  Elf64_Sxword;
113
114 // -------------------------------------------------------------------------
115 // ELF header
116
117 #define EI_NIDENT 16
118
119 typedef struct {
120     unsigned char   e_ident[EI_NIDENT];
121     Elf32_Half      e_type;
122     Elf32_Half      e_machine;
123     Elf32_Word      e_version;
124     Elf32_Addr      e_entry;
125     Elf32_Off       e_phoff;
126     Elf32_Off       e_shoff;
127     Elf32_Word      e_flags;
128     Elf32_Half      e_ehsize;
129     Elf32_Half      e_phentsize;
130     Elf32_Half      e_phnum;
131     Elf32_Half      e_shentsize;
132     Elf32_Half      e_shnum;
133     Elf32_Half      e_shtrndx;
134 } Elf32_Ehdr;
135
136 typedef struct {
137     unsigned char   e_ident[EI_NIDENT];
138     Elf64_Half      e_type;
139     Elf64_Half      e_machine;
140     Elf64_Word      e_version;
141     Elf64_Addr      e_entry;
142     Elf64_Off       e_phoff;
143     Elf64_Off       e_shoff;
144     Elf64_Word      e_flags;
145     Elf64_Half      e_ehsize;
146     Elf64_Half      e_phentsize;
147     Elf64_Half      e_phnum;
148     Elf64_Half      e_shentsize;
149     Elf64_Half      e_shnum;
150     Elf64_Half      e_shtrndx;
151 } Elf64_Ehdr;
152
153 // -------------------------------------------------------------------------
154 /* e_ident[] identification indexes */
155
156 #define EI_MAG0         0               /* file ID */
157 #define EI_MAG1         1               /* file ID */
158 #define EI_MAG2         2               /* file ID */
159 #define EI_MAG3         3               /* file ID */
160 #define EI_CLASS        4               /* file class */
161 #define EI_DATA         5               /* data encoding */
162 #define EI_VERSION      6               /* ELF header version */
163 #define EI_OSABI        7               /* Operating system/ABI identification */
164 #define EI_ABIVERSION   8               /* ABI version */
165 #define EI_PAD          9               /* start of pad bytes */
166
167 // -------------------------------------------------------------------------
168 /* e_ident[] magic number */
169
170 #define ELFMAG0         0x7f            /* e_ident[EI_MAG0] */
171 #define ELFMAG1         'E'             /* e_ident[EI_MAG1] */
172 #define ELFMAG2         'L'             /* e_ident[EI_MAG2] */
173 #define ELFMAG3         'F'             /* e_ident[EI_MAG3] */
174 #define ELFMAG          "\177ELF"       /* magic */
175 #define SELFMAG         4               /* size of magic */
176
177 // -------------------------------------------------------------------------
178 /* e_ident[] file class */
179
180 #define ELFCLASSNONE    0               /* invalid */
181 #define ELFCLASS32      1               /* 32-bit objs */
182 #define ELFCLASS64      2               /* 64-bit objs */
183 #define ELFCLASSNUM     3               /* number of classes */
184
185 // -------------------------------------------------------------------------
186 /* e_ident[] data encoding */
187
188 #define ELFDATANONE     0               /* invalid */
189 #define ELFDATA2LSB     1               /* Little-Endian */
190 #define ELFDATA2MSB     2               /* Big-Endian */
191 #define ELFDATANUM      3               /* number of data encode defines */
192
193 // -------------------------------------------------------------------------
194 /* e_ident */
195
196 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
197                       (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
198                       (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
199                       (ehdr).e_ident[EI_MAG3] == ELFMAG3)
200
201 // -------------------------------------------------------------------------
202 /* e_type */
203
204 #define ET_NONE         0               /* No file type */
205 #define ET_REL          1               /* relocatable file */
206 #define ET_EXEC         2               /* executable file */
207 #define ET_DYN          3               /* shared object file */
208 #define ET_CORE         4               /* core file */
209 #define ET_NUM          5               /* number of types */
210 #define ET_LOOS         0xfe00          /* Operating system-specific */
211 #define ET_HIOS         0xfeff          /* Operating system-specific */
212 #define ET_LOPROC       0xff00          /* reserved range for processor */
213 #define ET_HIPROC       0xffff          /*  specific e_type */
214
215 // -------------------------------------------------------------------------
216 /* e_machine */
217 // The following values taken from 22 June 2000 SysV ABI spec, updated with
218 // extra values from binutils elf/common.h.
219
220 #define EM_NONE                 0       // No machine
221 #define EM_M32                  1       // AT&T WE 32100
222 #define EM_SPARC                2       // SPARC
223 #define EM_386                  3       // Intel 80386
224 #define EM_68K                  4       // Motorola 68000
225 #define EM_88K                  5       // Motorola 88000
226 #define EM_860                  7       // Intel 80860
227 #define EM_MIPS                 8       // MIPS I Architecture
228 #define EM_S370                 9       // IBM System/370 Processor
229 #define EM_MIPS_RS3_LE          10      // MIPS RS3000 Little-endian
230 #define EM_PARISC               15      // Hewlett-Packard PA-RISC
231 #define EM_VPP500               17      // Fujitsu VPP500
232 #define EM_SPARC32PLUS          18      // Enhanced instruction set SPARC
233 #define EM_960                  19      // Intel 80960
234 #define EM_PPC                  20      // PowerPC
235 #define EM_PPC64                21      // 64-bit PowerPC
236 #define EM_V800                 36      // NEC V800
237 #define EM_FR20                 37      // Fujitsu FR20
238 #define EM_RH32                 38      // TRW RH-32
239 #define EM_RCE                  39      // Motorola RCE
240 #define EM_ARM                  40      // Advanced RISC Machines ARM
241 #define EM_ALPHA                41      // Digital Alpha
242 #define EM_SH                   42      // Hitachi SH
243 #define EM_SPARCV9              43      // SPARC Version 9
244 #define EM_TRICORE              44      // Siemens Tricore embedded processor
245 #define EM_ARC                  45      // Argonaut RISC Core, Argonaut Technologies Inc.
246 #define EM_H8_300               46      // Hitachi H8/300
247 #define EM_H8_300H              47      // Hitachi H8/300H
248 #define EM_H8S                  48      // Hitachi H8S
249 #define EM_H8_500               49      // Hitachi H8/500
250 #define EM_IA_64                50      // Intel IA-64 processor architecture
251 #define EM_MIPS_X               51      // Stanford MIPS-X
252 #define EM_COLDFIRE             52      // Motorola ColdFire
253 #define EM_68HC12               53      // Motorola M68HC12
254 #define EM_MMA                  54      // Fujitsu MMA Multimedia Accelerator
255 #define EM_PCP                  55      // Siemens PCP
256 #define EM_NCPU                 56      // Sony nCPU embedded RISC processor
257 #define EM_NDR1                 57      // Denso NDR1 microprocessor
258 #define EM_STARCORE             58      // Motorola Star*Core processor
259 #define EM_ME16                 59      // Toyota ME16 processor
260 #define EM_ST100                60      // STMicroelectronics ST100 processor
261 #define EM_TINYJ                61      // Advanced Logic Corp. TinyJ embedded processor family
262 #define EM_FX66                 66      // Siemens FX66 microcontroller
263 #define EM_ST9PLUS              67      // STMicroelectronics ST9+ 8/16 bit microcontroller
264 #define EM_ST7                  68      // STMicroelectronics ST7 8-bit microcontroller
265 #define EM_68HC16               69      // Motorola MC68HC16 Microcontroller
266 #define EM_68HC11               70      // Motorola MC68HC11 Microcontroller
267 #define EM_68HC08               71      // Motorola MC68HC08 Microcontroller
268 #define EM_68HC05               72      // Motorola MC68HC05 Microcontroller
269 #define EM_SVX                  73      // Silicon Graphics SVx
270 #define EM_ST19                 74      // STMicroelectronics ST19 8-bit microcontroller
271 #define EM_VAX                  75      // Digital VAX
272 #define EM_CRIS                 76      // Axis Communications 32-bit embedded processor
273 #define EM_JAVELIN              77      // Infineon Technologies 32-bit embedded processor
274 #define EM_FIREPATH             78      // Element 14 64-bit DSP Processor
275 #define EM_ZSP                  79      // LSI Logic 16-bit DSP Processor
276 #define EM_MMIX                 80      // Donald Knuth's educational 64-bit processor
277 #define EM_HUANY                81      // Harvard University machine-independent object files
278 #define EM_PRISM                82      // SiTera Prism
279
280 /* Cygnus PowerPC ELF backend.  Written in the absence of an ABI.  */
281 #define EM_CYGNUS_POWERPC 0x9025
282
283 /* Old version of Sparc v9, from before the ABI; this should be
284    removed shortly.  */
285 #define EM_OLD_SPARCV9  11
286
287 /* Old version of PowerPC, this should be removed shortly. */
288 #define EM_PPC_OLD      17
289
290 /* Cygnus ARC ELF backend.  Written in the absence of an ABI.  */
291 #define EM_CYGNUS_ARC 0x9040
292
293 /* Cygnus M32R ELF backend.  Written in the absence of an ABI.  */
294 #define EM_CYGNUS_M32R 0x9041
295
296 /* Alpha backend magic number.  Written in the absence of an ABI.  */
297 //#define EM_ALPHA        0x9026
298
299 /* D10V backend magic number.  Written in the absence of an ABI.  */
300 #define EM_CYGNUS_D10V  0x7650
301
302 /* D30V backend magic number.  Written in the absence of an ABI.  */
303 #define EM_CYGNUS_D30V  0x7676
304
305 /* V850 backend magic number.  Written in the absense of an ABI.  */
306 #define EM_CYGNUS_V850  0x9080
307
308 /* mn10200 and mn10300 backend magic numbers.
309    Written in the absense of an ABI.  */
310 #define EM_CYGNUS_MN10200       0xdead
311 #define EM_CYGNUS_MN10300       0xbeef
312
313 /* FR30 magic number - no EABI available.  */
314 #define EM_CYGNUS_FR30          0x3330
315
316 /* AVR magic number
317    Written in the absense of an ABI.  */
318 #define EM_AVR                  0x1057
319
320 // -------------------------------------------------------------------------
321 /* Version */
322
323 #define EV_NONE         0               /* Invalid */
324 #define EV_CURRENT      1               /* Current */
325 #define EV_NUM          2               /* number of versions */
326
327 // -------------------------------------------------------------------------
328 /* Section Header */
329
330 typedef struct {
331     Elf32_Word  sh_name;        /* name - index into section header
332                                    string table section */
333     Elf32_Word  sh_type;        /* type */
334     Elf32_Word  sh_flags;       /* flags */
335     Elf32_Addr  sh_addr;        /* address */
336     Elf32_Off   sh_offset;      /* file offset */
337     Elf32_Word  sh_size;        /* section size */
338     Elf32_Word  sh_link;        /* section header table index link */
339     Elf32_Word  sh_info;        /* extra information */
340     Elf32_Word  sh_addralign;   /* address alignment */
341     Elf32_Word  sh_entsize;     /* section entry size */
342 } Elf32_Shdr;
343
344 typedef struct {
345     Elf64_Word  sh_name;        /* section name */
346     Elf64_Word  sh_type;        /* section type */
347     Elf64_Xword sh_flags;       /* section flags */
348     Elf64_Addr  sh_addr;        /* virtual address */
349     Elf64_Off   sh_offset;      /* file offset */
350     Elf64_Xword sh_size;        /* section size */
351     Elf64_Word  sh_link;        /* link to another */
352     Elf64_Word  sh_info;        /* misc info */
353     Elf64_Xword sh_addralign;   /* memory alignment */
354     Elf64_Xword sh_entsize;     /* table entry size */
355 } Elf64_Shdr;
356
357 // -------------------------------------------------------------------------
358 /* Special Section Indexes */
359
360 #define SHN_UNDEF       0               /* undefined */
361 #define SHN_LORESERVE   0xff00          /* lower bounds of reserved indexes */
362 #define SHN_LOPROC      0xff00          /* reserved range for processor */
363 #define SHN_HIPROC      0xff1f          /*   specific section indexes */
364 #define SHN_LOOS        0xff20          /* reserved range for operating */
365 #define SHN_HIOS        0xff3f          /*   system specific section indexes */
366 #define SHN_ABS         0xfff1          /* absolute value */
367 #define SHN_COMMON      0xfff2          /* common symbol */
368 #define SHN_XINDEX      0xffff          /* escape value for oversize index */
369 #define SHN_HIRESERVE   0xffff          /* upper bounds of reserved indexes */
370
371 // -------------------------------------------------------------------------
372 /* sh_type */
373
374 #define SHT_NULL        0               /* inactive */
375 #define SHT_PROGBITS    1               /* program defined information */
376 #define SHT_SYMTAB      2               /* symbol table section */
377 #define SHT_STRTAB      3               /* string table section */
378 #define SHT_RELA        4               /* relocation section with addends*/
379 #define SHT_HASH        5               /* symbol hash table section */
380 #define SHT_DYNAMIC     6               /* dynamic section */
381 #define SHT_NOTE        7               /* note section */
382 #define SHT_NOBITS      8               /* no space section */
383 #define SHT_REL         9               /* relation section without addends */
384 #define SHT_SHLIB       10              /* reserved - purpose unknown */
385 #define SHT_DYNSYM      11              /* dynamic symbol table section */
386 #define SHT_INIT_ARRAY  14              /* init procedure array */
387 #define SHT_FINI_ARRAY  15              /* fini procedure array */
388 #define SHT_PREINIT_ARRAY 16            /* preinit procedure array */
389 #define SHT_GROUP       17              /* section group */
390 #define SHT_SYMTAB_SHNDX 18             /* oversize index table */
391 #define SHT_NUM         19              /* number of section types */
392 #define SHT_LOOS        0x60000000      /* reserved range for O/S */
393 #define SHT_HIOS        0x6fffffff      /*  specific section header types */
394 #define SHT_LOPROC      0x70000000      /* reserved range for processor */
395 #define SHT_HIPROC      0x7fffffff      /*  specific section header types */
396 #define SHT_LOUSER      0x80000000      /* reserved range for application */
397 #define SHT_HIUSER      0xffffffff      /*  specific indexes */
398
399 // -------------------------------------------------------------------------
400 /* Section names */
401
402 #define ELF_BSS         ".bss"          /* uninitialized data */
403 #define ELF_DATA        ".data"         /* initialized data */
404 #define ELF_DEBUG       ".debug"        /* debug */
405 #define ELF_DYNAMIC     ".dynamic"      /* dynamic linking information */
406 #define ELF_DYNSTR      ".dynstr"       /* dynamic string table */
407 #define ELF_DYNSYM      ".dynsym"       /* dynamic symbol table */
408 #define ELF_FINI        ".fini"         /* termination code */
409 #define ELF_GOT         ".got"          /* global offset table */
410 #define ELF_HASH        ".hash"         /* symbol hash table */
411 #define ELF_INIT        ".init"         /* initialization code */
412 #define ELF_REL_DATA    ".rel.data"     /* relocation data */
413 #define ELF_REL_FINI    ".rel.fini"     /* relocation termination code */
414 #define ELF_REL_INIT    ".rel.init"     /* relocation initialization code */
415 #define ELF_REL_DYN     ".rel.dyn"      /* relocaltion dynamic link info */
416 #define ELF_REL_RODATA  ".rel.rodata"   /* relocation read-only data */
417 #define ELF_REL_TEXT    ".rel.text"     /* relocation code */
418 #define ELF_RODATA      ".rodata"       /* read-only data */
419 #define ELF_SHSTRTAB    ".shstrtab"     /* section header string table */
420 #define ELF_STRTAB      ".strtab"       /* string table */
421 #define ELF_SYMTAB      ".symtab"       /* symbol table */
422 #define ELF_TEXT        ".text"         /* code */
423
424 // -------------------------------------------------------------------------
425 /* Section Attribute Flags - sh_flags */
426
427 #define SHF_WRITE               0x001           /* Writable */
428 #define SHF_ALLOC               0x002           /* occupies memory */
429 #define SHF_EXECINSTR           0x004           /* executable */
430 #define SHF_MERGE               0x010           /* merge data */
431 #define SHF_STRINGS             0x020           /* contains strings */
432 #define SHF_INFO_LINK           0x040           /* link in sh_info field */
433 #define SHF_LINK_ORDER          0x080           /* preserve link order */
434 #define SHF_OS_NONCONFORMING    0x100           /* special OS-specific */
435                                                 /*  processing needed */
436 #define SHF_GROUP               0x200           /* member of group */
437 #define SHF_MASKOS              0x0ff00000      /* reserved bits for OS */
438                                                 /*  specific section attributes */
439 #define SHF_MASKPROC            0xf0000000      /* reserved bits for processor */
440                                                 /*  specific section attributes */
441
442 // -------------------------------------------------------------------------
443 /* Symbol Table Entry */
444
445 typedef struct {
446     Elf32_Word          st_name;        /* name - index into string table */
447     Elf32_Addr          st_value;       /* symbol value */
448     Elf32_Word          st_size;        /* symbol size */
449     unsigned char       st_info;        /* type and binding */
450     unsigned char       st_other;       /* visibility */
451     Elf32_Half          st_shndx;       /* section header index */
452 } Elf32_Sym;
453
454 typedef struct {
455     Elf64_Word          st_name;        /* Symbol name index in str table */
456     unsigned char       st_info;        /* type / binding attrs */
457     unsigned char       st_other;       /* visibility */
458     Elf64_Half          st_shndx;       /* section index of symbol */
459     Elf64_Addr          st_value;       /* value of symbol */
460     Elf64_Xword          st_size;        /* size of symbol */
461 } Elf64_Sym;
462
463 // -------------------------------------------------------------------------
464 /* Symbol table index */
465
466 #define STN_UNDEF       0               /* undefined */
467
468 /* Extract symbol info - st_info */
469 #define ELF32_ST_BIND(x)        ((x) >> 4)
470 #define ELF32_ST_TYPE(x)        (((unsigned int) x) & 0xf)
471 #define ELF32_ST_INFO(b,t)      (((b) << 4) + ((t) & 0xf))
472
473 #define ELF64_ST_BIND(x)        ((x) >> 4)
474 #define ELF64_ST_TYPE(x)        (((unsigned int) x) & 0xf)
475 #define ELF64_ST_INFO(b,t)      (((b) << 4) + ((t) & 0xf))
476
477 #define ELF32_ST_VISIBILITY(o)  ((o)&0x3)
478 #define ELF64_ST_VISIBILITY(o)  ((o)&0x3)
479
480 // -------------------------------------------------------------------------
481 /* Symbol Binding - ELF32_ST_BIND - st_info */
482
483 #define STB_LOCAL       0               /* Local symbol */
484 #define STB_GLOBAL      1               /* Global symbol */
485 #define STB_WEAK        2               /* like global - lower precedence */
486 #define STB_NUM         3               /* number of symbol bindings */
487 #define STB_LOOS        10              /* reserved range for OS */
488 #define STB_HIOS        12              /*  specific symbol bindings */
489 #define STB_LOPROC      13              /* reserved range for processor */
490 #define STB_HIPROC      15              /*  specific symbol bindings */
491
492 // -------------------------------------------------------------------------
493 /* Symbol type - ELF32_ST_TYPE - st_info */
494
495 #define STT_NOTYPE      0               /* not specified */
496 #define STT_OBJECT      1               /* data object */
497 #define STT_FUNC        2               /* function */
498 #define STT_SECTION     3               /* section */
499 #define STT_FILE        4               /* file */
500 #define STT_COMMON      5               /* common block */
501 #define STT_NUM         6               /* number of symbol types */
502 #define STT_LOOS        10              /* reserved range for OS */
503 #define STT_HIOS        12              /*  specific symbol types */
504 #define STT_LOPROC      13              /* reserved range for processor */
505 #define STT_HIPROC      15              /*  specific symbol types */
506
507 // -------------------------------------------------------------------------
508 // symbol visibility in st_other
509
510 #define STV_DEFAULT     0               /* default to binding type */
511 #define STV_INTERNAL    1               /* processor specific */
512 #define STV_HIDDEN      2               /* invisible */
513 #define STV_PROTECTED   3               /* non-premptable */
514
515 // -------------------------------------------------------------------------
516 // 32 bit relocation records
517
518 /* Relocation entry with implicit addend */
519 typedef struct
520 {
521         Elf32_Addr      r_offset;       /* offset of relocation */
522         Elf32_Word      r_info;         /* symbol table index and type */
523 } Elf32_Rel;
524
525 /* Relocation entry with explicit addend */
526 typedef struct
527 {
528         Elf32_Addr      r_offset;       /* offset of relocation */
529         Elf32_Word      r_info;         /* symbol table index and type */
530         Elf32_Sword     r_addend;
531 } Elf32_Rela;
532
533 /* Extract relocation info - r_info */
534 #define ELF32_R_SYM(i)          ((i) >> 8)
535 #define ELF32_R_TYPE(i)         ((unsigned char) (i))
536 #define ELF32_R_INFO(s,t)       (((s) << 8) + (unsigned char)(t))
537
538 // -------------------------------------------------------------------------
539 // 64 bit equivalents of above structures and macros.
540
541 typedef struct {
542         Elf64_Addr      r_offset;       /* where to do it */
543         Elf64_Xword     r_info;         /* index & type of relocation */
544 } Elf64_Rel;
545
546 typedef struct {
547         Elf64_Addr      r_offset;       /* where to do it */
548         Elf64_Xword     r_info;         /* index & type of relocation */
549         Elf64_Sxword    r_addend;       /* adjustment value */
550 } Elf64_RelA;
551
552 #define ELF64_R_SYM(info)       ((info) >> 32)
553 #define ELF64_R_TYPE(info)      ((info) & 0xFFFFFFFF)
554 #define ELF64_R_INFO(s,t)       (((s) << 32) + (u_int32_t)(t))
555
556 // -------------------------------------------------------------------------
557 /* Program Header */
558
559 typedef struct {
560     Elf32_Word  p_type;         /* segment type */
561     Elf32_Off   p_offset;       /* segment offset */
562     Elf32_Addr  p_vaddr;        /* virtual address of segment */
563     Elf32_Addr  p_paddr;        /* physical address - ignored? */
564     Elf32_Word  p_filesz;       /* number of bytes in file for seg. */
565     Elf32_Word  p_memsz;        /* number of bytes in mem. for seg. */
566     Elf32_Word  p_flags;        /* flags */
567     Elf32_Word  p_align;        /* memory alignment */
568 } Elf32_Phdr;
569
570 typedef struct {
571     Elf64_Word  p_type;         /* entry type */
572     Elf64_Word  p_flags;        /* flags */
573     Elf64_Off   p_offset;       /* offset */
574     Elf64_Addr  p_vaddr;        /* virtual address */
575     Elf64_Addr  p_paddr;        /* physical address */
576     Elf64_Xword p_filesz;       /* file size */
577     Elf64_Xword p_memsz;        /* memory size */
578     Elf64_Xword p_align;        /* memory & file alignment */
579 } Elf64_Phdr;
580
581 // -------------------------------------------------------------------------
582 /* Segment types - p_type */
583
584 #define PT_NULL         0               /* unused */
585 #define PT_LOAD         1               /* loadable segment */
586 #define PT_DYNAMIC      2               /* dynamic linking section */
587 #define PT_INTERP       3               /* the RTLD */
588 #define PT_NOTE         4               /* auxiliary information */
589 #define PT_SHLIB        5               /* reserved - purpose undefined */
590 #define PT_PHDR         6               /* program header */
591 #define PT_NUM          7               /* Number of segment types */
592 #define PT_LOOS         0x60000000      /* reserved range for OS */
593 #define PT_HIOS         0x6fffffff      /*  specific segment types */
594 #define PT_LOPROC       0x70000000      /* reserved range for processor */
595 #define PT_HIPROC       0x7fffffff      /*  specific segment types */
596
597 // -------------------------------------------------------------------------
598 /* Segment flags - p_flags */
599
600 #define PF_X            0x1             /* Executable */
601 #define PF_W            0x2             /* Writable */
602 #define PF_R            0x4             /* Readable */
603 #define PF_MASKOS       0x0ff00000      /* reserved bits for OS */
604                                         /*  specific segment flags */
605 #define PF_MASKPROC     0xf0000000      /* reserved bits for processor */
606                                         /*  specific segment flags */
607
608 // -------------------------------------------------------------------------
609 /* Dynamic structure */
610
611 typedef struct {
612     Elf32_Sword         d_tag;  /* controls meaning of d_val */
613     union {
614         Elf32_Word      d_val;  /* Multiple meanings - see d_tag */
615         Elf32_Addr      d_ptr;  /* program virtual address */
616     } d_un;
617 } Elf32_Dyn;
618
619 extern Elf32_Dyn        _DYNAMIC[];     /* XXX not 64-bit clean */
620
621 typedef struct {
622     Elf64_Sxword        d_tag;  /* controls meaning of d_val */
623     union {
624         Elf64_Xword     d_val;
625         Elf64_Addr      d_ptr;
626     } d_un;
627 } Elf64_Dyn;
628
629 // -------------------------------------------------------------------------
630 /* Dynamic Array Tags - d_tag */
631
632 #define DT_NULL         0               /* marks end of _DYNAMIC array */
633 #define DT_NEEDED       1               /* string table offset of needed lib */
634 #define DT_PLTRELSZ     2               /* size of relocation entries in PLT */
635 #define DT_PLTGOT       3               /* address PLT/GOT */
636 #define DT_HASH         4               /* address of symbol hash table */
637 #define DT_STRTAB       5               /* address of string table */
638 #define DT_SYMTAB       6               /* address of symbol table */
639 #define DT_RELA         7               /* address of relocation table */
640 #define DT_RELASZ       8               /* size of relocation table */
641 #define DT_RELAENT      9               /* size of relocation entry */
642 #define DT_STRSZ        10              /* size of string table */
643 #define DT_SYMENT       11              /* size of symbol table entry */
644 #define DT_INIT         12              /* address of initialization func. */
645 #define DT_FINI         13              /* address of termination function */
646 #define DT_SONAME       14              /* string table offset of shared obj */
647 #define DT_RPATH        15              /* string table offset of library
648                                            search path */
649 #define DT_SYMBOLIC     16              /* start sym search in shared obj. */
650 #define DT_REL          17              /* address of rel. tbl. w addends */
651 #define DT_RELSZ        18              /* size of DT_REL relocation table */
652 #define DT_RELENT       19              /* size of DT_REL relocation entry */
653 #define DT_PLTREL       20              /* PLT referenced relocation entry */
654 #define DT_DEBUG        21              /* bugger */
655 #define DT_TEXTREL      22              /* Allow rel. mod. to unwritable seg */
656 #define DT_JMPREL       23              /* add. of PLT's relocation entries */
657 #define DT_BIND_NOW     24              /* Bind now regardless of env setting */
658 #define DT_INIT_ARRAY   25              /* init array address */
659 #define DT_FINI_ARRAY   26              /* fini array address */
660 #define DT_INIT_ARRAYSZ 27              /* init array size */
661 #define DT_FINI_ARRAYSZ 28              /* fini array size */
662 #define DT_RUNPATH      29              /* library search path */
663 #define DT_FLAGS        30              /* flags */
664 #define DT_ENCODING     32              /* encoding rules start here */
665 #define DT_PREINIT_ARRAY 32             /* preinit array address */
666 #define DT_PREINIT_ARRAYSZ 33           /* preinit array size */
667 #define DT_NUM          26              /* Number used. */
668 #define DT_LOOS         0x60000000      /* reserved range for OS */
669 #define DT_HIOS         0x6fffffff      /*  specific dynamic array tags */
670 #define DT_LOPROC       0x70000000      /* reserved range for processor */
671 #define DT_HIPROC       0x7fffffff      /*  specific dynamic array tags */
672
673 // -------------------------------------------------------------------------
674 // Values for DT_FLAGS entry
675
676 #define DF_ORIGIN       0x1             /* Uses $ORIGIN substitution string */
677 #define DF_SYMBOLIC     0x2             /* search for symbols here first */
678 #define DF_TEXTREL      0x4             /* text may be relocatable */
679 #define DF_BIND_NOW     0x8             /* bind references now, dammit */
680
681 // -------------------------------------------------------------------------
682 /* Note Definitions */
683
684 typedef struct {
685     Elf32_Word namesz;
686     Elf32_Word descsz;
687     Elf32_Word type;
688 } Elf32_Note;
689
690 typedef struct {
691     Elf64_Word namesz;
692     Elf64_Word descsz;
693     Elf64_Word type;
694 } Elf64_Note;
695
696 // -------------------------------------------------------------------------
697 // Hash table structure
698 // The same structure is used by both 32 and 64 bit formats
699
700 typedef struct {
701     Elf32_Word          nbucket;        /* number of buckets */
702     Elf32_Word          nchain;         /* number of chains */
703
704     /* The buckets follow this structure in memory and the chains
705        follow those. */
706 } Elf_Hash;
707
708 // -------------------------------------------------------------------------
709 #endif // ifndef CYGONCE_REDBOOT_ELF_H
710 // EOF elf.h
Note: See TracBrowser for help on using the browser.