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 $
27 s" arch-alpha" environment? [if] [if]
28 s" loader_version" environment? [if]
30 .( Loader version 0.3+ required) cr
34 .( Could not get loader version!) cr
39 s" arch-i386" environment? [if] [if]
40 s" loader_version" environment? [if]
42 .( Loader version 0.8+ required) cr
46 .( Could not get loader version!) cr
51 include /boot/support.4th
53 only forth definitions also support-functions
57 \ Prepares to boot as specified by loaded configuration files.
59 also support-functions definitions
61 : bootpath s" /boot/" ;
62 : modulepath s" module_path" ;
63 : saveenv ( addr len | 0 -1 -- addr' len | 0 -1 )
65 dup allocate abort" Out of memory"
70 : freeenv ( addr len | 0 -1 )
71 -1 = if drop else free abort" Freeing error" then
73 : restoreenv ( addr len | 0 -1 -- )
74 dup -1 = if ( it wasn't set )
80 r> free abort" Freeing error"
84 only forth also support-functions also builtins definitions
86 : boot-conf ( args 1 | 0 "args" -- flag )
90 \ Get next word on the command line
92 ?dup 0= if ( there wasn't anything )
94 else ( put in the number of strings )
99 if ( there are arguments )
100 \ Try to load the kernel
101 s" kernel_options" getenv dup -1 = if drop 2dup 1 else 2over 2 then
103 1 load if ( load command failed )
104 \ Remove garbage from the stack
106 \ Set the environment variable module_path, and try loading
109 \ First, save module_path value
110 modulepath getenv saveenv dup -1 = if 0 swap then 2>r
113 2dup modulepath setenv
115 \ Try to load the kernel
116 s" load ${kernel} ${kernel_options}" ['] evaluate catch
117 if ( load failed yet again )
118 \ Remove garbage from the stack
121 \ Try prepending /boot/
122 bootpath 2over nip over + allocate
129 0 2swap strcat 2swap strcat
130 2dup modulepath setenv
132 drop free if ( freeing memory error )
138 \ Now, once more, try to load the kernel
139 s" load ${kernel} ${kernel_options}" ['] evaluate catch
140 if ( failed once more )
146 else ( we found the kernel on the path passed )
148 2drop ( discard command line arguments )
150 then ( could not load kernel from directory passed )
152 \ Load the remaining modules, if the kernel was loaded at all
153 ['] load_modules catch if 2r> restoreenv 100 exit then
155 \ Call autoboot to perform the booting
158 \ Keep new module_path
162 then ( could not load kernel with name passed )
164 2drop ( discard command line arguments )
166 else ( try just a straight-forward kernel load )
167 s" load ${kernel} ${kernel_options}" ['] evaluate catch
168 if ( kernel load failed ) 2drop 100 exit then
170 then ( there are command line arguments )
172 \ Load the remaining modules, if the kernel was loaded at all
173 ['] load_modules catch if 100 exit then
175 \ Call autoboot to perform the booting
179 also forth definitions
181 only forth definitions also support-functions
183 \ ***** check-password
185 \ If a password was defined, execute autoboot and ask for
186 \ password if autoboot returns.
195 password .len @ read-password
196 dup password .len @ = if
197 2dup password .addr @ password .len @
198 compare 0= if r> drop true >r then
209 \ Initializes support.4th global variables, sets loader_conf_files,
210 \ process conf files, and, if any one such file was succesfully
211 \ read to the end, load kernel and modules.
213 : start ( -- ) ( throws: abort & user-defined )
214 s" /boot/defaults/loader.conf" initialize
216 \ Will *NOT* try to load kernel and modules if no configuration file
217 \ was succesfully loaded!
226 \ Overrides support.4th initialization word with one that does
227 \ everything start one does, short of loading the kernel and
228 \ modules. Returns a flag
230 : initialize ( -- flag )
231 s" /boot/defaults/loader.conf" initialize
238 \ Read a configuration file, whose name was specified on the command
239 \ line, if interpreted, or given on the stack, if compiled in.
241 : (read-conf) ( addr len -- )
242 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
243 strdup conf_files .len ! conf_files .addr !
244 include_conf_files \ Will recurse on new loader_conf_files definitions
247 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
257 \ ***** enable-module
259 \ Turn a module loading on.
261 : enable-module ( <module> -- )
262 bl parse module_options @ >r
267 r@ module.name dup .addr @ swap .len @
270 r@ module.name dup .addr @ swap .len @ type
271 true r> module.flag !
272 ." will be loaded." cr
278 type ." wasn't found." cr
281 \ ***** disable-module
283 \ Turn a module loading off.
285 : disable-module ( <module> -- )
286 bl parse module_options @ >r
291 r@ module.name dup .addr @ swap .len @
294 r@ module.name dup .addr @ swap .len @ type
295 false r> module.flag !
296 ." will not be loaded." cr
302 type ." wasn't found." cr
305 \ ***** toggle-module
307 \ Turn a module loading on/off.
309 : toggle-module ( <module> -- )
310 bl parse module_options @ >r
315 r@ module.name dup .addr @ swap .len @
318 r@ module.name dup .addr @ swap .len @ type
319 r@ module.flag @ 0= dup r> module.flag !
321 ." will be loaded." cr
323 ." will not be loaded." cr
330 type ." wasn't found." cr
335 \ Show loading information about a module.
337 : show-module ( <module> -- )
338 bl parse module_options @ >r
343 r@ module.name dup .addr @ swap .len @
346 ." Name: " r@ module.name dup .addr @ swap .len @ type cr
347 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
348 ." Type: " r@ module.type dup .addr @ swap .len @ type cr
349 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr
350 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
351 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
352 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
353 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
359 type ." wasn't found." cr
362 \ Words to be used inside configuration files
364 : retry false ; \ For use in load error commands
365 : ignore true ; \ For use in load error commands
367 \ Return to strict forth vocabulary