PageRenderTime 30ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/sys/boot/forth/loader.4th

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