BoxLambda OS Top-Level¶
BoxLambda OS Software Project top-level in the BoxLambda Directory Tree: sw/projects/boxlambda_os
Boot Sequence¶
This section describes the OS boot sequence. The OS boot sequence is preceded by the bootloader boot sequence, described here.
After the Bootloader has transferred control to the OS image it has loaded into EMEM, the OS startup code goes through the following sequence:
crt0.csets up a basic C environment as described in the early software startup sequence.main()performs the following steps:- Initialize Forth by calling
forth_core_init(). - Find and mount a filesystem boot volume:
- Attempt to mount the SD card volume
sd0:and the RAM disk volumeram:. - Search for a
ram:/forth/directory. If found,ram:is set as the Forth boot volume. - If
ram:/forth/is not found, search for asd0:/forthdirectory. If found,sd0:becomes the Forth boot volume. - If neither
ram:/forthnorsd0:/forthis found,main()prompts the user to insert an SD card or to upload a RAM disk containing the target filesystem.
- Attempt to mount the SD card volume
- Evaluate Forth module fs/forth/early.fs. This module contains some early definitions extending the core Word set. Currently, only the Word
c-funis defined here. - Redirect the C library's stdio to Forth's
emitandkeyWords. See stdio_redirect.cpp. - Initialize the Forth<->C Filesystem Foreign Function Interface (FFI). See fs_ffi.cpp.
- Check the Fast-Boot switch. If set, execute the Fast Boot sequence, otherwise, perform a Slow Boot. Fast Boot and Slow Boot are described in the following two subsections.
- Initialize Forth by calling
Slow Boot¶
- Evaluate the Forth modules listed in fs/forth/boxkern-includes.fs.
- Transfer control to Forth by evaluating fs/forth/init.fs.
init.fsis expected to invoke thequitWord, starting the Forth REPL.

The BoxLambda OS Slow Boot Sequence.
Fast Boot¶
- Copy the pre-compiled
boxkern_forth_imginto place, instantly populating the Forth dictionary with all the Words from the boxkern-includes modules. - Transfer control to Forth by evaluating fs/forth/init.fs.
init.fsis expected to invoke thequitWord, starting the Forth REPL.

The BoxLambda OS Fast Boot Sequence.
Generating boxkern_forth.img¶
The boxkern_forth_img, used during Fast Boot, is generated by performing a Slow Boot and recording the resulting Forth state (dictionary and core variables):
main()performs a Slow Boot.- Instead of including
init.fs,main()invokes the fastboot-save Word. fastboot-savesaves the Forth state (forth_imemandforth_emem) to a file calledboxkern_forth.img.fastboot-savesets theSDRAM_BASEmemory location to 1, signalling to thetarget.pyprocess running on the host PC that theboxkern_forth.imgis ready for retrieval.target.pytransfers the target filesystem to the host PC and extractsboxkern_forth.img.- The build system links the
boxkern_forth.imginto the Fast Boot BoxKern executableboxkernforth.

Generating boxkern_forth.img.
The BoxKern-Includes Mechanism¶
fs/forth/boxkern-includes/boxkern-includes.fs may look like a Forth module, but it's not.
The syntax is limited to lines starting with \, which are ignored, and lines beginning with the word boxkern_include followed by the full path of an .fs Forth module to be evaluated. These Forth modules must not include any submodules themselves.
The BoxKern loads and passes boxkern_include files to the Forth environment at boot time using Forth-C FFI function forth_eval_boxkern_includes_or_die(). This mechanism allows a limited form of Forth module loading until the Forth include Word can be defined. The order of the modules listed in boxkern-includes.fs is important because new Words build upon previously defined Words. The modules in boxkern-includes.fs build up a stack, with shell.fs on top.
The BoxKern-Includes mechanism is only used during Slow Boot. When Fast Boot is used, the modules listed in the boxkern-includes.fs list are part of the pre-compiled boxkern_forth.img, so boxkern-includes.fs evaluation can be skipped.
Words¶
fastboot-save ( -- )
- Fastboot helper Word: Save forth imem and emem up to
hereto fileboxkern-forth.img. See Generating boxkern_forth.img.