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.

117 lignes
4.1KB

  1. # Bootstrap guide
  2. You want to deploy Collapse OS on a new system? Read usage.txt
  3. and impl.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 come
  9. to this block to bootstrap itself some more.
  10. This binary can be separated in 5 distinct layers:
  11. 1. Boot code (B280)
  12. 2. Boot words (B305)
  13. 3. Core words (low) (B350)
  14. 4. Drivers
  15. 5. Core words (high)
  16. # Boot code (B280)
  17. This part contains core routines that underpins Forth fundamen-
  18. tal structures: dict navigation and search, PSP/RSP bounds
  19. checks, 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. 0x100 bytes. The beginning og the dict is intertwined in this
  24. layer because EXIT, (br), (?br) and (loop) are part of the
  25. stable ABI.
  26. # Boot words (B305)
  27. Then come the implementation of core Forth words in native
  28. assembly. Performance is not Collapse OS' primary design goal,
  29. so we try to keep this section to a minimum: we much prefer
  30. to implement our words in Forth.
  31. However, some words are in this section for performance
  32. reasons. Sometimes, the gain is too great to pass up.
  33. # Core words (low) (B350)
  34. Then comes the part where we begin defining words in Forth.
  35. Core words are designed to be cross-compiled (B260), from a
  36. full Forth interpreter. This means that it has access to more
  37. than boot words. This comes with tricky limitations.
  38. See B260 for details.
  39. # Drivers
  40. Up until now, we haven't implemented EMIT or KEY yet: those
  41. words are defined in the "high" part of core words because we
  42. generally need machine-specific drivers to implement (emit) and
  43. (key).
  44. Well, now is their time to shine. We split core in two
  45. precisely to fit drivers in there. This way, they have access
  46. to a pretty good vocabulary and they're also give the oppor-
  47. tunity to provide (emit) and (key).
  48. # Core words (high) (B350)
  49. Then come EMIT, KEY and everything that depend on it, until
  50. we have a full Forth interpreter. At the very end, we define
  51. tricky IMMEDIATEs that, if defined earlier, would break cross
  52. compilation.
  53. We end that with a hook words which is also where CURRENT will
  54. be on boot.
  55. So that's the anatomy of a Collapse OS binary. How do you build
  56. one? If your machine is already covered by a recipe, you're in
  57. luck: follow instructions.
  58. If you're deploying to a new machine, you'll have to write a
  59. new xcomp (cross compilation) unit. Let's look at its
  60. anatomy. First, we have constants. Some of them are device-
  61. specific, but some of them are always there. SYSVARS is the
  62. address at which the RAM starts on the system. System variables
  63. will go there and use 0x80 bytes. See B80.
  64. HERESTART determines where... HERE is at startup. 0 means
  65. "same as CURRENT".
  66. RS_ADDR is where RSP starts and PS_ADDR is where PSP starts.
  67. RSP and PSP are designed to be contiguous. RSP goes up and PSP
  68. goes down. If they meet, we know we have a stack overflow.
  69. Then, we load the assembler and cross compilation unit, which
  70. will be needed for the task ahead.
  71. Then, it's a matter of adding layer after layer. For most
  72. system, all those layers except the drivers will be added the
  73. same way. Drivers are a bit tricker and machine specific. I
  74. can't help you there, you'll have to use your wits.
  75. After we've loaded the high part of the core words, we're at
  76. the "wrapping up" part. We add what we call a "hook word" (an
  77. empty word with a single letter name) which doesn't cost us
  78. much and can be very useful if we need to augment the binary
  79. with more words, and at that point we have our future boot
  80. CURRENT, which PC yields. That is why we write it to the
  81. LATEST field of the stable ABI: This value will be used at
  82. boot.
  83. After the last word of the dictionary comes the "source init"
  84. part. The boot sequence is designed to interpret whatever comes
  85. after LATEST as Forth source, and this, until it reads ASCII
  86. EOT character (4). This is generally used for driver init.
  87. Good luck!