Contiki 3.x
elf32.h
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 
32 #ifndef ELF32_H
33 #define ELF32_H
34 
35 /*
36  * ELF definitions common to all 32-bit architectures.
37  */
38 
39 #define EI_NIDENT 16
40 
41 typedef unsigned long elf32_word;
42 typedef signed long elf32_sword;
43 typedef unsigned short elf32_half;
44 typedef unsigned long elf32_off;
45 typedef unsigned long elf32_addr;
46 
47 struct elf32_ehdr {
48  unsigned char e_ident[EI_NIDENT]; /* ident bytes */
49  elf32_half e_type; /* file type */
50  elf32_half e_machine; /* target machine */
51  elf32_word e_version; /* file version */
52  elf32_addr e_entry; /* start address */
53  elf32_off e_phoff; /* phdr file offset */
54  elf32_off e_shoff; /* shdr file offset */
55  elf32_word e_flags; /* file flags */
56  elf32_half e_ehsize; /* sizeof ehdr */
57  elf32_half e_phentsize; /* sizeof phdr */
58  elf32_half e_phnum; /* number phdrs */
59  elf32_half e_shentsize; /* sizeof shdr */
60  elf32_half e_shnum; /* number shdrs */
61  elf32_half e_shstrndx; /* shdr string index */
62 };
63 
64 /* Values for e_type. */
65 #define ET_NONE 0 /* Unknown type. */
66 #define ET_REL 1 /* Relocatable. */
67 #define ET_EXEC 2 /* Executable. */
68 #define ET_DYN 3 /* Shared object. */
69 #define ET_CORE 4 /* Core file. */
70 
71 struct elf32_shdr {
72  elf32_word sh_name; /* section name */
73  elf32_word sh_type; /* SHT_... */
74  elf32_word sh_flags; /* SHF_... */
75  elf32_addr sh_addr; /* virtual address */
76  elf32_off sh_offset; /* file offset */
77  elf32_word sh_size; /* section size */
78  elf32_word sh_link; /* misc info */
79  elf32_word sh_info; /* misc info */
80  elf32_word sh_addralign; /* memory alignment */
81  elf32_word sh_entsize; /* entry size if table */
82 };
83 
84 /* sh_type */
85 #define SHT_NULL 0 /* inactive */
86 #define SHT_PROGBITS 1 /* program defined information */
87 #define SHT_SYMTAB 2 /* symbol table section */
88 #define SHT_STRTAB 3 /* string table section */
89 #define SHT_RELA 4 /* relocation section with addends*/
90 #define SHT_HASH 5 /* symbol hash table section */
91 #define SHT_DYNAMIC 6 /* dynamic section */
92 #define SHT_NOTE 7 /* note section */
93 #define SHT_NOBITS 8 /* no space section */
94 #define SHT_REL 9 /* relation section without addends */
95 #define SHT_SHLIB 10 /* reserved - purpose unknown */
96 #define SHT_DYNSYM 11 /* dynamic symbol table section */
97 #define SHT_LOPROC 0x70000000 /* reserved range for processor */
98 #define SHT_HIPROC 0x7fffffff /* specific section header types */
99 #define SHT_LOUSER 0x80000000 /* reserved range for application */
100 #define SHT_HIUSER 0xffffffff /* specific indexes */
101 
102 struct elf32_rel {
103  elf32_addr r_offset; /* Location to be relocated. */
104  elf32_word r_info; /* Relocation type and symbol index. */
105 };
106 
107 struct elf32_rela {
108  elf32_addr r_offset; /* Location to be relocated. */
109  elf32_word r_info; /* Relocation type and symbol index. */
110  elf32_sword r_addend; /* Addend. */
111 };
112 
113 struct elf32_sym {
114  elf32_word st_name; /* String table index of name. */
115  elf32_addr st_value; /* Symbol value. */
116  elf32_word st_size; /* Size of associated object. */
117  unsigned char st_info; /* Type and binding information. */
118  unsigned char st_other; /* Reserved (not used). */
119  elf32_half st_shndx; /* Section index of symbol. */
120 };
121 
122 #define ELF32_R_SYM(info) ((info) >> 8)
123 #define ELF32_R_TYPE(info) ((unsigned char)(info))
124 
125 #define ELF_MAGIC_HEADER "\177ELF\001\001\001"
126 #define ELF_MAGIC_HEADER_SIZE 7
127 
128 #endif /* ELF32_H */