PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/sys/boot/forth/loader.4th

https://github.com/jwg286/freebsd_usb
Forth | 215 lines | 180 code | 35 blank | 0 comment | 21 complexity | 528ef25a5a0bd7ed86f952869861a25b MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, 0BSD, BSD-3-Clause
  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.26 2009/01/05 20:09:54 luigi Exp $
  26. s" arch-i386" environment? [if] [if]
  27. s" loader_version" environment? [if]
  28. 11 < [if]
  29. .( Loader version 1.1+ required) cr
  30. abort
  31. [then]
  32. [else]
  33. .( Could not get loader version!) cr
  34. abort
  35. [then]
  36. [then] [then]
  37. 256 dictthreshold ! \ 256 cells minimum free space
  38. 2048 dictincrease ! \ 2048 additional cells each time
  39. include /boot/support.4th
  40. \ ***** boot-conf
  41. \
  42. \ Prepares to boot as specified by loaded configuration files.
  43. only forth also support-functions also builtins definitions
  44. : boot
  45. 0= if ( interpreted ) get_arguments then
  46. \ Unload only if a path was passed
  47. dup if
  48. >r over r> swap
  49. c@ [char] - <> if
  50. 0 1 unload drop
  51. else
  52. s" kernelname" getenv? if ( a kernel has been loaded )
  53. 1 boot exit
  54. then
  55. load_kernel_and_modules
  56. ?dup if exit then
  57. 0 1 boot exit
  58. then
  59. else
  60. s" kernelname" getenv? if ( a kernel has been loaded )
  61. 1 boot exit
  62. then
  63. load_kernel_and_modules
  64. ?dup if exit then
  65. 0 1 boot exit
  66. then
  67. load_kernel_and_modules
  68. ?dup 0= if 0 1 boot then
  69. ;
  70. : boot-conf
  71. 0= if ( interpreted ) get_arguments then
  72. 0 1 unload drop
  73. load_kernel_and_modules
  74. ?dup 0= if 0 1 autoboot then
  75. ;
  76. also forth definitions also builtins
  77. builtin: boot
  78. builtin: boot-conf
  79. only forth definitions also support-functions
  80. \ ***** check-password
  81. \
  82. \ If a password was defined, execute autoboot and ask for
  83. \ password if autoboot returns.
  84. \ Do not exit unless the right password is given.
  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/defaults/loader.conf" initialize
  110. include_conf_files
  111. include_nextboot_file
  112. \ Will *NOT* try to load kernel and modules if no configuration file
  113. \ was succesfully loaded!
  114. any_conf_read? if
  115. load_kernel
  116. load_modules
  117. then
  118. ;
  119. \ ***** initialize
  120. \
  121. \ Overrides support.4th initialization word with one that does
  122. \ everything start one does, short of loading the kernel and
  123. \ modules. Returns a flag
  124. : initialize ( -- flag )
  125. s" /boot/defaults/loader.conf" initialize
  126. include_conf_files
  127. include_nextboot_file
  128. any_conf_read?
  129. ;
  130. \ ***** read-conf
  131. \
  132. \ Read a configuration file, whose name was specified on the command
  133. \ line, if interpreted, or given on the stack, if compiled in.
  134. : (read-conf) ( addr len -- )
  135. conf_files string=
  136. include_conf_files \ Will recurse on new loader_conf_files definitions
  137. ;
  138. : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
  139. state @ if
  140. \ Compiling
  141. postpone (read-conf)
  142. else
  143. \ Interpreting
  144. bl parse (read-conf)
  145. then
  146. ; immediate
  147. \ show, enable, disable, toggle module loading. They all take module from
  148. \ the next word
  149. : set-module-flag ( module_addr val -- ) \ set and print flag
  150. over module.flag !
  151. dup module.name strtype
  152. module.flag @ if ." will be loaded" else ." will not be loaded" then cr
  153. ;
  154. : enable-module find-module ?dup if true set-module-flag then ;
  155. : disable-module find-module ?dup if false set-module-flag then ;
  156. : toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
  157. \ ***** show-module
  158. \
  159. \ Show loading information about a module.
  160. : show-module ( <module> -- ) find-module ?dup if show-one-module then ;
  161. \ Words to be used inside configuration files
  162. : retry false ; \ For use in load error commands
  163. : ignore true ; \ For use in load error commands
  164. \ Return to strict forth vocabulary
  165. : #type
  166. over - >r
  167. type
  168. r> spaces
  169. ;
  170. : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
  171. : ?
  172. ['] ? execute
  173. s" boot-conf" s" load kernel and modules, then autoboot" .?
  174. s" read-conf" s" read a configuration file" .?
  175. s" enable-module" s" enable loading of a module" .?
  176. s" disable-module" s" disable loading of a module" .?
  177. s" toggle-module" s" toggle loading of a module" .?
  178. s" show-module" s" show module load data" .?
  179. ;
  180. only forth also