Mirror of CollapseOS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

118 lignes
4.3KB

  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. After having loaded that last layer, we end that with a hook
  52. word which is also where CURRENT will be on boot, which is then
  53. followed by the initialization string (see below).
  54. So that's the anatomy of a Collapse OS binary. How do you build
  55. one? If your machine is already covered by a recipe, you're in
  56. luck: follow instructions.
  57. If you're deploying to a new machine, you'll have to write a
  58. new xcomp (cross compilation) unit. Let's look at its
  59. anatomy. First, we have constants. Some of them are device-
  60. specific, but some of them are always there. SYSVARS is the
  61. address at which the RAM starts on the system. System variables
  62. will go there and use 0x80 bytes. See impl.txt.
  63. HERESTART determines where... HERE is at startup. 0 means
  64. "same as CURRENT".
  65. RS_ADDR is where RSP starts and PS_ADDR is where PSP starts.
  66. RSP and PSP are designed to be contiguous. RSP goes up and PSP
  67. goes down. If they meet, we know we have a stack overflow.
  68. Then, we load the assembler and cross compilation unit, which
  69. will be needed for the task ahead.
  70. Then, it's a matter of adding layer after layer. For most
  71. system, all those layers except the drivers will be added the
  72. same way. Drivers are a bit tricker and machine specific. I
  73. can't help you there, you'll have to use your wits.
  74. After we've loaded the high part of the core words, we're at
  75. the "wrapping up" part. We add what we call a "hook word", an
  76. empty word with a single letter name. This allows us to boot
  77. with CURRENT pointing to "source init" content rather than being
  78. an actual wordref.
  79. After the last word of the dictionary comes the "source init"
  80. part. The boot sequence is designed to interpret whatever comes
  81. after LATEST as Forth source, and this, until it reads ASCII
  82. EOT character (4). This is generally used for driver init.
  83. To produce a Collapse OS binary, you run that xcomp unit and
  84. then observe the values of "ORG @" and "H@". That will give you
  85. the start and stop offset of your binary, which you can then
  86. copy to your target media.
  87. Good luck!