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

/sys/boot/forth/loader.4th

https://github.com/blacklion/GEOM-Events
Forth | 192 lines | 158 code | 34 blank | 0 comment | 19 complexity | 0a97ca5273c402668efc1cf899571faf 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. \ $FreeBSD$
  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. include /boot/check-password.4th
  81. \ ***** start
  82. \
  83. \ Initializes support.4th global variables, sets loader_conf_files,
  84. \ process conf files, and, if any one such file was succesfully
  85. \ read to the end, load kernel and modules.
  86. : start ( -- ) ( throws: abort & user-defined )
  87. s" /boot/defaults/loader.conf" initialize
  88. include_conf_files
  89. include_nextboot_file
  90. \ Will *NOT* try to load kernel and modules if no configuration file
  91. \ was succesfully loaded!
  92. any_conf_read? if
  93. load_kernel
  94. load_modules
  95. then
  96. ;
  97. \ ***** initialize
  98. \
  99. \ Overrides support.4th initialization word with one that does
  100. \ everything start one does, short of loading the kernel and
  101. \ modules. Returns a flag
  102. : initialize ( -- flag )
  103. s" /boot/defaults/loader.conf" initialize
  104. include_conf_files
  105. include_nextboot_file
  106. any_conf_read?
  107. ;
  108. \ ***** read-conf
  109. \
  110. \ Read a configuration file, whose name was specified on the command
  111. \ line, if interpreted, or given on the stack, if compiled in.
  112. : (read-conf) ( addr len -- )
  113. conf_files string=
  114. include_conf_files \ Will recurse on new loader_conf_files definitions
  115. ;
  116. : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
  117. state @ if
  118. \ Compiling
  119. postpone (read-conf)
  120. else
  121. \ Interpreting
  122. bl parse (read-conf)
  123. then
  124. ; immediate
  125. \ show, enable, disable, toggle module loading. They all take module from
  126. \ the next word
  127. : set-module-flag ( module_addr val -- ) \ set and print flag
  128. over module.flag !
  129. dup module.name strtype
  130. module.flag @ if ." will be loaded" else ." will not be loaded" then cr
  131. ;
  132. : enable-module find-module ?dup if true set-module-flag then ;
  133. : disable-module find-module ?dup if false set-module-flag then ;
  134. : toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
  135. \ ***** show-module
  136. \
  137. \ Show loading information about a module.
  138. : show-module ( <module> -- ) find-module ?dup if show-one-module then ;
  139. \ Words to be used inside configuration files
  140. : retry false ; \ For use in load error commands
  141. : ignore true ; \ For use in load error commands
  142. \ Return to strict forth vocabulary
  143. : #type
  144. over - >r
  145. type
  146. r> spaces
  147. ;
  148. : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
  149. : ?
  150. ['] ? execute
  151. s" boot-conf" s" load kernel and modules, then autoboot" .?
  152. s" read-conf" s" read a configuration file" .?
  153. s" enable-module" s" enable loading of a module" .?
  154. s" disable-module" s" disable loading of a module" .?
  155. s" toggle-module" s" toggle loading of a module" .?
  156. s" show-module" s" show module load data" .?
  157. ;
  158. only forth also