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