hex0a.hex0 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ## Copyright (C) 2016 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 is free software: you an redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## stage0 is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. ## Self Bootstrapping Hex Assembler written in Hex
  17. ## And a shitload of comments
  18. ## That can be converted to assembly and compiled
  19. ## ELF Header
  20. 7F 45 4C 46 ## e_ident[EI_MAG0-3] ELF's magic number
  21. 02 ## e_ident[EI_CLASS] Indicating 64 bit
  22. 01 ## e_ident[EI_DATA] Indicating little endianness
  23. 01 ## e_ident[EI_VERSION] Indicating original elf
  24. 00 ## e_ident[EI_OSABI] Set at 0 because none cares
  25. 00 ## e_ident[EI_ABIVERSION] See above
  26. 00 00 00 00 00 00 00 ## e_ident[EI_PAD]
  27. 02 00 ## e_type Indicating Executable
  28. 3E 00 ## e_machine Indicating AMD64
  29. 01 00 00 00 ## e_version Indicating original elf
  30. FB 00 60 00 00 00 00 00 ## e_entry Address of the entry point
  31. 40 00 00 00 00 00 00 00 ## e_phoff Address of program header table
  32. 00 00 00 00 00 00 00 00 ## e_shoff Address of section header table
  33. 00 00 00 00 ## e_flags
  34. 40 00 ## e_ehsize Indicating our 64 Byte header
  35. 38 00 ## e_phentsize size of a program header table
  36. 01 00 ## e_phnum number of entries in program table
  37. 00 00 ## e_shentsize size of a section header table
  38. 00 00 ## e_shnum number of entries in section table
  39. 00 00 ## e_shstrndx index of the section names
  40. ## Program Header table
  41. 01 00 00 00 ## p_type
  42. 06 00 00 00 ## Flags
  43. 00 00 00 00 00 00 00 00 ## p_offset
  44. 00 00 60 00 00 00 00 00 ## p_vaddr
  45. 00 00 00 00 00 00 00 00 ## Undefined
  46. 9B 01 00 00 00 00 00 00 ## p_filesz
  47. 9B 01 00 00 00 00 00 00 ## p_memsz
  48. 00 00 20 00 00 00 00 00 ## Required alignment
  49. ## Hex
  50. 48 83 f8 23 # cmp $0x23,%rax
  51. 74 26 # je 6000a4 <purge_comment>
  52. 48 83 f8 30 # cmp $0x30,%rax
  53. 7c 6f # jl 6000f3 <ascii_other>
  54. 48 83 f8 3a # cmp $0x3a,%rax
  55. 7c 5a # jl 6000e4 <ascii_num>
  56. 48 83 f8 41 # cmp $0x41,%rax
  57. 7c 63 # jl 6000f3 <ascii_other>
  58. 48 83 f8 47 # cmp $0x47,%rax
  59. 7c 58 # jl 6000ee <ascii_high>
  60. 48 83 f8 61 # cmp $0x61,%rax
  61. 7c 57 # jl 6000f3 <ascii_other>
  62. 48 83 f8 67 # cmp $0x67,%rax
  63. 7c 47 # jl 6000e9 <ascii_low>
  64. eb 4f # jmp 6000f3 <ascii_other>
  65. ## Purge Comment
  66. 48 c7 c2 01 00 00 00 # mov $0x1,%rdx
  67. 48 c7 c6 99 01 60 00 # mov $0x600199,%rsi
  68. 48 c7 c7 00 00 00 00 # mov $0x0,%rdi
  69. 48 c7 c0 00 00 00 00 # mov $0x0,%rax
  70. 0f 05 # syscall
  71. 48 85 c0 # test %rax,%rax
  72. 0f 84 be 00 00 00 # je 600189 <Done>
  73. 8a 04 25 99 01 60 00 # mov 0x600199,%al
  74. 48 0f b6 c0 # movzbq %al,%rax
  75. 48 83 f8 0a # cmp $0xa,%rax
  76. 75 c8 # jne 6000a4 <purge_comment>
  77. 48 c7 c0 ff ff ff ff # mov $0xffffffffffffffff,%rax
  78. c3 # retq
  79. ## ascii num
  80. 48 83 e8 30 # sub $0x30,%rax
  81. c3 # retq
  82. ## ascii low
  83. 48 83 e8 57 # sub $0x57,%rax
  84. c3 # retq
  85. ## ascii high
  86. 48 83 e8 37 # sub $0x37,%rax
  87. c3 # retq
  88. ## ascii other
  89. 48 c7 c0 ff ff ff ff # mov $0xffffffffffffffff,%rax
  90. c3 # retq
  91. ## start
  92. 49 c7 c7 ff ff ff ff # mov $0xffffffffffffffff,%r15
  93. 49 c7 c6 00 00 00 00 # mov $0x0,%r14
  94. ## Loop
  95. 48 c7 c2 01 00 00 00 # mov $0x1,%rdx
  96. 48 c7 c6 99 01 60 00 # mov $0x600199,%rsi
  97. 48 c7 c7 00 00 00 00 # mov $0x0,%rdi
  98. 48 c7 c0 00 00 00 00 # mov $0x0,%rax
  99. 0f 05 # syscall
  100. 48 85 c0 # test %rax,%rax
  101. 74 5d # je 600189 <Done>
  102. 8a 04 25 99 01 60 00 # mov 0x600199,%al
  103. 48 0f b6 c0 # movzbq %al,%rax
  104. e8 3c ff ff ff # callq 600078 <hex>
  105. 48 83 f8 00 # cmp $0x0,%rax
  106. 7c c7 # jl 600109 <loop>
  107. 49 83 ff 00 # cmp $0x0,%r15
  108. 7d 0c # jge 600154 <print>
  109. 49 89 c6 # mov %rax,%r14
  110. 49 c7 c7 00 00 00 00 # mov $0x0,%r15
  111. eb b5 # jmp 600109 <loop>
  112. ## print
  113. 49 c1 e6 04 # shl $0x4,%r14
  114. 4c 01 f0 # add %r14,%rax
  115. 88 04 25 9a 01 60 00 # mov %al,0x60019a
  116. 49 c7 c7 ff ff ff ff # mov $0xffffffffffffffff,%r15
  117. 48 c7 c2 01 00 00 00 # mov $0x1,%rdx
  118. 48 c7 c6 9a 01 60 00 # mov $0x60019a,%rsi
  119. 48 c7 c7 01 00 00 00 # mov $0x1,%rdi
  120. 48 c7 c0 01 00 00 00 # mov $0x1,%rax
  121. 0f 05 # syscall
  122. eb 80 # jmp 600109 <loop>
  123. ## Done
  124. 48 c7 c7 00 00 00 00 # mov $0x0,%rdi
  125. 48 c7 c0 3c 00 00 00 # mov $0x3c,%rax
  126. 0f 05 # syscall
  127. ## Place for input, This actually isn't required but here it is
  128. 02 00 00