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