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.5.2.1 2000/07/07 00:14:34 obrien Exp $
26 \ $DragonFly: src/sys/boot/forth/loader.4th,v 1.2 2003/06/17 04:28:18 dillon Exp $
28 s" arch-alpha" environment? [if] [if]
29 s" loader_version" environment? [if]
31 .( Loader version 0.3+ 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 0.8+ required) cr
47 .( Could not get loader version!) cr
52 include /boot/support.4th
54 only forth definitions also support-functions
58 \ Prepares to boot as specified by loaded configuration files.
60 also support-functions definitions
62 : bootpath s" /boot/" ;
63 : modulepath s" module_path" ;
64 : saveenv ( addr len | 0 -1 -- addr' len | 0 -1 )
66 dup allocate abort" Out of memory"
71 : freeenv ( addr len | 0 -1 )
72 -1 = if drop else free abort" Freeing error" then
74 : restoreenv ( addr len | 0 -1 -- )
75 dup -1 = if ( it wasn't set )
81 r> free abort" Freeing error"
85 only forth also support-functions also builtins definitions
87 : boot-conf ( args 1 | 0 "args" -- flag )
91 \ Get next word on the command line
93 ?dup 0= if ( there wasn't anything )
95 else ( put in the number of strings )
100 if ( there are arguments )
101 \ Try to load the kernel
102 s" kernel_options" getenv dup -1 = if drop 2dup 1 else 2over 2 then
104 1 load if ( load command failed )
105 \ Remove garbage from the stack
107 \ Set the environment variable module_path, and try loading
110 \ First, save module_path value
111 modulepath getenv saveenv dup -1 = if 0 swap then 2>r
114 2dup modulepath setenv
116 \ Try to load the kernel
117 s" load ${kernel} ${kernel_options}" ['] evaluate catch
118 if ( load failed yet again )
119 \ Remove garbage from the stack
122 \ Try prepending /boot/
123 bootpath 2over nip over + allocate
130 0 2swap strcat 2swap strcat
131 2dup modulepath setenv
133 drop free if ( freeing memory error )
139 \ Now, once more, try to load the kernel
140 s" load ${kernel} ${kernel_options}" ['] evaluate catch
141 if ( failed once more )
147 else ( we found the kernel on the path passed )
149 2drop ( discard command line arguments )
151 then ( could not load kernel from directory passed )
153 \ Load the remaining modules, if the kernel was loaded at all
154 ['] load_modules catch if 2r> restoreenv 100 exit then
156 \ Call autoboot to perform the booting
159 \ Keep new module_path
163 then ( could not load kernel with name passed )
165 2drop ( discard command line arguments )
167 else ( try just a straight-forward kernel load )
168 s" load ${kernel} ${kernel_options}" ['] evaluate catch
169 if ( kernel load failed ) 2drop 100 exit then
171 then ( there are command line arguments )
173 \ Load the remaining modules, if the kernel was loaded at all
174 ['] load_modules catch if 100 exit then
176 \ Call autoboot to perform the booting
180 also forth definitions
182 only forth definitions also support-functions
184 \ ***** check-password
186 \ If a password was defined, execute autoboot and ask for
187 \ password if autoboot returns.
196 password .len @ read-password
197 dup password .len @ = if
198 2dup password .addr @ password .len @
199 compare 0= if r> drop true >r then
210 \ Initializes support.4th global variables, sets loader_conf_files,
211 \ process conf files, and, if any one such file was succesfully
212 \ read to the end, load kernel and modules.
214 : start ( -- ) ( throws: abort & user-defined )
215 s" /boot/defaults/loader.conf" initialize
217 \ Will *NOT* try to load kernel and modules if no configuration file
218 \ was succesfully loaded!
227 \ Overrides support.4th initialization word with one that does
228 \ everything start one does, short of loading the kernel and
229 \ modules. Returns a flag
231 : initialize ( -- flag )
232 s" /boot/defaults/loader.conf" initialize
239 \ Read a configuration file, whose name was specified on the command
240 \ line, if interpreted, or given on the stack, if compiled in.
242 : (read-conf) ( addr len -- )
243 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
244 strdup conf_files .len ! conf_files .addr !
245 include_conf_files \ Will recurse on new loader_conf_files definitions
248 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
258 \ ***** enable-module
260 \ Turn a module loading on.
262 : enable-module ( <module> -- )
263 bl parse module_options @ >r
268 r@ module.name dup .addr @ swap .len @
271 r@ module.name dup .addr @ swap .len @ type
272 true r> module.flag !
273 ." will be loaded." cr
279 type ." wasn't found." cr
282 \ ***** disable-module
284 \ Turn a module loading off.
286 : disable-module ( <module> -- )
287 bl parse module_options @ >r
292 r@ module.name dup .addr @ swap .len @
295 r@ module.name dup .addr @ swap .len @ type
296 false r> module.flag !
297 ." will not be loaded." cr
303 type ." wasn't found." cr
306 \ ***** toggle-module
308 \ Turn a module loading on/off.
310 : toggle-module ( <module> -- )
311 bl parse module_options @ >r
316 r@ module.name dup .addr @ swap .len @
319 r@ module.name dup .addr @ swap .len @ type
320 r@ module.flag @ 0= dup r> module.flag !
322 ." will be loaded." cr
324 ." will not be loaded." cr
331 type ." wasn't found." cr
336 \ Show loading information about a module.
338 : show-module ( <module> -- )
339 bl parse module_options @ >r
344 r@ module.name dup .addr @ swap .len @
347 ." Name: " r@ module.name dup .addr @ swap .len @ type cr
348 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
349 ." Type: " r@ module.type dup .addr @ swap .len @ type cr
350 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
351 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
352 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
353 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
354 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
360 type ." wasn't found." cr
363 \ Words to be used inside configuration files
365 : retry false ; \ For use in load error commands
366 : ignore true ; \ For use in load error commands
368 \ Return to strict forth vocabulary