1 \ Copyright (c) 1999 Daniel C. Sobral <dcs@FreeBSD.org>
2 \ Copyright (c) 2011-2015 Devin Teske <dteske@FreeBSD.org>
5 \ Redistribution and use in source and binary forms, with or without
6 \ modification, are permitted provided that the following conditions
8 \ 1. Redistributions of source code must retain the above copyright
9 \ notice, this list of conditions and the following disclaimer.
10 \ 2. Redistributions in binary form must reproduce the above copyright
11 \ notice, this list of conditions and the following disclaimer in the
12 \ documentation and/or other materials provided with the distribution.
14 \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 only forth definitions
30 s" arch-i386" environment? [if] [if]
31 s" loader_version" environment? [if]
33 .( Loader version 1.1+ required) cr
37 .( Could not get loader version!) cr
42 256 dictthreshold ! \ 256 cells minimum free space
43 2048 dictincrease ! \ 2048 additional cells each time
45 include /boot/support.4th
46 include /boot/color.4th
47 include /boot/delay.4th
48 include /boot/check-password.4th
50 only forth definitions
53 loader_color? dup ( -- bool bool )
61 \ menu-unset may not be present
62 s" beastie_disable" getenv
64 s" YES" compare-insensitive 0= if
84 only forth also support-functions also builtins definitions
87 0= if ( interpreted ) get_arguments then
89 \ Unload only if a path was passed
95 s" kernelname" getenv? if ( a kernel has been loaded )
99 load_kernel_and_modules
102 bootmsg 0 1 boot exit
105 s" kernelname" getenv? if ( a kernel has been loaded )
109 load_kernel_and_modules
112 bootmsg 0 1 boot exit
114 load_kernel_and_modules
115 ?dup 0= if bootmsg 0 1 boot then
120 \ Prepares to boot as specified by loaded configuration files.
123 0= if ( interpreted ) get_arguments then
125 load_kernel_and_modules
126 ?dup 0= if 0 1 autoboot then
129 also forth definitions previous
134 only forth definitions also support-functions
138 \ Initializes support.4th global variables, sets loader_conf_files,
139 \ processes conf files, and, if any one such file was succesfully
140 \ read to the end, loads kernel and modules.
142 : start ( -- ) ( throws: abort & user-defined )
143 s" /boot/defaults/loader.conf" initialize
145 include_nextboot_file
146 \ Will *NOT* try to load kernel and modules if no configuration file
147 \ was succesfully loaded!
149 s" loader_delay" getenv -1 = if
155 ." Loading Kernel and Modules (Ctrl-C to Abort)" cr
156 s" also support-functions" evaluate
157 s" set delay_command='load_xen_throw load_kernel load_modules'" evaluate
158 s" set delay_showdots" evaluate
166 \ Overrides support.4th initialization word with one that does
167 \ everything start one does, short of loading the kernel and
168 \ modules. Returns a flag
170 : initialize ( -- flag )
171 s" /boot/defaults/loader.conf" initialize
173 include_nextboot_file
179 \ Read a configuration file, whose name was specified on the command
180 \ line, if interpreted, or given on the stack, if compiled in.
182 : (read-conf) ( addr len -- )
184 include_conf_files \ Will recurse on new loader_conf_files definitions
187 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
197 \ show, enable, disable, toggle module loading. They all take module from
200 : set-module-flag ( module_addr val -- ) \ set and print flag
202 dup module.name strtype
203 module.flag @ if ." will be loaded" else ." will not be loaded" then cr
206 : enable-module find-module ?dup if true set-module-flag then ;
208 : disable-module find-module ?dup if false set-module-flag then ;
210 : toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
214 \ Show loading information about a module.
216 : show-module ( <module> -- ) find-module ?dup if show-one-module then ;
218 \ Words to be used inside configuration files
220 : retry false ; \ For use in load error commands
221 : ignore true ; \ For use in load error commands
223 \ Return to strict forth vocabulary
231 : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
235 s" boot-conf" s" load kernel and modules, then autoboot" .?
236 s" read-conf" s" read a configuration file" .?
237 s" enable-module" s" enable loading of a module" .?
238 s" disable-module" s" disable loading of a module" .?
239 s" toggle-module" s" toggle loading of a module" .?
240 s" show-module" s" show module load data" .?
241 s" try-include" s" try to load/interpret files" .?
244 : try-include ( -- ) \ see loader.4th(8)
245 ['] include ( -- xt ) \ get the execution token of `include'
246 catch ( xt -- exception# | 0 ) if \ failed
247 LF parse ( c -- s-addr/u ) 2drop \ advance >in to EOL (drop data)
248 \ ... prevents words unused by `include' from being interpreted
250 ; immediate \ interpret immediately for access to `source' (aka tib)
252 only forth definitions