README.PSL 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. This directory contains not just VSL, but a strange experiment to see
  2. how far it is possible to use VSL to do the initial parts of bootstrapping
  3. PSL.
  4. try-psl-compiler.sh
  5. This makes a compiler using the PSL "AMD64_ext" model and demonstrates
  6. it by compiling a small test function (see factorial.sl) to create
  7. factorial.s and dfactorial.s.
  8. try-to-make-main.sh
  9. Uses the technology as above to recreate an AMD64_ext version of main.s
  10. and of dmain.s, which should be components of the PSL kernel. On my
  11. computer this takes under 20 seconds. The output might be compared
  12. against main.s and dmain.s from the AMD64_ext part of the PSL tree.
  13. There are then files *main.s and *dmain.s which are just copies of those
  14. files taken from the corresponding dist/kernel/* directories in the PSL
  15. tree. Moving forward using those means that the next step does not need to
  16. depend on try-to-make-main.sh yielding a perfect result, but instead moves
  17. forward from the saved copies of main.s and dmain.s that are in the PSL
  18. tree and are expected to be in full working order.
  19. Although I have these for AMD64, AMD64_ext, bsd, mac and mingw64 targets
  20. at present I only make use of the AMD64_ext and mningw64 ones.
  21. main-dmain.sh
  22. Here I think I say "ha ha ha". This involves ugly sed scripts and an
  23. even uglier jiffy C program that takes either AMD64_ext_[d]main.s or
  24. mingw64_[d]main.s and creates an updated copy called just main.s and
  25. dmain.s.
  26. Several things are going on, but the main onjective is to end up with
  27. a single way of having generates the assembly code so that it will end up
  28. usable on Windows, Cygwin, Linux, BSD and Mac. The second objective is
  29. to render it forward-looking on those platforms.
  30. Code for the Mac is obliged to be relocatable, so absolute references
  31. from code to data are prolematic. To sort that out in a way that also
  32. suits the other platforms code that references (eg) symval+NNN is changed
  33. to show the reference as symval+NNN(%ip), making it explicitly pc
  34. relative.
  35. Mac and Linux have different ideas about the mapping between assembly code
  36. symbols and ones in object files and C: in particular one expects the
  37. source code to write names as "_symval" while the other wants just "symval".
  38. To deal with that the adjusted main.s and dmain.s define both variants.
  39. That is ugly but means that one version of the generated file works in more
  40. places.
  41. Recent versions of gcc on Linux default to using a scheme called "pie" that
  42. is there to allow for (more) randomization of the addresses of both code
  43. and data. The reasoning there is that the ranedomization makes it harder
  44. to create attack tools that exploit buffer overflows and similar weaknesses.
  45. The Macintosh tries to default to a similar scheme. To allow the Mac
  46. to follow its inclinations it appears to ve necessary to avoid building
  47. any absolute references to data into the code segment, although absolute
  48. references within the data segment seem OK. The PSL compiler put various
  49. bits of read-only data (eg some strings) in the text segment. To avoid
  50. the Mac linker moaning that is had to disable "pie" the relevant fragments
  51. in main.s now have .data/.text directives scattered around them.
  52. Mac and Linux assemblers diverge in ways that are minor as to when explicit
  53. length qualifiers are needed for some instructions and as to the characters
  54. that introduce comments. These issues are resolved by mapping to something
  55. that is acceptable in each case.
  56. One issue that this script can not deal with is that mingw64 and Cygwin
  57. use the Microsoft calling conventions and register allocations, while
  58. Linux and the Mac pass arguments in a different way. So it remains vital
  59. to start with versions of main.s and dmain.s that adhere to platform
  60. register usage. It is perhaps worth noting that internally PSL uses its
  61. own yet further allocation of registers (eg passing the first argument in
  62. RAX). When it is to call external code it has some mildly ugly sequences
  63. of instructions that copy registers to where the external world expects
  64. them to be. This causes me to wonder if there would be merit in altering
  65. the PSL compiler so that it could use system-natice register and calling
  66. conventions everywhere. But that is a though that goes beyond the current
  67. project!
  68. *.c
  69. bps.c, bpsheap.c, creloc.c, echo.c, ... started as copies of the
  70. corresponding file sin the AMD64_ext directory. An attempt has then been
  71. make to cause them to compile on Cygwin, Linux and Macintosh (and perhaps
  72. soon mingw64). Archaic C syntax has been monernised and everything fed
  73. through astyle to get the formatting consistent. Comments at the top
  74. giving an explanation of bugs fixed in the mid 1980s have been replaced
  75. by a shorter comments giving credit to those who worked on the system then.
  76. To allow for the issues in main.s as to whether symbols should be spelt
  77. with or without leading underscores, functions in the C code that are
  78. called from main are defined using _(name), where the underscore macro
  79. pastes on an extra underscore on platforms where that is needed.
  80. The intent is that future work will merge in cide from the mingw64
  81. support code in the PSL tree to provide a single set of files for
  82. everything that is common, and perhaps tu use #ifdef to separate out
  83. code fragments that are necessarily system-specific.
  84. A new file pslstubs.c is intended to be a repository for much of the
  85. system-specific code. At present it mainly contains Linux wrappers for
  86. low-level functions, defining versions of them with a leading underscore
  87. to their name. This looks ugly and bulky, but each such wrapper typically
  88. compiles into a single jump instructions so the overhead will not be
  89. too severe.
  90. A header file psl.h is intended to be a place to collect declarations of
  91. functions used in the PSL support code so that separate compilation
  92. can still verify consistency of use.
  93. While things are being developed and tested some of these files will
  94. have extra trace statements in them that send messages to stderr reporting
  95. on what is going on.
  96. psl-win.sh, psl-linux.sh and psl-mac.sh
  97. For the three platforms listed (and the "linux" one is expected to
  98. support Cygwin as well) these assemble main.s and dmain.s (as created
  99. using main-dmain.sh) and compile the *.c files to create an executable
  100. bpsl. They then invoke try-bpsl.sh to see how it gets on!
  101. fasl/*.b, winfasl/*.b
  102. Copies of the *.b files from psl/dist/kernel/*/lap. In due course just
  103. as try-to-make-main.sh builds main.s and dmain.s there ought to be a
  104. scheme that builds these using vsl and cross-compilation. But until that
  105. is in place using the pre-build ones is the best that can be done.
  106. Furthermore using the pre-built ones probably reduces the scope for
  107. errors while all this is being tested.
  108. try-bpsl.sh
  109. This is based on the PSL scripts that creata a "Bare PSL". This involves
  110. running bpsl with the pre-build *.b files available to it.
  111. As of the end of February the versions of bpsl created by the steps listed
  112. above start to run and a noticable number of function calls succeed, but
  113. for reasons that call for more debugging the creation of a first psl
  114. image file is not achieved. There are in fact a range of possible causes
  115. that may make the PIE-enabled setup systematically impossible to support,
  116. as well as all sorts of issues of mistakes (from conceptual to mere typos)
  117. in everything that is being looked at here. But part of the intention is
  118. to debug until limitations are properly uncovered and understood.
  119. ACN February 2018