README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. -*- mode: org; -*-
  2. * Copyright header
  3. ## Copyright (C) 2016 Jeremiah Orians
  4. ## This file is part of stage0.
  5. ##
  6. ## stage0 is free software: you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation, either version 3 of the License, or
  9. ## (at your option) any later version.
  10. ##
  11. ## stage0 is distributed in the hope that it will be useful,
  12. ## but 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 stage0. If not, see <http://www.gnu.org/licenses/>.
  18. The master repository for this work is located at:
  19. https://savannah.nongnu.org/projects/stage0/
  20. * If you wish to contribute:
  21. pull requests can be made at https://github.com/oriansj/stage0
  22. and https://gitlab.com/janneke/stage0
  23. or patches/diffs can be sent via email to Jeremiah (at) pdp10 [dot] guru
  24. or join us on freenode's #bootstrappable
  25. or update the wiki at https://bootstrapping.miraheze.org/wiki/Stage0
  26. * Goal
  27. This is a set of manually created hex programs in a Cthulhu Path to madness fashion.
  28. Which only have the goal of creating a bootstrapping path to a C compiler capable of
  29. compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.
  30. Additionally, all code must be able to be understood by 70% of the population of programmers.
  31. If the code can not be understood by that volume, it needs to be altered until it satisfies the above requirement.
  32. * Also found within
  33. This repo contains a few of my false start pieces that may be of interest to people who
  34. want to independently create the root binary. I welcome all bug fixes and code that aids
  35. in the above stated goal.
  36. * FYI
  37. I'll be adding more code and documentation as I build pieces.
  38. ALL code in this REPO is under the GPLv3 or Later.
  39. In order to build stage0 and all the pieces, one only needs to run make all.
  40. Each individual piece can be built by simply running make $piece with $piece being replaced by the actual part you want to make.
  41. The only pieces that have any external dependencies are the Web IDE (Python3+CherryPy), libvm (GCC) and vm (GCC+GNU getopt)
  42. Those wishing to work in Python, please checkout https://github.com/markjenkins/knightpies
  43. He does an amazing job
  44. * Future
  45. ** Software
  46. Add more ports to more hardware platforms.
  47. ** Hardware
  48. Implement the Knight processor in FPGA and then convert into TTL.
  49. * Need to know information
  50. ** stage0
  51. The stage0 is the ultimate lowest level of bootstrap that is useful for systems
  52. without firmware, operating systems nor any other provided software functionality
  53. Those with such capabilities can skip this stage as it requires human input.
  54. *** Hex0_monitor
  55. The Hex0_monitor provides dual functionality:
  56. 1) It assembles hex0 programs manually typed in
  57. 2) It writes the characters, providing minimal text input functionality.
  58. The first is essential for creating of the root binaries.
  59. The second is essential for creating source files before you have an editor.
  60. The distinction is important because only the Hex0 assembler in stage1 is built
  61. by the Hex0_monitor and from that point onwards it is used as a minimal text
  62. editor until a more advanced text editor can be bootstrapped.
  63. ** stage1
  64. The stage1 is dependent on the availability of text source files and at least a
  65. hex0 monitor or assembler. The steps in this stage can be fully automated should
  66. one trust their automation or performed manually on any hardware they trust.
  67. Regardless of which method selected, the resulting binaries MUST be identical.
  68. *** Hex0
  69. The Hex0 assembler or stage1_assembler-0 is the head node of the stage1 bootstrap.
  70. Its functionality is reduced compared to the stage0 monitor simply because it
  71. only performs half of the required functions; that of generating binaries from
  72. hex0 source files.
  73. Its most important features of note are:
  74. ; line comments and
  75. # line comments
  76. As careful notes are essential for this stage.
  77. *** Hex1
  78. The Hex1 assembler or stage1_assembler-1 is the next logical extension of the
  79. Hex0 assembler, single character labels and relative displacement using a prefix.
  80. In this case labels start with : thus the label a must be written :a and the
  81. prefix for relative offsets is @ thus the pointer must be written @a
  82. Further because of the mescc-tools standardization of syntax @label indicates a
  83. 16bit relative displacement.
  84. Alternative architectures porting this need not limit themselves to 16bit
  85. displacements should they so choose, rather they must provide at least 1 size
  86. of displacement or if they so desire, they may skip and write their Hex2
  87. assembler in Hex0 but as it is a much larger program, I recommend against it.
  88. *** Hex2
  89. The Hex2 assembler or stage1_assembler-2 or hex2_linker is as complex of a hex
  90. language that is both meaningful and worth the effort.
  91. Hex2's important advances over Hex1 are as follows:
  92. Support for long labels (Minimal 42 chars, ideally unlimited)
  93. Support for Absolute addressing ($label for 16bit absolute addresses)
  94. Support for Alternative pointer sizes (%label for 32bit relative and &label for
  95. 32bit absolute addresses)
  96. Optionally support for !label (8bit relative addressing) and ?label
  97. (Architecture specific size/properties) and/or @label1>label2 %label1>label2
  98. displacements may be implemented should the specific architecture require it
  99. for human readable hex2 source files (such as ELF headers).
  100. *** M0
  101. M0 or M0-macro or M1-macro is the minimal string replacement program with string
  102. processing functionality required to convert an Assembly like syntax into Hex2
  103. programs that can be compiled. Its rules are merely an extension of Hex2 with
  104. the goal of reducing the amount of hex that one would need to write.
  105. The 3 essential pieces are:
  106. 1) DEFINE STRING1 HEX_CHARACTERS (No extra whitespace nor \t or \n inside
  107. definition)
  108. 2) "Raw strings" allow every character except " as there is no support for
  109. string escapes, including NULL; which are converted to Hex chars for Hex2
  110. To convert back to the chars inside of the "quotes" with the addition of a
  111. trailing NULL character or the number desired (Must be at least 1, no upper
  112. bound) and restrictions such as padding to word boundaries are acceptable.
  113. 3) 'Raw char strings' will be passing anything inside of them (except ' which
  114. terminates the string).
  115. Thus by combining :label, @label, DEFINE SYSCALL 0F05, Raw strings and chars;
  116. one has created a rather flexible and powerful Assembler capable of building
  117. far more ambitious pieces in "Macro Assembly".
  118. ** stage2
  119. The stage2 is dependent on the availability of text source files and at least a
  120. functional macro assembler and can be used to build operating systems or other
  121. "Bootstrap" functionality that might be required to enable functional binaries;
  122. such as programs that set execute bits or generate dwarf stubs.
  123. *** FORTH
  124. Because a great many people stated FORTH would be an ideal bootstrapping language
  125. the time and effort was put forth by Caleb and Jeremiah to provide a framework
  126. for those people to contribute immediately; thus the FORTH was born.
  127. Several efforts were taken to make the FORTH more standard but ultimately it was
  128. determined, Assembly was preferable as the underlying architecture wasn't total
  129. garbage.
  130. It now sits waiting for any FORTH programmer who wishes to prove FORTH is a real
  131. bootstrapping language.
  132. *** Lisp
  133. The next recommendation in bootstrapping was Lisp, so efforts were taken to
  134. design the most minimal Lisp with all of the functionality described in the
  135. original Lisp papers. The task was completed relatively quickly compared to the
  136. FORTH and even had enhancements such as a compacting garbage collector.
  137. Ultimately it was found, the lisp that many rave about isn't entirely compatible
  138. with modern lisps or schemes; thus was shelved for any Lisper who wishes to pick
  139. it up.
  140. *** C
  141. After being told for months there is no way to write a proper C compiler in
  142. assembly and months of research without any human written C compilers in
  143. assembly found. To prove the point Jeremiah decided the First C compiler on the
  144. bootstrap would actually be a cross-compiler for x86, such that everyone would
  145. be able to verify it did exactly what it was supposed to and see it self-host
  146. its C version.
  147. ** stage3
  148. The stage3 is dependent on the availability of text source files and at least a
  149. functional M2-Planet level C compiler, FORTH and a Minimal Garbage collecting
  150. Lisp and can be used to build more advanced tools that can be used in
  151. bootstrapping whole operating systems with modern tool stacks.
  152. *** initial_library
  153. A library collection of very useful FORTH functionality designed to make the
  154. lives of any FORTH programmer easier.
  155. It now sits waiting for any FORTH programmer who wishes to build upon it.
  156. *** ascension
  157. A library collection of useful Lisp functionality designed to make the lives
  158. of any Lisp programmer easier.
  159. As it depends on archaic Lisp dialect; it will likely need to be replaced should
  160. the Lisp be properly fixed.
  161. *** blood-elf_x86
  162. The x86 program for a dwarf stub generator used in mescc-tools bootstrapping.
  163. Specifically mescc-tools-seed generation, which can be used to build M2-Planet
  164. and thus complete the circle.
  165. *** get_machine_x86
  166. The trivial x86 program that allows one to skip tests or scripts that will not
  167. run on that specific platform or run alternative commands depending upon the
  168. architecture.
  169. *** hex2_linker_x86
  170. The program that allows one to build the hex2 programs for any hardware platform
  171. on x86 and thus verify software builds for hardware one does not even have.
  172. *** M1-macro_x86
  173. The program that allows one to build the M1 program for any hardware platform
  174. on x86 and thus verify software builds for hardware one does not even have.
  175. *** M2-Planet_x86
  176. The x86 port of the M2-Planet C compiler v1.0 used as one of the paths in
  177. bootstrapping M2-Planet on x86 hardware.
  178. * Inspirations
  179. This work wouldn't have come so far without the inspirational work of others
  180. They are in alphabetical order of the Author's last names
  181. GRIMLEY EVANS, Edmund - bcompiler [http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html] :: The inspiration for hex0, hex1 and hex2
  182. GRIMLEY EVANS, Edmund - cc500 [http://homepage.ntlworld.com/edmund.grimley-evans/cc500] :: The inspiration for M2-Planet
  183. Jones, Richard W.M. - jonesforth [http://git.annexia.org/?p=jonesforth.git] :: The inspiration for stage2 FORTH and initial_library
  184. Piner, Steve and Deutsch, L. Peter - Expensive Typewriter [http://archive.computerhistory.org/resources/text/DEC/pdp-1/DEC.pdp_1.1972.102650079.pdf] :: The inspiration for SET
  185. kragensitaker - The Monitor [https://old.reddit.com/r/programming/comments/9x15g/programming_thought_experiment_stuck_in_a_room/c0ewj2c/] :: The inspiration for the hex0-monitor