source: mainline/abi/include/elf.h@ 207e8880

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 207e8880 was c0699467, checked in by Martin Decky <martin@…>, 14 years ago

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 * Copyright (c) 2006 Sergey Bondari
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup generic
30 * @{
31 */
32/** @file
33 */
34
35#ifndef ABI_ELF_H_
36#define ABI_ELF_H_
37
38/**
39 * Current ELF version
40 */
41#define EV_CURRENT 1
42
43/**
44 * ELF types
45 */
46#define ET_NONE 0 /* No type */
47#define ET_REL 1 /* Relocatable file */
48#define ET_EXEC 2 /* Executable */
49#define ET_DYN 3 /* Shared object */
50#define ET_CORE 4 /* Core */
51#define ET_LOPROC 0xff00 /* Processor specific */
52#define ET_HIPROC 0xffff /* Processor specific */
53
54/**
55 * ELF machine types
56 */
57#define EM_NO 0 /* No machine */
58#define EM_SPARC 2 /* SPARC */
59#define EM_386 3 /* i386 */
60#define EM_MIPS 8 /* MIPS RS3000 */
61#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 LE */
62#define EM_PPC 20 /* PPC32 */
63#define EM_PPC64 21 /* PPC64 */
64#define EM_ARM 40 /* ARM */
65#define EM_SPARCV9 43 /* SPARC64 */
66#define EM_IA_64 50 /* IA-64 */
67#define EM_X86_64 62 /* AMD64/EMT64 */
68
69/**
70 * ELF identification indexes
71 */
72#define EI_MAG0 0
73#define EI_MAG1 1
74#define EI_MAG2 2
75#define EI_MAG3 3
76#define EI_CLASS 4 /* File class */
77#define EI_DATA 5 /* Data encoding */
78#define EI_VERSION 6 /* File version */
79#define EI_OSABI 7
80#define EI_ABIVERSION 8
81#define EI_PAD 9 /* Start of padding bytes */
82#define EI_NIDENT 16 /* ELF identification table size */
83
84/**
85 * ELF magic number
86 */
87#define ELFMAG0 0x7f
88#define ELFMAG1 'E'
89#define ELFMAG2 'L'
90#define ELFMAG3 'F'
91
92/**
93 * ELF file classes
94 */
95#define ELFCLASSNONE 0
96#define ELFCLASS32 1
97#define ELFCLASS64 2
98
99/**
100 * ELF data encoding types
101 */
102#define ELFDATANONE 0
103#define ELFDATA2LSB 1 /* Least significant byte first (little endian) */
104#define ELFDATA2MSB 2 /* Most signigicant byte first (big endian) */
105
106/**
107 * ELF section types
108 */
109#define SHT_NULL 0
110#define SHT_PROGBITS 1
111#define SHT_SYMTAB 2
112#define SHT_STRTAB 3
113#define SHT_RELA 4
114#define SHT_HASH 5
115#define SHT_DYNAMIC 6
116#define SHT_NOTE 7
117#define SHT_NOBITS 8
118#define SHT_REL 9
119#define SHT_SHLIB 10
120#define SHT_DYNSYM 11
121#define SHT_LOOS 0x60000000
122#define SHT_HIOS 0x6fffffff
123#define SHT_LOPROC 0x70000000
124#define SHT_HIPROC 0x7fffffff
125#define SHT_LOUSER 0x80000000
126#define SHT_HIUSER 0xffffffff
127
128/**
129 * ELF section flags
130 */
131#define SHF_WRITE 0x1
132#define SHF_ALLOC 0x2
133#define SHF_EXECINSTR 0x4
134#define SHF_TLS 0x400
135#define SHF_MASKPROC 0xf0000000
136
137/** Macros for decomposing elf_symbol.st_info into binging and type */
138#define ELF_ST_BIND(i) ((i) >> 4)
139#define ELF_ST_TYPE(i) ((i) & 0x0f)
140#define ELF_ST_INFO(b, t) (((b) << 4) + ((t) & 0x0f))
141
142/**
143 * Symbol binding
144 */
145#define STB_LOCAL 0
146#define STB_GLOBAL 1
147#define STB_WEAK 2
148#define STB_LOPROC 13
149#define STB_HIPROC 15
150
151/**
152 * Symbol types
153 */
154#define STT_NOTYPE 0
155#define STT_OBJECT 1
156#define STT_FUNC 2
157#define STT_SECTION 3
158#define STT_FILE 4
159#define STT_LOPROC 13
160#define STT_HIPROC 15
161
162/**
163 * Program segment types
164 */
165#define PT_NULL 0
166#define PT_LOAD 1
167#define PT_DYNAMIC 2
168#define PT_INTERP 3
169#define PT_NOTE 4
170#define PT_SHLIB 5
171#define PT_PHDR 6
172#define PT_LOPROC 0x70000000
173#define PT_HIPROC 0x7fffffff
174
175/**
176 * Program segment attributes.
177 */
178#define PF_X 1
179#define PF_W 2
180#define PF_R 4
181
182/**
183 * ELF data types
184 *
185 * These types are found to be identical in both 32-bit and 64-bit
186 * ELF object file specifications. They are the only types used
187 * in ELF header.
188 */
189typedef uint64_t elf_xword;
190typedef int64_t elf_sxword;
191typedef uint32_t elf_word;
192typedef int32_t elf_sword;
193typedef uint16_t elf_half;
194
195/**
196 * 32-bit ELF data types.
197 *
198 * These types are specific for 32-bit format.
199 */
200typedef uint32_t elf32_addr;
201typedef uint32_t elf32_off;
202
203/**
204 * 64-bit ELF data types.
205 *
206 * These types are specific for 64-bit format.
207 */
208typedef uint64_t elf64_addr;
209typedef uint64_t elf64_off;
210
211/** ELF header */
212struct elf32_header {
213 uint8_t e_ident[EI_NIDENT];
214 elf_half e_type;
215 elf_half e_machine;
216 elf_word e_version;
217 elf32_addr e_entry;
218 elf32_off e_phoff;
219 elf32_off e_shoff;
220 elf_word e_flags;
221 elf_half e_ehsize;
222 elf_half e_phentsize;
223 elf_half e_phnum;
224 elf_half e_shentsize;
225 elf_half e_shnum;
226 elf_half e_shstrndx;
227};
228
229struct elf64_header {
230 uint8_t e_ident[EI_NIDENT];
231 elf_half e_type;
232 elf_half e_machine;
233 elf_word e_version;
234 elf64_addr e_entry;
235 elf64_off e_phoff;
236 elf64_off e_shoff;
237 elf_word e_flags;
238 elf_half e_ehsize;
239 elf_half e_phentsize;
240 elf_half e_phnum;
241 elf_half e_shentsize;
242 elf_half e_shnum;
243 elf_half e_shstrndx;
244};
245
246/**
247 * ELF segment header.
248 * Segments headers are also known as program headers.
249 */
250struct elf32_segment_header {
251 elf_word p_type;
252 elf32_off p_offset;
253 elf32_addr p_vaddr;
254 elf32_addr p_paddr;
255 elf_word p_filesz;
256 elf_word p_memsz;
257 elf_word p_flags;
258 elf_word p_align;
259};
260
261struct elf64_segment_header {
262 elf_word p_type;
263 elf_word p_flags;
264 elf64_off p_offset;
265 elf64_addr p_vaddr;
266 elf64_addr p_paddr;
267 elf_xword p_filesz;
268 elf_xword p_memsz;
269 elf_xword p_align;
270};
271
272/**
273 * ELF section header
274 */
275struct elf32_section_header {
276 elf_word sh_name;
277 elf_word sh_type;
278 elf_word sh_flags;
279 elf32_addr sh_addr;
280 elf32_off sh_offset;
281 elf_word sh_size;
282 elf_word sh_link;
283 elf_word sh_info;
284 elf_word sh_addralign;
285 elf_word sh_entsize;
286};
287
288struct elf64_section_header {
289 elf_word sh_name;
290 elf_word sh_type;
291 elf_xword sh_flags;
292 elf64_addr sh_addr;
293 elf64_off sh_offset;
294 elf_xword sh_size;
295 elf_word sh_link;
296 elf_word sh_info;
297 elf_xword sh_addralign;
298 elf_xword sh_entsize;
299};
300
301/**
302 * ELF symbol table entry
303 */
304struct elf32_symbol {
305 elf_word st_name;
306 elf32_addr st_value;
307 elf_word st_size;
308 uint8_t st_info;
309 uint8_t st_other;
310 elf_half st_shndx;
311};
312
313struct elf64_symbol {
314 elf_word st_name;
315 uint8_t st_info;
316 uint8_t st_other;
317 elf_half st_shndx;
318 elf64_addr st_value;
319 elf_xword st_size;
320};
321
322/*
323 * ELF note segment entry
324 */
325struct elf32_note {
326 elf_word namesz;
327 elf_word descsz;
328 elf_word type;
329};
330
331/*
332 * NOTE: namesz, descsz and type should be 64-bits wide (elf_xword)
333 * per the 64-bit ELF spec. The Linux kernel however screws up and
334 * defines them as Elf64_Word, which is 32-bits wide(!). We are trying
335 * to make our core files compatible with Linux GDB target so we copy
336 * the blunder here.
337 */
338struct elf64_note {
339 elf_word namesz;
340 elf_word descsz;
341 elf_word type;
342};
343
344#ifdef __32_BITS__
345typedef struct elf32_header elf_header_t;
346typedef struct elf32_segment_header elf_segment_header_t;
347typedef struct elf32_section_header elf_section_header_t;
348typedef struct elf32_symbol elf_symbol_t;
349typedef struct elf32_note elf_note_t;
350#endif
351
352#ifdef __64_BITS__
353typedef struct elf64_header elf_header_t;
354typedef struct elf64_segment_header elf_segment_header_t;
355typedef struct elf64_section_header elf_section_header_t;
356typedef struct elf64_symbol elf_symbol_t;
357typedef struct elf64_note elf_note_t;
358#endif
359
360#endif
361
362/** @}
363 */
Note: See TracBrowser for help on using the repository browser.