/freebsd3/sys/boot/forth/loader.4th

https://github.com/deathmaker1/kame · Forth · 192 lines · 170 code · 22 blank · 0 comment · 7 complexity · 715b63224f71529d033444add716494c MD5 · raw file

  1. \ Copyright (c) 1999 Daniel C. Sobral <dcs@freebsd.org>
  2. \ All rights reserved.
  3. \
  4. \ Redistribution and use in source and binary forms, with or without
  5. \ modification, are permitted provided that the following conditions
  6. \ are met:
  7. \ 1. Redistributions of source code must retain the above copyright
  8. \ notice, this list of conditions and the following disclaimer.
  9. \ 2. Redistributions in binary form must reproduce the above copyright
  10. \ notice, this list of conditions and the following disclaimer in the
  11. \ documentation and/or other materials provided with the distribution.
  12. \
  13. \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. \ SUCH DAMAGE.
  24. \
  25. \ $Id: loader.4th,v 1.2.2.1 1999/04/24 17:44:34 dcs Exp $
  26. include /boot/support.4th
  27. only forth definitions also support-functions
  28. \ ***** boot-conf
  29. \
  30. \ Prepares to boot as specified by loaded configuration files.
  31. : boot-conf
  32. load_kernel
  33. load_modules
  34. 0 autoboot
  35. ;
  36. \ ***** start
  37. \
  38. \ Initializes support.4th global variables, sets loader_conf_files,
  39. \ process conf files, and, if any one such file was succesfully
  40. \ read to the end, load kernel and modules.
  41. : start ( -- ) ( throws: abort & user-defined )
  42. s" /boot/defaults/loader.conf" initialize
  43. include_conf_files
  44. \ Will *NOT* try to load kernel and modules if no configuration file
  45. \ was succesfully loaded!
  46. any_conf_read? if
  47. load_kernel
  48. load_modules
  49. then
  50. ;
  51. \ ***** read-conf
  52. \
  53. \ Read a configuration file, whose name was specified on the command
  54. \ line, if interpreted, or given on the stack, if compiled in.
  55. : (read-conf) ( addr len -- )
  56. conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
  57. strdup conf_files .len ! conf_files .addr !
  58. include_conf_files \ Will recurse on new loader_conf_files definitions
  59. ;
  60. : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
  61. state @ if
  62. \ Compiling
  63. postpone (read-conf)
  64. else
  65. \ Interpreting
  66. bl parse (read-conf)
  67. then
  68. ; immediate
  69. \ ***** enable-module
  70. \
  71. \ Turn a module loading on.
  72. : enable-module ( <module> -- )
  73. bl parse module_options @ >r
  74. begin
  75. r@
  76. while
  77. 2dup
  78. r@ module.name dup .addr @ swap .len @
  79. compare 0= if
  80. 2drop
  81. r@ module.name dup .addr @ swap .len @ type
  82. true r> module.flag !
  83. ." will be loaded." cr
  84. exit
  85. then
  86. r> module.next @ >r
  87. repeat
  88. r> drop
  89. type ." wasn't found." cr
  90. ;
  91. \ ***** disable-module
  92. \
  93. \ Turn a module loading off.
  94. : disable-module ( <module> -- )
  95. bl parse module_options @ >r
  96. begin
  97. r@
  98. while
  99. 2dup
  100. r@ module.name dup .addr @ swap .len @
  101. compare 0= if
  102. 2drop
  103. r@ module.name dup .addr @ swap .len @ type
  104. false r> module.flag !
  105. ." will not be loaded." cr
  106. exit
  107. then
  108. r> module.next @ >r
  109. repeat
  110. r> drop
  111. type ." wasn't found." cr
  112. ;
  113. \ ***** toggle-module
  114. \
  115. \ Turn a module loading on/off.
  116. : toggle-module ( <module> -- )
  117. bl parse module_options @ >r
  118. begin
  119. r@
  120. while
  121. 2dup
  122. r@ module.name dup .addr @ swap .len @
  123. compare 0= if
  124. 2drop
  125. r@ module.name dup .addr @ swap .len @ type
  126. r@ module.flag @ 0= dup r> module.flag !
  127. if
  128. ." will be loaded." cr
  129. else
  130. ." will not be loaded." cr
  131. then
  132. exit
  133. then
  134. r> module.next @ >r
  135. repeat
  136. r> drop
  137. type ." wasn't found." cr
  138. ;
  139. \ ***** show-module
  140. \
  141. \ Show loading information about a module.
  142. : show-module ( <module> -- )
  143. bl parse module_options @ >r
  144. begin
  145. r@
  146. while
  147. 2dup
  148. r@ module.name dup .addr @ swap .len @
  149. compare 0= if
  150. 2drop
  151. ." Name: " r@ module.name dup .addr @ swap .len @ type cr
  152. ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
  153. ." Type: " r@ module.type dup .addr @ swap .len @ type cr
  154. ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
  155. ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
  156. ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
  157. ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
  158. ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
  159. exit
  160. then
  161. r> module.next @ >r
  162. repeat
  163. r> drop
  164. type ." wasn't found." cr
  165. ;
  166. \ Words to be used inside configuration files
  167. : retry false ; \ For use in load error commands
  168. : ignore true ; \ For use in load error commands
  169. \ Return to strict forth vocabulary
  170. only forth also