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.8 2005/02/20 16:31:53 swildner Exp $
28 s" arch-i386" environment? [if] [if]
29 s" loader_version" environment? [if]
31 .( Loader version 1.1+ required) cr
35 .( Could not get loader version!) cr
40 256 dictthreshold ! \ 256 cells minimum free space
41 2048 dictincrease ! \ 2048 additional cells each time
43 include /boot/support.4th
47 \ Prepares to boot as specified by loaded configuration files.
49 only forth also support-functions also builtins definitions
52 0= if ( interpreted ) get_arguments then
54 \ Unload only if a path was passed
60 s" kernelname" getenv? if ( a kernel has been loaded )
63 load_kernel_and_modules
68 s" kernelname" getenv? if ( a kernel has been loaded )
71 load_kernel_and_modules
75 load_kernel_and_modules
76 ?dup 0= if 0 1 boot then
80 0= if ( interpreted ) get_arguments then
82 load_kernel_and_modules
83 ?dup 0= if 0 1 autoboot then
86 also forth definitions also builtins
91 only forth definitions also support-functions
93 \ ***** check-password
95 \ If a password was defined, execute autoboot and ask for
96 \ password if autoboot returns.
105 password .len @ read-password
106 dup password .len @ = if
107 2dup password .addr @ password .len @
108 compare 0= if r> drop true >r then
119 \ Initializes support.4th global variables, sets loader_conf_files,
120 \ process conf files, and, if any one such file was succesfully
121 \ read to the end, load kernel and modules.
123 : start ( -- ) ( throws: abort & user-defined )
124 s" boot.nfsroot.path" getenv? if
125 s" /boot/defaults/loader-bootp.conf" initialize
127 s" /boot/defaults/loader.conf" initialize
130 include_nextboot_file
131 \ Will *NOT* try to load kernel and modules if no configuration file
132 \ was succesfully loaded!
141 \ Overrides support.4th initialization word with one that does
142 \ everything start one does, short of loading the kernel and
143 \ modules. Returns a flag
145 : initialize ( -- flag )
146 s" boot.nfsroot.path" getenv? if
147 s" /boot/defaults/loader-bootp.conf" initialize
149 s" /boot/defaults/loader.conf" initialize
152 include_nextboot_file
158 \ Read a configuration file, whose name was specified on the command
159 \ line, if interpreted, or given on the stack, if compiled in.
161 : (read-conf) ( addr len -- )
162 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
163 strdup conf_files .len ! conf_files .addr !
164 include_conf_files \ Will recurse on new loader_conf_files definitions
167 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
177 \ ***** enable-module
179 \ Turn a module loading on.
181 : enable-module ( <module> -- )
182 bl parse module_options @ >r
187 r@ module.name dup .addr @ swap .len @
190 r@ module.name dup .addr @ swap .len @ type
191 true r> module.flag !
192 ." will be loaded." cr
198 type ." wasn't found." cr
201 \ ***** disable-module
203 \ Turn a module loading off.
205 : disable-module ( <module> -- )
206 bl parse module_options @ >r
211 r@ module.name dup .addr @ swap .len @
214 r@ module.name dup .addr @ swap .len @ type
215 false r> module.flag !
216 ." will not be loaded." cr
222 type ." wasn't found." cr
225 \ ***** toggle-module
227 \ Turn a module loading on/off.
229 : toggle-module ( <module> -- )
230 bl parse module_options @ >r
235 r@ module.name dup .addr @ swap .len @
238 r@ module.name dup .addr @ swap .len @ type
239 r@ module.flag @ 0= dup r> module.flag !
241 ." will be loaded." cr
243 ." will not be loaded." cr
250 type ." wasn't found." cr
255 \ Show loading information about a module.
257 : show-module ( <module> -- )
258 bl parse module_options @ >r
263 r@ module.name dup .addr @ swap .len @
266 ." Name: " r@ module.name dup .addr @ swap .len @ type cr
267 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
268 ." Type: " r@ module.type dup .addr @ swap .len @ type cr
269 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
270 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
271 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
272 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
273 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
279 type ." wasn't found." cr
282 \ Words to be used inside configuration files
284 : retry false ; \ For use in load error commands
285 : ignore true ; \ For use in load error commands
287 \ Return to strict forth vocabulary
295 : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
299 s" boot-conf" s" load kernel and modules, then autoboot" .?
300 s" read-conf" s" read a configuration file" .?
301 s" enable-module" s" enable loading of a module" .?
302 s" disable-module" s" disable loading of a module" .?
303 s" toggle-module" s" toggle loading of a module" .?
304 s" show-module" s" show module load data" .?