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