loader.4th revision 50477
1\ Copyright (c) 1999 Daniel C. Sobral <dcs@freebsd.org> 2\ All rights reserved. 3\ 4\ Redistribution and use in source and binary forms, with or without 5\ modification, are permitted provided that the following conditions 6\ are met: 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. 12\ 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 23\ SUCH DAMAGE. 24\ 25\ $FreeBSD: head/sys/boot/forth/loader.4th 50477 1999-08-28 01:08:13Z peter $ 26 27include /boot/support.4th 28 29only forth definitions also support-functions 30 31\ ***** boot-conf 32\ 33\ Prepares to boot as specified by loaded configuration files. 34 35: boot-conf 36 load_kernel 37 load_modules 38 0 autoboot 39; 40 41\ ***** start 42\ 43\ Initializes support.4th global variables, sets loader_conf_files, 44\ process conf files, and, if any one such file was succesfully 45\ read to the end, load kernel and modules. 46 47: start ( -- ) ( throws: abort & user-defined ) 48 s" /boot/defaults/loader.conf" initialize 49 include_conf_files 50 \ Will *NOT* try to load kernel and modules if no configuration file 51 \ was succesfully loaded! 52 any_conf_read? if 53 load_kernel 54 load_modules 55 then 56; 57 58\ ***** initialize 59\ 60\ Overrides support.4th initialization word with one that does 61\ everything start one does, short of loading the kernel and 62\ modules. Returns a flag 63 64: initialize ( -- flag ) 65 s" /boot/defaults/loader.conf" initialize 66 include_conf_files 67 any_conf_read? 68; 69 70\ ***** read-conf 71\ 72\ Read a configuration file, whose name was specified on the command 73\ line, if interpreted, or given on the stack, if compiled in. 74 75: (read-conf) ( addr len -- ) 76 conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then 77 strdup conf_files .len ! conf_files .addr ! 78 include_conf_files \ Will recurse on new loader_conf_files definitions 79; 80 81: read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined ) 82 state @ if 83 \ Compiling 84 postpone (read-conf) 85 else 86 \ Interpreting 87 bl parse (read-conf) 88 then 89; immediate 90 91\ ***** enable-module 92\ 93\ Turn a module loading on. 94 95: enable-module ( <module> -- ) 96 bl parse module_options @ >r 97 begin 98 r@ 99 while 100 2dup 101 r@ module.name dup .addr @ swap .len @ 102 compare 0= if 103 2drop 104 r@ module.name dup .addr @ swap .len @ type 105 true r> module.flag ! 106 ." will be loaded." cr 107 exit 108 then 109 r> module.next @ >r 110 repeat 111 r> drop 112 type ." wasn't found." cr 113; 114 115\ ***** disable-module 116\ 117\ Turn a module loading off. 118 119: disable-module ( <module> -- ) 120 bl parse module_options @ >r 121 begin 122 r@ 123 while 124 2dup 125 r@ module.name dup .addr @ swap .len @ 126 compare 0= if 127 2drop 128 r@ module.name dup .addr @ swap .len @ type 129 false r> module.flag ! 130 ." will not be loaded." cr 131 exit 132 then 133 r> module.next @ >r 134 repeat 135 r> drop 136 type ." wasn't found." cr 137; 138 139\ ***** toggle-module 140\ 141\ Turn a module loading on/off. 142 143: toggle-module ( <module> -- ) 144 bl parse module_options @ >r 145 begin 146 r@ 147 while 148 2dup 149 r@ module.name dup .addr @ swap .len @ 150 compare 0= if 151 2drop 152 r@ module.name dup .addr @ swap .len @ type 153 r@ module.flag @ 0= dup r> module.flag ! 154 if 155 ." will be loaded." cr 156 else 157 ." will not be loaded." cr 158 then 159 exit 160 then 161 r> module.next @ >r 162 repeat 163 r> drop 164 type ." wasn't found." cr 165; 166 167\ ***** show-module 168\ 169\ Show loading information about a module. 170 171: show-module ( <module> -- ) 172 bl parse module_options @ >r 173 begin 174 r@ 175 while 176 2dup 177 r@ module.name dup .addr @ swap .len @ 178 compare 0= if 179 2drop 180 ." Name: " r@ module.name dup .addr @ swap .len @ type cr 181 ." Path: " r@ module.loadname dup .addr @ swap .len @ type cr 182 ." Type: " r@ module.type dup .addr @ swap .len @ type cr 183 ." Flags: " r@ module.args dup .addr @ swap .len @ type cr 184 ." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr 185 ." After load: " r@ module.afterload dup .addr @ swap .len @ type cr 186 ." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr 187 ." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr 188 exit 189 then 190 r> module.next @ >r 191 repeat 192 r> drop 193 type ." wasn't found." cr 194; 195 196\ Words to be used inside configuration files 197 198: retry false ; \ For use in load error commands 199: ignore true ; \ For use in load error commands 200 201\ Return to strict forth vocabulary 202 203only forth also 204 205