elf.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  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. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _ELF_H_
  30. #define _ELF_H_
  31. /*
  32. * Simplified ELF definitions for OS/161 and System/161.
  33. *
  34. * Restrictions:
  35. * 32-bit only
  36. * No support for .o files or linker structures
  37. * Does not define all the random symbols a standard elf header would.
  38. */
  39. /* Get MD bits */
  40. #include <machine/elf.h>
  41. /*
  42. * ELF file header. This appears at the very beginning of an ELF file.
  43. */
  44. #define ELF_NIDENT 16
  45. typedef struct {
  46. unsigned char e_ident[ELF_NIDENT]; /* magic number et al. */
  47. uint16_t e_type; /* type of file this is */
  48. uint16_t e_machine; /* processor type file is for */
  49. uint32_t e_version; /* ELF version */
  50. uint32_t e_entry; /* address of program entry point */
  51. uint32_t e_phoff; /* location in file of phdrs */
  52. uint32_t e_shoff; /* ignore */
  53. uint32_t e_flags; /* ignore */
  54. uint16_t e_ehsize; /* actual size of file header */
  55. uint16_t e_phentsize; /* actual size of phdr */
  56. uint16_t e_phnum; /* number of phdrs */
  57. uint16_t e_shentsize; /* ignore */
  58. uint16_t e_shnum; /* ignore */
  59. uint16_t e_shstrndx; /* ignore */
  60. } Elf32_Ehdr;
  61. /* Offsets for the 1-byte fields within e_ident[] */
  62. #define EI_MAG0 0 /* '\177' */
  63. #define EI_MAG1 1 /* 'E' */
  64. #define EI_MAG2 2 /* 'L' */
  65. #define EI_MAG3 3 /* 'F' */
  66. #define EI_CLASS 4 /* File class - always ELFCLASS32 */
  67. #define EI_DATA 5 /* Data encoding - ELFDATA2LSB or ELFDATA2MSB*/
  68. #define EI_VERSION 6 /* ELF version - EV_CURRENT*/
  69. #define EI_OSABI 7 /* OS/syscall ABI identification */
  70. #define EI_ABIVERSION 8 /* syscall ABI version */
  71. #define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
  72. /* Values for these fields */
  73. /* For e_ident[EI_MAG0..3] */
  74. #define ELFMAG0 0x7f
  75. #define ELFMAG1 'E'
  76. #define ELFMAG2 'L'
  77. #define ELFMAG3 'F'
  78. /* For e_ident[EI_CLASS] */
  79. #define ELFCLASSNONE 0 /* Invalid class */
  80. #define ELFCLASS32 1 /* 32-bit objects */
  81. #define ELFCLASS64 2 /* 64-bit objects */
  82. /* e_ident[EI_DATA] */
  83. #define ELFDATANONE 0 /* Invalid data encoding */
  84. #define ELFDATA2LSB 1 /* 2's complement values, LSB first */
  85. #define ELFDATA2MSB 2 /* 2's complement values, MSB first */
  86. /* e_ident[EI_VERSION] */
  87. #define EV_NONE 0 /* Invalid version */
  88. #define EV_CURRENT 1 /* Current version */
  89. /* e_ident[EI_OSABI] */
  90. #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
  91. #define ELFOSABI_HPUX 1 /* HP-UX operating system */
  92. #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
  93. /*
  94. * Values for e_type
  95. */
  96. #define ET_NONE 0 /* No file type */
  97. #define ET_REL 1 /* Relocatable file */
  98. #define ET_EXEC 2 /* Executable file */
  99. #define ET_DYN 3 /* Shared object file */
  100. #define ET_CORE 4 /* Core file */
  101. #define ET_NUM 5
  102. /*
  103. * Values for e_machine
  104. */
  105. #define EM_NONE 0 /* No machine */
  106. #define EM_M32 1 /* AT&T WE 32100 */
  107. #define EM_SPARC 2 /* SPARC */
  108. #define EM_386 3 /* Intel 80386 */
  109. #define EM_68K 4 /* Motorola 68000 */
  110. #define EM_88K 5 /* Motorola 88000 */
  111. #define EM_486 6 /* Intel 80486 */
  112. #define EM_860 7 /* Intel 80860 */
  113. #define EM_MIPS 8 /* MIPS I Architecture */
  114. #define EM_S370 9 /* Amdahl UTS on System/370 */
  115. #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
  116. #define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
  117. #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
  118. #define EM_NCUBE 16 /* NCube XXX reserved */
  119. #define EM_VPP500 17 /* Fujitsu VPP500 */
  120. #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
  121. #define EM_960 19 /* Intel 80960 */
  122. #define EM_PPC 20 /* PowerPC */
  123. #define EM_V800 36 /* NEC V800 */
  124. #define EM_FR20 37 /* Fujitsu FR20 */
  125. #define EM_RH32 38 /* TRW RH-32 */
  126. #define EM_RCE 39 /* Motorola RCE */
  127. #define EM_ARM 40 /* Advanced RISC Machines ARM */
  128. #define EM_ALPHA 41 /* DIGITAL Alpha */
  129. #define EM_SH 42 /* Hitachi Super-H */
  130. #define EM_SPARCV9 43 /* SPARC Version 9 */
  131. #define EM_TRICORE 44 /* Siemens Tricore */
  132. #define EM_ARC 45 /* Argonaut RISC Core */
  133. #define EM_H8_300 46 /* Hitachi H8/300 */
  134. #define EM_H8_300H 47 /* Hitachi H8/300H */
  135. #define EM_H8S 48 /* Hitachi H8S */
  136. #define EM_H8_500 49 /* Hitachi H8/500 */
  137. #define EM_IA_64 50 /* Intel Merced Processor */
  138. #define EM_MIPS_X 51 /* Stanford MIPS-X */
  139. #define EM_COLDFIRE 52 /* Motorola Coldfire */
  140. #define EM_68HC12 53 /* Motorola MC68HC12 */
  141. #define EM_VAX 75 /* DIGITAL VAX */
  142. #define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
  143. #define EM_NUM 36903
  144. /*
  145. * "Program Header" - runtime segment header.
  146. * There are Ehdr.e_phnum of these located at one position within the file.
  147. *
  148. * Note: if p_memsz > p_filesz, the leftover space should be zero-filled.
  149. */
  150. typedef struct {
  151. uint32_t p_type; /* Type of segment */
  152. uint32_t p_offset; /* Location of data within file */
  153. uint32_t p_vaddr; /* Virtual address */
  154. uint32_t p_paddr; /* Ignore */
  155. uint32_t p_filesz; /* Size of data within file */
  156. uint32_t p_memsz; /* Size of data to be loaded into memory*/
  157. uint32_t p_flags; /* Flags */
  158. uint32_t p_align; /* Required alignment - can ignore */
  159. } Elf32_Phdr;
  160. /* values for p_type */
  161. #define PT_NULL 0 /* Program header table entry unused */
  162. #define PT_LOAD 1 /* Loadable program segment */
  163. #define PT_DYNAMIC 2 /* Dynamic linking information */
  164. #define PT_INTERP 3 /* Program interpreter */
  165. #define PT_NOTE 4 /* Auxiliary information */
  166. #define PT_SHLIB 5 /* Reserved, unspecified semantics */
  167. #define PT_PHDR 6 /* Entry for header table itself */
  168. #define PT_NUM 7
  169. #define PT_MIPS_REGINFO 0x70000000
  170. /* values for p_flags */
  171. #define PF_R 0x4 /* Segment is readable */
  172. #define PF_W 0x2 /* Segment is writable */
  173. #define PF_X 0x1 /* Segment is executable */
  174. typedef Elf32_Ehdr Elf_Ehdr;
  175. typedef Elf32_Phdr Elf_Phdr;
  176. #endif /* _ELF_H_ */