loader.4th revision 262701
144603Sdcs\ Copyright (c) 1999 Daniel C. Sobral <dcs@freebsd.org>
244603Sdcs\ All rights reserved.
344603Sdcs\
444603Sdcs\ Redistribution and use in source and binary forms, with or without
544603Sdcs\ modification, are permitted provided that the following conditions
644603Sdcs\ are met:
744603Sdcs\ 1. Redistributions of source code must retain the above copyright
844603Sdcs\    notice, this list of conditions and the following disclaimer.
944603Sdcs\ 2. Redistributions in binary form must reproduce the above copyright
1044603Sdcs\    notice, this list of conditions and the following disclaimer in the
1144603Sdcs\    documentation and/or other materials provided with the distribution.
1244603Sdcs\
1344603Sdcs\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1444603Sdcs\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1544603Sdcs\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1644603Sdcs\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1744603Sdcs\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1844603Sdcs\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1944603Sdcs\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2044603Sdcs\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2144603Sdcs\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2244603Sdcs\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2344603Sdcs\ SUCH DAMAGE.
2444603Sdcs\
2550477Speter\ $FreeBSD: stable/10/sys/boot/forth/loader.4th 262701 2014-03-03 07:16:39Z dteske $
2644603Sdcs
2761694Sdcss" arch-i386" environment? [if] [if]
2861694Sdcs	s" loader_version" environment?  [if]
2987636Sjhb		11 < [if]
3087636Sjhb			.( Loader version 1.1+ required) cr
3161694Sdcs			abort
3261694Sdcs		[then]
3361694Sdcs	[else]
3461694Sdcs		.( Could not get loader version!) cr
3561694Sdcs		abort
3661694Sdcs	[then]
3761694Sdcs[then] [then]
3861379Sdcs
3977444Sdcs256 dictthreshold !  \ 256 cells minimum free space
4077444Sdcs2048 dictincrease !  \ 2048 additional cells each time
4177444Sdcs
4244603Sdcsinclude /boot/support.4th
43241361Sdteskeinclude /boot/color.4th
4444603Sdcs
4565883Sdcsonly forth also support-functions also builtins definitions
4661376Sdcs
47262701Sdteske: bootmsg ( -- )
48262701Sdteske  loader_color? if
49262701Sdteske    ." [37;44mBooting...[0m" cr
50262701Sdteske  else
51262701Sdteske    ." Booting..." cr
52262701Sdteske  then
53262701Sdteske;
54262701Sdteske
55228985Spluknet: try-menu-unset
56229881Spluknet  \ menu-unset may not be present
57229881Spluknet  s" beastie_disable" getenv
58229881Spluknet  dup -1 <> if
59229881Spluknet    s" YES" compare-insensitive 0= if
60229881Spluknet      exit
61229881Spluknet    then
62229881Spluknet  else
63229881Spluknet    drop
64229881Spluknet  then
65228985Spluknet  s" menu-unset"
66229881Spluknet  sfind if
67229881Spluknet    execute
68229881Spluknet  else
69229881Spluknet    drop
70228985Spluknet  then
71242667Sdteske  s" menusets-unset"
72242667Sdteske  sfind if
73242667Sdteske    execute
74242667Sdteske  else
75242667Sdteske    drop
76242667Sdteske  then
77228985Spluknet;
78228985Spluknet
7965883Sdcs: boot
8065949Sdcs  0= if ( interpreted ) get_arguments then
8161376Sdcs
8265630Sdcs  \ Unload only if a path was passed
8365883Sdcs  dup if
8465883Sdcs    >r over r> swap
8565630Sdcs    c@ [char] - <> if
8665630Sdcs      0 1 unload drop
8765630Sdcs    else
8866871Sdcs      s" kernelname" getenv? if ( a kernel has been loaded )
89228985Spluknet        try-menu-unset
90262701Sdteske        bootmsg 1 boot exit
9165938Sdcs      then
9266871Sdcs      load_kernel_and_modules
9366871Sdcs      ?dup if exit then
94228985Spluknet      try-menu-unset
95262701Sdteske      bootmsg 0 1 boot exit
9665630Sdcs    then
9765630Sdcs  else
9866871Sdcs    s" kernelname" getenv? if ( a kernel has been loaded )
99228985Spluknet      try-menu-unset
100262701Sdteske      bootmsg 1 boot exit
10165938Sdcs    then
10266871Sdcs    load_kernel_and_modules
10366871Sdcs    ?dup if exit then
104228985Spluknet    try-menu-unset
105262701Sdteske    bootmsg 0 1 boot exit
10665630Sdcs  then
10765945Sdcs  load_kernel_and_modules
108262701Sdteske  ?dup 0= if bootmsg 0 1 boot then
10965621Sdcs;
11065621Sdcs
111228985Spluknet\ ***** boot-conf
112228985Spluknet\
113228985Spluknet\	Prepares to boot as specified by loaded configuration files.
114228985Spluknet
11565621Sdcs: boot-conf
11665949Sdcs  0= if ( interpreted ) get_arguments then
11765630Sdcs  0 1 unload drop
11865945Sdcs  load_kernel_and_modules
11965621Sdcs  ?dup 0= if 0 1 autoboot then
12065621Sdcs;
12165621Sdcs
12265621Sdcsalso forth definitions also builtins
12365883Sdcs
12465621Sdcsbuiltin: boot
12561376Sdcsbuiltin: boot-conf
12665883Sdcs
12761376Sdcsonly forth definitions also support-functions
12861376Sdcs
129222417Sjulianinclude /boot/check-password.4th
13053672Sdcs
13144603Sdcs\ ***** start
13244603Sdcs\
13344603Sdcs\       Initializes support.4th global variables, sets loader_conf_files,
134262701Sdteske\       processes conf files, and, if any one such file was succesfully
135262701Sdteske\       read to the end, loads kernel and modules.
13644603Sdcs
13744603Sdcs: start  ( -- ) ( throws: abort & user-defined )
13844603Sdcs  s" /boot/defaults/loader.conf" initialize
13944603Sdcs  include_conf_files
14097201Sgordon  include_nextboot_file
14144603Sdcs  \ Will *NOT* try to load kernel and modules if no configuration file
14244603Sdcs  \ was succesfully loaded!
14344603Sdcs  any_conf_read? if
14444603Sdcs    load_kernel
14544603Sdcs    load_modules
14644603Sdcs  then
14744603Sdcs;
14844603Sdcs
14947198Sdcs\ ***** initialize
15047198Sdcs\
15147198Sdcs\	Overrides support.4th initialization word with one that does
15247198Sdcs\	everything start one does, short of loading the kernel and
15347198Sdcs\	modules. Returns a flag
15447198Sdcs
15547198Sdcs: initialize ( -- flag )
15647198Sdcs  s" /boot/defaults/loader.conf" initialize
15747198Sdcs  include_conf_files
15897201Sgordon  include_nextboot_file
15947198Sdcs  any_conf_read?
16047198Sdcs;
16147198Sdcs
16244603Sdcs\ ***** read-conf
16344603Sdcs\
16444603Sdcs\	Read a configuration file, whose name was specified on the command
16544603Sdcs\	line, if interpreted, or given on the stack, if compiled in.
16644603Sdcs
16744603Sdcs: (read-conf)  ( addr len -- )
168186789Sluigi  conf_files string=
16944603Sdcs  include_conf_files \ Will recurse on new loader_conf_files definitions
17044603Sdcs;
17144603Sdcs
17244603Sdcs: read-conf  ( <filename> | addr len -- ) ( throws: abort & user-defined )
17344603Sdcs  state @ if
17444603Sdcs    \ Compiling
17544603Sdcs    postpone (read-conf)
17644603Sdcs  else
17744603Sdcs    \ Interpreting
17844603Sdcs    bl parse (read-conf)
17944603Sdcs  then
18044603Sdcs; immediate
18144603Sdcs
182186789Sluigi\ show, enable, disable, toggle module loading. They all take module from
183186789Sluigi\ the next word
18446005Sdcs
185186789Sluigi: set-module-flag ( module_addr val -- ) \ set and print flag
186186789Sluigi  over module.flag !
187186789Sluigi  dup module.name strtype
188186789Sluigi  module.flag @ if ."  will be loaded" else ."  will not be loaded" then cr
18946005Sdcs;
19046005Sdcs
191186789Sluigi: enable-module find-module ?dup if true set-module-flag then ;
19246005Sdcs
193186789Sluigi: disable-module find-module ?dup if false set-module-flag then ;
19446005Sdcs
195186789Sluigi: toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
19646005Sdcs
19744603Sdcs\ ***** show-module
19844603Sdcs\
19944603Sdcs\	Show loading information about a module.
20044603Sdcs
201186789Sluigi: show-module ( <module> -- ) find-module ?dup if show-one-module then ;
20244603Sdcs
20344603Sdcs\ Words to be used inside configuration files
20444603Sdcs
20544603Sdcs: retry false ;         \ For use in load error commands
20644603Sdcs: ignore true ;         \ For use in load error commands
20744603Sdcs
20844603Sdcs\ Return to strict forth vocabulary
20944603Sdcs
21065949Sdcs: #type
21165949Sdcs  over - >r
21265949Sdcs  type
21365949Sdcs  r> spaces
21465949Sdcs;
21565949Sdcs
21665949Sdcs: .? 2 spaces 2swap 15 #type 2 spaces type cr ;
21765949Sdcs
21865949Sdcs: ?
21965949Sdcs  ['] ? execute
22065949Sdcs  s" boot-conf" s" load kernel and modules, then autoboot" .?
22165949Sdcs  s" read-conf" s" read a configuration file" .?
22265949Sdcs  s" enable-module" s" enable loading of a module" .?
22365949Sdcs  s" disable-module" s" disable loading of a module" .?
22465949Sdcs  s" toggle-module" s" toggle loading of a module" .?
22565949Sdcs  s" show-module" s" show module load data" .?
22665949Sdcs;
22765949Sdcs
22844603Sdcsonly forth also
22947198Sdcs
230