PageRenderTime 71ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/kame/kame
Forth | 228 lines | 202 code | 26 blank | 0 comment | 9 complexity | 32bc519158482b75b2e43323349de3f9 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  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. \ $FreeBSD: src/sys/boot/forth/loader.4th,v 1.5 1999/11/24 17:56:39 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. \ ***** check-password
  37. \
  38. \ If a password was defined, execute autoboot and ask for
  39. \ password if autoboot returns.
  40. : check-password
  41. password .addr @ if
  42. 0 autoboot
  43. false >r
  44. begin
  45. bell emit bell emit
  46. ." Password: "
  47. password .len @ read-password
  48. dup password .len @ = if
  49. 2dup password .addr @ password .len @
  50. compare 0= if r> drop true >r then
  51. then
  52. drop free drop
  53. r@
  54. until
  55. r> drop
  56. then
  57. ;
  58. \ ***** start
  59. \
  60. \ Initializes support.4th global variables, sets loader_conf_files,
  61. \ process conf files, and, if any one such file was succesfully
  62. \ read to the end, load kernel and modules.
  63. : start ( -- ) ( throws: abort & user-defined )
  64. s" /boot/defaults/loader.conf" initialize
  65. include_conf_files
  66. \ Will *NOT* try to load kernel and modules if no configuration file
  67. \ was succesfully loaded!
  68. any_conf_read? if
  69. load_kernel
  70. load_modules
  71. then
  72. ;
  73. \ ***** initialize
  74. \
  75. \ Overrides support.4th initialization word with one that does
  76. \ everything start one does, short of loading the kernel and
  77. \ modules. Returns a flag
  78. : initialize ( -- flag )
  79. s" /boot/defaults/loader.conf" initialize
  80. include_conf_files
  81. any_conf_read?
  82. ;
  83. \ ***** read-conf
  84. \
  85. \ Read a configuration file, whose name was specified on the command
  86. \ line, if interpreted, or given on the stack, if compiled in.
  87. : (read-conf) ( addr len -- )
  88. conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
  89. strdup conf_files .len ! conf_files .addr !
  90. include_conf_files \ Will recurse on new loader_conf_files definitions
  91. ;
  92. : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
  93. state @ if
  94. \ Compiling
  95. postpone (read-conf)
  96. else
  97. \ Interpreting
  98. bl parse (read-conf)
  99. then
  100. ; immediate
  101. \ ***** enable-module
  102. \
  103. \ Turn a module loading on.
  104. : enable-module ( <module> -- )
  105. bl parse module_options @ >r
  106. begin
  107. r@
  108. while
  109. 2dup
  110. r@ module.name dup .addr @ swap .len @
  111. compare 0= if
  112. 2drop
  113. r@ module.name dup .addr @ swap .len @ type
  114. true r> module.flag !
  115. ." will be loaded." cr
  116. exit
  117. then
  118. r> module.next @ >r
  119. repeat
  120. r> drop
  121. type ." wasn't found." cr
  122. ;
  123. \ ***** disable-module
  124. \
  125. \ Turn a module loading off.
  126. : disable-module ( <module> -- )
  127. bl parse module_options @ >r
  128. begin
  129. r@
  130. while
  131. 2dup
  132. r@ module.name dup .addr @ swap .len @
  133. compare 0= if
  134. 2drop
  135. r@ module.name dup .addr @ swap .len @ type
  136. false r> module.flag !
  137. ." will not be loaded." cr
  138. exit
  139. then
  140. r> module.next @ >r
  141. repeat
  142. r> drop
  143. type ." wasn't found." cr
  144. ;
  145. \ ***** toggle-module
  146. \
  147. \ Turn a module loading on/off.
  148. : toggle-module ( <module> -- )
  149. bl parse module_options @ >r
  150. begin
  151. r@
  152. while
  153. 2dup
  154. r@ module.name dup .addr @ swap .len @
  155. compare 0= if
  156. 2drop
  157. r@ module.name dup .addr @ swap .len @ type
  158. r@ module.flag @ 0= dup r> module.flag !
  159. if
  160. ." will be loaded." cr
  161. else
  162. ." will not be loaded." cr
  163. then
  164. exit
  165. then
  166. r> module.next @ >r
  167. repeat
  168. r> drop
  169. type ." wasn't found." cr
  170. ;
  171. \ ***** show-module
  172. \
  173. \ Show loading information about a module.
  174. : show-module ( <module> -- )
  175. bl parse module_options @ >r
  176. begin
  177. r@
  178. while
  179. 2dup
  180. r@ module.name dup .addr @ swap .len @
  181. compare 0= if
  182. 2drop
  183. ." Name: " r@ module.name dup .addr @ swap .len @ type cr
  184. ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
  185. ." Type: " r@ module.type dup .addr @ swap .len @ type cr
  186. ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
  187. ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
  188. ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
  189. ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
  190. ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
  191. exit
  192. then
  193. r> module.next @ >r
  194. repeat
  195. r> drop
  196. type ." wasn't found." cr
  197. ;
  198. \ Words to be used inside configuration files
  199. : retry false ; \ For use in load error commands
  200. : ignore true ; \ For use in load error commands
  201. \ Return to strict forth vocabulary
  202. only forth also