4 /* Standard ELF types. */
8 #include <arch/boot/boot.h>
10 /* Type for a 16-bit quantity. */
11 typedef uint16_t Elf32_Half;
12 typedef uint16_t Elf64_Half;
14 /* Types for signed and unsigned 32-bit quantities. */
15 typedef uint32_t Elf32_Word;
16 typedef int32_t Elf32_Sword;
17 typedef uint32_t Elf64_Word;
18 typedef int32_t Elf64_Sword;
20 /* Types for signed and unsigned 64-bit quantities. */
21 typedef uint64_t Elf32_Xword;
22 typedef int64_t Elf32_Sxword;
23 typedef uint64_t Elf64_Xword;
24 typedef int64_t Elf64_Sxword;
26 /* Type of addresses. */
27 typedef uint32_t Elf32_Addr;
28 typedef uint64_t Elf64_Addr;
30 /* Type of file offsets. */
31 typedef uint32_t Elf32_Off;
32 typedef uint64_t Elf64_Off;
34 /* Type for section indices, which are 16-bit quantities. */
35 typedef uint16_t Elf32_Section;
36 typedef uint16_t Elf64_Section;
38 /* Type of symbol indices. */
39 typedef uint32_t Elf32_Symndx;
40 typedef uint64_t Elf64_Symndx;
43 /* The ELF file header. This appears at the start of every ELF file. */
45 #define EI_NIDENT (16)
49 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
50 Elf32_Half e_type; /* Object file type */
51 Elf32_Half e_machine; /* Architecture */
52 Elf32_Word e_version; /* Object file version */
53 Elf32_Addr e_entry; /* Entry point virtual address */
54 Elf32_Off e_phoff; /* Program header table file offset */
55 Elf32_Off e_shoff; /* Section header table file offset */
56 Elf32_Word e_flags; /* Processor-specific flags */
57 Elf32_Half e_ehsize; /* ELF header size in bytes */
58 Elf32_Half e_phentsize; /* Program header table entry size */
59 Elf32_Half e_phnum; /* Program header table entry count */
60 Elf32_Half e_shentsize; /* Section header table entry size */
61 Elf32_Half e_shnum; /* Section header table entry count */
62 Elf32_Half e_shstrndx; /* Section header string table index */
67 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
68 Elf64_Half e_type; /* Object file type */
69 Elf64_Half e_machine; /* Architecture */
70 Elf64_Word e_version; /* Object file version */
71 Elf64_Addr e_entry; /* Entry point virtual address */
72 Elf64_Off e_phoff; /* Program header table file offset */
73 Elf64_Off e_shoff; /* Section header table file offset */
74 Elf64_Word e_flags; /* Processor-specific flags */
75 Elf64_Half e_ehsize; /* ELF header size in bytes */
76 Elf64_Half e_phentsize; /* Program header table entry size */
77 Elf64_Half e_phnum; /* Program header table entry count */
78 Elf64_Half e_shentsize; /* Section header table entry size */
79 Elf64_Half e_shnum; /* Section header table entry count */
80 Elf64_Half e_shstrndx; /* Section header string table index */
83 /* Fields in the e_ident array. The EI_* macros are indices into the
84 array. The macros under each EI_* macro are the values the byte
87 #define EI_MAG0 0 /* File identification byte 0 index */
88 #define ELFMAG0 0x7f /* Magic number byte 0 */
90 #define EI_MAG1 1 /* File identification byte 1 index */
91 #define ELFMAG1 'E' /* Magic number byte 1 */
93 #define EI_MAG2 2 /* File identification byte 2 index */
94 #define ELFMAG2 'L' /* Magic number byte 2 */
96 #define EI_MAG3 3 /* File identification byte 3 index */
97 #define ELFMAG3 'F' /* Magic number byte 3 */
99 /* Conglomeration of the identification bytes, for easy testing as a word. */
100 #define ELFMAG "\177ELF"
103 #define EI_CLASS 4 /* File class byte index */
104 #define ELFCLASSNONE 0 /* Invalid class */
105 #define ELFCLASS32 1 /* 32-bit objects */
106 #define ELFCLASS64 2 /* 64-bit objects */
107 #define ELFCLASSNUM 3
109 #define EI_DATA 5 /* Data encoding byte index */
110 #define ELFDATANONE 0 /* Invalid data encoding */
111 #define ELFDATA2LSB 1 /* 2's complement, little endian */
112 #define ELFDATA2MSB 2 /* 2's complement, big endian */
115 #define EI_VERSION 6 /* File version byte index */
116 /* Value must be EV_CURRENT */
118 #define EI_OSABI 7 /* OS ABI identification */
119 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
120 #define ELFOSABI_HPUX 1 /* HP-UX */
121 #define ELFOSABI_ARM 97 /* ARM */
122 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
124 #define EI_ABIVERSION 8 /* ABI version */
126 #define EI_PAD 9 /* Byte index of padding bytes */
128 /* Legal values for e_type (object file type). */
130 #define ET_NONE 0 /* No file type */
131 #define ET_REL 1 /* Relocatable file */
132 #define ET_EXEC 2 /* Executable file */
133 #define ET_DYN 3 /* Shared object file */
134 #define ET_CORE 4 /* Core file */
135 #define ET_NUM 5 /* Number of defined types */
136 #define ET_LOPROC 0xff00 /* Processor-specific */
137 #define ET_HIPROC 0xffff /* Processor-specific */
139 /* Legal values for e_machine (architecture). */
141 #define EM_NONE 0 /* No machine */
142 #define EM_M32 1 /* AT&T WE 32100 */
143 #define EM_SPARC 2 /* SUN SPARC */
144 #define EM_386 3 /* Intel 80386 */
145 #define EM_68K 4 /* Motorola m68k family */
146 #define EM_88K 5 /* Motorola m88k family */
147 #define EM_486 6 /* Intel 80486 */
148 #define EM_860 7 /* Intel 80860 */
149 #define EM_MIPS 8 /* MIPS R3000 big-endian */
150 #define EM_S370 9 /* Amdahl */
151 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
152 #define EM_RS6000 11 /* RS6000 */
154 #define EM_PARISC 15 /* HPPA */
155 #define EM_nCUBE 16 /* nCUBE */
156 #define EM_VPP500 17 /* Fujitsu VPP500 */
157 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
158 #define EM_960 19 /* Intel 80960 */
159 #define EM_PPC 20 /* PowerPC */
161 #define EM_V800 36 /* NEC V800 series */
162 #define EM_FR20 37 /* Fujitsu FR20 */
163 #define EM_RH32 38 /* TRW RH32 */
164 #define EM_MMA 39 /* Fujitsu MMA */
165 #define EM_ARM 40 /* ARM */
166 #define EM_FAKE_ALPHA 41 /* Digital Alpha */
167 #define EM_SH 42 /* Hitachi SH */
168 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
169 #define EM_TRICORE 44 /* Siemens Tricore */
170 #define EM_ARC 45 /* Argonaut RISC Core */
171 #define EM_H8_300 46 /* Hitachi H8/300 */
172 #define EM_H8_300H 47 /* Hitachi H8/300H */
173 #define EM_H8S 48 /* Hitachi H8S */
174 #define EM_H8_500 49 /* Hitachi H8/500 */
175 #define EM_IA_64 50 /* Intel Merced */
176 #define EM_MIPS_X 51 /* Stanford MIPS-X */
177 #define EM_COLDFIRE 52 /* Motorola Coldfire */
178 #define EM_68HC12 53 /* Motorola M68HC12 */
181 /* If it is necessary to assign new unofficial EM_* values, please
182 pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
183 chances of collision with official or non-GNU unofficial values. */
185 #define EM_ALPHA 0x9026
187 /* Legal values for e_version (version). */
189 #define EV_NONE 0 /* Invalid ELF version */
190 #define EV_CURRENT 1 /* Current version */
194 /* Program segment header. */
198 Elf32_Word p_type; /* Segment type */
199 Elf32_Off p_offset; /* Segment file offset */
200 Elf32_Addr p_vaddr; /* Segment virtual address */
201 Elf32_Addr p_paddr; /* Segment physical address */
202 Elf32_Word p_filesz; /* Segment size in file */
203 Elf32_Word p_memsz; /* Segment size in memory */
204 Elf32_Word p_flags; /* Segment flags */
205 Elf32_Word p_align; /* Segment alignment */
210 Elf64_Word p_type; /* Segment type */
211 Elf64_Word p_flags; /* Segment flags */
212 Elf64_Off p_offset; /* Segment file offset */
213 Elf64_Addr p_vaddr; /* Segment virtual address */
214 Elf64_Addr p_paddr; /* Segment physical address */
215 Elf64_Xword p_filesz; /* Segment size in file */
216 Elf64_Xword p_memsz; /* Segment size in memory */
217 Elf64_Xword p_align; /* Segment alignment */
220 /* Legal values for p_type (segment type). */
222 #define PT_NULL 0 /* Program header table entry unused */
223 #define PT_LOAD 1 /* Loadable program segment */
224 #define PT_DYNAMIC 2 /* Dynamic linking information */
225 #define PT_INTERP 3 /* Program interpreter */
226 #define PT_NOTE 4 /* Auxiliary information */
227 #define PT_SHLIB 5 /* Reserved */
228 #define PT_PHDR 6 /* Entry for header table itself */
229 #define PT_NUM 7 /* Number of defined types. */
230 #define PT_LOOS 0x60000000 /* Start of OS-specific */
231 #define PT_HIOS 0x6fffffff /* End of OS-specific */
232 #define PT_LOPROC 0x70000000 /* Start of processor-specific */
233 #define PT_HIPROC 0x7fffffff /* End of processor-specific */
235 /* Legal values for p_flags (segment flags). */
237 #define PF_X (1 << 0) /* Segment is executable */
238 #define PF_W (1 << 1) /* Segment is writable */
239 #define PF_R (1 << 2) /* Segment is readable */
240 #define PF_MASKPROC 0xf0000000 /* Processor-specific */
243 /* Note section contents. Each entry in the note section begins with
244 a header of a fixed form. */
248 Elf32_Word n_namesz; /* Length of the note's name. */
249 Elf32_Word n_descsz; /* Length of the note's descriptor. */
250 Elf32_Word n_type; /* Type of the note. */
255 Elf64_Word n_namesz; /* Length of the note's name. */
256 Elf64_Word n_descsz; /* Length of the note's descriptor. */
257 Elf64_Word n_type; /* Type of the note. */
260 /* Known names of notes. */
262 /* Solaris entries in the note section have this name. */
263 #define ELF_NOTE_SOLARIS "SUNW Solaris"
265 /* Note entries for GNU systems have this name. */
266 #define ELF_NOTE_GNU "GNU"
269 /* Defined types of notes for Solaris. */
271 /* Value of descriptor (one word) is desired pagesize for the binary. */
272 #define ELF_NOTE_PAGESIZE_HINT 1
275 /* Defined note types for GNU systems. */
277 /* ABI information. The descriptor consists of words:
278 word 0: OS descriptor
279 word 1: major version of the ABI
280 word 2: minor version of the ABI
281 word 3: subminor version of the ABI
283 #define ELF_NOTE_ABI 1
285 /* Known OSes. These value can appear in word 0 of an ELF_NOTE_ABI
286 note section entry. */
287 #define ELF_NOTE_OS_LINUX 0
288 #define ELF_NOTE_OS_GNU 1
289 #define ELF_NOTE_OS_SOLARIS2 2
292 /* Motorola 68k specific definitions. */
294 /* Intel 80386 specific definitions. */
296 /* SUN SPARC specific definitions. */
298 /* Values for Elf64_Ehdr.e_flags. */
300 #define EF_SPARCV9_MM 3
301 #define EF_SPARCV9_TSO 0
302 #define EF_SPARCV9_PSO 1
303 #define EF_SPARCV9_RMO 2
304 #define EF_SPARC_EXT_MASK 0xFFFF00
305 #define EF_SPARC_SUN_US1 0x000200
306 #define EF_SPARC_HAL_R1 0x000400
308 /* MIPS R3000 specific definitions. */
310 /* Legal values for e_flags field of Elf32_Ehdr. */
312 #define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */
313 #define EF_MIPS_PIC 2 /* Contains PIC code */
314 #define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */
315 #define EF_MIPS_XGOT 8
316 #define EF_MIPS_64BIT_WHIRL 16
317 #define EF_MIPS_ABI2 32
318 #define EF_MIPS_ABI_ON32 64
319 #define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */
321 /* Legal values for MIPS architecture level. */
323 #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
324 #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
325 #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
326 #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
327 #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
329 /* Legal values for p_type field of Elf32_Phdr. */
331 #define PT_MIPS_REGINFO 0x70000000 /* Register usage information */
332 #define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */
333 #define PT_MIPS_OPTIONS 0x70000002
335 /* Special program header types. */
337 #define PF_MIPS_LOCAL 0x10000000
340 /* HPPA specific definitions. */
342 /* Legal values for e_flags field of Elf32_Ehdr. */
344 #define EF_PARISC_TRAPNL 1 /* Trap nil pointer dereference. */
345 #define EF_PARISC_EXT 2 /* Program uses arch. extensions. */
346 #define EF_PARISC_ARCH 0xffff0000 /* Architecture version. */
347 /* Defined values are:
348 0x020b PA-RISC 1.0 big-endian
349 0x0210 PA-RISC 1.1 big-endian
350 0x028b PA-RISC 1.0 little-endian
351 0x0290 PA-RISC 1.1 little-endian
355 /* Alpha specific definitions. */
357 /* Legal values for e_flags field of Elf64_Ehdr. */
359 #define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */
360 #define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */
363 /* PowerPC specific declarations */
365 /* ARM specific declarations */
367 /* Processor specific flags for the ELF header e_flags field. */
368 #define EF_ARM_RELEXEC 0x01
369 #define EF_ARM_HASENTRY 0x02
370 #define EF_ARM_INTERWORK 0x04
371 #define EF_ARM_APCS_26 0x08
372 #define EF_ARM_APCS_FLOAT 0x10
373 #define EF_ARM_PIC 0x20
374 #define EF_ALIGN8 0x40 /* 8-bit structure alignment is in use */
375 #define EF_NEW_ABI 0x80
376 #define EF_OLD_ABI 0x100
378 /* ARM-specific program header flags */
379 #define PF_ARM_SB 0x10000000 /* Segment contains the location
380 addressed by the static base */
382 #if ELF_CLASS == ELFCLASS32
383 typedef Elf32_Ehdr Elf_ehdr;
384 typedef Elf32_Phdr Elf_phdr;
387 #if ELF_CLASS == ELFCLASS64
388 typedef Elf64_Ehdr Elf_ehdr;
389 typedef Elf64_Phdr Elf_phdr;
392 int elf_check_arch(Elf_ehdr *ehdr);
393 void jmp_to_elf_entry(void *entry, unsigned long buffer, unsigned long bounce_size);
395 int elfboot(struct lb_memory *mem);
396 /* Temporary compile fix, FILO should be dropped from coreboot */
397 int filo(struct lb_memory *mem);
399 #define FIRMWARE_TYPE "coreboot"
400 #define BOOTLOADER "elfboot"
401 #define BOOTLOADER_VERSION "1.3"