elf.h 4.0 KB

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