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.
253 In addition to disks and partitions, ZFS pools are also listed.
256 is specified, more details are printed.
257 For ZFS pools the output resembles
262 Displays loaded modules.
265 is specified, more details are shown.
267 .It Ic lszfs Ar filesystem
268 A ZFS extended command that can be used to explore the ZFS filesystem
270 Lists the immediate children of the
272 The filesystem hierarchy is rooted at a filesystem with the same name
275 .It Ic more Ar file Op Ar
276 Display the files specified, with a pause at each
285 Reads a line of input from the terminal, storing it in
288 A timeout can be specified with
290 though it will be canceled at the first key pressed.
291 A prompt may also be displayed through the
296 Immediately reboots the system.
298 .It Ic set Ar variable
299 .It Ic set Ar variable Ns = Ns Ar value
300 Set loader's environment variables.
302 .It Ic show Op Va variable
303 Displays the specified variable's value, or all variables and their
309 Remove all modules from memory.
311 .It Ic unset Va variable
314 from the environment.
317 Lists available commands.
321 supports the following format for specifying ZFS filesystems which
324 refers to a device specification:
326 .Ar zfs:pool/filesystem:
330 is a ZFS filesystem name as described in
332 .Ss Builtin Environment Variables
335 has actually two different kinds of
338 There are ANS Forth's
339 .Em environmental queries ,
340 and a separate space of environment variables used by builtins, which
341 are not directly available to Forth words.
342 It is the latter type that this section covers.
344 Environment variables can be set and unset through the
348 builtins, and can have their values interactively examined through the
352 Their values can also be accessed as described in
355 Notice that these environment variables are not inherited by any shell
356 after the system has been booted.
358 A few variables are set automatically by
360 Others can affect the behavior of either
362 or the kernel at boot.
363 Some options may require a value,
364 while others define behavior just by being set.
365 Both types of builtin variables are described below.
366 .Bl -tag -width bootfile
367 .It Va autoboot_delay
370 will wait before booting.
371 If this variable is not defined,
373 will default to 10 seconds.
379 will be automatically attempted after processing
380 .Pa /boot/loader.rc ,
383 will be processed normally, defaulting to 10 seconds delay.
387 no delay will be inserted, but user still will be able to interrupt
389 process and escape into the interactive mode by pressing some key
390 on the console while kernel and
391 modules are being loaded.
395 no delay will be inserted and
397 will engage interactive mode only if
399 has failed for some reason.
415 .It Va boot_reconfigure
431 Will set custom arguments for the kernel.
436 startup will parse the
438 value to set boot prefixed variables listed above, any unrecognized options
439 are added to kernel command line verbatim.
441 The name of the kernel.
443 Defines the current console or consoles.
444 Multiple consoles may be specified.
445 In that case, the first listed console will become the default console for
449 Selects the default device.
450 Syntax for devices is odd.
454 if the Forth's current state is interpreting.
456 Define the number of lines on the screen, to be used by the pager.
458 Sets the list of directories which will be searched for modules
459 named in a load command or implicitly required by a dependency.
460 The default value for this variable is
461 .Dq Li /platform/i86pc/${ISADIR}
467 .Dq Li "${interpret}" .
470 is unset, the default prompt is
473 If set, the value is used to set
479 Other variables are used for loader or to set kernel properties or for
480 informational purposes.
482 When a builtin command is executed, the rest of the line is taken
483 by it as arguments, and it is processed by a special parser which
484 is not used for regular Forth commands.
486 This special parser applies the following rules to the parsed text:
489 All backslash characters are preprocessed.
492 \eb , \ef , \er , \en and \et are processed as in C.
494 \es is converted to a space.
501 Useful for things like
504 \e0xN and \e0xNN are replaced by the hex N or NN.
506 \eNNN is replaced by the octal NNN
510 \e" , \e' and \e$ will escape these characters, preventing them from
511 receiving special treatment in Step 2, described below.
513 \e\e will be replaced with a single \e .
515 In any other occurrence, backslash will just be removed.
518 Every string between non-escaped quotes or double-quotes will be treated
519 as a single word for the purposes of the remaining steps.
525 with the value of the environment variable
528 Space-delimited arguments are passed to the called builtin command.
529 Spaces can also be escaped through the use of \e\e .
532 An exception to this parsing rule exists, and is described in
533 .Sx Builtins And FORTH .
534 .Ss Builtins And FORTH
535 All builtin words are state-smart, immediate words.
536 If interpreted, they behave exactly as described previously.
537 If they are compiled, though,
538 they extract their arguments from the stack instead of the command line.
540 If compiled, the builtin words expect to find, at execution time, the
541 following parameters on the stack:
542 .D1 Ar addrN lenN ... addr2 len2 addr1 len1 N
545 are strings which will compose the command line that will be parsed
546 into the builtin's arguments.
547 Internally, these strings are concatenated in from 1 to N,
548 with a space put between each one.
550 If no arguments are passed, a 0
552 be passed, even if the builtin accepts no arguments.
554 While this behavior has benefits, it has its trade-offs.
555 If the execution token of a builtin is acquired (through
563 the builtin behavior will depend on the system state
571 This is particularly annoying for programs that want or need to
573 In this case, the use of a proxy is recommended.
578 is a Forth interpreter written in C, in the form of a forth
579 virtual machine library that can be called by C functions and vice
584 each line read interactively is then fed to
588 back to execute the builtin words.
595 The words available to
597 can be classified into four groups.
600 Forth standard words, extra
604 words, and the builtin commands;
605 the latter were already described.
608 Forth standard words are listed in the
611 The words falling in the two other groups are described in the
612 following subsections.
614 .Bl -tag -width wid-set-super
622 This is the STRING word set's
629 This is the STRING word set's
639 .Ss Loader Extra Words
640 .Bl -tag -width XXXXXXXX
642 Evaluates the remainder of the input buffer, after having printed it first.
644 Evaluates the remainder of the input buffer under a
650 but without outputting a trailing space.
651 .It Ic fclose Pq Ar fd --
653 .It Ic fkey Pq Ar fd -- char
654 Reads a single character from a file.
655 .It Ic fload Pq Ar fd --
658 .It Ic fopen Pq Ar addr len mode Li -- Ar fd
660 Returns a file descriptor, or \-1 in case of failure.
663 parameter selects whether the file is to be opened for read access, write
666 .Dv O_RDONLY , O_WRONLY ,
670 .Pa /boot/forth/support.4th ,
671 indicating read only, write only, and read-write access, respectively.
674 .Pq Ar fd addr len -- len'
682 Returns the actual number of bytes read, or -1 in case of error or end of
684 .It Ic heap? Pq -- Ar cells
685 Return the space remaining in the dictionary heap, in cells.
686 This is not related to the heap used by dynamic memory allocation words.
687 .It Ic inb Pq Ar port -- char
688 Reads a byte from a port.
689 .It Ic key Pq -- Ar char
690 Reads a single character from the console.
691 .It Ic key? Pq -- Ar flag
694 if there is a character available to be read from the console.
699 .It Ic outb Pq Ar port char --
700 Writes a byte to a port.
701 .It Ic seconds Pq -- Ar u
702 Returns the number of seconds since midnight.
703 .It Ic tib> Pq -- Ar addr len
704 Returns the remainder of the input buffer as a string on the stack.
706 .Ss Loader Defined Environmental Queries
710 if the architecture is IA32.
716 The following values are thrown by
718 .Bl -tag -width XXXXX -offset indent
720 Any type of error in the processing of a builtin.
731 Out of interpreting text.
733 Need more text to succeed -- will finish on next run.
741 .Bl -tag -width /boot/defaults/loader.conf -compact
742 .It Pa /boot/defaults/loader.conf
743 .It Pa /boot/conf.d/*
744 .It Pa /boot/loader.conf
745 .It Pa /boot/loader.conf.local
747 configuration files, as described in
749 .It Pa /boot/loader.help
752 Contains the help messages.
753 .It Pa /boot/loader.rc
755 bootstrapping script.
756 .It Pa /boot/forth/loader.4th
757 Extra builtin-like words.
758 .It Pa /boot/forth/support.4th
766 Boot in single user mode:
770 Load the kernel, a boot_archive, and then autoboot in five seconds.
771 Notice that a kernel must be loaded before any other
773 command is attempted.
774 .Bd -literal -offset indent
775 load /platform/i86pc/kernel/amd64/unix
776 load -t rootfs /platform/i86pc/amd64/boot_archive
780 Set the default device used for loading a kernel from a ZFS filesystem:
781 .Bd -literal -offset indent
782 set currdev=zfs:rpool/ROOT/knowngood:
787 as shown in the example above is supported, it is advisable to use loader
788 beadm command or boot environment menu instead.
789 The reason is, the beadm or menu selection will also instruct loader to clean up
790 the currently set configuration and load configuration from the new boot
796 For the purposes of ANS Forth compliance, loader is an
798 ANS Forth System with Environmental Restrictions, Providing
804 parse, pick, roll, refill, to, value, \e, false, true,
807 compile\&, , erase, nip, tuck
812 from the Core Extensions word set, Providing the Exception Extensions
813 word set, Providing the Locals Extensions word set, Providing the
814 Memory-Allocation Extensions word set, Providing
818 bye, forget, see, words,
825 from the Programming-Tools extension word set, Providing the
826 Search-Order extensions word set.