loader.4th revision 262701
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: stable/10/sys/boot/forth/loader.4th 262701 2014-03-03 07:16:39Z dteske $
26
27s" arch-i386" environment? [if] [if]
28	s" loader_version" environment?  [if]
29		11 < [if]
30			.( Loader version 1.1+ required) cr
31			abort
32		[then]
33	[else]
34		.( Could not get loader version!) cr
35		abort
36	[then]
37[then] [then]
38
39256 dictthreshold !  \ 256 cells minimum free space
402048 dictincrease !  \ 2048 additional cells each time
41
42include /boot/support.4th
43include /boot/color.4th
44
45only forth also support-functions also builtins definitions
46
47: bootmsg ( -- )
48  loader_color? if
49    ." [37;44mBooting...[0m" cr
50  else
51    ." Booting..." cr
52  then
53;
54
55: try-menu-unset
56  \ menu-unset may not be present
57  s" beastie_disable" getenv
58  dup -1 <> if
59    s" YES" compare-insensitive 0= if
60      exit
61    then
62  else
63    drop
64  then
65  s" menu-unset"
66  sfind if
67    execute
68  else
69    drop
70  then
71  s" menusets-unset"
72  sfind if
73    execute
74  else
75    drop
76  then
77;
78
79: boot
80  0= if ( interpreted ) get_arguments then
81
82  \ Unload only if a path was passed
83  dup if
84    >r over r> swap
85    c@ [char] - <> if
86      0 1 unload drop
87    else
88      s" kernelname" getenv? if ( a kernel has been loaded )
89        try-menu-unset
90        bootmsg 1 boot exit
91      then
92      load_kernel_and_modules
93      ?dup if exit then
94      try-menu-unset
95      bootmsg 0 1 boot exit
96    then
97  else
98    s" kernelname" getenv? if ( a kernel has been loaded )
99      try-menu-unset
100      bootmsg 1 boot exit
101    then
102    load_kernel_and_modules
103    ?dup if exit then
104    try-menu-unset
105    bootmsg 0 1 boot exit
106  then
107  load_kernel_and_modules
108  ?dup 0= if bootmsg 0 1 boot then
109;
110
111\ ***** boot-conf
112\
113\	Prepares to boot as specified by loaded configuration files.
114
115: boot-conf
116  0= if ( interpreted ) get_arguments then
117  0 1 unload drop
118  load_kernel_and_modules
119  ?dup 0= if 0 1 autoboot then
120;
121
122also forth definitions also builtins
123
124builtin: boot
125builtin: boot-conf
126
127only forth definitions also support-functions
128
129include /boot/check-password.4th
130
131\ ***** start
132\
133\       Initializes support.4th global variables, sets loader_conf_files,
134\       processes conf files, and, if any one such file was succesfully
135\       read to the end, loads kernel and modules.
136
137: start  ( -- ) ( throws: abort & user-defined )
138  s" /boot/defaults/loader.conf" initialize
139  include_conf_files
140  include_nextboot_file
141  \ Will *NOT* try to load kernel and modules if no configuration file
142  \ was succesfully loaded!
143  any_conf_read? if
144    load_kernel
145    load_modules
146  then
147;
148
149\ ***** initialize
150\
151\	Overrides support.4th initialization word with one that does
152\	everything start one does, short of loading the kernel and
153\	modules. Returns a flag
154
155: initialize ( -- flag )
156  s" /boot/defaults/loader.conf" initialize
157  include_conf_files
158  include_nextboot_file
159  any_conf_read?
160;
161
162\ ***** read-conf
163\
164\	Read a configuration file, whose name was specified on the command
165\	line, if interpreted, or given on the stack, if compiled in.
166
167: (read-conf)  ( addr len -- )
168  conf_files string=
169  include_conf_files \ Will recurse on new loader_conf_files definitions
170;
171
172: read-conf  ( <filename> | addr len -- ) ( throws: abort & user-defined )
173  state @ if
174    \ Compiling
175    postpone (read-conf)
176  else
177    \ Interpreting
178    bl parse (read-conf)
179  then
180; immediate
181
182\ show, enable, disable, toggle module loading. They all take module from
183\ the next word
184
185: set-module-flag ( module_addr val -- ) \ set and print flag
186  over module.flag !
187  dup module.name strtype
188  module.flag @ if ."  will be loaded" else ."  will not be loaded" then cr
189;
190
191: enable-module find-module ?dup if true set-module-flag then ;
192
193: disable-module find-module ?dup if false set-module-flag then ;
194
195: toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
196
197\ ***** show-module
198\
199\	Show loading information about a module.
200
201: show-module ( <module> -- ) find-module ?dup if show-one-module then ;
202
203\ Words to be used inside configuration files
204
205: retry false ;         \ For use in load error commands
206: ignore true ;         \ For use in load error commands
207
208\ Return to strict forth vocabulary
209
210: #type
211  over - >r
212  type
213  r> spaces
214;
215
216: .? 2 spaces 2swap 15 #type 2 spaces type cr ;
217
218: ?
219  ['] ? execute
220  s" boot-conf" s" load kernel and modules, then autoboot" .?
221  s" read-conf" s" read a configuration file" .?
222  s" enable-module" s" enable loading of a module" .?
223  s" disable-module" s" disable loading of a module" .?
224  s" toggle-module" s" toggle loading of a module" .?
225  s" show-module" s" show module load data" .?
226;
227
228only forth also
229
230