1ca987d46SWarner Losh\ Copyright (c) 1999 Daniel C. Sobral <dcs@FreeBSD.org> 2ca987d46SWarner Losh\ Copyright (c) 2011-2015 Devin Teske <dteske@FreeBSD.org> 3ca987d46SWarner Losh\ All rights reserved. 4ca987d46SWarner Losh\ 5ca987d46SWarner Losh\ Redistribution and use in source and binary forms, with or without 6ca987d46SWarner Losh\ modification, are permitted provided that the following conditions 7ca987d46SWarner Losh\ are met: 8ca987d46SWarner Losh\ 1. Redistributions of source code must retain the above copyright 9ca987d46SWarner Losh\ notice, this list of conditions and the following disclaimer. 10ca987d46SWarner Losh\ 2. Redistributions in binary form must reproduce the above copyright 11ca987d46SWarner Losh\ notice, this list of conditions and the following disclaimer in the 12ca987d46SWarner Losh\ documentation and/or other materials provided with the distribution. 13ca987d46SWarner Losh\ 14ca987d46SWarner Losh\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ca987d46SWarner Losh\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ca987d46SWarner Losh\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ca987d46SWarner Losh\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18ca987d46SWarner Losh\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ca987d46SWarner Losh\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ca987d46SWarner Losh\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ca987d46SWarner Losh\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ca987d46SWarner Losh\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ca987d46SWarner Losh\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ca987d46SWarner Losh\ SUCH DAMAGE. 25ca987d46SWarner Losh\ 26ca987d46SWarner Losh\ $FreeBSD$ 27ca987d46SWarner Losh 28ca987d46SWarner Loshonly forth definitions 29ca987d46SWarner Losh 30*68861a62SToomas Soome\ provide u> if needed 31*68861a62SToomas Soomes" u>" sfind [if] drop [else] 32*68861a62SToomas Soome drop 33*68861a62SToomas Soome: u> 34*68861a62SToomas Soome 2dup u< if 2drop 0 exit then 35*68861a62SToomas Soome swap u< if -1 exit then 36*68861a62SToomas Soome 0 37*68861a62SToomas Soome; 38*68861a62SToomas Soome[then] 39*68861a62SToomas Soome 40*68861a62SToomas Soome\ provide xemit if needed 41*68861a62SToomas Soomes" xemit" sfind [if] drop [else] 42*68861a62SToomas Soome drop 43*68861a62SToomas Soome: xemit 44*68861a62SToomas Soome dup 0x80 u< if emit exit then 45*68861a62SToomas Soome 0 swap 0x3F 46*68861a62SToomas Soome begin 2dup u> while 47*68861a62SToomas Soome 2/ >r dup 0x3F and 0x80 or swap 6 rshift r> 48*68861a62SToomas Soome repeat 0x7F xor 2* or 49*68861a62SToomas Soome begin dup 0x80 u< 0= while emit repeat drop 50*68861a62SToomas Soome; 51*68861a62SToomas Soome[then] 52*68861a62SToomas Soome 53ca987d46SWarner Loshs" arch-i386" environment? [if] [if] 54ca987d46SWarner Losh s" loader_version" environment? [if] 55ca987d46SWarner Losh 11 < [if] 56ca987d46SWarner Losh .( Loader version 1.1+ required) cr 57ca987d46SWarner Losh abort 58ca987d46SWarner Losh [then] 59ca987d46SWarner Losh [else] 60ca987d46SWarner Losh .( Could not get loader version!) cr 61ca987d46SWarner Losh abort 62ca987d46SWarner Losh [then] 63ca987d46SWarner Losh[then] [then] 64ca987d46SWarner Losh 65ca987d46SWarner Losh256 dictthreshold ! \ 256 cells minimum free space 66ca987d46SWarner Losh2048 dictincrease ! \ 2048 additional cells each time 67ca987d46SWarner Losh 68ca987d46SWarner Loshinclude /boot/support.4th 69ca987d46SWarner Loshinclude /boot/color.4th 70ca987d46SWarner Loshinclude /boot/delay.4th 71ca987d46SWarner Loshinclude /boot/check-password.4th 72ca987d46SWarner Losh 73ca987d46SWarner Loshonly forth definitions 74ca987d46SWarner Losh 75ca987d46SWarner Losh: bootmsg ( -- ) 76ca987d46SWarner Losh loader_color? dup ( -- bool bool ) 77ca987d46SWarner Losh if 7 fg 4 bg then 78ca987d46SWarner Losh ." Booting..." 79ca987d46SWarner Losh if me then 80ca987d46SWarner Losh cr 81ca987d46SWarner Losh; 82ca987d46SWarner Losh 83ca987d46SWarner Losh: try-menu-unset 84ca987d46SWarner Losh \ menu-unset may not be present 85ca987d46SWarner Losh s" beastie_disable" getenv 86ca987d46SWarner Losh dup -1 <> if 87ca987d46SWarner Losh s" YES" compare-insensitive 0= if 88ca987d46SWarner Losh exit 89ca987d46SWarner Losh then 90ca987d46SWarner Losh else 91ca987d46SWarner Losh drop 92ca987d46SWarner Losh then 93ca987d46SWarner Losh s" menu-unset" 94ca987d46SWarner Losh sfind if 95ca987d46SWarner Losh execute 96ca987d46SWarner Losh else 97ca987d46SWarner Losh drop 98ca987d46SWarner Losh then 99ca987d46SWarner Losh s" menusets-unset" 100ca987d46SWarner Losh sfind if 101ca987d46SWarner Losh execute 102ca987d46SWarner Losh else 103ca987d46SWarner Losh drop 104ca987d46SWarner Losh then 105ca987d46SWarner Losh; 106ca987d46SWarner Losh 107ca987d46SWarner Loshonly forth also support-functions also builtins definitions 108ca987d46SWarner Losh 109ca987d46SWarner Losh: boot 110ca987d46SWarner Losh 0= if ( interpreted ) get_arguments then 111ca987d46SWarner Losh 112ca987d46SWarner Losh \ Unload only if a path was passed 113ca987d46SWarner Losh dup if 114ca987d46SWarner Losh >r over r> swap 115ca987d46SWarner Losh c@ [char] - <> if 116ca987d46SWarner Losh 0 1 unload drop 117ca987d46SWarner Losh else 118ca987d46SWarner Losh s" kernelname" getenv? if ( a kernel has been loaded ) 119ca987d46SWarner Losh try-menu-unset 120ca987d46SWarner Losh bootmsg 1 boot exit 121ca987d46SWarner Losh then 122ca987d46SWarner Losh load_kernel_and_modules 123ca987d46SWarner Losh ?dup if exit then 124ca987d46SWarner Losh try-menu-unset 125ca987d46SWarner Losh bootmsg 0 1 boot exit 126ca987d46SWarner Losh then 127ca987d46SWarner Losh else 128ca987d46SWarner Losh s" kernelname" getenv? if ( a kernel has been loaded ) 129ca987d46SWarner Losh try-menu-unset 130ca987d46SWarner Losh bootmsg 1 boot exit 131ca987d46SWarner Losh then 132ca987d46SWarner Losh load_kernel_and_modules 133ca987d46SWarner Losh ?dup if exit then 134ca987d46SWarner Losh try-menu-unset 135ca987d46SWarner Losh bootmsg 0 1 boot exit 136ca987d46SWarner Losh then 137ca987d46SWarner Losh load_kernel_and_modules 138ca987d46SWarner Losh ?dup 0= if bootmsg 0 1 boot then 139ca987d46SWarner Losh; 140ca987d46SWarner Losh 141ca987d46SWarner Losh\ ***** boot-conf 142ca987d46SWarner Losh\ 143ca987d46SWarner Losh\ Prepares to boot as specified by loaded configuration files. 144ca987d46SWarner Losh 145ca987d46SWarner Losh: boot-conf 146ca987d46SWarner Losh 0= if ( interpreted ) get_arguments then 147ca987d46SWarner Losh 0 1 unload drop 148ca987d46SWarner Losh load_kernel_and_modules 149ca987d46SWarner Losh ?dup 0= if 0 1 autoboot then 150ca987d46SWarner Losh; 151ca987d46SWarner Losh 152ca987d46SWarner Loshalso forth definitions previous 153ca987d46SWarner Losh 154ca987d46SWarner Loshbuiltin: boot 155ca987d46SWarner Loshbuiltin: boot-conf 156ca987d46SWarner Losh 157ca987d46SWarner Loshonly forth definitions also support-functions 158ca987d46SWarner Losh 159ca987d46SWarner Losh\ ***** start 160ca987d46SWarner Losh\ 161ca987d46SWarner Losh\ Initializes support.4th global variables, sets loader_conf_files, 162ca987d46SWarner Losh\ processes conf files, and, if any one such file was successfully 163ca987d46SWarner Losh\ read to the end, loads kernel and modules. 164ca987d46SWarner Losh 165ca987d46SWarner Losh: start ( -- ) ( throws: abort & user-defined ) 166ca987d46SWarner Losh s" /boot/defaults/loader.conf" initialize 167ca987d46SWarner Losh include_conf_files 168ca987d46SWarner Losh include_nextboot_file 169ca987d46SWarner Losh \ If the user defined a post-initialize hook, call it now 170ca987d46SWarner Losh s" post-initialize" sfind if execute else drop then 171ca987d46SWarner Losh \ Will *NOT* try to load kernel and modules if no configuration file 172ca987d46SWarner Losh \ was successfully loaded! 173ca987d46SWarner Losh any_conf_read? if 174ca987d46SWarner Losh s" loader_delay" getenv -1 = if 175ca987d46SWarner Losh load_xen_throw 176ca987d46SWarner Losh load_kernel 177ca987d46SWarner Losh load_modules 178ca987d46SWarner Losh else 179ca987d46SWarner Losh drop 180ca987d46SWarner Losh ." Loading Kernel and Modules (Ctrl-C to Abort)" cr 181ca987d46SWarner Losh s" also support-functions" evaluate 182ca987d46SWarner Losh s" set delay_command='load_xen_throw load_kernel load_modules'" evaluate 183ca987d46SWarner Losh s" set delay_showdots" evaluate 184ca987d46SWarner Losh delay_execute 185ca987d46SWarner Losh then 186ca987d46SWarner Losh then 187ca987d46SWarner Losh; 188ca987d46SWarner Losh 189ca987d46SWarner Losh\ ***** initialize 190ca987d46SWarner Losh\ 191ca987d46SWarner Losh\ Overrides support.4th initialization word with one that does 192ca987d46SWarner Losh\ everything start one does, short of loading the kernel and 193ca987d46SWarner Losh\ modules. Returns a flag. 194ca987d46SWarner Losh 195ca987d46SWarner Losh: initialize ( -- flag ) 196ca987d46SWarner Losh s" /boot/defaults/loader.conf" initialize 197ca987d46SWarner Losh include_conf_files 198ca987d46SWarner Losh include_nextboot_file 199ca987d46SWarner Losh \ If the user defined a post-initialize hook, call it now 200ca987d46SWarner Losh s" post-initialize" sfind if execute else drop then 201ca987d46SWarner Losh any_conf_read? 202ca987d46SWarner Losh; 203ca987d46SWarner Losh 204ca987d46SWarner Losh\ ***** read-conf 205ca987d46SWarner Losh\ 206ca987d46SWarner Losh\ Read a configuration file, whose name was specified on the command 207ca987d46SWarner Losh\ line, if interpreted, or given on the stack, if compiled in. 208ca987d46SWarner Losh 209ca987d46SWarner Losh: (read-conf) ( addr len -- ) 210ca987d46SWarner Losh conf_files string= 211ca987d46SWarner Losh include_conf_files \ Will recurse on new loader_conf_files definitions 212ca987d46SWarner Losh; 213ca987d46SWarner Losh 214ca987d46SWarner Losh: read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined ) 215ca987d46SWarner Losh state @ if 216ca987d46SWarner Losh \ Compiling 217ca987d46SWarner Losh postpone (read-conf) 218ca987d46SWarner Losh else 219ca987d46SWarner Losh \ Interpreting 220ca987d46SWarner Losh bl parse (read-conf) 221ca987d46SWarner Losh then 222ca987d46SWarner Losh; immediate 223ca987d46SWarner Losh 224ca987d46SWarner Losh\ show, enable, disable, toggle module loading. They all take module from 225ca987d46SWarner Losh\ the next word 226ca987d46SWarner Losh 227ca987d46SWarner Losh: set-module-flag ( module_addr val -- ) \ set and print flag 228ca987d46SWarner Losh over module.flag ! 229ca987d46SWarner Losh dup module.name strtype 230ca987d46SWarner Losh module.flag @ if ." will be loaded" else ." will not be loaded" then cr 231ca987d46SWarner Losh; 232ca987d46SWarner Losh 233ca987d46SWarner Losh: enable-module find-module ?dup if true set-module-flag then ; 234ca987d46SWarner Losh 235ca987d46SWarner Losh: disable-module find-module ?dup if false set-module-flag then ; 236ca987d46SWarner Losh 237ca987d46SWarner Losh: toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ; 238ca987d46SWarner Losh 239ca987d46SWarner Losh\ ***** show-module 240ca987d46SWarner Losh\ 241ca987d46SWarner Losh\ Show loading information about a module. 242ca987d46SWarner Losh 243ca987d46SWarner Losh: show-module ( <module> -- ) find-module ?dup if show-one-module then ; 244ca987d46SWarner Losh 245ca987d46SWarner Losh\ Words to be used inside configuration files 246ca987d46SWarner Losh 247ca987d46SWarner Losh: retry false ; \ For use in load error commands 248ca987d46SWarner Losh: ignore true ; \ For use in load error commands 249ca987d46SWarner Losh 250ca987d46SWarner Losh\ Return to strict forth vocabulary 251ca987d46SWarner Losh 252ca987d46SWarner Losh: #type 253ca987d46SWarner Losh over - >r 254ca987d46SWarner Losh type 255ca987d46SWarner Losh r> spaces 256ca987d46SWarner Losh; 257ca987d46SWarner Losh 258ca987d46SWarner Losh: .? 2 spaces 2swap 15 #type 2 spaces type cr ; 259ca987d46SWarner Losh 260ca987d46SWarner Losh\ Execute the ? command to print all the commands defined in 261ca987d46SWarner Losh\ C, then list the ones we support here. Please note that this 262ca987d46SWarner Losh\ doesn't use pager_* routines that the C implementation of ? 263ca987d46SWarner Losh\ does, so these will always appear, even if you stop early 264ca987d46SWarner Losh\ there. And they may cause the commands to scroll off the 265ca987d46SWarner Losh\ screen if the number of commands modulus LINES is close 266ca987d46SWarner Losh\ to LINEs.... 267ca987d46SWarner Losh: ? 268ca987d46SWarner Losh ['] ? execute 269ca987d46SWarner Losh s" boot-conf" s" load kernel and modules, then autoboot" .? 270ca987d46SWarner Losh s" read-conf" s" read a configuration file" .? 271ca987d46SWarner Losh s" enable-module" s" enable loading of a module" .? 272ca987d46SWarner Losh s" disable-module" s" disable loading of a module" .? 273ca987d46SWarner Losh s" toggle-module" s" toggle loading of a module" .? 274ca987d46SWarner Losh s" show-module" s" show module load data" .? 275ca987d46SWarner Losh s" try-include" s" try to load/interpret files" .? 276ca987d46SWarner Losh; 277ca987d46SWarner Losh 278ca987d46SWarner Losh: try-include ( -- ) \ see loader.4th(8) 279ca987d46SWarner Losh ['] include ( -- xt ) \ get the execution token of `include' 280ca987d46SWarner Losh catch ( xt -- exception# | 0 ) if \ failed 281ca987d46SWarner Losh LF parse ( c -- s-addr/u ) 2drop \ advance >in to EOL (drop data) 282ca987d46SWarner Losh \ ... prevents words unused by `include' from being interpreted 283ca987d46SWarner Losh then 284ca987d46SWarner Losh; immediate \ interpret immediately for access to `source' (aka tib) 285ca987d46SWarner Losh 286ca987d46SWarner Loshonly forth definitions 287