| Main index | Section 8 | Options |
It provides a scripting language that can be used to automate tasks, do pre-configuration or assist in recovery procedures. This scripting language is roughly divided in two main components. The smaller one is a set of commands designed for direct use by the casual user, called "builtin commands" for historical reasons. The main drive behind these commands is user-friendliness. The bigger component is an ANS Forth compatible Forth interpreter based on FICL, by John Sadler.
During initialization, loader_4th will probe for a console and set the console variable, or set it to serial console ("comconsole") if the previous boot stage used that. If multiple consoles are selected, they will be listed separated by spaces. Then, devices are probed, currdev and loaddev are set, and LINES is set to 24. Next, FICL is initialized, the builtin words are added to its vocabulary, and /boot/boot.4th is processed if it exists. No disk switching is possible while that file is being read. The inner interpreter loader_4th will use with FICL is then set to interpret, which is FICL's default. After that, /boot/loader.rc is processed if available. These files are processed through the include command, which reads all of them into memory before processing them, making disk changes possible.
At this point, if an autoboot has not been tried, and if autoboot_delay is not set to "NO" (not case sensitive), then an autoboot will be tried. If the system gets past this point, prompt will be set and loader_4th will engage interactive mode. Please note that historically even when autoboot_delay is set to "0" user will be able to interrupt autoboot process by pressing some key on the console while kernel and modules are being loaded. In some cases such behaviour may be undesirable, to prevent it set autoboot_delay to "-1", in this case loader_4th will engage interactive mode only if autoboot has failed.
This special parser applies the following rules to the parsed text:
An exception to this parsing rule exists, and is described in BUILTINS AND FORTH.
If compiled, the builtin words expect to find, at execution time, the following parameters on the stack: where addrX lenX are strings which will compose the command line that will be parsed into the builtin's arguments. Internally, these strings are concatenated in from 1 to N, with a space put between each one.
If no arguments are passed, a 0 must be passed, even if the builtin accepts no arguments.
While this behavior has benefits, it has its trade-offs. If the execution token of a builtin is acquired (through ' or [']), and then passed to catch or execute, the builtin behavior will depend on the system state at the time catch or execute is processed! This is particularly annoying for programs that want or need to handle exceptions. In this case, the use of a proxy is recommended. For example:
: (boot) boot;
In loader_4th, each line read interactively is then fed to FICL, which may call loader_4th back to execute the builtin words. The builtin include will also feed FICL, one line at a time.
The words available to FICL can be classified into four groups. The ANS Forth standard words, extra FICL words, extra FreeBSD words, and the builtin commands; the latter were already described. The ANS Forth standard words are listed in the STANDARDS section. The words falling in the two other groups are described in the following subsections.
| .env
.ver -roll 2constant >name body> compare | |
| This is the STRING word set's compare. | |
| compile-only
endif forget-wid parse-word sliteral | |
| This is the STRING word set's sliteral. | |
| wid-set-super
w@ w! x. empty cell- -rot | |
| amp;$ (--) | Evaluates the remainder of the input buffer, after having printed it first. |
| amp;% (--) | Evaluates the remainder of the input buffer under a catch exception guard. |
| .# | Works like . but without outputting a trailing space. |
| fclose (fd --) | |
| Closes a file. | |
| fkey (fd -- char) | |
| Reads a single character from a file. | |
| fload (fd --) | |
| Processes a file fd. | |
| fopen (addr len mode-- fd) | |
| Opens a file. Returns a file descriptor, or -1 in case of failure. The mode parameter selects whether the file is to be opened for read access, write access, or both. The constants O_RDONLY, O_WRONLY, and O_RDWR are defined in /boot/support.4th, indicating read only, write only, and read-write access, respectively. | |
| fread (fd addr len -- len') Tries to read len bytes from file fd into buffer addr. Returns the actual number of bytes read, or -1 in case of error or end of file. | |
| heap? (-- cells) | |
| Return the space remaining in the dictionary heap, in cells. This is not related to the heap used by dynamic memory allocation words. | |
| inb (port -- char) | |
| Reads a byte from a port. | |
| key (-- char) | |
| Reads a single character from the console. | |
| key? (-- flag) | |
| Returns true if there is a character available to be read from the console. | |
| ms (u --) | Waits u microseconds. |
| outb (port char --) | |
| Writes a byte to a port. | |
| seconds (-- u) | |
| Returns the number of seconds since midnight. | |
| tib> (-- addr len) | |
| Returns the remainder of the input buffer as a string on the stack. | |
| trace! (flag --) | |
| Activates or deactivates tracing. Does not work with catch. | |
| arch-i386 | |
| TRUE if the architecture is IA32. | |
| FreeBSD_version | |
| FreeBSD version at compile time. | |
| loader_version | |
| loader_4th version. | |
One can prevent unauthorized access to the loader_4th command line by setting the password, or setting autoboot_delay to -1. See loader.conf(5) for details. In order for this to be effective, one should also configure the firmware (BIOS or UEFI) to prevent booting from unauthorized devices.
Currently, MD is only supported in loader.efi(8).
| /boot/loader | loader_4th itself. |
| /boot/boot.4th | Additional FICL initialization. |
| /boot/defaults/loader.conf
/boot/loader.4th | |
| Extra builtin-like words. | |
| /boot/loader.conf
/boot/loader.conf.local | |
| loader_4th configuration files, as described in loader.conf(5). | |
| /boot/loader.rc | loader_4th bootstrapping script. |
| /boot/loader.help | Loaded by help. Contains the help messages. |
| /boot/support.4th | loader.conf processing words. |
| /usr/share/examples/bootforth/ | |
| Assorted examples. | |
boot -s
Load the kernel, a splash screen, and then autoboot in five seconds. Notice that a kernel must be loaded before any other load command is attempted.
load kernel load splash_bmp load -t splash_image_data /boot/chuckrulez.bmp autoboot 5
Set the disk unit of the root device to 2, and then boot. This would be needed in a system with two IDE disks, with the second IDE disk hardwired to ada2 instead of ada1.
set root_disk_unit=2 boot /boot/kernel/kernel
Set the default device used for loading a kernel from a ZFS filesystem:
set currdev=zfs:tank/ROOT/knowngood:
| 100 | Any type of error in the processing of a builtin. |
| -1 | Abort executed. |
| -2 | Abort" executed. |
| -56 | Quit executed. |
| -256 | Out of interpreting text. |
| -257 | Need more text to succeed -- will finish on next run. |
| -258 | Bye executed. |
| -259 | Unspecified error. |
FICL was written by John Sadler <john_sadler@alum.mit.edu>.
| LOADER_4TH (8) | September 29, 2021 |
| Main index | Section 8 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
