00001 /* 00002 * HT Editor 00003 * elfstruc.h 00004 * 00005 * Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de) 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 as 00009 * published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 /* mostly assembled from TIS ELF 1.1g and BFD-ELF */ 00022 00023 #ifndef __ELFSTRUC_H__ 00024 #define __ELFSTRUC_H__ 00025 00026 #include "global.h" 00027 00028 /* all architectures */ 00029 typedef unsigned char elf_unsigned_char; 00030 00031 /* 32bit architectures */ 00032 typedef dword elf32_addr; 00033 typedef word elf32_half; 00034 typedef dword elf32_off; 00035 typedef dword elf32_sword; 00036 typedef dword elf32_word; 00037 00038 /* 64bit architectures */ 00039 typedef qword elf64_addr; 00040 typedef qword elf64_off; 00041 typedef qword elf64_sword; 00042 typedef qword elf64_word; 00043 typedef dword elf64_half; 00044 typedef word elf64_quarter; 00045 00046 /* 00047 * ELF header 00048 */ 00049 00050 /* e_ident */ 00051 #define ELF_EI_MAG0 0 00052 #define ELF_EI_MAG1 1 00053 #define ELF_EI_MAG2 2 00054 #define ELF_EI_MAG3 3 00055 #define ELF_EI_CLASS 4 00056 #define ELF_EI_DATA 5 00057 #define ELF_EI_VERSION 6 00058 #define ELF_EI_OSABI 7 00059 #define ELF_EI_ABIVERSION 8 00060 #define ELF_EI_PAD 9 00061 00062 #define EI_NIDENT 16 00063 00064 #define ELFMAG0 0x7f 00065 #define ELFMAG1 'E' 00066 #define ELFMAG2 'L' 00067 #define ELFMAG3 'F' 00068 00069 #define ELFCLASSNONE 0 00070 #define ELFCLASS32 1 00071 #define ELFCLASS64 2 00072 00073 #define ELFDATANONE 0 00074 #define ELFDATA2LSB 1 00075 #define ELFDATA2MSB 2 00076 00077 #define ELFOSABI_SYSV 0 00078 #define ELFOSABI_HPUX 1 00079 #define ELFOSABI_NETBSD 2 00080 #define ELFOSABI_LINUX 3 00081 #define ELFOSABI_HURD 4 00082 #define ELFOSABI_86OPEN 5 00083 #define ELFOSABI_SOLARIS 6 00084 #define ELFOSABI_MONTEREY 7 00085 #define ELFOSABI_IRIX 8 00086 #define ELFOSABI_FREEBSD 9 00087 #define ELFOSABI_TRU64 10 00088 #define ELFOSABI_MODESTO 11 00089 #define ELFOSABI_OPENBSD 12 00090 #define ELFOSABI_ARM 97 00091 #define ELFOSABI_STANDALONE 255 00092 00093 /* e_type */ 00094 #define ELF_ET_NONE 0 00095 #define ELF_ET_REL 1 00096 #define ELF_ET_EXEC 2 00097 #define ELF_ET_DYN 3 00098 #define ELF_ET_CORE 4 00099 #define ELF_ET_LOOS 0xFE00 00100 #define ELF_ET_HIOS 0xFEFF 00101 #define ELF_ET_LOPROC 0xFF00 00102 #define ELF_ET_HIPROC 0xFFFF 00103 00104 /* e_machine */ 00105 #define ELF_EM_NONE 0 00106 #define ELF_EM_M32 1 00107 #define ELF_EM_SPARC 2 00108 #define ELF_EM_386 3 00109 #define ELF_EM_68K 4 00110 #define ELF_EM_88K 5 00111 #define ELF_EM_486 6 /* Intel 80486 */ 00112 #define ELF_EM_860 7 /* Intel 80860 */ 00113 #define ELF_EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */ 00114 #define ELF_EM_S370 9 /* IBM System/370 */ 00115 #define ELF_EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */ /* Depreciated */ 00116 #define ELF_EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian (Oct 4 1999 Draft)*/ /* Depreciated */ 00117 00118 #define ELF_EM_PARISC 15 /* HPPA */ 00119 00120 #define ELF_EM_VPP550 17 /* Fujitsu VPP500 */ 00121 #define ELF_EM_SPARC32PLUS 18 /* Sun's "v8plus" */ 00122 #define ELF_EM_960 19 /* Intel 80960 */ 00123 #define ELF_EM_PPC 20 /* PowerPC */ 00124 #define ELF_EM_PPC64 21 /* 64-bit PowerPC */ 00125 00126 #define ELF_EM_V800 36 /* NEC V800 series */ 00127 #define ELF_EM_FR20 37 /* Fujitsu FR20 */ 00128 #define ELF_EM_RH32 38 /* TRW RH32 */ 00129 #define ELF_EM_MCORE 39 /* Motorola M*Core */ /* May also be taken by Fujitsu MMA */ 00130 #define ELF_EM_RCE 39 /* Old name for MCore */ 00131 #define ELF_EM_ARM 40 /* ARM */ 00132 #define ELF_EM_OLD_ALPHA 41 /* Digital Alpha */ 00133 #define ELF_EM_SH 42 /* Hitachi SH */ 00134 #define ELF_EM_SPARCV9 43 /* SPARC v9 64-bit */ 00135 #define ELF_EM_TRICORE 44 /* Siemens Tricore embedded processor */ 00136 #define ELF_EM_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */ 00137 #define ELF_EM_H8_300 46 /* Hitachi H8/300 */ 00138 #define ELF_EM_H8_300H 47 /* Hitachi H8/300H */ 00139 #define ELF_EM_H8S 48 /* Hitachi H8S */ 00140 #define ELF_EM_H8_500 49 /* Hitachi H8/500 */ 00141 #define ELF_EM_IA_64 50 /* Intel IA-64 Processor */ 00142 #define ELF_EM_MIPS_X 51 /* Stanford MIPS-X */ 00143 #define ELF_EM_COLDFIRE 52 /* Motorola Coldfire */ 00144 #define ELF_EM_68HC12 53 /* Motorola M68HC12 */ 00145 #define ELF_EM_MMA 54 /* Fujitsu Multimedia Accelerator */ 00146 #define ELF_EM_PCP 55 /* Siemens PCP */ 00147 #define ELF_EM_NCPU 56 /* Sony nCPU embedded RISC processor */ 00148 #define ELF_EM_NDR1 57 /* Denso NDR1 microprocesspr */ 00149 #define ELF_EM_STARCORE 58 /* Motorola Star*Core processor */ 00150 #define ELF_EM_ME16 59 /* Toyota ME16 processor */ 00151 #define ELF_EM_ST100 60 /* STMicroelectronics ST100 processor */ 00152 #define ELF_EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor */ 00153 #define ELF_EM_X86_64 62 /* X86-64 (AMD Opteron) */ 00154 00155 #define ELF_EM_FX66 66 /* Siemens FX66 microcontroller */ 00156 #define ELF_EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ 00157 #define ELF_EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ 00158 #define ELF_EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ 00159 #define ELF_EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ 00160 #define ELF_EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ 00161 #define ELF_EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ 00162 #define ELF_EM_SVX 73 /* Silicon Graphics SVx */ 00163 #define ELF_EM_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */ 00164 #define ELF_EM_VAX 75 /* Digital VAX */ 00165 00166 #define ELF_EM_PJ 99 /* picoJava */ 00167 00168 /* e_version */ 00169 #define ELF_EV_NONE 0 00170 #define ELF_EV_CURRENT 1 00171 00172 struct ELF_HEADER { 00173 elf_unsigned_char e_ident[EI_NIDENT]; 00174 }; 00175 00176 struct ELF_HEADER32 { 00177 elf32_half e_type; 00178 elf32_half e_machine; 00179 elf32_word e_version; 00180 elf32_addr e_entry; 00181 elf32_off e_phoff; 00182 elf32_off e_shoff; 00183 elf32_word e_flags; 00184 elf32_half e_ehsize; 00185 elf32_half e_phentsize; 00186 elf32_half e_phnum; 00187 elf32_half e_shentsize; 00188 elf32_half e_shnum; 00189 elf32_half e_shstrndx; 00190 }; 00191 00192 struct ELF_HEADER64 { 00193 elf64_quarter e_type; 00194 elf64_quarter e_machine; 00195 elf64_half e_version; 00196 elf64_addr e_entry; 00197 elf64_off e_phoff; 00198 elf64_off e_shoff; 00199 elf64_half e_flags; 00200 elf64_quarter e_ehsize; 00201 elf64_quarter e_phentsize; 00202 elf64_quarter e_phnum; 00203 elf64_quarter e_shentsize; 00204 elf64_quarter e_shnum; 00205 elf64_quarter e_shstrndx; 00206 }; 00207 00208 /* 00209 * ELF section header 00210 */ 00211 00212 /* indices */ 00213 #define ELF_SHN_UNDEF 0 00214 #define ELF_SHN_ABS 0xfff1 00215 #define ELF_SHN_COMMON 0xfff2 00216 00217 /* sh_type */ 00218 #define ELF_SHT_NULL 0 00219 #define ELF_SHT_PROGBITS 1 00220 #define ELF_SHT_SYMTAB 2 00221 #define ELF_SHT_STRTAB 3 00222 #define ELF_SHT_RELA 4 00223 #define ELF_SHT_HASH 5 00224 #define ELF_SHT_DYNAMIC 6 00225 #define ELF_SHT_NOTE 7 00226 #define ELF_SHT_NOBITS 8 00227 #define ELF_SHT_REL 9 00228 #define ELF_SHT_SHLIB 10 00229 #define ELF_SHT_DYNSYM 11 00230 00231 #define ELF_SHT_INIT_ARRAY 14 00232 #define ELF_SHT_FINI_ARRAY 15 00233 #define ELF_SHT_PREINIT_ARRAY 16 00234 00235 /* sh_flags */ 00236 #define ELF_SHF_WRITE (1<<0) 00237 #define ELF_SHF_ALLOC (1<<1) 00238 #define ELF_SHF_EXECINSTR (1<<2) 00239 // 1<<3 missing 00240 #define ELF_SHF_MERGE (1<<4) 00241 #define ELF_SHF_STRINGS (1<<5) 00242 #define ELF_SHF_INFO_LINK (1<<6) 00243 #define ELF_SHF_LINK_ORDER (1<<7) 00244 #define ELF_SHF_OS_NONCONFORMING (1<<8) 00245 00246 struct ELF_SECTION_HEADER32 { 00247 elf32_word sh_name; 00248 elf32_word sh_type; 00249 elf32_word sh_flags; 00250 elf32_addr sh_addr; 00251 elf32_off sh_offset; 00252 elf32_word sh_size; 00253 elf32_word sh_link; 00254 elf32_word sh_info; 00255 elf32_word sh_addralign; 00256 elf32_word sh_entsize; 00257 }; 00258 00259 struct ELF_SECTION_HEADER64 { 00260 elf64_half sh_name; 00261 elf64_half sh_type; 00262 elf64_word sh_flags; 00263 elf64_addr sh_addr; 00264 elf64_off sh_offset; 00265 elf64_word sh_size; 00266 elf64_half sh_link; 00267 elf64_half sh_info; 00268 elf64_word sh_addralign; 00269 elf64_word sh_entsize; 00270 }; 00271 00272 /* 00273 * ELF program header 00274 */ 00275 00276 #define ELF_PT_NULL 0 00277 #define ELF_PT_LOAD 1 00278 #define ELF_PT_DYNAMIC 2 00279 #define ELF_PT_INTERP 3 00280 #define ELF_PT_NOTE 4 00281 #define ELF_PT_SHLIB 5 00282 #define ELF_PT_PHDR 6 00283 00284 struct ELF_PROGRAM_HEADER32 { 00285 elf32_word p_type; 00286 elf32_off p_offset; 00287 elf32_addr p_vaddr; 00288 elf32_addr p_paddr; 00289 elf32_word p_filesz; 00290 elf32_word p_memsz; 00291 elf32_word p_flags; 00292 elf32_word p_align; 00293 }; 00294 00295 struct ELF_PROGRAM_HEADER64 { 00296 elf64_half p_type; 00297 elf64_half p_flags; 00298 elf64_off p_offset; 00299 elf64_addr p_vaddr; 00300 elf64_addr p_paddr; 00301 elf64_word p_filesz; 00302 elf64_word p_memsz; 00303 elf64_word p_align; 00304 }; 00305 00306 /* 00307 * ELF symbol 00308 */ 00309 00310 #define ELF_STB_LOCAL 0 00311 #define ELF_STB_GLOBAL 1 00312 #define ELF_STB_WEAK 2 00313 00314 #define ELF_STT_NOTYPE 0 00315 #define ELF_STT_OBJECT 1 00316 #define ELF_STT_FUNC 2 00317 #define ELF_STT_SECTION 3 00318 #define ELF_STT_FILE 4 00319 #define ELF_STT_COMMON 5 00320 00321 #define ELF32_ST_BIND(i) ((i)>>4) 00322 #define ELF32_ST_TYPE(i) ((i)&0xf) 00323 #define ELF32_ST_INFO(b,t) (((b)>>4)|((t)&0xf)) 00324 00325 #define ELF64_ST_BIND(i) ((i)>>4) 00326 #define ELF64_ST_TYPE(i) ((i)&0xf) 00327 #define ELF64_ST_INFO(b,t) (((b)>>4)|((t)&0xf)) 00328 00329 struct ELF_SYMBOL32 { 00330 elf32_word st_name; 00331 elf32_addr st_value; 00332 elf32_word st_size; 00333 elf_unsigned_char st_info; 00334 elf_unsigned_char st_other; 00335 elf32_half st_shndx; 00336 }; 00337 00338 struct ELF_SYMBOL64 { 00339 elf64_half st_name; 00340 elf_unsigned_char st_info; 00341 elf_unsigned_char st_other; 00342 elf64_quarter st_shndx; 00343 elf64_word st_value; 00344 elf64_word st_size; 00345 }; 00346 00347 /* 00348 * ELF relocation 00349 */ 00350 00351 #define ELF32_R_SYM(i) ((i)>>8) 00352 #define ELF32_R_TYPE(i) ((unsigned char)(i)) 00353 #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) 00354 00355 #define ELF_R_386_NONE 0 00356 #define ELF_R_386_32 1 00357 #define ELF_R_386_PC32 2 00358 #define ELF_R_386_GOT32 3 00359 #define ELF_R_386_PLT32 4 00360 #define ELF_R_386_COPY 5 00361 #define ELF_R_386_GLOB_DAT 6 00362 #define ELF_R_386_JMP_SLOT 7 00363 #define ELF_R_386_RELATIVE 8 00364 #define ELF_R_386_GOTOFF 9 00365 #define ELF_R_386_GOTPC 10 00366 00367 struct ELF_REL32 { 00368 elf32_addr r_offset; 00369 elf32_word r_info; 00370 }; 00371 00372 struct ELF_REL64 { 00373 elf64_addr r_offset; 00374 elf64_word r_info; 00375 }; 00376 00377 struct ELF_RELA32 { 00378 elf32_addr r_offset; 00379 elf32_word r_info; 00380 elf32_sword r_addend; 00381 }; 00382 00383 struct ELF_RELA64 { 00384 elf64_addr r_offset; 00385 elf64_word r_info; 00386 elf64_sword r_addend; 00387 }; 00388 00389 extern byte ELF_HEADER_struct[]; 00390 extern byte ELF_HEADER32_struct[]; 00391 extern byte ELF_SECTION_HEADER32_struct[]; 00392 extern byte ELF_PROGRAM_HEADER32_struct[]; 00393 extern byte ELF_SYMBOL32_struct[]; 00394 extern byte ELF_REL32_struct[]; 00395 extern byte ELF_RELA32_struct[]; 00396 extern byte ELF_HEADER64_struct[]; 00397 extern byte ELF_SECTION_HEADER64_struct[]; 00398 extern byte ELF_PROGRAM_HEADER64_struct[]; 00399 extern byte ELF_SYMBOL64_struct[]; 00400 extern byte ELF_REL64_struct[]; 00401 extern byte ELF_RELA64_struct[]; 00402 00403 struct ELFAddress { 00404 union { 00405 uint32 a32; 00406 qword a64; 00407 }; 00408 }; 00409 00410 #endif /* __ELFSTRUC_H__ */