1 .\" Copyright (c) 1999 Daniel C. Sobral
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
30 .Nd kernel bootstrapping final stage
36 kernel bootstrapping process.
37 The actual name for the stage depends on the platform.
38 On IA32 (i386) architectures with BIOS firmware, it is a
42 It is linked statically to libstand and usually located in the directory
56 can load files from the
59 The NFS and TFTP based boot is enabled via
63 also does support uncompressing gzip files while reading.
64 The uncompression will happen automatically if the compressed file is stored
65 without .gz suffix or if the file is accessed by leaving out the .gz suffix from
67 If the file is referred by full name, including .gz suffix, then the file
68 content is read as is and the uncompression is not performed.
71 provides a scripting language that can be used to
72 automate tasks, do pre-configuration or assist in recovery
74 This scripting language is roughly divided in
76 The smaller one is a set of commands
77 designed for direct use by the casual user, called "builtin
78 commands" for historical reasons.
79 The main drive behind these commands is user-friendliness.
80 The bigger component is an
82 Forth compatible Forth interpreter based on FICL, by
85 During initialization,
87 will probe for a console and set the
89 variable, or set it to serial console
90 .Pq Do Li ttya Dc - Dq Li ttyd
91 if the previous boot stage used that.
92 If multiple consoles are selected, they will be listed separated by commas.
93 Then, devices are probed,
105 is initialized, the builtin words are added to its vocabulary.
106 The inner interpreter
117 is processed if available.
118 These files are processed through the
120 command, which reads all of them into memory before processing them,
121 making disk changes possible.
125 has not been tried, and if
129 (not case sensitive), then an
132 If the system gets past this point,
136 will engage interactive mode.
137 Please note that historically even when
141 user will be able to interrupt autoboot process by pressing some key
142 on the console while kernel and modules are being loaded.
144 cases such behaviour may be undesirable, to prevent it set
150 will engage interactive mode only if
156 builtin commands take parameters from the command line.
157 If an error condition occurs, an exception will be generated,
158 which can be intercepted using
160 Forth exception handling
162 If not intercepted, an error message will be displayed and
163 the interpreter's state will be reset, emptying the stack and restoring
166 The builtin commands available are:
168 .Bl -tag -width Ds -compact
169 .It Ic autoboot Op Ar seconds Op Ar prompt
170 Proceeds to bootstrap the system after a number of seconds, if not
171 interrupted by the user.
172 Displays a countdown prompt
173 warning the user the system is about to be booted,
174 unless interrupted by a key press.
175 The kernel will be loaded first if necessary.
176 Defaults to 10 seconds.
179 Displays statistics about disk cache usage.
183 .It Ic boot Ar kernelname Op Cm ...
184 .It Ic boot Fl flag Cm ...
185 Immediately proceeds to bootstrap the system, loading the kernel
187 Any flags or arguments are passed to the kernel, but they
188 must precede the kernel name, if a kernel name is provided.
191 The behavior of this builtin is changed if
195 .It Ic chain Ar device
196 Chain load another boot loader from the specified device.
197 Device can be either disk name or partition.
203 Displays text on the screen.
204 A new line will be printed unless
209 Displays memory usage statistics.
210 For debugging purposes only.
212 .It Ic help Op topic Op subtopic
213 Shows help messages read from
214 .Pa /boot/loader.help .
217 will list the topics available.
219 .It Ic include Ar file Op Ar
220 Process script files.
221 Each file, in turn, is completely read into memory,
222 and then each of its lines is passed to the command line interpreter.
223 If any error is returned by the interpreter, the include
224 command aborts immediately, without reading any other files, and
225 returns an error itself (see
232 Loads a kernel or file of opaque contents tagged as being of the type
234 Kernel and modules can be either in a.out or ELF format.
235 Any arguments passed after the name of the file to be loaded
236 will be passed as arguments to that file.
242 Displays a listing of files in the directory
244 or the root directory if
249 is specified, file sizes will be shown too.
252 Lists all of the devices from which it may be possible to load modules.
255 is specified, more details are printed.
258 Displays loaded modules.
261 is specified, more details are shown.
263 .It Ic more Ar file Op Ar
264 Display the files specified, with a pause at each
273 Reads a line of input from the terminal, storing it in
276 A timeout can be specified with
278 though it will be canceled at the first key pressed.
279 A prompt may also be displayed through the
284 Immediately reboots the system.
286 .It Ic set Ar variable
287 .It Ic set Ar variable Ns = Ns Ar value
288 Set loader's environment variables.
290 .It Ic show Op Va variable
291 Displays the specified variable's value, or all variables and their
297 Remove all modules from memory.
299 .It Ic unset Va variable
302 from the environment.
305 Lists available commands.
307 .Ss Builtin Environment Variables
310 has actually two different kinds of
313 There are ANS Forth's
314 .Em environmental queries ,
315 and a separate space of environment variables used by builtins, which
316 are not directly available to Forth words.
317 It is the latter type that this section covers.
319 Environment variables can be set and unset through the
323 builtins, and can have their values interactively examined through the
327 Their values can also be accessed as described in
330 Notice that these environment variables are not inherited by any shell
331 after the system has been booted.
333 A few variables are set automatically by
335 Others can affect the behavior of either
337 or the kernel at boot.
338 Some options may require a value,
339 while others define behavior just by being set.
340 Both types of builtin variables are described below.
341 .Bl -tag -width bootfile
342 .It Va autoboot_delay
345 will wait before booting.
346 If this variable is not defined,
348 will default to 10 seconds.
354 will be automatically attempted after processing
355 .Pa /boot/loader.rc ,
358 will be processed normally, defaulting to 10 seconds delay.
362 no delay will be inserted, but user still will be able to interrupt
364 process and escape into the interactive mode by pressing some key
365 on the console while kernel and
366 modules are being loaded.
370 no delay will be inserted and
372 will engage interactive mode only if
374 has failed for some reason.
390 .It Va boot_reconfigure
406 Will set custom arguments for the kernel.
411 startup will parse the
413 value to set boot prefixed variables listed above, any unrecognized options
414 are added to kernel command line verbatim.
416 The name of the kernel.
418 Defines the current console or consoles.
419 Multiple consoles may be specified.
420 In that case, the first listed console will become the default console for
424 Selects the default device.
425 Syntax for devices is odd.
429 if the Forth's current state is interpreting.
431 Define the number of lines on the screen, to be used by the pager.
433 Sets the list of directories which will be searched for modules
434 named in a load command or implicitly required by a dependency.
435 The default value for this variable is
436 .Dq Li /platform/i86pc/${ISADIR}
442 .Dq Li "${interpret}" .
445 is unset, the default prompt is
448 If set, the value is used to set
454 Other variables are used for loader or to set kernel properties or for
455 informational purposes.
457 When a builtin command is executed, the rest of the line is taken
458 by it as arguments, and it is processed by a special parser which
459 is not used for regular Forth commands.
461 This special parser applies the following rules to the parsed text:
464 All backslash characters are preprocessed.
467 \eb , \ef , \er , \en and \et are processed as in C.
469 \es is converted to a space.
476 Useful for things like
479 \e0xN and \e0xNN are replaced by the hex N or NN.
481 \eNNN is replaced by the octal NNN
485 \e" , \e' and \e$ will escape these characters, preventing them from
486 receiving special treatment in Step 2, described below.
488 \e\e will be replaced with a single \e .
490 In any other occurrence, backslash will just be removed.
493 Every string between non-escaped quotes or double-quotes will be treated
494 as a single word for the purposes of the remaining steps.
500 with the value of the environment variable
503 Space-delimited arguments are passed to the called builtin command.
504 Spaces can also be escaped through the use of \e\e .
507 An exception to this parsing rule exists, and is described in
508 .Sx Builtins And FORTH .
509 .Ss Builtins And FORTH
510 All builtin words are state-smart, immediate words.
511 If interpreted, they behave exactly as described previously.
512 If they are compiled, though,
513 they extract their arguments from the stack instead of the command line.
515 If compiled, the builtin words expect to find, at execution time, the
516 following parameters on the stack:
517 .D1 Ar addrN lenN ... addr2 len2 addr1 len1 N
520 are strings which will compose the command line that will be parsed
521 into the builtin's arguments.
522 Internally, these strings are concatenated in from 1 to N,
523 with a space put between each one.
525 If no arguments are passed, a 0
527 be passed, even if the builtin accepts no arguments.
529 While this behavior has benefits, it has its trade-offs.
530 If the execution token of a builtin is acquired (through
538 the builtin behavior will depend on the system state
546 This is particularly annoying for programs that want or need to
548 In this case, the use of a proxy is recommended.
553 is a Forth interpreter written in C, in the form of a forth
554 virtual machine library that can be called by C functions and vice
559 each line read interactively is then fed to
563 back to execute the builtin words.
570 The words available to
572 can be classified into four groups.
575 Forth standard words, extra
579 words, and the builtin commands;
580 the latter were already described.
583 Forth standard words are listed in the
586 The words falling in the two other groups are described in the
587 following subsections.
589 .Bl -tag -width wid-set-super
597 This is the STRING word set's
604 This is the STRING word set's
614 .Ss Loader Extra Words
615 .Bl -tag -width XXXXXXXX
617 Evaluates the remainder of the input buffer, after having printed it first.
619 Evaluates the remainder of the input buffer under a
625 but without outputting a trailing space.
626 .It Ic fclose Pq Ar fd --
628 .It Ic fkey Pq Ar fd -- char
629 Reads a single character from a file.
630 .It Ic fload Pq Ar fd --
633 .It Ic fopen Pq Ar addr len mode Li -- Ar fd
635 Returns a file descriptor, or \-1 in case of failure.
638 parameter selects whether the file is to be opened for read access, write
641 .Dv O_RDONLY , O_WRONLY ,
645 .Pa /boot/forth/support.4th ,
646 indicating read only, write only, and read-write access, respectively.
649 .Pq Ar fd addr len -- len'
657 Returns the actual number of bytes read, or -1 in case of error or end of
659 .It Ic heap? Pq -- Ar cells
660 Return the space remaining in the dictionary heap, in cells.
661 This is not related to the heap used by dynamic memory allocation words.
662 .It Ic inb Pq Ar port -- char
663 Reads a byte from a port.
664 .It Ic key Pq -- Ar char
665 Reads a single character from the console.
666 .It Ic key? Pq -- Ar flag
669 if there is a character available to be read from the console.
674 .It Ic outb Pq Ar port char --
675 Writes a byte to a port.
676 .It Ic seconds Pq -- Ar u
677 Returns the number of seconds since midnight.
678 .It Ic tib> Pq -- Ar addr len
679 Returns the remainder of the input buffer as a string on the stack.
681 .Ss Loader Defined Environmental Queries
685 if the architecture is IA32.
691 The following values are thrown by
693 .Bl -tag -width XXXXX -offset indent
695 Any type of error in the processing of a builtin.
706 Out of interpreting text.
708 Need more text to succeed -- will finish on next run.
716 .Bl -tag -width /boot/defaults/loader.conf -compact
717 .It Pa /boot/defaults/loader.conf
718 .It Pa /boot/conf.d/*
719 .It Pa /boot/loader.conf
720 .It Pa /boot/loader.conf.local
722 configuration files, as described in
724 .It Pa /boot/loader.help
727 Contains the help messages.
728 .It Pa /boot/loader.rc
730 bootstrapping script.
731 .It Pa /boot/forth/loader.4th
732 Extra builtin-like words.
733 .It Pa /boot/forth/support.4th
736 .It Pa /boot/zfsloader
741 Boot in single user mode:
745 Load the kernel, a boot_archive, and then autoboot in five seconds.
746 Notice that a kernel must be loaded before any other
748 command is attempted.
749 .Bd -literal -offset indent
750 load /platform/i86pc/kernel/amd64/unix
751 load -t rootfs /platform/i86pc/amd64/boot_archive
759 For the purposes of ANS Forth compliance, loader is an
761 ANS Forth System with Environmental Restrictions, Providing
767 parse, pick, roll, refill, to, value, \e, false, true,
770 compile\&, , erase, nip, tuck
775 from the Core Extensions word set, Providing the Exception Extensions
776 word set, Providing the Locals Extensions word set, Providing the
777 Memory-Allocation Extensions word set, Providing
781 bye, forget, see, words,
788 from the Programming-Tools extension word set, Providing the
789 Search-Order extensions word set.