summaryrefslogtreecommitdiff
path: root/ecos/packages/services/objloader/current/include/elf.h
blob: ea981ddee436cff5f98624a3dd50d34f8c2d956b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#ifndef __ELF_H__
#define __ELF_H__

/* =================================================================
 *
 *      elf.f
 *
 * ================================================================= 
 * ####ECOSGPLCOPYRIGHTBEGIN####
 * -------------------------------------------
 * This file is part of eCos, the Embedded Configurable Operating
 * System.
 * Copyright (C) 2005 eCosCentric Ltd.
 *
 * eCos is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 or (at your option)
 * any later version.
 * 
 * eCos is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with eCos; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 * 
 * As a special exception, if other files instantiate templates or
 * use macros or inline functions from this file, or you compile this
 * file and link it with other works to produce a work based on this
 * file, this file does not by itself cause the resulting work to be
 * covered by the GNU General Public License. However the source code
 * for this file must still be made available in accordance with
 * section (3) of the GNU General Public License.
 * 
 * This exception does not invalidate any other reasons why a work
 * based on this file might be covered by the GNU General Public
 * License.
 *
 * -------------------------------------------
 * ####ECOSGPLCOPYRIGHTEND####
 * =================================================================
 * #####DESCRIPTIONBEGIN####
 * 
 *  Author(s):    atonizzo@lycos.com
 *  Date:         2005-05-13
 *  Purpose:      
 *  Description:  
 *               
 * ####DESCRIPTIONEND####
 * 
 * =================================================================
 */

typedef cyg_uint32     Elf32_Addr;
typedef cyg_uint16     Elf32_Half;
typedef cyg_uint32     Elf32_Off;
typedef cyg_int32      Elf32_Sword;
typedef cyg_uint32     Elf32_Word;

#define EI_NIDENT      16
typedef struct
{
    unsigned char e_ident[EI_NIDENT];
    Elf32_Half e_type;
    Elf32_Half e_machine;
    Elf32_Word e_version;
    Elf32_Addr e_entry;
    Elf32_Off  e_phoff;
    Elf32_Off  e_shoff;
    Elf32_Word e_flags;
    Elf32_Half e_ehsize;
    Elf32_Half e_phentsize;
    Elf32_Half e_phnum;
    Elf32_Half e_shentsize;
    Elf32_Half e_shnum;
    Elf32_Half e_shstrndx;
} Elf32_Ehdr;

// The ELFCLASS* macros are the defined values of e_ident[EI_CLASS].
#define ELFCLASSNONE      0   // Invalid class.
#define ELFCLASS32        1   // 32-bit objects.
#define ELFCLASS64        2   // 64-bit objects.

// The ELFDATA* macros are the allowed values of e_ident[EI_DATA].
#define ELFDATA2LSB     1 // Little Endian
#define ELFDATA2MSB     2 // Big Endian.

// The ET_* macros define the values of the e_type field of the ElfXX_Ehdr
//   structure.
#define ET_NONE         0 // No file type.
#define ET_REL          1 // Relocatable file.
#define ET_EXEC         2 // Executable file.
#define ET_DYN          3 // Shared object file.
#define ET_CORE         4 // Core file.
#define ET_LOPROC       0xff00 // Processor-specific.

// The ELFMAG* macros are the values of e_ident[EI_MAG0-4]
#define ELFMAG0         0x7f      // magic number, byte 0 
#define ELFMAG1         'E'       // magic number, byte 1 
#define ELFMAG2         'L'       // magic number, byte 2 
#define ELFMAG3         'F'       // magic number, byte 3 
#define ELFMAG          "\177ELF" // magic string 
#define SELFMAG         4         // magic string length 

#define EI_MAG0         0
#define EI_MAG1         1
#define EI_MAG2         2
#define EI_MAG3         3
#define EI_CLASS        4
#define EI_DATA         5 
#define EI_VERSION      6
#define EI_PAD          7 

typedef struct 
{
    Elf32_Word sh_name; 		// section name.
    Elf32_Word sh_type;         // SHT_...
    Elf32_Word sh_flags;        // SHF_...
    Elf32_Addr sh_addr;         // virtual address
    Elf32_Off  sh_offset;       // file offset
    Elf32_Word sh_size;         // section size
    Elf32_Word sh_link;         // misc info 
    Elf32_Word sh_info;         // misc info 
    Elf32_Word sh_addralign;    // memory alignment
    Elf32_Word sh_entsize;      // entry size if table.
} Elf32_Shdr;

// Symbols table entry.
typedef struct
{
    Elf32_Word    st_name;                // Symbol name (string tbl index).
    Elf32_Addr    st_value;               // Symbol value.
    Elf32_Word    st_size;                // Symbol size.
    unsigned char st_info;                // Symbol type and binding.
    unsigned char st_other;               // Symbol visibility.
    Elf32_Half    st_shndx;               // Section index.
} Elf32_Sym;

typedef struct 
{
    Elf32_Addr r_offset;
    Elf32_Word r_info;
} Elf32_Rel;

typedef struct
{ 
    Elf32_Addr  r_offset;
    Elf32_Word  r_info;
    Elf32_Sword r_addend;
} Elf32_Rela;


#define SHT_NULL        0
#define SHT_PROGBITS    1
#define SHT_SYMTAB      2
#define SHT_STRTAB      3
#define SHT_RELA        4
#define SHT_HASH        5
#define SHT_DYNAMIC     6
#define SHT_NOTE        7
#define SHT_NOBITS      8
#define SHT_REL         9
#define SHT_SHLIB      10
#define SHT_DYNSYM     11

#define SHN_UNDEF       0
#define SHN_LORESERVE   0xff00
#define SHN_LOPROC      0xff00
#define SHN_HIPROC      0xff1f
#define SHN_ABS         0xfff1
#define SHN_COMMON      0xfff2
#define SHN_HIRESERVE   0xffff

#define STT_NOTYPE            0
#define STT_OBJECT            1
#define STT_FUNC              2
#define STT_SECTION           3
#define STT_FILE              4
#define STT_LOPROC           13
#define STT_HIPROC           15

#define STB_LOCAL            0
#define STB_GLOBAL           1
#define STB_WEAK             2
#define STB_LOPROC          13
#define STB_HIPROC          15

// The ELF_STRING_xxx macros are names of common sections
#define ELF_STRING_bss          ".bss"
#define ELF_STRING_hbss         ".hbss"
#define ELF_STRING_sbss         ".sbss"
#define ELF_STRING_tbss         ".tbss"
#define ELF_STRING_data         ".data"
#define ELF_STRING_hdata        ".hdata"
#define ELF_STRING_sdata        ".sdata"
#define ELF_STRING_sdata2       ".sdata2"
#define ELF_STRING_fini         ".fini"
#define ELF_STRING_init         ".init"
#define ELF_STRING_interp       ".interp"
#define ELF_STRING_rodata       ".rodata"
#define ELF_STRING_text         ".text"
#define ELF_STRING_comment      ".comment"
#define ELF_STRING_dynamic      ".dynamic"
#define ELF_STRING_dynstr       ".dynstr"
#define ELF_STRING_dynsym       ".dynsym"
#define ELF_STRING_dlt          ".dlt"
#define ELF_STRING_note         ".note"
#define ELF_STRING_opd          ".opd"
#define ELF_STRING_plt          ".plt"
#define ELF_STRING_bss_rela     ".rela.bss"
#define ELF_STRING_hbss_rela    ".rela.hbss"
#define ELF_STRING_data_rela    ".rela.data"
#define ELF_STRING_dlt_rela     ".rela.dlt"
#define ELF_STRING_plt_rela     ".rela.plt"
#define ELF_STRING_sdata_rela   ".rela.sdata"
#define ELF_STRING_strtab       ".strtab"
#define ELF_STRING_symtab       ".symtab"
#define ELF_STRING_hash         ".hash"
#define ELF_STRING_shstrtab     ".shstrtab"
#define ELF_STRING_shsymtab     ".shsymtab"
#define ELF_STRING_rela         ".rela"
#define ELF_STRING_rel          ".rel"

#define ELF32_R_SYM(i)  ((i)>>8)
#define ELF32_R_TYPE(i) ((unsigned char)(i))

#define ELF32_ST_BIND(i)  ((i)>>4)
#define ELF32_ST_TYPE(i)  ((i)&0x0F)


#endif