Open Firmware Quick Reference

Table of Contents

Syntax

A stack diagram such as (n1 n2 -- n3) or (adr len --) or (--) shows a command's stack effect. Items before the -- must be present on the stack before the command executes; the command uses them and removes them from the stack. Items after the -- are results that the commands leaves on the stack for use by subsequent commands.

If no stack diagram is shown, the command does not take any arguments from or leave any results on the stack.

showstack turns on stack display mode.

Booting

boot [device-specifier] [arguments] Load and execute a program (usually an operating system). If device-specifier or arguments are omitted, the values of boot-device and boot-file are used.
load [device-specifier] [arguments] Load a program and leave it in memory for inspection or debugging.
[device-specifier] The name (full path name or alias) of a device. Examples:
/pci/scsi@7/disk@4:\boot\vmlinux.gz
cdrom (CD-ROM drive specified by cdrom devalias)
disk (hard disk specified by disk devalias)
net (network specified by net devalias)
[arguments] The remainder of the line is passed verbatim to the booted program.

Device Specifiers

A device specifier is a text string that identifies a node in the device tree. It may include optional arguments to use when opening that node.

The general form of a full pathname is:
   / component / component / ...

The general form of a component is:
    name @ address : arguments

Example:
   /pci/scsi@7/disk@3:2,\boot\vmlinux.gz

This device specifier selects the PCI bus, then a SCSI host adapter at PCI device number 7, then a disk at SCSI target number 3. The argument that is passed to that disk driver selects partition number 2, then a file named vmlinux.gz in a subdirectory named "/boot". Note the use of backslash (\) instead of slash (/) in the argument string, because of the restriction against using (/) in an argument.

If intermediate node names are omitted in a pathname, Open Firmware will do its best to locate the node anyway. Thus, in many cases, an abbreviated form of the above path would work, e.g.:    /disk@3:2,\boot\vmlinux.gz

If there is no leading slash (/) and the first component is a device alias, the alias is replaced by its expansion, repetitively if necessary.

Device Aliases

Device aliases are shorthand forms of full pathnames.
devalias Display all current device aliases.
devalias alias Display the device path name corresponding to alias.
devalias alias device-path Define an alias representing the device path.
If an alias with the same name already exists, the new value supersedes the old.
nvalias alias device-path Define a persistent alias (stored in NVRAM)
nvunalias alias Delete a persistent alias from NVRAM

Editor Keys (for Command Lines and NVRAMRC)

               ESC- = Press and release Escape key first; ^ = Press and hold Control key

 
Prev. Line
Beg. Line
Prev. Word
Prev. Char
Next Char
Next Word
End Line
Next Line
Move
^P
up-arrow
^A
ESC-B
^B
left-arrow
^F
right-arrow
ESC-F
^E
^N
down-arrow
Delete

^U
^W
ESC-H
Delete
Backspace
^D
ESC-D
^K


Re-type line
Show all lines
Paste after ^K
Complete command
Show all matches
Exit Editor
Split Line
Single Step

^R
^L
^Y
TAB
^/
^?
^}
^C
^O
^T

Configuration Variable Commands

Configuration variables are stored in non-volatile memory so their values persist across power-cycles.
printenv [variable] If variable is given, show its current value. Otherwise show all configuration variables and their current and default values. Numbers are usually shown in decimal.
setenv variable value Set variable to the given decimal or text value. Changes are permanent, but sometimes they only take effect after a reset. Some systems let you create new user-defined configuration variables.
set-default variable Set variable to its default value.
set-defaults Set all configuration variables to their default values.
unsetenv variable
Delete a user-defined configuration variable.

Common Configuration Variables

Additional configuration variables may be available on some systems. Use printenv to see them all.
Name
Default Value
Meaning
auto-boot? true If true, boot automatically after power-on or reset.
boot-device disk Device from which to boot.
boot-file empty string File to boot (an empty string lets secondary booter choose default).
diag-device net Diagnostic boot source device.
diag-file empty string File from which to boot in diagnostic mode.
diag-switch? false If true, run in diagnostic mode.
fcode-debug? false If true, include name fields for plug-in device FCodes.
input-device keyboard Power-on input device (usually keyboard or com1 ).
local-mac-address? false If true, network drivers use their own MAC address, not system’s.
mfg-switch? false If true, repeat system self-tests until interrupted.
nvramrc empty string Contents of NVRAMRC script.
oem-banner empty string Custom OEM banner (enabled by oem-banner? true).
oem-banner? false If true, use custom OEM banner.
output-device screen Power-on output device (usually screen, ttya, or ttyb).
pci-probe-list system-specific, e.g. 0,1,2,3 Which PCI slots are probed and in what order.
screen-#columns 80 Number of on-screen columns (characters/line).
screen-#rows system-specific, e.g. 30 Number of on-screen rows (lines).
scsi-initiator-id 7 SCSI bus address of host adapter, range 0-7.
security-#badlogins no default Number of incorrect security password attempts.
security-mode none Firmware security level (none, command, or full).
security-password no default Firmware security password (never displayed). Do not set this directly.
selftest-#megs 1 Megabytes of RAM to test. Ignored if diag-switch? is true.
use-nvramrc? false If true, execute commands in NVRAMRC during system start-up.
watchdog-reboot? false If true, reboot after watchdog reset.

NVRAMRC Script Editor

nvedit Enter the NVRAMRC editor. If data remains in the temporary buffer from a previous nvedit session, resume editing those previous contents. If not, read the contents of NVRAMRC into the temporary buffer and begin editing it.
nvalias alias device-path Store the command "devalias alias device-path" in NVRAMRC. (The alias persists until the nvunalias or set-defaults commands are executed.)
nvunalias alias Delete the corresponding alias from NVRAMRC.
nvrun Execute the contents of the temporary buffer.

Example:
ok nvedit 
(use editor commands)
^C (control-C to finish)
Store script to NVRAM [y/n]? y
Enable script [y/n]? y
ok

Device Tree Browsing

.properties Display the names and values of the current node’s properties.
dev device-path Select the indicated device node, making it the current node.
dev node-name Search for a node with the given name in the subtree below the current node, and select the first such node found.
dev .. Select the device node that is the parent of the current node.
dev / Select the root machine node.
device-end
dend
De-select the current device node, leaving no node selected.
ls Display the names of the current node’s children.
pwd Display the device path name that names the current node.
show-devs [device-path] Display all the devices known to the system directly beneath a given level in the device hierarchy. (Without a device-path, it shows the entire device tree.)
words Display the names of the current node’s methods.
sift-devs ccc ( -- ) Search all device nodes and show all method names that contain the sequence of characters ccc.

Help

help List main help categories.
help category Show help for all commands in the category. Use only the first word of the category description.
help command Show help for individual command (where available).

Diagnostics

probe-scsi Identify devices attached to the built-in SCSI bus.
probe-scsi-all [device-path] Perform probe-scsi on all SCSI buses installed in the system below the specified node. (If device-path is absent, the root node is used.)
test device-specifier Execute the specified device’s self-test method. For example:
test floppy - test the floppy drive, if installed
test /memory - test number of megabytes specified in selftest-#megs; or test all of memory if diag-switch? is true
test net - test the network connection
test-all [device-specifier] Test all devices (that have a built-in self-test method) below the specified node. (If device-specifier is absent, the root node is used.)
watch-clock Test the clock function.
watch-net Monitor the network connection passively. Displays a period for each packet received.

System Information

banner Display the power-on banner.
.version Display the version and date of the boot PROM.

Emergency Keys

serial line break Interrupt what the firmware is doing. The method for sending a line break differs between different terminal emulator programs. For minicom it is ALT-F or CTRL-A F. Most Windows terminal emulators have a menu selection for sending a line break.
i (Lower case ‘i’, typed on the serial console very early in the startup sequence). Interrupt the early startup sequence, for debugging purposes.
Implementation-dependent PC keyboard chords.
These chords only work when the PC keyboard is directly connected to the Open Firmware system.
Ctrl-Break (For a directly-connected PC-style keyboard) Interrupt what the firmware is doing.
Fn (Function keys on a PC-style keyboard). Various function keys perform emergency functions such as resetting the NVRAM to its default values and interrupting the early startup sequence. The specific assignments vary from implementation to implementation.

File Loading

byte-load ( adr span -- ) Interpret a loaded FCode binary file. span is usually 1.
dl ( -- ) Load a Forth file over a serial line with TIP and interpret. Type:
~C cat filename
^-D

dlbin ( -- ) Load a binary file over a serial line with TIP. Type: ~C cat filename
dload filename ( adr -- ) Load specified file over Ethernet at given address.
go ( -- ) Begin executing a previously-loaded binary program, or resume executing an interrupted program. (Called automatically by boot .)
init-program ( -- ) Prepare a loaded program for execution. (Called automatically by load and boot.)
load-base ( -- adr ) Address where load first places the data it reads from a device. The program image may be moved elsewhere as init-program prepares it for execution.

Generic Registers

These generic register commands, and the processor-specific ones in later sections, access the register values in the saved-program-state area, not the instantaneous current values of the hardware registers. Changes to the saved values take effect when the interrupted program is restarted.
.fregisters ( -- ) Display the saved values of the floating point registers.
.registers ( -- ) Display the saved values of the general registers and selected special registers.
ctrace ( -- ) Display the return stack showing C subroutines.
set-pc ( value -- ) Set %pc to the given value, and set %npc to (value+4).
to regname ( value -- ) Change the saved value of a register. Use in the form:
value to regname.

x86 Registers

Register values are saved when a program is interrupted by a breakpoint. Changes to those saved values take effect when the program is resumed.
to regname ( value -- ) Change the saved value of a register. Use in the form:
value to regname.
%eip %pc ( -- value ) Return the saved value of the program counter register.
%eax %ecx %edx %ebx %esp %ebp %esi %edi ( -- value ) Return the saved value of a general register.
%es %cs %ss %ds %fs %gs ( -- value ) Return the saved value of a segment register.
%cr3 %eflags %tlink %esp0 %esp1 %esp2 %ss0 %ss1 %ss2 %ldt %tio ( -- value ) Return the saved value of a special register.
idtr@ gdtr@ tr@ ldtr@ cr0@ cr2@ cr3@ cr4@ dr0@ dr1@ dr2@ dr3@ dr6@ dr7@ tr6@ tr7@ ds@ cs@ ss@ es@ fs@ gs@ ( -- value ) Return the current (not saved) value of a special register.
idtr! gdtr! tr! ldtr! cr0! cr2! cr3! cr4! dr0! dr1! dr2! dr3! dr6! dr7! tr6! tr7! ( value -- ) Set the current (not saved) value of a special register.

MIPS Registers

Register values are saved when a program is interrupted by a breakpoint. Changes to those saved values take effect when the program is resumed.
to regname ( value -- ) Change the saved value of a register. Use in the form:
value to regname.
$0-$31 $at $a0-$a3 $v0-$v1 $t0-$t9 $s0-$s8 $k0-$k1 $gp $sp $ra ( -- value ) Return the saved value of the given integer register.
$f0-$f31 $fcsr $feir ( -- value ) Return the saved value of the given floating point register.
$sr $cause $badvaddr $badpaddr $sigset $hi $lo etc. ( -- value ) Return the saved value of the given special register.
index@ random@ entrylo0@ entrylo1@ context@ pagemask@ wired@ badvaddr@ count@ entryhi@ compare@ sr@ cause@ epc@ prid@ config@ lladdr@ watchlo@ watchhi@ xcontext@ perr@ cacherr@ taglo@ errorepc@ ( -- value ) Return the current (not the saved) value of a CP0 register.
index! entrylo0! entrylo1! context! pagemask! wired! count! entryhi! compare! sr! cause! epc! config! lladdr! watchlo! watchhi! xcontext! perr! taglo! errorepc! ( value -- ) Set the current (not the saved) value of a CP0 register.

SPARC Registers

Register values are saved when a program is interrupted by a breakpoint. Changes to those saved values take effect when the program is resumed.
%f0 through %f31 ( -- value ) Return the saved value of the given floating point register.
%fsr ( -- value ) Return the saved value of the given floating point register.
%g0 through %g7 ( -- value ) Return the saved value of the given register.
%i0 through %i7 ( -- value ) Return the saved value of the given register.
%L0 through %L7 ( -- value ) Return the saved value of the given register.
%o0 through %o7 ( -- value ) Return the saved value of the given register.
%pc %npc %psr ( -- value ) Return the saved value of the given register.
%y %wim %tbr ( -- value ) Return the saved value of the given register.
.locals ( -- ) Display the saved values of the i, L and o registers.
.psr ( -- ) Formatted display of the %psr data.
.window ( window# -- ) Display the desired window.
w ( window# -- ) Set the current window for displaying %ix %Lx or %ox.

Breakpoints

+bp ( adr -- ) Add a breakpoint at the given address.
-bp ( adr -- ) Remove the breakpoint at the given address.
--bp ( -- ) Remove the most-recently-set breakpoint.
.bp ( -- ) Display all currently set breakpoints.
.breakpoint ( -- ) Perform a specified action when a breakpoint occurs
(Example, [’] .registers is .breakpoint).
.instruction ( -- ) Display the address, opcode for the last-encountered breakpoint.
.step ( -- ) Perform a specified action when a single step occurs (see .breakpoint).
bpoff ( -- ) Remove all breakpoints.
finish-loop ( -- ) Execute until the end of this loop.
go ( -- ) Continue from a breakpoint. This can be used to go to an arbitrary address by setting up the processor’s program counter before issuing go.
gos ( n -- ) Execute go n times.
hop ( -- ) (Like the step command.) Treats a subroutine call as a single instruction.
hops ( n -- ) Execute hop n times.
return ( -- ) Execute until the end of this subroutine.
returnL ( -- ) Execute until the end of this leaf subroutine.
skip ( -- ) Skip (do not execute) the current instruction.
step ( -- ) Single-step one instruction.
steps ( n -- ) Execute step n times.
till ( adr -- ) Execute until the given address is encountered. Equivalent to +bp go.

Disassembler

+dis ( -- ) Continue disassembling where the last disassembly left off.
dis ( adr -- ) Begin disassembling at the given address.

Miscellaneous Operations

get-msecs ( -- ms ) Return the approximate current time in milliseconds.
ms ( n -- ) Delay for n milliseconds. Resolution is 1 millisecond.
bye
reset-all
( -- ) Reset the entire system (similar to a power cycle).
map? ( virt -- ) Display memory map information for the virtual address (for systems that use virtual addressing>.
sync ( -- ) Call the operating system to write any pending information to the hard disk.

Numeric Usage

A numeric stack is used for all numeric parameters. Typing any integer puts that value on top of the stack. (Previous values are “pushed” down.) The right-hand item in a set always indicates the topmost stack item.
Data Type
Meaning
| Alternate stack results.
Example: ( input -- adr len false | result true ).
? Unknown stack items (changed from ???).
??? Unknown stack items.
xt Execution token.
adr Memory address (generally a virtual address).
adr16 Memory address, must be 16-bit aligned.
adr32 Memory address, must be 32-bit aligned.
adr64 Memory address, must be 64-bit aligned.
byte bxxx 8-bit value (smallest byte in a 32-bit word).
char 7-bit value (smallest byte), high bit unspecified.
cnt/len/size Count or length, typically in bytes.
flag xxx? 0 = false; any other value = true (usually -1).
long Lxxx 32-bit value.
n n1 n2 n3 Normal signed values (32-bit).
+n u Unsigned, positive values (32-bit).
n[64] or
(n.low n.hi)
or x
Extended-precision (64-bit) numbers (2 stack items).
phys Physical address (actual hardware address).
pstr Packed string (adr len means unpacked string).
virt Virtual address (address used by software).
word wxxx 16-bit value (smallest two bytes in a 32-bit word).

Changing the Number Base

decimal ( -- ) Set the number base to 10.
d# number ( -- n ) Interpret the next number in decimal; base is unchanged.
hex ( -- ) Set the number base to 16.
h# number ( -- n ) Interpret the next number in hex; base is unchanged.
.d ( n -- ) Display n in decimal without changing base.
.h ( n -- ) Display n in hex without changing base.

Basic Number Display

. ( n -- ) Display a number in the current base.
u. ( n -- ) Display a number in the current base, unsigned.
ud. ( x -- ) Display a 64-bit number in the current base, unsigned
.x
( n -- )
Display a number in hex.
.d
( n -- )
Display a number in decimal.
.s ( -- ) Display contents of data stack.
showstack ( -- ) Execute .s automatically before each ok prompt.

Forth Debugging

ftrace ( -- ) Show the Forth calling sequence saved at the last exception.
debug name ( -- ) Run the debugger the next time name is called.
(debug ( xt -- ) Run the debugger the next time the word indicated by xt is called.
debugging name ( -- ) Execute name now under the debugger.
see name ( -- ) Decompile the named command.
(see) ( xt -- ) Decompile the word indicated by xt
sifting ccc ( -- ) Display all word names that contain the sequence of characters ccc.
words ( -- ) Display all visible words in the dictionary.
.calls ( xt -- ) Display a list of all words that call the word whose execution token is xt.

Forth Debugger Keys

These keystrokes control the Forth debugger when it is active (see debug above). As you step through a Forth definition, the debugger displays the word that is about to execute and the current stack contents.
KeyAction
<space> Execute displayed word
D Down: Step down into displayed word
U Up: Finish current definition and step in its caller
C Continue: trace current definition without stopping
F Forth: enter a subordinate Forth interpreter
G Go: resume normal execution (stop debugging)
H Help: display this message
? Display short list of debug commands
R RSTrace: Show contents of Forth return stack
S See: Decompile definition being debugged
$ Display top of stack as adr,len text string
Q Quit: abandon execution of the debugged word
( Restrict debugger to the part of the definition after and including the word to be executed next.
This is useful for debugging words with loops in then.
< Restrict debugger to the part of the definition after the word to be executed next.
) Restrict to debugger to the part of the definition before the word to be executed next.
* Undo (, >, or )

Stack Manipulation

-rot ( n1 n2 n3 -- n3 n1 n2 ) Rotate three stack items so top item goes under.
>r ( n -- ) Move a stack item to the return stack. (Use with caution.)
?dup ( n -- n n | 0 ) Duplicate the top stack item if non-zero.
2drop ( n1 n2 -- ) Remove two items from the stack.
2dup ( n1 n2 -- n1 n2 n1 n2 ) Duplicate two stack items.
2over ( n1 n2 n3 n4 -- n1 n2 n3 n4 n1 n2 ) Copy second two stack items.
2swap ( n1 n2 n3 n4 -- n3 n4 n1 n2 ) Exchange two pairs of stack items.
clear ( ??? -- ) Empty the stack.
depth ( ??? -- ??? +n ) Return the number of items on the stack.
drop ( n -- ) Remove the top item from the stack.
dup ( n -- n n ) Duplicate the top stack item.
nip ( n1 n2 -- n2 ) Discard the second stack item.
over ( n1 n2 -- n1 n2 n1 ) Copy the second stack item to the top of the stack.
pick ( ??? +n -- ??? n2 ) Copy +n-th stack item (1 pick = over).
r> ( -- n ) Move a return stack item to the stack. (Use with caution.)
r@ ( -- n ) Copy the top of the return stack to the stack.
roll ( ??? +n -- ? ) Rotate +n stack items (2 roll = rot).
rot ( n1 n2 n3 -- n2 n3 n1 ) Rotate three stack items so third item comes to the top.
swap ( n1 n2 -- n2 n1 ) Exchange the top two stack items.
tuck ( n1 n2 -- n2 n1 n2 ) Copy the top stack item below the second item.

Arithmetic Functions

* ( n1 n2 -- n3 ) Multiply n1 * n2.
+ ( n1 n2 -- n3 ) Add n1 + n2.
- ( n1 n2 -- n3 ) Subtract n1 - n2
/ ( n1 n2 -- quot ) Divide n1 / n2; remainder is discarded.
<<
lshift
( n1 +n -- n2 ) Left-shift n1 by +n bits.
>>
rshift
( n1 +n -- n2 ) Right-shift n1 by +n bits.
>>a ( n1 +n -- n2 ) Arithmetic right-shift n1 by +n bits.
abs ( n -- u ) Absolute value.
and ( n1 n2 -- n3 ) Bitwise logical AND.
bounds ( startadr len -- endadr startadr ) Convert startadr len to endadr startadr for do loop.
bljoin ( b.low b2 b3 b.hi -- long ) Join four bytes to form a 32-bit longword.
bwjoin ( b.low b.hi -- word ) Join two bytes to form a 16-bit word.
lbsplit ( long -- b.low b2 b3 b.hi ) Split a 32-bit longword into four bytes.
lwsplit ( long -- w.low w.hi ) Split a 32-bit longword into two 16-bit words.
max ( n1 n2 -- n3 ) n3 is maximum of n1 and n2.
min ( n1 n2 -- n3 ) n3 is minimum of n1 and n2.
mod ( n1 n2 -- rem ) Remainder of n1 / n2.
negate ( n1 -- n2 ) Change the sign of n1.
not
invert
( n1 -- n2 ) Bitwise ones complement.
or ( n1 n2 -- n3 ) Bitwise logical OR.
wbsplit ( word -- b.low b.hi ) Split 16-bit word into two bytes.
wljoin ( w.low w.hi -- long ) Join two words to form a longword.
xor ( n1 n2 -- n3 ) Bitwise exclusive OR.

Memory Access

! ( n adr16 -- ) Store a 32-bit number at adr16, must be 16-bit aligned.
+! ( n adr16 -- ) Add n to the 32-bit number stored at adr16, must be 16-bit aligned.
@ ( adr16 -- n ) Fetch a 32-bit number from adr16, must be 16-bit aligned.
c! ( n adr -- ) Store low byte of n at adr.
c@ ( adr -- byte ) Fetch a byte from adr.
cpeek ( adr -- false | byte true ) Fetch the byte at adr. Return the data and true if the access was successful. Return false if a read access error occurred. (Also lpeek, wpeek.)
cpoke ( byte adr -- okay? ) Store the byte to adr. Return true if the access was successful. Return false if a write access error occurred. (Also lpoke, wpoke.)
comp ( adr1 adr2 len -- n ) Compare two byte arrays, n = 0 if arrays are identical, n = 1 if first byte that is different is greater in array#1, n = -1 otherwise.
dump ( adr len -- ) Display len bytes of memory starting at adr.
fill ( adr size byte -- ) Set size bytes of memory to byte.
L! ( n adr32 -- ) Store a 32-bit number at adr32.
L@ ( adr32 -- long ) Fetch a 32-bit number from adr32.
x! ( x adr64 -- ) Store a 64-bit number at adr64, must be 64-bit aligned.
x@ ( adr64 -- x ) Fetch a 64-bit number from adr64, must be 64-bit aligned.
move ( adr1 adr2 u -- ) Copy u bytes from adr1 to adr2, handle overlap properly.
w! ( n adr16 -- ) Store a 16-bit number at adr16, must be 16-bit aligned.
w@ ( adr16 -- word ) Fetch a 16-bit number from adr16, must be 16-bit aligned.

Memory Allocation

alloc-mem ( size -- virt ) Allocate and map size bytes of available memory; return the virtual address.Unmap with free-mem.
free-mem ( virt size -- ) Free memory allocated by alloc-mem.

Defining Words

: name ( -- )
name ( ??? -- ? )
Start creating a new colon definition.
; ( -- ) Finish creating a new colon definition.
buffer: name ( size -- )
name ( -- adr64 )
Create a named array in temporary storage.
constant name ( n -- )
name ( -- n )
Define a constant (for example, 3 constant bar).
create name ( -- )
name ( -- adr16 )
Generic defining word.
defer name ( -- )
name ( ??? -- ? )
Define forward reference or execution vector.
does> ( -- adr16 ) Start the run-time clause for defining words.
value name ( n -- )
name ( -- n )
Create a changeable, named 32-bit quantity.
variable name ( -- )
name ( -- adr16 )
Define a variable.

Dictionary Searching

name ( -- xt ) Find the named word in the dictionary. (Returns the execution token. Use outside definitions.)  The space after ' is mandatory.
[’] name ( -- xt ) Similar to ’ but is used either inside or outside definitions.
$find ( adr len --
adr len false | xt n )
Find a word. n = 0 if not found, n = 1 if immediate, n = -1 otherwise.

Dictionary Compilation

, ( n -- ) Place a number in the dictionary.
c, ( byte -- ) Place a byte in the dictionary.
w, ( word -- ) Place a 16-bit number in the dictionary.
L, ( long -- ) Place a 32-bit number in the dictionary.
allot ( n -- ) Allocate n bytes in the dictionary.
forget name ( -- ) Remove word from dictionary and all subsequent words.
here ( -- adr ) Address of top of dictionary.
is name
to name
( n -- ) Install a new action in a defer word or value.
patch new old name ( -- ) Replace the first occurrence of old with new in the word name.
New and old can be either word names or numbers.
(patch ( new-n old-n xt -- ) Replace old-n with new-n in word indicated by xt.

Controlling Text Input

( ccc ) ( -- ) Begin a comment, terminated by the next ). The space after ( is mandatory.
\ rest-of-line ( -- ) Skip the rest of the line.
char ccc ( -- char ) Get numerical value of first ASCII character of next word.
[char] ccc
( -- char )
Version of char for use inside definitions.
key ( -- char ) Read a character from the assigned input device’s keyboard.
key? ( -- flag ) True if a key has been typed on the input device’s keyboard.

Displaying Text

cr ( -- ) Terminate a line on the display and go to the next line.
emit ( char -- ) Display the character.
type ( adr +n -- ) Display n characters.

Manipulating Text Strings

" ccc" ( -- adr len ) Collect an input stream string, either interpreted or compiled. Within the string, use "(00,ff...) to include arbitrary byte values.  The space after " is mandatory.
." ccc" ( -- ) Compile a string for later display.  The space after " is mandatory.
bl ( -- char ) ASCII code for the space character; decimal 32.
count ( pstr -- adr +n ) Unpack a packed string.

Redirecting I/O

input ( device -- ) Select device (com1, com2, keyboard, or device-specifier ) for subsequent input.
io ( device -- ) Select device for subsequent input and output.
output ( device -- ) Select device (com1, com2, screen, or device-specifier) for subsequent output.

Comparison

< ( n1 n2 -- flag ) True if n1 < n2.
<= ( n1 n2 -- flag ) True if n1 <= n2.
<> ( n1 n2 -- flag ) True if n1 <> n2.
= ( n1 n2 -- flag ) True if n1 = n2.
> ( n1 n2 -- flag ) True if n1 > n2.
>= ( n1 n2 -- flag ) True if n1 >= n2.
between ( n min max -- flag ) True if min <= n <= max.
u< ( u1 u2 -- flag ) True if u1 < u2, unsigned.
u<= ( u1 u2 -- flag ) True if u1 <= u2, unsigned.
u> ( u1 u2 -- flag ) True if u1 > u2, unsigned.
u>= ( u1 u2 -- flag ) True if u1 >= u2, unsigned.
within ( n min max -- flag ) True if min <= n < max.

if-then-else Conditionals

else ( -- ) Execute the following code if if failed.
if ( flag -- ) Execute the following code if flag is true.
then ( -- ) Terminate if...then...else.

begin (Conditional) Loop

again ( -- ) End a begin...again infinite loop.
begin ( -- ) Begin a begin...while...repeat, begin...until, or begin...again loop.
repeat ( -- ) End a begin...while...repeat loop.
until ( flag -- ) Continue executing a begin...until loop until flag is true.
while ( flag -- ) Continue executing a begin...while...repeat loop while flag is true.

do (Counted) Loop

+loop ( n -- ) End a do...+loop construct; add n to loop index and return to do (if n < 0, index goes from start to end inclusive).
?do ( end start -- ) Begin ?do...loop to be executed 0 or more times. Index goes from start to end-1 inclusive. If end = start, loop is not executed.
do ( end start -- ) Begin a do...loop. Index goes from start to end-1 inclusive. Example:
10 0 do i . loop (prints 0 1 2...d e f).
i ( -- n ) Loop index.
j ( -- n ) Loop index for next enclosing loop.
leave ( -- ) Exit from do...loop.
loop ( -- ) End of do...loop.

case Statement

( value )  
case
2 of ." it was two" endof
0 of ." it was zero" endof
." it was " dup . ( optional default clause )
endcase

Program Execution Control

abort ( -- ) Abort current execution and interpret keyboard commands.
abort" ccc" ( abort? -- ) If flag is true, abort and display message.  The space after " is mandatory.
evaluate ( adr len -- ) Interpret Forth source from an array.
execute ( xt -- ) Execute the word whose execution token is on the stack.
exit ( -- ) Return from the current word. (Cannot be used in counted loops.)
quit ( -- ) Same as abort, but leave stack intact.

Table of Contents

Open Firmware

Syntax
Booting
Device Specifiers
Device Aliases
Editor Keys (for Command Lines and NVRAMRC)
Configuration Variable Commands
Common Configuration Variables
NVRAMRC Script Editor
Device Tree Browsing
Help
Diagnostics
System Information
Emergency Keys
File Loading
Generic Registers
x86 Registers
MIPS Registers
SPARC Registers
Breakpoints
Disassembler
Miscellaneous Operations

Forth Language

Numeric Usage
Changing the Number Base
Basic Number Display
Forth Debugging
Forth Debugger Keys
Stack Manipulation
Arithmetic Functions
Memory Access
Memory Allocation
Defining Words
Dictionary Searching
Dictionary Compilation
Controlling Text Input
Displaying Text
Manipulating Text Strings
Redirecting I/O
Comparison
if-then-else Conditionals
begin (Conditional) Loop
do (Counted) Loop
case Statement
Program Execution Control

Copyright © 2002 FirmWorks     All Rights Reserved
Copyright © 1993 Sun Microsystems, Inc