]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/services/objloader/v2_0/include/elf.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / services / objloader / v2_0 / include / elf.h
1 #ifndef __ELF_H__
2 #define __ELF_H__
3
4 /* =================================================================
5  *
6  *      elf.h
7  *
8  * ================================================================= 
9  * ####ECOSGPLCOPYRIGHTBEGIN####
10  * -------------------------------------------
11  * This file is part of eCos, the Embedded Configurable Operating
12  * System.
13  * Copyright (C) 2005 eCosCentric Ltd.
14  *
15  * eCos is free software; you can redistribute it and/or modify it
16  * under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 or (at your option)
18  * any later version.
19  * 
20  * eCos is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * General Public License for more details.
24  * 
25  * You should have received a copy of the GNU General Public License
26  * along with eCos; if not, write to the Free Software Foundation,
27  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28  * 
29  * As a special exception, if other files instantiate templates or
30  * use macros or inline functions from this file, or you compile this
31  * file and link it with other works to produce a work based on this
32  * file, this file does not by itself cause the resulting work to be
33  * covered by the GNU General Public License. However the source code
34  * for this file must still be made available in accordance with
35  * section (3) of the GNU General Public License.
36  * 
37  * This exception does not invalidate any other reasons why a work
38  * based on this file might be covered by the GNU General Public
39  * License.
40  *
41  * -------------------------------------------
42  * ####ECOSGPLCOPYRIGHTEND####
43  * =================================================================
44  * #####DESCRIPTIONBEGIN####
45  * 
46  *  Author(s):    Anthony Tonizzo (atonizzo@gmail.com)
47  *  Date:         2005-05-13
48  *  Purpose:      
49  *  Description:  
50  *               
51  * ####DESCRIPTIONEND####
52  * 
53  * =================================================================
54  */
55
56 typedef cyg_uint32     Elf32_Addr;
57 typedef cyg_uint16     Elf32_Half;
58 typedef cyg_uint32     Elf32_Off;
59 typedef cyg_int32      Elf32_Sword;
60 typedef cyg_uint32     Elf32_Word;
61
62 #define EI_NIDENT      16
63 typedef struct
64 {
65     unsigned char e_ident[EI_NIDENT];
66     Elf32_Half e_type;
67     Elf32_Half e_machine;
68     Elf32_Word e_version;
69     Elf32_Addr e_entry;
70     Elf32_Off  e_phoff;
71     Elf32_Off  e_shoff;
72     Elf32_Word e_flags;
73     Elf32_Half e_ehsize;
74     Elf32_Half e_phentsize;
75     Elf32_Half e_phnum;
76     Elf32_Half e_shentsize;
77     Elf32_Half e_shnum;
78     Elf32_Half e_shstrndx;
79 } Elf32_Ehdr;
80
81 // The ELFCLASS* macros are the defined values of e_ident[EI_CLASS].
82 #define ELFCLASSNONE      0   // Invalid class.
83 #define ELFCLASS32        1   // 32-bit objects.
84 #define ELFCLASS64        2   // 64-bit objects.
85
86 // The ELFDATA* macros are the allowed values of e_ident[EI_DATA].
87 #define ELFDATA2LSB     1 // Little Endian
88 #define ELFDATA2MSB     2 // Big Endian.
89
90 // The ET_* macros define the values of the e_type field of the ElfXX_Ehdr
91 //   structure.
92 #define ET_NONE         0 // No file type.
93 #define ET_REL          1 // Relocatable file.
94 #define ET_EXEC         2 // Executable file.
95 #define ET_DYN          3 // Shared object file.
96 #define ET_CORE         4 // Core file.
97 #define ET_LOPROC       0xff00 // Processor-specific.
98
99 // The ELFMAG* macros are the values of e_ident[EI_MAG0-4]
100 #define ELFMAG0         0x7f      // magic number, byte 0 
101 #define ELFMAG1         'E'       // magic number, byte 1 
102 #define ELFMAG2         'L'       // magic number, byte 2 
103 #define ELFMAG3         'F'       // magic number, byte 3 
104 #define ELFMAG          "\177ELF" // magic string 
105 #define SELFMAG         4         // magic string length 
106
107 #define EI_MAG0         0
108 #define EI_MAG1         1
109 #define EI_MAG2         2
110 #define EI_MAG3         3
111 #define EI_CLASS        4
112 #define EI_DATA         5 
113 #define EI_VERSION      6
114 #define EI_PAD          7 
115
116 typedef struct 
117 {
118     Elf32_Word sh_name;                 // section name.
119     Elf32_Word sh_type;         // SHT_...
120     Elf32_Word sh_flags;        // SHF_...
121     Elf32_Addr sh_addr;         // virtual address
122     Elf32_Off  sh_offset;       // file offset
123     Elf32_Word sh_size;         // section size
124     Elf32_Word sh_link;         // misc info 
125     Elf32_Word sh_info;         // misc info 
126     Elf32_Word sh_addralign;    // memory alignment
127     Elf32_Word sh_entsize;      // entry size if table.
128 } Elf32_Shdr;
129
130 // Symbols table entry.
131 typedef struct
132 {
133     Elf32_Word    st_name;                // Symbol name (string tbl index).
134     Elf32_Addr    st_value;               // Symbol value.
135     Elf32_Word    st_size;                // Symbol size.
136     unsigned char st_info;                // Symbol type and binding.
137     unsigned char st_other;               // Symbol visibility.
138     Elf32_Half    st_shndx;               // Section index.
139 } Elf32_Sym;
140
141 typedef struct 
142 {
143     Elf32_Addr r_offset;
144     Elf32_Word r_info;
145 } Elf32_Rel;
146
147 typedef struct
148
149     Elf32_Addr  r_offset;
150     Elf32_Word  r_info;
151     Elf32_Sword r_addend;
152 } Elf32_Rela;
153
154
155 #define SHT_NULL        0
156 #define SHT_PROGBITS    1
157 #define SHT_SYMTAB      2
158 #define SHT_STRTAB      3
159 #define SHT_RELA        4
160 #define SHT_HASH        5
161 #define SHT_DYNAMIC     6
162 #define SHT_NOTE        7
163 #define SHT_NOBITS      8
164 #define SHT_REL         9
165 #define SHT_SHLIB      10
166 #define SHT_DYNSYM     11
167
168 #define SHN_UNDEF       0
169 #define SHN_LORESERVE   0xff00
170 #define SHN_LOPROC      0xff00
171 #define SHN_HIPROC      0xff1f
172 #define SHN_ABS         0xfff1
173 #define SHN_COMMON      0xfff2
174 #define SHN_HIRESERVE   0xffff
175
176 #define STT_NOTYPE            0
177 #define STT_OBJECT            1
178 #define STT_FUNC              2
179 #define STT_SECTION           3
180 #define STT_FILE              4
181 #define STT_LOPROC           13
182 #define STT_HIPROC           15
183
184 #define STB_LOCAL            0
185 #define STB_GLOBAL           1
186 #define STB_WEAK             2
187 #define STB_LOPROC          13
188 #define STB_HIPROC          15
189
190 // The ELF_STRING_xxx macros are names of common sections
191 #define ELF_STRING_bss          ".bss"
192 #define ELF_STRING_hbss         ".hbss"
193 #define ELF_STRING_sbss         ".sbss"
194 #define ELF_STRING_tbss         ".tbss"
195 #define ELF_STRING_data         ".data"
196 #define ELF_STRING_hdata        ".hdata"
197 #define ELF_STRING_sdata        ".sdata"
198 #define ELF_STRING_sdata2       ".sdata2"
199 #define ELF_STRING_fini         ".fini"
200 #define ELF_STRING_init         ".init"
201 #define ELF_STRING_interp       ".interp"
202 #define ELF_STRING_rodata       ".rodata"
203 #define ELF_STRING_text         ".text"
204 #define ELF_STRING_comment      ".comment"
205 #define ELF_STRING_dynamic      ".dynamic"
206 #define ELF_STRING_dynstr       ".dynstr"
207 #define ELF_STRING_dynsym       ".dynsym"
208 #define ELF_STRING_dlt          ".dlt"
209 #define ELF_STRING_note         ".note"
210 #define ELF_STRING_opd          ".opd"
211 #define ELF_STRING_plt          ".plt"
212 #define ELF_STRING_bss_rela     ".rela.bss"
213 #define ELF_STRING_hbss_rela    ".rela.hbss"
214 #define ELF_STRING_data_rela    ".rela.data"
215 #define ELF_STRING_dlt_rela     ".rela.dlt"
216 #define ELF_STRING_plt_rela     ".rela.plt"
217 #define ELF_STRING_sdata_rela   ".rela.sdata"
218 #define ELF_STRING_strtab       ".strtab"
219 #define ELF_STRING_symtab       ".symtab"
220 #define ELF_STRING_hash         ".hash"
221 #define ELF_STRING_shstrtab     ".shstrtab"
222 #define ELF_STRING_shsymtab     ".shsymtab"
223 #define ELF_STRING_rela         ".rela"
224 #define ELF_STRING_rel          ".rel"
225
226 #define ELF32_R_SYM(i)  ((i)>>8)
227 #define ELF32_R_TYPE(i) ((unsigned char)(i))
228
229 #define ELF32_ST_BIND(i)  ((i)>>4)
230 #define ELF32_ST_TYPE(i)  ((i)&0x0F)
231
232
233 #endif
234