PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/kame/kame
Forth | 311 lines | 274 code | 37 blank | 0 comment | 18 complexity | 18dc9bc68a945be2b7d535cb3cd39be8 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.24 2002/05/24 02:28:58 gordon Exp $
  26. s" arch-alpha" environment? [if] [if]
  27. s" loader_version" environment? [if]
  28. 12 < [if]
  29. .( Loader version 1.2+ required) cr
  30. abort
  31. [then]
  32. [else]
  33. .( Could not get loader version!) cr
  34. abort
  35. [then]
  36. [then] [then]
  37. s" arch-i386" environment? [if] [if]
  38. s" loader_version" environment? [if]
  39. 11 < [if]
  40. .( Loader version 1.1+ required) cr
  41. abort
  42. [then]
  43. [else]
  44. .( Could not get loader version!) cr
  45. abort
  46. [then]
  47. [then] [then]
  48. 256 dictthreshold ! \ 256 cells minimum free space
  49. 2048 dictincrease ! \ 2048 additional cells each time
  50. include /boot/support.4th
  51. \ ***** boot-conf
  52. \
  53. \ Prepares to boot as specified by loaded configuration files.
  54. only forth also support-functions also builtins definitions
  55. : boot
  56. 0= if ( interpreted ) get_arguments then
  57. \ Unload only if a path was passed
  58. dup if
  59. >r over r> swap
  60. c@ [char] - <> if
  61. 0 1 unload drop
  62. else
  63. s" kernelname" getenv? if ( a kernel has been loaded )
  64. 1 boot exit
  65. then
  66. load_kernel_and_modules
  67. ?dup if exit then
  68. 0 1 boot exit
  69. then
  70. else
  71. s" kernelname" getenv? if ( a kernel has been loaded )
  72. 1 boot exit
  73. then
  74. load_kernel_and_modules
  75. ?dup if exit then
  76. 0 1 boot exit
  77. then
  78. load_kernel_and_modules
  79. ?dup 0= if 0 1 boot then
  80. ;
  81. : boot-conf
  82. 0= if ( interpreted ) get_arguments then
  83. 0 1 unload drop
  84. load_kernel_and_modules
  85. ?dup 0= if 0 1 autoboot then
  86. ;
  87. also forth definitions also builtins
  88. builtin: boot
  89. builtin: boot-conf
  90. only forth definitions also support-functions
  91. \ ***** check-password
  92. \
  93. \ If a password was defined, execute autoboot and ask for
  94. \ password if autoboot returns.
  95. : check-password
  96. password .addr @ if
  97. 0 autoboot
  98. false >r
  99. begin
  100. bell emit bell emit
  101. ." Password: "
  102. password .len @ read-password
  103. dup password .len @ = if
  104. 2dup password .addr @ password .len @
  105. compare 0= if r> drop true >r then
  106. then
  107. drop free drop
  108. r@
  109. until
  110. r> drop
  111. then
  112. ;
  113. \ ***** start
  114. \
  115. \ Initializes support.4th global variables, sets loader_conf_files,
  116. \ process conf files, and, if any one such file was succesfully
  117. \ read to the end, load kernel and modules.
  118. : start ( -- ) ( throws: abort & user-defined )
  119. s" /boot/defaults/loader.conf" initialize
  120. include_conf_files
  121. include_nextboot_file
  122. \ Will *NOT* try to load kernel and modules if no configuration file
  123. \ was succesfully loaded!
  124. any_conf_read? if
  125. load_kernel
  126. load_modules
  127. then
  128. ;
  129. \ ***** initialize
  130. \
  131. \ Overrides support.4th initialization word with one that does
  132. \ everything start one does, short of loading the kernel and
  133. \ modules. Returns a flag
  134. : initialize ( -- flag )
  135. s" /boot/defaults/loader.conf" initialize
  136. include_conf_files
  137. include_nextboot_file
  138. any_conf_read?
  139. ;
  140. \ ***** read-conf
  141. \
  142. \ Read a configuration file, whose name was specified on the command
  143. \ line, if interpreted, or given on the stack, if compiled in.
  144. : (read-conf) ( addr len -- )
  145. conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
  146. strdup conf_files .len ! conf_files .addr !
  147. include_conf_files \ Will recurse on new loader_conf_files definitions
  148. ;
  149. : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
  150. state @ if
  151. \ Compiling
  152. postpone (read-conf)
  153. else
  154. \ Interpreting
  155. bl parse (read-conf)
  156. then
  157. ; immediate
  158. \ ***** enable-module
  159. \
  160. \ Turn a module loading on.
  161. : enable-module ( <module> -- )
  162. bl parse module_options @ >r
  163. begin
  164. r@
  165. while
  166. 2dup
  167. r@ module.name dup .addr @ swap .len @
  168. compare 0= if
  169. 2drop
  170. r@ module.name dup .addr @ swap .len @ type
  171. true r> module.flag !
  172. ." will be loaded." cr
  173. exit
  174. then
  175. r> module.next @ >r
  176. repeat
  177. r> drop
  178. type ." wasn't found." cr
  179. ;
  180. \ ***** disable-module
  181. \
  182. \ Turn a module loading off.
  183. : disable-module ( <module> -- )
  184. bl parse module_options @ >r
  185. begin
  186. r@
  187. while
  188. 2dup
  189. r@ module.name dup .addr @ swap .len @
  190. compare 0= if
  191. 2drop
  192. r@ module.name dup .addr @ swap .len @ type
  193. false r> module.flag !
  194. ." will not be loaded." cr
  195. exit
  196. then
  197. r> module.next @ >r
  198. repeat
  199. r> drop
  200. type ." wasn't found." cr
  201. ;
  202. \ ***** toggle-module
  203. \
  204. \ Turn a module loading on/off.
  205. : toggle-module ( <module> -- )
  206. bl parse module_options @ >r
  207. begin
  208. r@
  209. while
  210. 2dup
  211. r@ module.name dup .addr @ swap .len @
  212. compare 0= if
  213. 2drop
  214. r@ module.name dup .addr @ swap .len @ type
  215. r@ module.flag @ 0= dup r> module.flag !
  216. if
  217. ." will be loaded." cr
  218. else
  219. ." will not be loaded." cr
  220. then
  221. exit
  222. then
  223. r> module.next @ >r
  224. repeat
  225. r> drop
  226. type ." wasn't found." cr
  227. ;
  228. \ ***** show-module
  229. \
  230. \ Show loading information about a module.
  231. : show-module ( <module> -- )
  232. bl parse module_options @ >r
  233. begin
  234. r@
  235. while
  236. 2dup
  237. r@ module.name dup .addr @ swap .len @
  238. compare 0= if
  239. 2drop
  240. ." Name: " r@ module.name dup .addr @ swap .len @ type cr
  241. ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
  242. ." Type: " r@ module.type dup .addr @ swap .len @ type cr
  243. ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
  244. ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
  245. ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
  246. ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
  247. ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
  248. exit
  249. then
  250. r> module.next @ >r
  251. repeat
  252. r> drop
  253. type ." wasn't found." cr
  254. ;
  255. \ Words to be used inside configuration files
  256. : retry false ; \ For use in load error commands
  257. : ignore true ; \ For use in load error commands
  258. \ Return to strict forth vocabulary
  259. : #type
  260. over - >r
  261. type
  262. r> spaces
  263. ;
  264. : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
  265. : ?
  266. ['] ? execute
  267. s" boot-conf" s" load kernel and modules, then autoboot" .?
  268. s" read-conf" s" read a configuration file" .?
  269. s" enable-module" s" enable loading of a module" .?
  270. s" disable-module" s" disable loading of a module" .?
  271. s" toggle-module" s" toggle loading of a module" .?
  272. s" show-module" s" show module load data" .?
  273. ;
  274. only forth also