source: mainline/kernel/generic/include/lib/elf.h@ 74e6b1f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 74e6b1f was 74e6b1f, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Write register state to core files (amd64).

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