elf.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef _PPC_BOOT_ELF_H_
  2. #define _PPC_BOOT_ELF_H_
  3. /* 32-bit ELF base types. */
  4. typedef unsigned int Elf32_Addr;
  5. typedef unsigned short Elf32_Half;
  6. typedef unsigned int Elf32_Off;
  7. typedef signed int Elf32_Sword;
  8. typedef unsigned int Elf32_Word;
  9. /* 64-bit ELF base types. */
  10. typedef unsigned long long Elf64_Addr;
  11. typedef unsigned short Elf64_Half;
  12. typedef signed short Elf64_SHalf;
  13. typedef unsigned long long Elf64_Off;
  14. typedef signed int Elf64_Sword;
  15. typedef unsigned int Elf64_Word;
  16. typedef unsigned long long Elf64_Xword;
  17. typedef signed long long Elf64_Sxword;
  18. /* These constants are for the segment types stored in the image headers */
  19. #define PT_NULL 0
  20. #define PT_LOAD 1
  21. #define PT_DYNAMIC 2
  22. #define PT_INTERP 3
  23. #define PT_NOTE 4
  24. #define PT_SHLIB 5
  25. #define PT_PHDR 6
  26. #define PT_TLS 7 /* Thread local storage segment */
  27. #define PT_LOOS 0x60000000 /* OS-specific */
  28. #define PT_HIOS 0x6fffffff /* OS-specific */
  29. #define PT_LOPROC 0x70000000
  30. #define PT_HIPROC 0x7fffffff
  31. #define PT_GNU_EH_FRAME 0x6474e550
  32. #define PT_GNU_STACK (PT_LOOS + 0x474e551)
  33. /* These constants define the different elf file types */
  34. #define ET_NONE 0
  35. #define ET_REL 1
  36. #define ET_EXEC 2
  37. #define ET_DYN 3
  38. #define ET_CORE 4
  39. #define ET_LOPROC 0xff00
  40. #define ET_HIPROC 0xffff
  41. /* These constants define the various ELF target machines */
  42. #define EM_NONE 0
  43. #define EM_PPC 20 /* PowerPC */
  44. #define EM_PPC64 21 /* PowerPC64 */
  45. #define EI_NIDENT 16
  46. typedef struct elf32_hdr {
  47. unsigned char e_ident[EI_NIDENT];
  48. Elf32_Half e_type;
  49. Elf32_Half e_machine;
  50. Elf32_Word e_version;
  51. Elf32_Addr e_entry; /* Entry point */
  52. Elf32_Off e_phoff;
  53. Elf32_Off e_shoff;
  54. Elf32_Word e_flags;
  55. Elf32_Half e_ehsize;
  56. Elf32_Half e_phentsize;
  57. Elf32_Half e_phnum;
  58. Elf32_Half e_shentsize;
  59. Elf32_Half e_shnum;
  60. Elf32_Half e_shstrndx;
  61. } Elf32_Ehdr;
  62. typedef struct elf64_hdr {
  63. unsigned char e_ident[16]; /* ELF "magic number" */
  64. Elf64_Half e_type;
  65. Elf64_Half e_machine;
  66. Elf64_Word e_version;
  67. Elf64_Addr e_entry; /* Entry point virtual address */
  68. Elf64_Off e_phoff; /* Program header table file offset */
  69. Elf64_Off e_shoff; /* Section header table file offset */
  70. Elf64_Word e_flags;
  71. Elf64_Half e_ehsize;
  72. Elf64_Half e_phentsize;
  73. Elf64_Half e_phnum;
  74. Elf64_Half e_shentsize;
  75. Elf64_Half e_shnum;
  76. Elf64_Half e_shstrndx;
  77. } Elf64_Ehdr;
  78. /* These constants define the permissions on sections in the program
  79. header, p_flags. */
  80. #define PF_R 0x4
  81. #define PF_W 0x2
  82. #define PF_X 0x1
  83. typedef struct elf32_phdr {
  84. Elf32_Word p_type;
  85. Elf32_Off p_offset;
  86. Elf32_Addr p_vaddr;
  87. Elf32_Addr p_paddr;
  88. Elf32_Word p_filesz;
  89. Elf32_Word p_memsz;
  90. Elf32_Word p_flags;
  91. Elf32_Word p_align;
  92. } Elf32_Phdr;
  93. typedef struct elf64_phdr {
  94. Elf64_Word p_type;
  95. Elf64_Word p_flags;
  96. Elf64_Off p_offset; /* Segment file offset */
  97. Elf64_Addr p_vaddr; /* Segment virtual address */
  98. Elf64_Addr p_paddr; /* Segment physical address */
  99. Elf64_Xword p_filesz; /* Segment size in file */
  100. Elf64_Xword p_memsz; /* Segment size in memory */
  101. Elf64_Xword p_align; /* Segment alignment, file & memory */
  102. } Elf64_Phdr;
  103. #define EI_MAG0 0 /* e_ident[] indexes */
  104. #define EI_MAG1 1
  105. #define EI_MAG2 2
  106. #define EI_MAG3 3
  107. #define EI_CLASS 4
  108. #define EI_DATA 5
  109. #define EI_VERSION 6
  110. #define EI_OSABI 7
  111. #define EI_PAD 8
  112. #define ELFMAG0 0x7f /* EI_MAG */
  113. #define ELFMAG1 'E'
  114. #define ELFMAG2 'L'
  115. #define ELFMAG3 'F'
  116. #define ELFMAG "\177ELF"
  117. #define SELFMAG 4
  118. #define ELFCLASSNONE 0 /* EI_CLASS */
  119. #define ELFCLASS32 1
  120. #define ELFCLASS64 2
  121. #define ELFCLASSNUM 3
  122. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  123. #define ELFDATA2LSB 1
  124. #define ELFDATA2MSB 2
  125. #define EV_NONE 0 /* e_version, EI_VERSION */
  126. #define EV_CURRENT 1
  127. #define EV_NUM 2
  128. #define ELFOSABI_NONE 0
  129. #define ELFOSABI_LINUX 3
  130. struct elf_info {
  131. unsigned long loadsize;
  132. unsigned long memsize;
  133. unsigned long elfoffset;
  134. };
  135. int parse_elf64(void *hdr, struct elf_info *info);
  136. int parse_elf32(void *hdr, struct elf_info *info);
  137. #endif /* _PPC_BOOT_ELF_H_ */