[zbin] Fix check for existence of most recent output byte
[ipxe.git] / src / include / elf.h
1 #ifndef ELF_H
2 #define ELF_H
3
4 FILE_LICENCE ( GPL2_OR_LATER );
5
6 #define EI_NIDENT 16 /* Size of e_ident array. */
7
8 /* Values for e_type. */
9 #define ET_NONE 0 /* No file type */
10 #define ET_REL 1 /* Relocatable file */
11 #define ET_EXEC 2 /* Executable file */
12 #define ET_DYN 3 /* Shared object file */
13 #define ET_CORE 4 /* Core file */
14
15 /* Values for e_machine (architecute). */
16 #define EM_NONE 0 /* No machine */
17 #define EM_M32 1 /* AT&T WE 32100 */
18 #define EM_SPARC 2 /* SUN SPARC */
19 #define EM_386 3 /* Intel 80386+ */
20 #define EM_68K 4 /* Motorola m68k family */
21 #define EM_88K 5 /* Motorola m88k family */
22 #define EM_486 6 /* Perhaps disused */
23 #define EM_860 7 /* Intel 80860 */
24 #define EM_MIPS 8 /* MIPS R3000 big-endian */
25 #define EM_S370 9 /* IBM System/370 */
26 #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */
27
28 #define EM_PARISC 15 /* HPPA */
29 #define EM_VPP500 17 /* Fujitsu VPP500 */
30 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
31 #define EM_960 19 /* Intel 80960 */
32 #define EM_PPC 20 /* PowerPC */
33 #define EM_PPC64 21 /* PowerPC 64-bit */
34 #define EM_S390 22 /* IBM S390 */
35
36 #define EM_V800 36 /* NEC V800 series */
37 #define EM_FR20 37 /* Fujitsu FR20 */
38 #define EM_RH32 38 /* TRW RH-32 */
39 #define EM_RCE 39 /* Motorola RCE */
40 #define EM_ARM 40 /* ARM */
41 #define EM_FAKE_ALPHA 41 /* Digital Alpha */
42 #define EM_SH 42 /* Hitachi SH */
43 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
44 #define EM_TRICORE 44 /* Siemens Tricore */
45 #define EM_ARC 45 /* Argonaut RISC Core */
46 #define EM_H8_300 46 /* Hitachi H8/300 */
47 #define EM_H8_300H 47 /* Hitachi H8/300H */
48 #define EM_H8S 48 /* Hitachi H8S */
49 #define EM_H8_500 49 /* Hitachi H8/500 */
50 #define EM_IA_64 50 /* Intel Merced */
51 #define EM_MIPS_X 51 /* Stanford MIPS-X */
52 #define EM_COLDFIRE 52 /* Motorola Coldfire */
53 #define EM_68HC12 53 /* Motorola M68HC12 */
54 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
55 #define EM_PCP 55 /* Siemens PCP */
56 #define EM_NCPU 56 /* Sony nCPU embeeded RISC */
57 #define EM_NDR1 57 /* Denso NDR1 microprocessor */
58 #define EM_STARCORE 58 /* Motorola Start*Core processor */
59 #define EM_ME16 59 /* Toyota ME16 processor */
60 #define EM_ST100 60 /* STMicroelectronic ST100 processor */
61 #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
62 #define EM_X86_64 62 /* AMD x86-64 architecture */
63 #define EM_PDSP 63 /* Sony DSP Processor */
64
65 #define EM_FX66 66 /* Siemens FX66 microcontroller */
66 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
67 #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
68 #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
69 #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
70 #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
71 #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
72 #define EM_SVX 73 /* Silicon Graphics SVx */
73 #define EM_AT19 74 /* STMicroelectronics ST19 8 bit mc */
74 #define EM_VAX 75 /* Digital VAX */
75 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
76 #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */
77 #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
78 #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
79 #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
80 #define EM_HUANY 81 /* Harvard University machine-independent object files */
81 #define EM_PRISM 82 /* SiTera Prism */
82 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
83 #define EM_FR30 84 /* Fujitsu FR30 */
84 #define EM_D10V 85 /* Mitsubishi D10V */
85 #define EM_D30V 86 /* Mitsubishi D30V */
86 #define EM_V850 87 /* NEC v850 */
87 #define EM_M32R 88 /* Mitsubishi M32R */
88 #define EM_MN10300 89 /* Matsushita MN10300 */
89 #define EM_MN10200 90 /* Matsushita MN10200 */
90 #define EM_PJ 91 /* picoJava */
91 #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
92 #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
93 #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
94 #define EM_NUM 95
95
96 /* Values for p_type. */
97 #define PT_NULL 0 /* Unused entry. */
98 #define PT_LOAD 1 /* Loadable segment. */
99 #define PT_DYNAMIC 2 /* Dynamic linking information segment. */
100 #define PT_INTERP 3 /* Pathname of interpreter. */
101 #define PT_NOTE 4 /* Auxiliary information. */
102 #define PT_SHLIB 5 /* Reserved (not used). */
103 #define PT_PHDR 6 /* Location of program header itself. */
104
105 /* Values for p_flags. */
106 #define PF_X 0x1 /* Executable. */
107 #define PF_W 0x2 /* Writable. */
108 #define PF_R 0x4 /* Readable. */
109
110
111 #define ELF_PROGRAM_RETURNS_BIT 0x8000000 /* e_flags bit 31 */
112
113 #define EI_MAG0 0
114 #define ELFMAG0 0x7f
115
116 #define EI_MAG1 1
117 #define ELFMAG1 'E'
118
119 #define EI_MAG2 2
120 #define ELFMAG2 'L'
121
122 #define EI_MAG3 3
123 #define ELFMAG3 'F'
124
125 #define ELFMAG "\177ELF"
126 #define SELFMAG 4
127
128 #define EI_CLASS 4 /* File class byte index */
129 #define ELFCLASSNONE 0 /* Invalid class */
130 #define ELFCLASS32 1 /* 32-bit objects */
131 #define ELFCLASS64 2 /* 64-bit objects */
132
133 #define EI_DATA 5 /* Data encodeing byte index */
134 #define ELFDATANONE 0 /* Invalid data encoding */
135 #define ELFDATA2LSB 1 /* 2's complement little endian */
136 #define ELFDATA2MSB 2 /* 2's complement big endian */
137
138 #define EI_VERSION 6 /* File version byte index */
139 /* Value must be EV_CURRENT */
140
141 #define EV_NONE 0 /* Invalid ELF Version */
142 #define EV_CURRENT 1 /* Current version */
143
144 #define ELF32_PHDR_SIZE (8*4) /* Size of an elf program header */
145
146 #ifndef ASSEMBLY
147
148 #include <stdint.h>
149
150 /*
151 * ELF definitions common to all 32-bit architectures.
152 */
153
154 typedef uint32_t Elf32_Addr;
155 typedef uint16_t Elf32_Half;
156 typedef uint32_t Elf32_Off;
157 typedef int32_t Elf32_Sword;
158 typedef uint32_t Elf32_Word;
159 typedef uint32_t Elf32_Size;
160
161 typedef uint64_t Elf64_Addr;
162 typedef uint16_t Elf64_Half;
163 typedef uint64_t Elf64_Off;
164 typedef int32_t Elf64_Sword;
165 typedef uint32_t Elf64_Word;
166 typedef uint64_t Elf64_Size;
167
168 /*
169 * ELF header.
170 */
171 typedef struct {
172 unsigned char e_ident[EI_NIDENT]; /* File identification. */
173 Elf32_Half e_type; /* File type. */
174 Elf32_Half e_machine; /* Machine architecture. */
175 Elf32_Word e_version; /* ELF format version. */
176 Elf32_Addr e_entry; /* Entry point. */
177 Elf32_Off e_phoff; /* Program header file offset. */
178 Elf32_Off e_shoff; /* Section header file offset. */
179 Elf32_Word e_flags; /* Architecture-specific flags. */
180 Elf32_Half e_ehsize; /* Size of ELF header in bytes. */
181 Elf32_Half e_phentsize; /* Size of program header entry. */
182 Elf32_Half e_phnum; /* Number of program header entries. */
183 Elf32_Half e_shentsize; /* Size of section header entry. */
184 Elf32_Half e_shnum; /* Number of section header entries. */
185 Elf32_Half e_shstrndx; /* Section name strings section. */
186 } Elf32_Ehdr;
187
188 typedef struct {
189 unsigned char e_ident[EI_NIDENT]; /* File identification. */
190 Elf64_Half e_type; /* File type. */
191 Elf64_Half e_machine; /* Machine architecture. */
192 Elf64_Word e_version; /* ELF format version. */
193 Elf64_Addr e_entry; /* Entry point. */
194 Elf64_Off e_phoff; /* Program header file offset. */
195 Elf64_Off e_shoff; /* Section header file offset. */
196 Elf64_Word e_flags; /* Architecture-specific flags. */
197 Elf64_Half e_ehsize; /* Size of ELF header in bytes. */
198 Elf64_Half e_phentsize; /* Size of program header entry. */
199 Elf64_Half e_phnum; /* Number of program header entries. */
200 Elf64_Half e_shentsize; /* Size of section header entry. */
201 Elf64_Half e_shnum; /* Number of section header entries. */
202 Elf64_Half e_shstrndx; /* Section name strings section. */
203 } Elf64_Ehdr;
204
205 /*
206 * Program header.
207 */
208 typedef struct {
209 Elf32_Word p_type; /* Entry type. */
210 Elf32_Off p_offset; /* File offset of contents. */
211 Elf32_Addr p_vaddr; /* Virtual address (not used). */
212 Elf32_Addr p_paddr; /* Physical address. */
213 Elf32_Size p_filesz; /* Size of contents in file. */
214 Elf32_Size p_memsz; /* Size of contents in memory. */
215 Elf32_Word p_flags; /* Access permission flags. */
216 Elf32_Size p_align; /* Alignment in memory and file. */
217 } Elf32_Phdr;
218
219 typedef struct {
220 Elf64_Word p_type; /* Entry type. */
221 Elf64_Word p_flags; /* Access permission flags. */
222 Elf64_Off p_offset; /* File offset of contents. */
223 Elf64_Addr p_vaddr; /* Virtual address (not used). */
224 Elf64_Addr p_paddr; /* Physical address. */
225 Elf64_Size p_filesz; /* Size of contents in file. */
226 Elf64_Size p_memsz; /* Size of contents in memory. */
227 Elf64_Size p_align; /* Alignment in memory and file. */
228 } Elf64_Phdr;
229
230 /* Standardized Elf image notes for booting... The name for all of these is ELFBoot */
231
232 #endif /* ASSEMBLY */
233
234 #endif /* ELF_H */