Mirror of CollapseOS
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

134 líneas
4.8KB

  1. # Bootstrap guide
  2. You want to deploy Collapse OS on a new system? Read usage.txt,
  3. impl.txt, cross.txt, then continue here.
  4. What is Collapse OS? It is a binary placed either in ROM on
  5. in RAM by a bootloader. That binary, when executed, initializes
  6. itself to a Forth interpreter. In most cases, that Forth
  7. interpreter will have some access to a mass storage device,
  8. which allows it to access Collapse OS' disk blocks and bootstrap
  9. itself some more.
  10. This binary can be separated in 5 distinct layers:
  11. 1. Arch-specific boot code (B280 for Z80)
  12. 2. Arch-specific boot words (B305 for Z80)
  13. 3. Arch-independant core words (low) (B350)
  14. 4. Drivers, might contain arch-specific code
  15. 5. Arch-independant core words (high) (B390)
  16. # Boot code
  17. This part contains core routines that underpins Forth fundamen-
  18. tal structures: dict navigation and FIND, PSP/RSP bounds checks,
  19. word types.
  20. It also of course does core initialization: set RSP/PSP, HERE
  21. CURRENT, then call BOOT.
  22. It also contains what we call the "stable ABI" in its first
  23. few (<0x20) bytes.
  24. # Boot words
  25. Then come the implementation of core Forth words in native
  26. assembly. Performance is not Collapse OS' primary design goal,
  27. so we try to keep this section to a minimum: we much prefer
  28. to implement our words in Forth.
  29. However, some words are in this section for performance
  30. reasons. Sometimes, the gain is too great to pass up.
  31. # Core words (low)
  32. Then comes the part where we begin defining words in Forth.
  33. Core words are designed to be cross-compiled (B260), from a
  34. full Forth interpreter. This means that it has access to more
  35. than boot words. This comes with tricky limitations.
  36. See B260 for details.
  37. # Drivers
  38. Core words don't include (key) and (emit) implementations be-
  39. cause that's hardware-dependant. This is where we need to load
  40. code that implement it, as well as any other code we want to
  41. include in the binary.
  42. We do it now because if we wait until the high layer of core
  43. words is loaded, we'll have messed up immediates and ":" will
  44. be broken. If we load our code before, we won't have access to
  45. a wide vocabulary.
  46. # Core words (high)
  47. The final layer of core words contains the BOOT word as well
  48. as tricky immediates which, if they're defined sooner, mess
  49. cross compilation up. Once this layer is loaded, we become
  50. severly limited in the words we can use without messing up.
  51. # Hook word
  52. After having loaded that last core words layer, we end that
  53. with a hook word, the "(entry) _" line. A hook word is an empty
  54. word at the end of the dictionary which serves 3 purposes:
  55. 1. After having created that word, PC conveniently holds the
  56. value that should go in the LATEST field in stable ABI. Had
  57. the word been non-empty, getting that value would be less
  58. straightforward.
  59. 2. Because LATEST points to an empty word, it means that it also
  60. points to the initialization string, which directly follows.
  61. If it was non-empty, we would need to know the word's length
  62. to get to that string.
  63. 3. If, for some reason, you want to "graft" another dictionary
  64. on top of this one, having it end with an empty word makes
  65. grafting convenient: you already know what your "prev field"
  66. offset should be for the grafting to be correct.
  67. # Initialization string
  68. After the last word of the dictionary comes the "source init"
  69. part. The boot sequence is designed to interpret whatever comes
  70. after LATEST as Forth source, and this, until it reads ASCII
  71. EOT character (4). This is generally used for driver init.
  72. # Building it
  73. So that's the anatomy of a Collapse OS binary. How do you build
  74. one? If your machine is already covered by a recipe, you're in
  75. luck: follow instructions.
  76. If you're deploying to a new machine, you'll have to write a
  77. new xcomp (cross compilation) unit. Let's look at its
  78. anatomy. First, we have constants. Some of them are device-
  79. specific, but some of them are always there. SYSVARS is the
  80. address at which the RAM starts on the system. System variables
  81. will go there and use 0x80 bytes. See impl.txt.
  82. HERESTART determines where... HERE is at startup. 0 means
  83. "same as CURRENT".
  84. RS_ADDR is where RSP starts and PS_ADDR is where PSP starts.
  85. RSP and PSP are designed to be contiguous. RSP goes up and PSP
  86. goes down. If they meet, we know we have a stack overflow.
  87. Then, we load the assembler and cross compilation unit, which
  88. will be needed for the task ahead.
  89. Then, it's a matter of adding layer after layer. For most
  90. system, all those layers except the drivers will be added the
  91. same way. Drivers are a bit tricker and machine specific. I
  92. can't help you there, you'll have to use your wits.
  93. After we've loaded the high part of the core words, we're at
  94. the "wrapping up" part. We add the hook word and init string.
  95. To produce a Collapse OS binary, you run that xcomp unit and
  96. then observe the values of "ORG @" and "H@". That will give you
  97. the start and stop offset of your binary, which you can then
  98. copy to your target media.
  99. Good luck!