Rev 909 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 909 | Rev 910 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Sergey Bondari |
2 | * Copyright (C) 2006 Sergey Bondari |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef __ELF32_H__ |
29 | #ifndef __ELF32_H__ |
30 | #define __ELF32_H__ |
30 | #define __ELF32_H__ |
31 | 31 | ||
32 | #include <arch/types.h> |
32 | #include <arch/types.h> |
33 | #include <mm/as.h> |
33 | #include <mm/as.h> |
34 | 34 | ||
35 | /** |
35 | /** |
36 | * current ELF version |
36 | * current ELF version |
37 | */ |
37 | */ |
38 | #define EV_CURRENT 1 |
38 | #define EV_CURRENT 1 |
39 | 39 | ||
40 | /** |
40 | /** |
41 | * ELF types |
41 | * ELF types |
42 | */ |
42 | */ |
43 | #define ET_NONE 0 // No type |
43 | #define ET_NONE 0 // No type |
44 | #define ET_REL 1 // Relocatable file |
44 | #define ET_REL 1 // Relocatable file |
45 | #define ET_EXEC 2 // Executable |
45 | #define ET_EXEC 2 // Executable |
46 | #define ET_DYN 3 // Shared object |
46 | #define ET_DYN 3 // Shared object |
47 | #define ET_CORE 4 // Core |
47 | #define ET_CORE 4 // Core |
48 | #define ET_LOPROC 0xff00 // Processor specific |
48 | #define ET_LOPROC 0xff00 // Processor specific |
49 | #define ET_HIPROC 0xffff // Processor specific |
49 | #define ET_HIPROC 0xffff // Processor specific |
50 | 50 | ||
51 | /** |
51 | /** |
52 | * ELF machine types |
52 | * ELF machine types |
53 | */ |
53 | */ |
54 | #define EM_NO 0 // No machine |
54 | #define EM_NO 0 // No machine |
55 | #define EM_M32 1 // AT&T WE 32100 |
- | |
56 | #define EM_SPARC 2 // SPARC |
55 | #define EM_SPARC 2 // SPARC |
57 | #define EM_386 3 // i386 |
56 | #define EM_386 3 // i386 |
58 | #define EM_68K 4 // Motorola 68000 |
- | |
59 | #define EM_88K 5 // Motorola 88000 |
- | |
60 | #define EM_860 7 // i80860 |
- | |
61 | #define EM_MIPS 8 // MIPS RS3000 |
57 | #define EM_MIPS 8 // MIPS RS3000 |
- | 58 | #define EM_MIPS_RS3_LE 10 // MIPS RS3000 LE |
|
- | 59 | #define EM_PPC 20 // PPC32 |
|
- | 60 | #define EM_PPC64 21 // PPC64 |
|
- | 61 | #define EM_SPARCV9 43 // SPARC64 |
|
- | 62 | #define EM_IA_64 50 // IA-64 |
|
- | 63 | #define EM_X86_64 62 // AMD64/EMT64 |
|
62 | 64 | ||
63 | /** |
65 | /** |
64 | * ELF identification indexes |
66 | * ELF identification indexes |
65 | */ |
67 | */ |
66 | #define EI_MAG0 0 |
68 | #define EI_MAG0 0 |
67 | #define EI_MAG1 1 |
69 | #define EI_MAG1 1 |
68 | #define EI_MAG2 2 |
70 | #define EI_MAG2 2 |
69 | #define EI_MAG3 3 |
71 | #define EI_MAG3 3 |
70 | #define EI_CLASS 4 // File class |
72 | #define EI_CLASS 4 // File class |
71 | #define EI_DATA 5 // Data encoding |
73 | #define EI_DATA 5 // Data encoding |
72 | #define EI_VERSION 6 // File version |
74 | #define EI_VERSION 6 // File version |
73 | #define EI_PAD 7 // Start of padding bytes |
75 | #define EI_PAD 7 // Start of padding bytes |
74 | #define EI_NIDENT 16 // ELF identification table size |
76 | #define EI_NIDENT 16 // ELF identification table size |
75 | 77 | ||
76 | /** |
78 | /** |
77 | * ELF magic number |
79 | * ELF magic number |
78 | */ |
80 | */ |
79 | #define ELFMAG0 0x7f |
81 | #define ELFMAG0 0x7f |
80 | #define ELFMAG1 'E' |
82 | #define ELFMAG1 'E' |
81 | #define ELFMAG2 'L' |
83 | #define ELFMAG2 'L' |
82 | #define ELFMAG3 'F' |
84 | #define ELFMAG3 'F' |
83 | 85 | ||
84 | /** |
86 | /** |
85 | * ELF file classes |
87 | * ELF file classes |
86 | */ |
88 | */ |
87 | #define ELFCLASSNONE 0 |
89 | #define ELFCLASSNONE 0 |
88 | #define ELFCLASS32 1 |
90 | #define ELFCLASS32 1 |
89 | #define ELFCLASS64 2 |
91 | #define ELFCLASS64 2 |
90 | 92 | ||
91 | /** |
93 | /** |
92 | * ELF data encoding types |
94 | * ELF data encoding types |
93 | */ |
95 | */ |
94 | #define ELFDATANONE 0 |
96 | #define ELFDATANONE 0 |
95 | #define ELFDATA2LSB 1 // Least significant byte first (little endian) |
97 | #define ELFDATA2LSB 1 // Least significant byte first (little endian) |
96 | #define ELFDATA2MSB 2 // Most signigicant byte first (Big endian) |
98 | #define ELFDATA2MSB 2 // Most signigicant byte first (Big endian) |
97 | 99 | ||
98 | /** |
100 | /** |
99 | * ELF error return codes |
101 | * ELF error return codes |
100 | */ |
102 | */ |
101 | #define EE_OK 0 // No error |
103 | #define EE_OK 0 // No error |
102 | #define EE_INVALID 1 // invalid ELF image |
104 | #define EE_INVALID 1 // invalid ELF image |
103 | #define EE_MEMORY 2 // cannot allocate address space |
105 | #define EE_MEMORY 2 // cannot allocate address space |
104 | #define EE_INCOMPATIBLE 3 // ELF image is not compatible with current architecture |
106 | #define EE_INCOMPATIBLE 3 // ELF image is not compatible with current architecture |
105 | #define EE_UNSUPPORTED 4 // Non-supported ELF (e.g. dynamic ELFs) |
107 | #define EE_UNSUPPORTED 4 // Non-supported ELF (e.g. dynamic ELFs) |
106 | 108 | ||
107 | 109 | ||
108 | /** |
110 | /** |
109 | * ELF section types |
111 | * ELF section types |
110 | */ |
112 | */ |
111 | #define SHT_NULL 0 |
113 | #define SHT_NULL 0 |
112 | #define SHT_PROGBITS 1 |
114 | #define SHT_PROGBITS 1 |
113 | #define SHT_SYMTAB 2 |
115 | #define SHT_SYMTAB 2 |
114 | #define SHT_STRTAB 3 |
116 | #define SHT_STRTAB 3 |
115 | #define SHT_RELA 4 |
117 | #define SHT_RELA 4 |
116 | #define SHT_HASH 5 |
118 | #define SHT_HASH 5 |
117 | #define SHT_DYNAMIC 6 |
119 | #define SHT_DYNAMIC 6 |
118 | #define SHT_NOTE 7 |
120 | #define SHT_NOTE 7 |
119 | #define SHT_NOBITS 8 |
121 | #define SHT_NOBITS 8 |
120 | #define SHT_REL 9 |
122 | #define SHT_REL 9 |
121 | #define SHT_SHLIB 10 |
123 | #define SHT_SHLIB 10 |
122 | #define SHT_DYNSYM 11 |
124 | #define SHT_DYNSYM 11 |
123 | #define SHT_LOPROC 0x70000000 |
125 | #define SHT_LOPROC 0x70000000 |
124 | #define SHT_HIPROC 0x7fffffff |
126 | #define SHT_HIPROC 0x7fffffff |
125 | #define SHT_LOUSER 0x80000000 |
127 | #define SHT_LOUSER 0x80000000 |
126 | #define SHT_HIUSER 0xffffffff |
128 | #define SHT_HIUSER 0xffffffff |
127 | 129 | ||
128 | /** |
130 | /** |
129 | * ELF section flags |
131 | * ELF section flags |
130 | */ |
132 | */ |
131 | #define SHF_WRITE 0x1 |
133 | #define SHF_WRITE 0x1 |
132 | #define SHF_ALLOC 0x2 |
134 | #define SHF_ALLOC 0x2 |
133 | #define SHF_EXECINSTR 0x4 |
135 | #define SHF_EXECINSTR 0x4 |
134 | #define SHF_MASKPROC 0xf0000000 |
136 | #define SHF_MASKPROC 0xf0000000 |
135 | 137 | ||
136 | 138 | ||
137 | /** |
139 | /** |
138 | * Symbol binding |
140 | * Symbol binding |
139 | */ |
141 | */ |
140 | #define STB_LOCAL 0 |
142 | #define STB_LOCAL 0 |
141 | #define STB_GLOBAL 1 |
143 | #define STB_GLOBAL 1 |
142 | #define STB_WEAK 2 |
144 | #define STB_WEAK 2 |
143 | #define STB_LOPROC 13 |
145 | #define STB_LOPROC 13 |
144 | #define STB_HIPROC 15 |
146 | #define STB_HIPROC 15 |
145 | 147 | ||
146 | /** |
148 | /** |
147 | * Symbol types |
149 | * Symbol types |
148 | */ |
150 | */ |
149 | #define STT_NOTYPE 0 |
151 | #define STT_NOTYPE 0 |
150 | #define STT_OBJECT 1 |
152 | #define STT_OBJECT 1 |
151 | #define STT_FUNC 2 |
153 | #define STT_FUNC 2 |
152 | #define STT_SECTION 3 |
154 | #define STT_SECTION 3 |
153 | #define STT_FILE 4 |
155 | #define STT_FILE 4 |
154 | #define STT_LOPROC 13 |
156 | #define STT_LOPROC 13 |
155 | #define STT_HIPROC 15 |
157 | #define STT_HIPROC 15 |
156 | 158 | ||
157 | 159 | ||
158 | /** |
160 | /** |
159 | * Program segment types |
161 | * Program segment types |
160 | */ |
162 | */ |
161 | #define PT_NULL 0 |
163 | #define PT_NULL 0 |
162 | #define PT_LOAD 1 |
164 | #define PT_LOAD 1 |
163 | #define PT_DYNAMIC 2 |
165 | #define PT_DYNAMIC 2 |
164 | #define PT_INTERP 3 |
166 | #define PT_INTERP 3 |
165 | #define PT_NOTE 4 |
167 | #define PT_NOTE 4 |
166 | #define PT_SHLIB 5 |
168 | #define PT_SHLIB 5 |
167 | #define PT_PHDR 6 |
169 | #define PT_PHDR 6 |
168 | #define PT_LOPROC 0x70000000 |
170 | #define PT_LOPROC 0x70000000 |
169 | #define PT_HIPROC 0x7fffffff |
171 | #define PT_HIPROC 0x7fffffff |
170 | 172 | ||
171 | /** |
173 | /** |
172 | * 32-bit ELF data types |
174 | * 32-bit ELF data types |
173 | */ |
175 | */ |
174 | typedef __u32 elf32_addr; |
176 | typedef __u32 elf32_addr; |
175 | typedef __u16 elf32_half; |
177 | typedef __u16 elf32_half; |
176 | typedef __u32 elf32_off; |
178 | typedef __u32 elf32_off; |
177 | typedef int elf32_sword; |
179 | typedef int elf32_sword; |
178 | typedef __u32 elf32_word; |
180 | typedef __u32 elf32_word; |
179 | 181 | ||
180 | /** |
182 | /** |
181 | * 32-bit ELF header |
183 | * 32-bit ELF header |
182 | */ |
184 | */ |
183 | struct elf32_header { |
185 | struct elf32_header { |
184 | __u8 e_ident[EI_NIDENT]; |
186 | __u8 e_ident[EI_NIDENT]; |
185 | elf32_half e_type; |
187 | elf32_half e_type; |
186 | elf32_half e_machine; |
188 | elf32_half e_machine; |
187 | elf32_word e_version; |
189 | elf32_word e_version; |
188 | elf32_addr e_entry; |
190 | elf32_addr e_entry; |
189 | elf32_off e_phoff; |
191 | elf32_off e_phoff; |
190 | elf32_off e_shoff; |
192 | elf32_off e_shoff; |
191 | elf32_word e_flags; |
193 | elf32_word e_flags; |
192 | elf32_half e_ehsize; |
194 | elf32_half e_ehsize; |
193 | elf32_half e_phentsize; |
195 | elf32_half e_phentsize; |
194 | elf32_half e_phnum; |
196 | elf32_half e_phnum; |
195 | elf32_half e_shentsize; |
197 | elf32_half e_shentsize; |
196 | elf32_half e_shnum; |
198 | elf32_half e_shnum; |
197 | elf32_half e_shstrndx; |
199 | elf32_half e_shstrndx; |
198 | }; |
200 | }; |
199 | 201 | ||
200 | 202 | ||
201 | /* |
203 | /* |
202 | * 32-bit ELF section header |
204 | * 32-bit ELF section header |
203 | */ |
205 | */ |
204 | struct elf32_section_header { |
206 | struct elf32_section_header { |
205 | elf32_word sh_name; |
207 | elf32_word sh_name; |
206 | elf32_word sh_type; |
208 | elf32_word sh_type; |
207 | elf32_word sh_flags; |
209 | elf32_word sh_flags; |
208 | elf32_addr sh_addr; |
210 | elf32_addr sh_addr; |
209 | elf32_off sh_offset; |
211 | elf32_off sh_offset; |
210 | elf32_word sh_size; |
212 | elf32_word sh_size; |
211 | elf32_word sh_link; |
213 | elf32_word sh_link; |
212 | elf32_word sh_info; |
214 | elf32_word sh_info; |
213 | elf32_word sh_addralign; |
215 | elf32_word sh_addralign; |
214 | elf32_word sh_entsize; |
216 | elf32_word sh_entsize; |
215 | }; |
217 | }; |
216 | 218 | ||
217 | 219 | ||
218 | /* |
220 | /* |
219 | * 32-bit ELF symbol table entry |
221 | * 32-bit ELF symbol table entry |
220 | */ |
222 | */ |
221 | struct elf32_symbol { |
223 | struct elf32_symbol { |
222 | elf32_word st_name; |
224 | elf32_word st_name; |
223 | elf32_addr st_value; |
225 | elf32_addr st_value; |
224 | elf32_word st_size; |
226 | elf32_word st_size; |
225 | __u8 st_info; |
227 | __u8 st_info; |
226 | __u8 st_other; |
228 | __u8 st_other; |
227 | elf32_half st_shndx; |
229 | elf32_half st_shndx; |
228 | }; |
230 | }; |
229 | 231 | ||
230 | 232 | ||
231 | /* |
233 | /* |
232 | * 32-bit ELF program header |
234 | * 32-bit ELF program header |
233 | */ |
235 | */ |
234 | struct elf32_program_header { |
236 | struct elf32_program_header { |
235 | elf32_word p_type; |
237 | elf32_word p_type; |
236 | elf32_off p_offset; |
238 | elf32_off p_offset; |
237 | elf32_addr pv_addr; |
239 | elf32_addr pv_addr; |
238 | elf32_addr pp_addr; |
240 | elf32_addr pp_addr; |
239 | elf32_word p_filesz; |
241 | elf32_word p_filesz; |
240 | elf32_word p_memsz; |
242 | elf32_word p_memsz; |
241 | elf32_word p_flags; |
243 | elf32_word p_flags; |
242 | elf32_word p_align; |
244 | elf32_word p_align; |
243 | }; |
245 | }; |
244 | 246 | ||
245 | typedef struct elf32_header elf32_header_t; |
247 | typedef struct elf32_header elf32_header_t; |
246 | typedef struct elf32_section_header elf32_section_header_t; |
248 | typedef struct elf32_section_header elf32_section_header_t; |
247 | typedef struct elf32_symbol elf32_symbol_t; |
249 | typedef struct elf32_symbol elf32_symbol_t; |
248 | typedef struct elf32_program_header elf32_program_header_t; |
250 | typedef struct elf32_program_header elf32_program_header_t; |
249 | 251 | ||
250 | 252 | ||
251 | 253 | ||
252 | extern int elf32_load(__address header, as_t * as); |
254 | extern int elf32_load(__address header, as_t * as); |
253 | 255 | ||
254 | #endif |
256 | #endif |
255 | 257 |