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.5 2004/10/14 09:06:21 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.nfsroot.path" getenv? if
137 s" kernel.BOOTP" s" kernel" setenv
138 s" /boot/defaults/loader-bootp.conf" initialize
140 s" kernel" s" kernel" setenv
141 s" /boot/defaults/loader.conf" initialize
144 include_nextboot_file
145 \ Will *NOT* try to load kernel and modules if no configuration file
146 \ was succesfully loaded!
155 \ Overrides support.4th initialization word with one that does
156 \ everything start one does, short of loading the kernel and
157 \ modules. Returns a flag
159 : initialize ( -- flag )
160 s" /boot/defaults/loader.conf" initialize
162 include_nextboot_file
168 \ Read a configuration file, whose name was specified on the command
169 \ line, if interpreted, or given on the stack, if compiled in.
171 : (read-conf) ( addr len -- )
172 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
173 strdup conf_files .len ! conf_files .addr !
174 include_conf_files \ Will recurse on new loader_conf_files definitions
177 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
187 \ ***** enable-module
189 \ Turn a module loading on.
191 : enable-module ( <module> -- )
192 bl parse module_options @ >r
197 r@ module.name dup .addr @ swap .len @
200 r@ module.name dup .addr @ swap .len @ type
201 true r> module.flag !
202 ." will be loaded." cr
208 type ." wasn't found." cr
211 \ ***** disable-module
213 \ Turn a module loading off.
215 : disable-module ( <module> -- )
216 bl parse module_options @ >r
221 r@ module.name dup .addr @ swap .len @
224 r@ module.name dup .addr @ swap .len @ type
225 false r> module.flag !
226 ." will not be loaded." cr
232 type ." wasn't found." cr
235 \ ***** toggle-module
237 \ Turn a module loading on/off.
239 : toggle-module ( <module> -- )
240 bl parse module_options @ >r
245 r@ module.name dup .addr @ swap .len @
248 r@ module.name dup .addr @ swap .len @ type
249 r@ module.flag @ 0= dup r> module.flag !
251 ." will be loaded." cr
253 ." will not be loaded." cr
260 type ." wasn't found." cr
265 \ Show loading information about a module.
267 : show-module ( <module> -- )
268 bl parse module_options @ >r
273 r@ module.name dup .addr @ swap .len @
276 ." Name: " r@ module.name dup .addr @ swap .len @ type cr
277 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
278 ." Type: " r@ module.type dup .addr @ swap .len @ type cr
279 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
280 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
281 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
282 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
283 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
289 type ." wasn't found." cr
292 \ Words to be used inside configuration files
294 : retry false ; \ For use in load error commands
295 : ignore true ; \ For use in load error commands
297 \ Return to strict forth vocabulary
305 : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
309 s" boot-conf" s" load kernel and modules, then autoboot" .?
310 s" read-conf" s" read a configuration file" .?
311 s" enable-module" s" enable loading of a module" .?
312 s" disable-module" s" disable loading of a module" .?
313 s" toggle-module" s" toggle loading of a module" .?
314 s" show-module" s" show module load data" .?