2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2001,2002 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* 32-bit data types */
22 typedef unsigned long Elf32_Addr
;
23 typedef unsigned short Elf32_Half
;
24 typedef unsigned long Elf32_Off
;
25 typedef signed long Elf32_Sword
;
26 typedef unsigned long Elf32_Word
;
27 /* "unsigned char" already exists */
35 /* first four characters are defined below */
45 #define EI_CLASS 4 /* data sizes */
46 #define ELFCLASS32 1 /* i386 -- up to 32-bit data sizes present */
48 #define EI_DATA 5 /* data type and ordering */
49 #define ELFDATA2LSB 1 /* i386 -- LSB 2's complement */
51 #define EI_VERSION 6 /* version number. "e_version" must be the same */
52 #define EV_CURRENT 1 /* current version number */
54 #define EI_OSABI 7 /* operating system/ABI indication */
55 #define ELFOSABI_FREEBSD 9
57 #define EI_ABIVERSION 8 /* ABI version */
59 #define EI_PAD 9 /* from here in is just padding */
61 #define EI_BRAND 8 /* start of OS branding (This is
62 obviously illegal against the ELF
65 unsigned char e_ident
[EI_NIDENT
]; /* basic identification block */
67 #define ET_EXEC 2 /* we only care about executable types */
68 Elf32_Half e_type
; /* file types */
70 #define EM_386 3 /* i386 -- obviously use this one */
71 Elf32_Half e_machine
; /* machine types */
72 Elf32_Word e_version
; /* use same as "EI_VERSION" above */
73 Elf32_Addr e_entry
; /* entry point of the program */
74 Elf32_Off e_phoff
; /* program header table file offset */
75 Elf32_Off e_shoff
; /* section header table file offset */
76 Elf32_Word e_flags
; /* flags */
77 Elf32_Half e_ehsize
; /* elf header size in bytes */
78 Elf32_Half e_phentsize
; /* program header entry size */
79 Elf32_Half e_phnum
; /* number of entries in program header */
80 Elf32_Half e_shentsize
; /* section header entry size */
81 Elf32_Half e_shnum
; /* number of entries in section header */
84 #define SHN_LORESERVE 0xff00
85 #define SHN_LOPROC 0xff00
86 #define SHN_HIPROC 0xff1f
87 #define SHN_ABS 0xfff1
88 #define SHN_COMMON 0xfff2
89 #define SHN_HIRESERVE 0xffff
90 Elf32_Half e_shstrndx
; /* section header table index */
95 #define BOOTABLE_I386_ELF(h) \
96 ((h.e_ident[EI_MAG0] == ELFMAG0) & (h.e_ident[EI_MAG1] == ELFMAG1) \
97 & (h.e_ident[EI_MAG2] == ELFMAG2) & (h.e_ident[EI_MAG3] == ELFMAG3) \
98 & (h.e_ident[EI_CLASS] == ELFCLASS32) & (h.e_ident[EI_DATA] == ELFDATA2LSB) \
99 & (h.e_ident[EI_VERSION] == EV_CURRENT) & (h.e_type == ET_EXEC) \
100 & (h.e_machine == EM_386) & (h.e_version == EV_CURRENT))
102 /* section table - ? */
105 Elf32_Word sh_name
; /* Section name (string tbl index) */
106 Elf32_Word sh_type
; /* Section type */
107 Elf32_Word sh_flags
; /* Section flags */
108 Elf32_Addr sh_addr
; /* Section virtual addr at execution */
109 Elf32_Off sh_offset
; /* Section file offset */
110 Elf32_Word sh_size
; /* Section size in bytes */
111 Elf32_Word sh_link
; /* Link to another section */
112 Elf32_Word sh_info
; /* Additional section information */
113 Elf32_Word sh_addralign
; /* Section alignment */
114 Elf32_Word sh_entsize
; /* Entry size if section holds table */
118 /* symbol table - page 4-25, figure 4-15 */
124 unsigned char st_info
;
125 unsigned char st_other
;
130 /* symbol type and binding attributes - page 4-26 */
132 #define ELF32_ST_BIND(i) ((i) >> 4)
133 #define ELF32_ST_TYPE(i) ((i) & 0xf)
134 #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
136 /* symbol binding - page 4-26, figure 4-16 */
141 #define STB_LOPROC 13
142 #define STB_HIPROC 15
144 /* symbol types - page 4-28, figure 4-17 */
149 #define STT_SECTION 3
151 #define STT_LOPROC 13
152 #define STT_HIPROC 15
155 /* Macros to split/combine relocation type and symbol page 4-32 */
157 #define ELF32_R_SYM(__i) ((__i)>>8)
158 #define ELF32_R_TYPE(__i) ((unsigned char) (__i))
159 #define ELF32_R_INFO(__s, __t) (((__s)<<8) + (unsigned char) (__t))
162 /* program header - page 5-2, figure 5-1 */
177 /* segment types - page 5-3, figure 5-2 */
187 #define PT_LOPROC 0x70000000
188 #define PT_HIPROC 0x7fffffff
190 /* segment permissions - page 5-6 */
195 #define PF_MASKPROC 0xf0000000
198 /* dynamic structure - page 5-15, figure 5-9 */
212 /* Dynamic array tags - page 5-16, figure 5-10. */
216 #define DT_PLTRELSZ 2
230 #define DT_SYMBOLIC 16
236 #define DT_TEXTREL 22