README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. This repository utilizes submodules, so you need to clone this repository using
  51. `git clone --recursive`. If you have already cloned it run `git submodule update
  52. --init` or after a pull be sure to do: `git submodule update --recursive`
  53. ** stage0
  54. The stage0 is the ultimate lowest level of bootstrap that is useful for systems
  55. without firmware, operating systems nor any other provided software functionality
  56. Those with such capabilities can skip this stage as it requires human input.
  57. *** Hex0_monitor
  58. The Hex0_monitor provides dual functionality:
  59. 1) It assembles hex0 programs manually typed in
  60. 2) It writes the characters, providing minimal text input functionality.
  61. The first is essential for creating of the root binaries.
  62. The second is essential for creating source files before you have an editor.
  63. The distinction is important because only the Hex0 assembler in stage1 is built
  64. by the Hex0_monitor and from that point onwards it is used as a minimal text
  65. editor until a more advanced text editor can be bootstrapped.
  66. ** stage1
  67. The stage1 is dependent on the availability of text source files and at least a
  68. hex0 monitor or assembler. The steps in this stage can be fully automated should
  69. one trust their automation or performed manually on any hardware they trust.
  70. Regardless of which method selected, the resulting binaries MUST be identical.
  71. *** Hex0
  72. The Hex0 assembler or stage1_assembler-0 is the head node of the stage1 bootstrap.
  73. Its functionality is reduced compared to the stage0 monitor simply because it
  74. only performs half of the required functions; that of generating binaries from
  75. hex0 source files.
  76. Its most important features of note are:
  77. ; line comments and
  78. # line comments
  79. As careful notes are essential for this stage.
  80. *** Hex1
  81. The Hex1 assembler or stage1_assembler-1 is the next logical extension of the
  82. Hex0 assembler, single character labels and relative displacement using a prefix.
  83. In this case labels start with : thus the label a must be written :a and the
  84. prefix for relative offsets is @ thus the pointer must be written @a
  85. Further because of the mescc-tools standardization of syntax @label indicates a
  86. 16bit relative displacement.
  87. Alternative architectures porting this need not limit themselves to 16bit
  88. displacements should they so choose, rather they must provide at least 1 size
  89. of displacement or if they so desire, they may skip and write their Hex2
  90. assembler in Hex0 but as it is a much larger program, I recommend against it.
  91. *** Hex2
  92. The Hex2 assembler or stage1_assembler-2 or hex2_linker is as complex of a hex
  93. language that is both meaningful and worth the effort.
  94. Hex2's important advances over Hex1 are as follows:
  95. Support for long labels (Minimal 42 chars, ideally unlimited)
  96. Support for Absolute addressing ($label for 16bit absolute addresses)
  97. Support for Alternative pointer sizes (%label for 32bit relative and &label for
  98. 32bit absolute addresses)
  99. Optionally support for !label (8bit relative addressing) and ?label
  100. (Architecture specific size/properties) and/or @label1>label2 %label1>label2
  101. displacements may be implemented should the specific architecture require it
  102. for human readable hex2 source files (such as ELF headers).
  103. *** M0
  104. M0 or M0-macro or M1-macro is the minimal string replacement program with string
  105. processing functionality required to convert an Assembly like syntax into Hex2
  106. programs that can be compiled. Its rules are merely an extension of Hex2 with
  107. the goal of reducing the amount of hex that one would need to write.
  108. The 3 essential pieces are:
  109. 1) DEFINE STRING1 HEX_CHARACTERS (No extra whitespace nor \t or \n inside
  110. definition)
  111. 2) "Raw strings" allow every character except " as there is no support for
  112. string escapes, including NULL; which are converted to Hex chars for Hex2
  113. To convert back to the chars inside of the "quotes" with the addition of a
  114. trailing NULL character or the number desired (Must be at least 1, no upper
  115. bound) and restrictions such as padding to word boundaries are acceptable.
  116. 3) 'Raw char strings' will be passing anything inside of them (except ' which
  117. terminates the string).
  118. Thus by combining :label, @label, DEFINE SYSCALL 0F05, Raw strings and chars;
  119. one has created a rather flexible and powerful Assembler capable of building
  120. far more ambitious pieces in "Macro Assembly".
  121. ** stage2
  122. The stage2 is dependent on the availability of text source files and at least a
  123. functional macro assembler and can be used to build operating systems or other
  124. "Bootstrap" functionality that might be required to enable functional binaries;
  125. such as programs that set execute bits or generate dwarf stubs.
  126. *** FORTH
  127. Because a great many people stated FORTH would be an ideal bootstrapping language
  128. the time and effort was put forth by Caleb and Jeremiah to provide a framework
  129. for those people to contribute immediately; thus the FORTH was born.
  130. Several efforts were taken to make the FORTH more standard but ultimately it was
  131. determined, Assembly was preferable as the underlying architecture wasn't total
  132. garbage.
  133. It now sits waiting for any FORTH programmer who wishes to prove FORTH is a real
  134. bootstrapping language.
  135. *** Lisp
  136. The next recommendation in bootstrapping was Lisp, so efforts were taken to
  137. design the most minimal Lisp with all of the functionality described in the
  138. original Lisp papers. The task was completed relatively quickly compared to the
  139. FORTH and even had enhancements such as a compacting garbage collector.
  140. Ultimately it was found, the lisp that many rave about isn't entirely compatible
  141. with modern lisps or schemes; thus was shelved for any Lisper who wishes to pick
  142. it up.
  143. *** C
  144. After being told for months there is no way to write a proper C compiler in
  145. assembly and months of research without any human written C compilers in
  146. assembly found. To prove the point Jeremiah decided the First C compiler on the
  147. bootstrap would actually be a cross-compiler for x86, such that everyone would
  148. be able to verify it did exactly what it was supposed to and see it self-host
  149. its C version.
  150. ** stage3
  151. The stage3 is dependent on the availability of text source files and at least a
  152. functional M2-Planet level C compiler, FORTH and a Minimal Garbage collecting
  153. Lisp and can be used to build more advanced tools that can be used in
  154. bootstrapping whole operating systems with modern tool stacks.
  155. *** initial_library
  156. A library collection of very useful FORTH functionality designed to make the
  157. lives of any FORTH programmer easier.
  158. It now sits waiting for any FORTH programmer who wishes to build upon it.
  159. *** ascension
  160. A library collection of useful Lisp functionality designed to make the lives
  161. of any Lisp programmer easier.
  162. As it depends on archaic Lisp dialect; it will likely need to be replaced should
  163. the Lisp be properly fixed.
  164. *** blood-elf_x86
  165. The x86 program for a dwarf stub generator used in mescc-tools bootstrapping.
  166. Specifically mescc-tools-seed generation, which can be used to build M2-Planet
  167. and thus complete the circle.
  168. *** get_machine_x86
  169. The trivial x86 program that allows one to skip tests or scripts that will not
  170. run on that specific platform or run alternative commands depending upon the
  171. architecture.
  172. *** hex2_linker_x86
  173. The program that allows one to build the hex2 programs for any hardware platform
  174. on x86 and thus verify software builds for hardware one does not even have.
  175. *** M1-macro_x86
  176. The program that allows one to build the M1 program for any hardware platform
  177. on x86 and thus verify software builds for hardware one does not even have.
  178. *** M2-Planet_x86
  179. The x86 port of the M2-Planet C compiler v1.0 used as one of the paths in
  180. bootstrapping M2-Planet on x86 hardware.
  181. * Inspirations
  182. This work wouldn't have come so far without the inspirational work of others
  183. They are in alphabetical order of the Author's last names
  184. GRIMLEY EVANS, Edmund - bcompiler [http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html] :: The inspiration for hex0, hex1 and hex2
  185. GRIMLEY EVANS, Edmund - cc500 [http://homepage.ntlworld.com/edmund.grimley-evans/cc500] :: The inspiration for M2-Planet
  186. Jones, Richard W.M. - jonesforth [http://git.annexia.org/?p=jonesforth.git] :: The inspiration for stage2 FORTH and initial_library
  187. 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
  188. 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