1 \ Copyright (c) 1999 Daniel C. Sobral <dcs@freebsd.org>
4 \ Redistribution and use in source and binary forms, with or without
5 \ modification, are permitted provided that the following conditions
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.
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
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.3 2003/11/10 06:08:34 dillon Exp $
28 s" arch-alpha" environment? [if] [if]
29 s" loader_version" environment? [if]
31 .( Loader version 1.2+ required) cr
35 .( Could not get loader version!) cr
40 s" arch-i386" environment? [if] [if]
41 s" loader_version" environment? [if]
43 .( Loader version 1.1+ required) cr
47 .( Could not get loader version!) cr
52 256 dictthreshold ! \ 256 cells minimum free space
53 2048 dictincrease ! \ 2048 additional cells each time
55 include /boot/support.4th
59 \ Prepares to boot as specified by loaded configuration files.
61 only forth also support-functions also builtins definitions
64 0= if ( interpreted ) get_arguments then
66 \ Unload only if a path was passed
72 s" kernelname" getenv? if ( a kernel has been loaded )
75 load_kernel_and_modules
80 s" kernelname" getenv? if ( a kernel has been loaded )
83 load_kernel_and_modules
87 load_kernel_and_modules
88 ?dup 0= if 0 1 boot then
92 0= if ( interpreted ) get_arguments then
94 load_kernel_and_modules
95 ?dup 0= if 0 1 autoboot then
98 also forth definitions also builtins
103 only forth definitions also support-functions
105 \ ***** check-password
107 \ If a password was defined, execute autoboot and ask for
108 \ password if autoboot returns.
117 password .len @ read-password
118 dup password .len @ = if
119 2dup password .addr @ password .len @
120 compare 0= if r> drop true >r then
131 \ Initializes support.4th global variables, sets loader_conf_files,
132 \ process conf files, and, if any one such file was succesfully
133 \ read to the end, load kernel and modules.
135 : start ( -- ) ( throws: abort & user-defined )
136 s" /boot/defaults/loader.conf" initialize
138 include_nextboot_file
139 \ Will *NOT* try to load kernel and modules if no configuration file
140 \ was succesfully loaded!
149 \ Overrides support.4th initialization word with one that does
150 \ everything start one does, short of loading the kernel and
151 \ modules. Returns a flag
153 : initialize ( -- flag )
154 s" /boot/defaults/loader.conf" initialize
156 include_nextboot_file
162 \ Read a configuration file, whose name was specified on the command
163 \ line, if interpreted, or given on the stack, if compiled in.
165 : (read-conf) ( addr len -- )
166 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
167 strdup conf_files .len ! conf_files .addr !
168 include_conf_files \ Will recurse on new loader_conf_files definitions
171 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
181 \ ***** enable-module
183 \ Turn a module loading on.
185 : enable-module ( <module> -- )
186 bl parse module_options @ >r
191 r@ module.name dup .addr @ swap .len @
194 r@ module.name dup .addr @ swap .len @ type
195 true r> module.flag !
196 ." will be loaded." cr
202 type ." wasn't found." cr
205 \ ***** disable-module
207 \ Turn a module loading off.
209 : disable-module ( <module> -- )
210 bl parse module_options @ >r
215 r@ module.name dup .addr @ swap .len @
218 r@ module.name dup .addr @ swap .len @ type
219 false r> module.flag !
220 ." will not be loaded." cr
226 type ." wasn't found." cr
229 \ ***** toggle-module
231 \ Turn a module loading on/off.
233 : toggle-module ( <module> -- )
234 bl parse module_options @ >r
239 r@ module.name dup .addr @ swap .len @
242 r@ module.name dup .addr @ swap .len @ type
243 r@ module.flag @ 0= dup r> module.flag !
245 ." will be loaded." cr
247 ." will not be loaded." cr
254 type ." wasn't found." cr
259 \ Show loading information about a module.
261 : show-module ( <module> -- )
262 bl parse module_options @ >r
267 r@ module.name dup .addr @ swap .len @
270 ." Name: " r@ module.name dup .addr @ swap .len @ type cr
271 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
272 ." Type: " r@ module.type dup .addr @ swap .len @ type cr
273 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
274 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
275 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
276 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
277 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
283 type ." wasn't found." cr
286 \ Words to be used inside configuration files
288 : retry false ; \ For use in load error commands
289 : ignore true ; \ For use in load error commands
291 \ Return to strict forth vocabulary
299 : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
303 s" boot-conf" s" load kernel and modules, then autoboot" .?
304 s" read-conf" s" read a configuration file" .?
305 s" enable-module" s" enable loading of a module" .?
306 s" disable-module" s" disable loading of a module" .?
307 s" toggle-module" s" toggle loading of a module" .?
308 s" show-module" s" show module load data" .?