elf32-header.hex2 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ### Copyright (C) 2016 Jeremiah Orians
  2. ### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  3. ###
  4. ### This file is part of GNU Mes.
  5. ###
  6. ### GNU Mes is free software; you can redistribute it and/or modify it
  7. ### under the terms of the GNU General Public License as published by
  8. ### the Free Software Foundation; either version 3 of the License, or (at
  9. ### your option) any later version.
  10. ###
  11. ### GNU Mes is distributed in the hope that it will be useful, but
  12. ### WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ### GNU General Public License for more details.
  15. ###
  16. ### You should have received a copy of the GNU General Public License
  17. ### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  18. ### Commentary:
  19. # elf32-header.hex2: 32 bit elf header in hex2, with text segment, data
  20. # segment and symbol tables.
  21. # stage0's hex2 format for x86
  22. # !<label> 1 byte relative
  23. # $<label> 2 byte address
  24. # @<label> 2 byte relative
  25. # &<label> 4 byte address
  26. # %<label> 4 byte relative
  27. # local_<label> function-local
  28. # string_<index> string #<index>
  29. ### Code:
  30. :ELF_base
  31. 7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
  32. 01 # e_ident[EI_CLASS] Indicating 32 bit
  33. 01 # e_ident[EI_DATA] Indicating little endianness
  34. 01 # e_ident[EI_VERSION] Indicating original elf
  35. 00 # e_ident[EI_OSABI] Set at 0 because none cares
  36. 00 # e_ident[EI_ABIVERSION] See above
  37. 00 00 00 00 00 00 00 # e_ident[EI_PAD]
  38. 02 00 # e_type Indicating Executable
  39. 03 00 # e_machine Indicating 32bit x86
  40. 01 00 00 00 # e_version Indicating original elf
  41. &ELF_text # e_entry Address of the entry point
  42. %ELF_program_headers>ELF_base # e_phoff Address of program header table
  43. %ELF_section_headers>ELF_base # e_shoff Address of section header table
  44. 00 00 00 00 # e_flags
  45. 34 00 # e_ehsize Indicating our 52 Byte header
  46. 20 00 # e_phentsize size of a program header table
  47. 01 00 # e_phnum number of entries in program table
  48. 28 00 # e_shentsize size of a section header table
  49. 07 00 # e_shnum number of entries in section table
  50. 04 00 # e_shstrndx index of the section names
  51. # @34
  52. 00 00 00 00
  53. 00 00 00 00
  54. 00 00 00 00
  55. # @40
  56. :ELF_program_headers
  57. :ELF_program_header__text
  58. 01 00 00 00 # ph_type: PT-LOAD = 1
  59. 00 00 00 00 # ph_offset
  60. &ELF_base # ph_vaddr
  61. &ELF_base # ph_physaddr
  62. %ELF_end>ELF_base # ph_filesz
  63. %ELF_end>ELF_base # ph_memsz
  64. 07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
  65. 01 00 00 00 # ph_align
  66. # @60
  67. #:ELF_program_header__data # NOT USED
  68. # FIXME: linux 4.17 does not allow this overlap
  69. # Uhuuh, elf segment at 0000000001000000
  70. # requested but the memory is mapped already
  71. 01 00 00 00 # ph_type: PT-LOAD = 1
  72. 00 00 00 00 # ph_offset
  73. &ELF_base # ph_vaddr
  74. &ELF_base # ph_physaddr
  75. %ELF_end>ELF_base # ph_filesz
  76. %ELF_end>ELF_base # ph_memsz
  77. 07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
  78. 01 00 00 00 # ph_align
  79. # @80
  80. :ELF_comment
  81. 4d 45 53 00 # MES
  82. 00 00 00 00 # align
  83. 00 00 00 00
  84. 00 00 00 00
  85. 4d 45 53 00 # MES
  86. 00 00 00 00 # align
  87. 00 00 00 00
  88. 00 00 00 00
  89. # @a0
  90. :ELF_shstr
  91. 00
  92. :ELF_shstr__text
  93. 2e 74 65 78 74 00 # .text
  94. :ELF_shstr__data
  95. 2e 64 61 74 61 00 # .data
  96. :ELF_shstr__comment
  97. 2e 63 6f 6d 6d 65 6e 74 00 # .comment
  98. :ELF_shstr__shstr
  99. 2e 73 68 73 74 72 74 61 62 00 # .shstrtab
  100. :ELF_shstr__sym
  101. 2e 73 79 6d 74 61 62 00 # .symtab
  102. :ELF_shstr__str
  103. 2e 73 74 72 74 61 62 00 # .strtab
  104. # @d0
  105. :ELF_section_headers
  106. 00 00 00 00 # sh_name
  107. 00 00 00 00 # sh_type
  108. 00 00 00 00 # sh_flags
  109. 00 00 00 00 # sh_addr
  110. 00 00 00 00 # sh_offset
  111. 00 00 00 00 # sh_length
  112. 00 00 00 00 # sh_link
  113. 00 00 00 00 # sh_info
  114. 01 00 00 00 # sh_1?
  115. 00 00 00 00 # sh_entsize
  116. ## FIXME: M0 for calculations?
  117. :ELF_section_header_text
  118. %ELF_shstr__text>ELF_shstr # sh_name
  119. 01 00 00 00 # sh_type = SHT_PROGBITS = 1
  120. 06 00 00 00 # sh_flags = SHF-ALLOC|SHF-EXEC =2 | 4 = 6
  121. &ELF_text # sh_addr
  122. %ELF_text>ELF_base # sh_offset
  123. %ELF_data>ELF_text # sh_length
  124. 00 00 00 00 # sh_link
  125. 00 00 00 00 # sh_info
  126. 01 00 00 00 # sh_1?
  127. 00 00 00 00 # sh_entsize
  128. :ELF_section_header_data
  129. %ELF_shstr__data>ELF_shstr # sh_name
  130. 01 00 00 00 # sh_type = SHT_PROGBITS = 1
  131. 03 00 00 00 # sh_flags = SHF-WRITE|SHF-ALLOC = 1 | 2 = 3
  132. &ELF_data # sh_addr
  133. %ELF_data>ELF_base # sh_offset
  134. %ELF_sym>ELF_data # sh_length
  135. 00 00 00 00 # sh_link
  136. 00 00 00 00 # sh_info
  137. 01 00 00 00 # sh_1?
  138. 00 00 00 00 # sh_entsize
  139. :ELF_section_header_comment
  140. %ELF_shstr__comment>ELF_shstr # sh_name
  141. 01 00 00 00 # sh_type = SHT_PROGBITS = 1
  142. 00 00 00 00 # sh_flags
  143. &ELF_comment # sh_addr
  144. %ELF_comment>ELF_base # sh_offset
  145. %ELF_shstr>ELF_comment # sh_length
  146. 00 00 00 00 # sh_link
  147. 00 00 00 00 # sh_info
  148. 01 00 00 00 # sh_1?
  149. 00 00 00 00 # sh_entsize
  150. :ELF_section_header_shstr
  151. %ELF_shstr__shstr>ELF_shstr # sh_name
  152. 03 00 00 00 # sh_type: str-sht-strtab
  153. 00 00 00 00 # sh_flags
  154. &ELF_shstr # sh_addr
  155. %ELF_shstr>ELF_base # sh_offset
  156. %ELF_section_headers>ELF_shstr # sh_length
  157. 00 00 00 00 # sh_link
  158. 00 00 00 00 # sh_info
  159. 01 00 00 00 # sh_1?
  160. 00 00 00 00 # sh_entsize
  161. :ELF_section_header_sym
  162. %ELF_shstr__sym>ELF_shstr # sh_name
  163. 02 00 00 00 # sh_type: str-sht-symtab
  164. 00 00 00 00 # sh_flags
  165. &ELF_sym # sh_addr
  166. %ELF_sym>ELF_base # sh_offset
  167. %ELF_end>ELF_sym # sh_length
  168. 06 00 00 00 # sh_link:6
  169. 00 00 00 00 # sh_info
  170. 01 00 00 00 # sh_1?
  171. 10 00 00 00 # sh_entsize
  172. :ELF_section_header_str
  173. %ELF_shstr__str>ELF_shstr # sh_name
  174. 03 00 00 00 # sh_type: str-sht-strtab
  175. 00 00 00 00 # sh_flags
  176. &ELF_str # sh_addr
  177. %ELF_str>ELF_base # sh_offset
  178. %ELF_sym>ELF_str # sh_length
  179. 00 00 00 00 # sh_link
  180. 00 00 00 00 # sh_info
  181. 01 00 00 00 # sh_1?
  182. 00 00 00 00 # sh_entsize
  183. # @1e8
  184. 00 00 00 00 # align
  185. 00 00 00 00
  186. # @1f0
  187. 00 00 00 00 # align
  188. 00 00 00 00
  189. 00 00 00 00
  190. 00 00 00 00
  191. # @200
  192. :ELF_text