Contiki 2.5
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  * @(#)$Id: elf32.h,v 1.1 2006/12/01 15:12:27 bg- Exp $
30  */
31 
32 /* @(#)$Id: elf32.h,v 1.1 2006/12/01 15:12:27 bg- Exp $ */
33 
34 #ifndef ELF32_H
35 #define ELF32_H
36 
37 /*
38  * ELF definitions common to all 32-bit architectures.
39  */
40 
41 #define EI_NIDENT 16
42 
43 typedef unsigned long elf32_word;
44 typedef signed long elf32_sword;
45 typedef unsigned short elf32_half;
46 typedef unsigned long elf32_off;
47 typedef unsigned long elf32_addr;
48 
49 struct elf32_ehdr {
50  unsigned char e_ident[EI_NIDENT]; /* ident bytes */
51  elf32_half e_type; /* file type */
52  elf32_half e_machine; /* target machine */
53  elf32_word e_version; /* file version */
54  elf32_addr e_entry; /* start address */
55  elf32_off e_phoff; /* phdr file offset */
56  elf32_off e_shoff; /* shdr file offset */
57  elf32_word e_flags; /* file flags */
58  elf32_half e_ehsize; /* sizeof ehdr */
59  elf32_half e_phentsize; /* sizeof phdr */
60  elf32_half e_phnum; /* number phdrs */
61  elf32_half e_shentsize; /* sizeof shdr */
62  elf32_half e_shnum; /* number shdrs */
63  elf32_half e_shstrndx; /* shdr string index */
64 };
65 
66 /* Values for e_type. */
67 #define ET_NONE 0 /* Unknown type. */
68 #define ET_REL 1 /* Relocatable. */
69 #define ET_EXEC 2 /* Executable. */
70 #define ET_DYN 3 /* Shared object. */
71 #define ET_CORE 4 /* Core file. */
72 
73 struct elf32_shdr {
74  elf32_word sh_name; /* section name */
75  elf32_word sh_type; /* SHT_... */
76  elf32_word sh_flags; /* SHF_... */
77  elf32_addr sh_addr; /* virtual address */
78  elf32_off sh_offset; /* file offset */
79  elf32_word sh_size; /* section size */
80  elf32_word sh_link; /* misc info */
81  elf32_word sh_info; /* misc info */
82  elf32_word sh_addralign; /* memory alignment */
83  elf32_word sh_entsize; /* entry size if table */
84 };
85 
86 /* sh_type */
87 #define SHT_NULL 0 /* inactive */
88 #define SHT_PROGBITS 1 /* program defined information */
89 #define SHT_SYMTAB 2 /* symbol table section */
90 #define SHT_STRTAB 3 /* string table section */
91 #define SHT_RELA 4 /* relocation section with addends*/
92 #define SHT_HASH 5 /* symbol hash table section */
93 #define SHT_DYNAMIC 6 /* dynamic section */
94 #define SHT_NOTE 7 /* note section */
95 #define SHT_NOBITS 8 /* no space section */
96 #define SHT_REL 9 /* relation section without addends */
97 #define SHT_SHLIB 10 /* reserved - purpose unknown */
98 #define SHT_DYNSYM 11 /* dynamic symbol table section */
99 #define SHT_LOPROC 0x70000000 /* reserved range for processor */
100 #define SHT_HIPROC 0x7fffffff /* specific section header types */
101 #define SHT_LOUSER 0x80000000 /* reserved range for application */
102 #define SHT_HIUSER 0xffffffff /* specific indexes */
103 
104 struct elf32_rel {
105  elf32_addr r_offset; /* Location to be relocated. */
106  elf32_word r_info; /* Relocation type and symbol index. */
107 };
108 
109 struct elf32_rela {
110  elf32_addr r_offset; /* Location to be relocated. */
111  elf32_word r_info; /* Relocation type and symbol index. */
112  elf32_sword r_addend; /* Addend. */
113 };
114 
115 struct elf32_sym {
116  elf32_word st_name; /* String table index of name. */
117  elf32_addr st_value; /* Symbol value. */
118  elf32_word st_size; /* Size of associated object. */
119  unsigned char st_info; /* Type and binding information. */
120  unsigned char st_other; /* Reserved (not used). */
121  elf32_half st_shndx; /* Section index of symbol. */
122 };
123 
124 #define ELF32_R_SYM(info) ((info) >> 8)
125 #define ELF32_R_TYPE(info) ((unsigned char)(info))
126 
127 #define ELF_MAGIC_HEADER "\177ELF\001\001\001"
128 #define ELF_MAGIC_HEADER_SIZE 7
129 
130 #endif /* ELF32_H */