A P P E N D I X I

Forth Word Reference

This appendix contains the Forth commands supported by OpenBoot.

For the most part, the commands are listed in the order in which they were introduced in the chapters. Some of the tables in this appendix show commands that are not listed elsewhere in this manual. These additional commands (such as memory mapping or output display primitives, or machine-specific register commands) are also part of the set of words in the OpenBoot implementation of Forth; they are included with relevant groups of commands.


Stack Item Notation
TABLE I-1 Stack Item Notation

Notation

Description

|

Alternate stack results shown with space, e.g. ( input -- addr len false | result true )

|

Alternate stack items shown without space, e.g. ( input -- addr len | 0 result ).

???

Unknown stack item(s).

...

Unknown stack item(s). If used on both sides of a stack comment, means the same stack items are present on both sides.

< > <space>

Space delimiter. Leading spaces are ignored.

a-addr

Variable-aligned address.

addr

Memory address (generally a virtual address).

addr len

Address and length for memory region

byte b xxx

8-bit value (low order byte in a 32-bit word).

char

7-bit value (low order byte), high bit unspecified.

cnt len size

Count or length.

dxxx

Double (extended-precision) numbers. 2 stack items, most significant cell on top of stack.

<eol>

End-of-line delimiter.

false

0 (false flag).

ihandle

Pointer for an instance of a package.

n n1 n2 n3

Normal signed values (32-bit).

nu nu1

Signed or unsigned values (32-bit).

<nothing>

Zero stack items.

phandle

Pointer for a package.

phys

Physical address (actual hardware address).

phys.lo phys.hi

Lower/upper cell of physical address

pstr

Packed string.

quad qxxx

Quadlet (32-bit value).

qaddr

Quadlet (32-bit) aligned address

{text}

Optional text. Causes default behavior if omitted.

"text<delim>"

Input buffer text, parsed when command is executed. Text delimiter is enclosed in <>.

[text<delim>]

Text immediately following on the same line as the command, parsed immediately. Text delimiter is enclosed in <>.

true

-1 (true flag).

uxxx

Unsigned value, positive values (32-bit).

virt

Virtual address (address used by software).

waddr

Doublet (16-bit) aligned address

word wxxx

Doublet (16-bit value, low order two bytes in a 32-bit word).

x x1

Arbitrary stack item.

x.lo x.hi

Low/high significant bits of a data item

xt

Execution token.

xxx?

Flag. Name indicates usage (e.g. done? ok? error? ).

xyz-str xyz-len

Address and length for unpacked string.

xyz-sys

Control-flow stack items, implementation-dependent.

( C: -- )

Compilation stack diagram.

( -- ) ( E: -- )

Execution stack diagram.

( R: -- )

Return stack diagram.



Commands for Browsing the Device Tree
TABLE I-2 Commands for Browsing the Device Tree

Command

Description

.properties

Display the names and values of the current node's properties.

dev device-path

Choose the specified device node, making it the current node.

dev node-name

Search for a node with the specified name in the subtree below the current node, and choose the first such node found.

dev ..

Choose the device node that is the parent of the current node.

dev /

Choose the root machine node.

device-end

Leave the device tree.

" device-path" find-device

Choose the specified device node, similar to dev .

ls

Display the names of the current node's children.

pwd

Display the device path name that names the current node.

see wordname

Decompile the specified word.

show-devs [device-path]

Display all the devices known to the system directly beneath a given device in the device hierarchy. show-devs used by itself shows the entire device tree.

words

Display the names of the current node's methods.

" device-path" select-dev

Select the specified device and make it the active node.



Common Options for the boot Command
TABLE I-3 Common Options for the boot Command

Parameter

Description

boot [ device-specifier ] [ filename ] [ options ]
[ device-specifier ]

The name (full path name or alias) of the boot device. Typical values include:

cdrom (CD-PROM drive)

disk (hard disk)

floppy (3-1/2" diskette drive)

net (Ethernet)

tape (SCSI tape)

[ filename ]

The name of the program to be booted (for example, stand/diag ). filename is relative to the root of the selected device and partition (if specified). If filename is not specified, the boot program uses the value of the boot-file NVRAM parameter (see Chapter 3).

[ options ]

(These options are specific to the operating system, and may differ from system to system.)



System Information Display Commands
TABLE I-4 System Information Display Commands

Command

Description

banner

Display power-on banner.

show-sbus

Display list of installed and probed SBus devices.

.enet-addr

Display current Ethernet address.

.idprom

Display ID PROM contents, formatted.

.traps

Display a list of SPARC trap types.

.version

Display version and date of the boot PROM.

.speed

Display CPU and bus speeds.

show-devs

Display all installed and probed devices.



Viewing or Changing Configuration Variables
TABLE I-5 Viewing or Changing Configuration Variables

Command

Description

printenv

Display all current parameters and current default values.

(Numbers are usually shown as decimal values.)

printenv parameter shows the current value of the named parameter.

setenv parameter value

Set parameter to the specified decimal or text value.

(Changes are permanent, but usually only take effect after a reset.)

set-default parameter

Reset the value of the named parameter to the factory default.

set-defaults

Reset parameter values to the factory defaults.

password

Set security-password.



NVRAMRC Editor Commands
TABLE I-6 NVRAMRC Editor Commands

Command

Description

nvalias alias device-pat

Store the command " devalias alias device-path " in NVRAMRC. The alias persists until the nvunalias or set-defaults commands are executed.

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.

nvquit

Discard the contents of the temporary buffer, without writing it to NVRAMRC. Prompt for confirmation.

nvrecover

Recover the contents of NVRAMRC if they have been lost as a result of the execution of set-defaults ; then enter the editor as with nvedit . nvrecover fails if nvedit is executed between the time that the NVRAMRC contents were lost and the time that nvrecover is executed.

nvrun

Execute the contents of the temporary buffer.

nvstore

Copy the contents of the temporary buffer to NVRAMRC; discard the contents of the temporary buffer.

nvunalias alias

Delete the corresponding alias from NVRAMRC.



NVRAM Script Editor Keystroke Commands
TABLE I-7 NVRAM Script Editor Keystroke Commands

Keystroke

Description

Control-B

Moves backward one character.

Escape B

Moves backward one word.

Control-F

Moves forward one character.

Escape F

Moves forward one word.

Control-A

Moves backward to beginning of the line.

Control-E

Moves forward to end of the line.

Control-N

Moves to the next line of the script editing buffer.

Control-P

Moves to the previous line of the script editing buffer.

Return (Enter)

Inserts a newline at the cursor position and advances to the next line.

Control-O

Inserts a newline at the cursor position and stays on the current line.

Control-K

Erases from the cursor position to the end of the line, storing the erased characters in a save buffer. If at the end of a line, joins the next line to the current line (i.e. deletes the newline).

Delete

Erases the previous character.

Backspace

Erases the previous character.

Control-H

Erases the previous character.

Escape H

Erases from beginning of word to just before the cursor, storing erased characters in a save buffer.

Control-W

Erases from beginning of word to just before the cursor, storing erased characters in a save buffer.

Control-D

Erases the next character.

Escape D

Erases from the cursor to the end of the word, storing the erased characters in a save buffer.

Control-U

Erases the entire line, storing the erased characters in a save buffer.

Control-Y

Inserts the contents of the save buffer before the cursor.

Control-Q

Quotes the next character (i.e. allows you to insert control characters).

Control-R

Retypes the line.

Control-L

Displays the entire contents of the editing buffer.

Control-C

Exits the script editor, returning to the OpenBoot command interpreter. The temporary buffer is preserved, but is not written back to the script. (Use nvstore afterwards to write it back.)



Stack Manipulation Commands
TABLE I-8 Stack Manipulation Commands

Command

Stack Diagram

Description

clear

( ??? -- )

Empty the stack.

depth

( -- u )

Return the number of items on the stack.

drop

( x -- )

Remove top item from the stack.

2drop

( x1 x2 -- )

Remove 2 items from the stack.

3drop

( x1 x2 x3 -- )

Remove 3 items from the stack.

dup

( x -- x x )

Duplicate the top stack item.

2dup

( x1 x2 -- x1 x2 x1 x2 )

Duplicate 2 stack items.

3dup

( x1 x2 x3 -- x1 x2 x3 x1 x2 x3 )

Duplicate 3 stack items.

?dup

( x -- x x | 0 )

Duplicate the top stack item if it is non-zero.

nip

( x1 x2 -- x2 )

Discard the second stack item.

over

( x1 x2 -- x1 x2 x1 )

Copy second stack item to top of stack.

2over

( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )

Copy second 2 stack items.

pick

( xu ... x1 x0 u -- xu ... x1 x0 xu )

Copy u -th stack item ( 1 pick = over ).

>r

( x -- ) (R: -- x )

Move a stack item to the return stack.

r>

( -- x ) ( R: x -- )

Move a return stack item to the stack.

r@

( -- x ) ( R: x -- x )

Copy the top of the return stack to the stack.

roll

( xu ... x1 x0 u -- xu-1 ... x1 x0 xu )

Rotate u stack items ( 2 roll = rot ).

rot

( x1 x2 x3 -- x2 x3 x1 )

Rotate 3 stack items.

-rot

( x1 x2 x3 -- x3 x1 x2 )

Inversely rotate 3 stack items.

2rot

( x1 x2 x3 x4 x5 x6 -- x3 x4 x5 x6 x1 x2 )

Rotate 3 pairs of stack items.

swap

( x1 x2 -- x2 x1 )

Exchange the top 2 stack items.

2swap

( x1 x2 x3 x4 -- x3 x4 x1 x2 )

Exchange 2 pairs of stack items.

tuck

( x1 x2 -- x2 x1 x2 )

Copy top stack item below second item.



Single-Precision Arithmetic Functions
TABLE I-9 Single-Precision Arithmetic Functions

Command

Stack Diagram

Description

+

( nu1 nu2 -- sum )

Add nu1 + nu2 .

-

( nu1 nu2 -- diff )

Subtract nu1 - nu2 .

*

( nu1 nu2 -- prod )

Multiply nu1 * nu2 .

*/

( nu1 nu2 nu3 -- quot )

Calculates nu1 * nu2 / n3 .

/

( n1 n2 -- quot )

Divide n1 by n2 ; remainder is discarded.

1+

( nu1 -- nu2 )

Add 1.

1-

( nu1 -- nu2 )

Subtract 1.

2+

( nu1 -- nu2 )

Add 2.

2-

( nu1 -- nu2 )

Subtract 2.

abs

( n -- u )

Absolute value.

bounds

( n count -- n+count n )

Prepare arguments for do or ?do loop.

even

( n -- n | n+1 )

Round to nearest even integer >= n .

max

( n1 n2 -- n1|n2 )

Return the maximum of n1 and n2 .

min

( n1 n2 -- n1|n2 )

Return the minimum of n1 and n2 .

mod

( n1 n2 -- rem )

Remainder of n1 / n2 .

*/mod

( n1 n2 n3 -- rem quot )

Remainder, quotient of n1 * n2 / n3 .

/mod

( n1 n2 -- rem quot )

Remainder, quotient of n1 / n2 .

negate

( n1 -- n2 )

Change the sign of n1 .

u*

( u1 u2 -- uprod )

Multiply 2 unsigned numbers yielding an unsigned product.

u/mod

( u1 u2 -- urem uquot )

Divide unsigned number by an unsigned number; yield remainder and quotient.



Bit-wise Logical Operators
TABLE I-10 Bit-wise Logical Operators

Command

Stack Diagram

Description

2*

( x1 -- x2 )

Multiply by 2.

2/

( x1 -- x2 )

Divide by 2.

>>a

( x1 u -- x2 )

Arithmetic right-shift x1 by u bits.

and

( x1 x2 -- x3 )

Bitwise logical AND.

invert

( x1 -- x2 )

Invert all bits of x1 .

lshift

( x1 u -- x2 )

Left-shift x1 by u bits. Zero-fill low bits.

or

( x1 x2 -- x3 )

Bitwise logical OR.

rshift

( x1 u -- x2 )

Right-shift x1 by u bits. Zero-fill high bits.

u2/

( x1 -- x2 )

Logical right shift 1 bit; zero shifted into high bit.

xor

( x1 x2 -- x3 )

Bitwise exclusive OR.



Double Number Arithmetic Functions
TABLE I-11 Double Number Arithmetic Functions

Command

Stack Diagram

Description

d+

(d1 d2 -- d.sum )

Add d1 to d2 yielding double number d.sum.

d-

(d1 d2 -- d.diff )

Subtract d2 from d1 yielding double number d.diff.

fm/mod

( d n -- rem quot )

Divide d by n.

m*

( n1 n2 -- d )

Signed multiply with double-number product.

s>d

( n1 -- d1 )

Convert a number to a double number.

sm/rem

( d n -- rem quot )

Divide d by n , symmetric division.

um*

( u1 u2 -- ud )

Unsigned multiply yielding unsigned double number product.

um/mod

( ud u -- urem uprod )

Divide ud by u .



32-Bit Data Type Conversion Functions
TABLE I-12 32-Bit Data Type Conversion Functions

Command

Stack Diagram

Description

bljoin

( b.low b2 b3 b.hi -- quad )

Join four bytes to form a quadlet

bwjoin

( b.low b.hi -- word )

Join two bytes to form a doublet.

lbflip

( quad1 -- quad2 )

Reverse the bytes within a quadlet

lbsplit

( quad -- b.low b2 b3 b.hi )

Split a quadlet into four bytes.

lwflip

( quad1 -- quad2 )

Swap the doublets within a quadlet.

lwsplit

( quad -- w.low w.hi )

Split a quadlet into two doublets.

wbflip

( word1 -- word2 )

Swap the bytes within a doublet.

wbsplit

( word -- b.low b.hi )

Split a doublet into two bytes.

wljoin

( w.low w.hi -- quad )

Join two doublets to form a quadlet.



64-Bit Data Type Conversion Functions
TABLE I-13 64-Bit Data Type Conversion Functions

Command

Stack Diagram

Description

bxjoin

( b.lo b.2 b.3 b.4 b.5 b.6 b.7 b.hi -- o )

Join 8 bytes to form an octlet.

lxjoin

( quad.lo quad.hi -- o )

Join 2 quadlets to form an octlet.

wxjoin

( w.lo w.2 w.3 w.hi -- o )

Join four doublets to form an octlet.

xbflip

( oct1 -- oct2 )

Reverse the bytes within an octlet.

xbflips

( oaddr len -- )

Reverse the bytes within each octlet in the given region.The behavior is undefined if len is not a multiple of /x .

xbsplit

( o -- b.lo b.2 b.3 b.4 b.5 b.6 b.7 b.hi )

Split an octlet into 8 bytes.

xlflip

( oct1 -- oct2 )

Reverse the quadlets within an octlet. The bytes within each quadlet are not reversed.

xlflips

( oaddr len -- )

Reverse the quadlets within each octlet in the given region. The bytes within each quadlet are not reversed. The behavior is undefined if len is not a multiple of /x .

xlsplit

( o -- quad.lo quad.hi )

Split on octlet into 2 quadlets.

xwflip

( oct1 -- oct2 )

Reverse the doublets within an octlet. The bytes within each doublet are not reversed.

xwflips

( oaddr len -- )

Reverse the doublets within each octlet in the given region. The bytes within each doublet are not reversed. The behavior is undefined if len is not a multiple of /x .

xwsplit

( o -- w.lo w.2 w.3 w.hi )

Split an octlet into 4 doublets.



Address Arithmetic Functions
TABLE I-14 Address Arithmetic Functions

Command

Stack Diagram

Description

aligned

( n1 -- n1 | a-addr)

Increase n1 if necessary to yield a variable aligned address.

/c

( -- n )

The number of address units to a byte: 1.

/c*

( nu1 -- nu2 )

Synonym for chars .

ca+

( addr1 index -- addr2 )

Increment addr1 by index times the value of /c .

ca1+

( addr1 -- addr2 )

Synonym for char+ .

char+

( addr1 -- addr2 )

Increment addr1 by the value of /c .

cell+

( addr1 -- addr2 )

Increment addr1 by the value of /n .

chars

( nu1 -- nu2 )

Multiply nu1 by the value of /c .

cells

( nu1 -- nu2 )

Multiply nu1 by the value of /n .

/l

( -- n )

Number of address units to a quadlet; typically 4.

/l*

( nu1 -- nu2 )

Multiply nu1 by the value of /l .

la+

( addr1 index -- addr2 )

Increment addr1 by index times the value of /l .

la1+

( addr1 -- addr2 )

Increment addr1 by the value of /l .

/n

( -- n )

Number of address units in a cell.

/n*

( nu1 -- nu2 )

Synonym for cells .

na+

( addr1 index -- addr2 )

Increment addr1 by index times the value of /n .

na1+

( addr1 -- addr2 )

Synonym for cell+ .

/w

( -- n )

Number of address units to a doublet; typically 2.

/w*

( nu1 -- nu2 )

Multiply nu1 by the value of /w .

wa+

( addr1 index -- addr2 )

Increment addr1 by index times the value of /w .

wa1+

( addr1 -- addr2 )

Increment addr1 by the value of /w .



64-Bit Address Arithmetic Functions
TABLE I-15 64-Bit Address Arithmetic Functions

Command

Stack Diagram

Description

/x

( -- n )

Number of address units in an octlet, typically 8.

/x*

( nu1 -- nu2 )

Multiply nu1 by the value of /x .

xa+

( addr1 index -- addr2 )

Increment addr1 by index times the value of /x .

xa1+

( addr1 -- addr2 )

Increment addr1 by the value of /x .



Memory Access Commands
TABLE I-16 Memory Access Commands

Command

Stack Diagram

Description

!

( x a-addr -- )

Store a number at a-addr .

+!

( nu a-addr -- )

Add nu to the number stored at a-addr .

@

( a-addr -- x )

Fetch a number from a-addr .

2!

( x1 x2 a-addr -- )

Store 2 numbers at a-addr , x2 at lower address.

2@

( a-addr -- x1 x2 )

Fetch 2 numbers from a-addr , x2 from lower address.

blank

( addr len -- )

Set len bytes of memory beginning at addr to the space character (decimal 32).

c!

( byte addr -- )

Store byte at addr .

c@

( addr -- byte )

Fetch a byte from addr .

cpeek

( addr -- false | byte true )

Attempt to fetch the byte at addr . Return the data and true if the access was successful. Return false if a read access error occurred.

cpoke

( byte addr -- okay? )

Attempt to store the byte to addr . Return true if the access was successful. Return false if a write access error occurred.

comp

( addr1 addr2 len -- diff? )

Compare two byte arrays. diff? is 0 if the arrays are identical,
diff? is -1 if the first byte that is different is lesser in the string at addr1 , diff? is 1 otherwise.

dump

( addr len -- )

Display len bytes of memory starting at addr .

erase

( addr len -- )

Set len bytes of memory beginning at addr to 0 .

fill

( addr len byte -- )

Set len bytes of memory beginning at addr to the value byte .

l!

( quad qaddr -- )

Store a quadlet q at qaddr .

l@

( qaddr -- quad )

Fetch a quadlet q from qaddr .

lbflips

( qaddr len -- )

Reverse the bytes within each quadlet in the specified region.

lwflips

( qaddr len -- )

Swap the doublets within each quadlet in specified region.

lpeek

( qaddr -- false | quad true )

Attempt to fetch the 32-bit quantity at qaddr . Return the data and true if the access was successful. Return false if a read access error occurred.

lpoke

( quad qaddr -- okay? )

Attempt to store the 32-bit quantity at qaddr . Return true if the access was successful. Return false if a a write access error occurred.

move

( src-addr dest-addr len -- )

Copy len bytes from src-addr to dest-addr .

off

( a-addr -- )

Store false at a-addr .

on

( a-addr -- )

Store true at a-addr .

unaligned-l!

( quad addr -- )

Store a quadlet q , any alignment

unaligned-l@

( addr -- quad )

Fetch a quadlet q , any alignment.

unaligned-w!

( w addr -- )

Store a doublet w , any alignment.

unaligned-w@

( addr -- w )

Fetch a doublet w , any alignment.

w!

( w waddr -- )

Store a doublet w at waddr .

w@

( waddr -- w)

Fetch a doublet w from waddr .

<w@

( waddr -- n )

Fetch doublet w from waddr , sign-extended.

wbflips

( waddr len -- )

Swap the bytes within each doublet in the specified region.

wpeek

( waddr -- false | w true )

Attempt to fetch the 16-bit quantity at waddr . Return the data and true if the access was successful. Return false if a read access error occurred.

wpoke

( w waddr -- okay? )

Attempt to store the 16-bit quantity to waddr . Return true if the access was successful. Return false if a write access error occurred.



64-Bit Memory Access Functions
TABLE I-17 64-Bit Memory Access Functions

Command

Stack Diagram

Description

<l@

( qaddr -- n )

Fetch quadlet from qaddr, sign-extended.

x,

( o -- )

Compile an octlet, o, into the dictionary (doublet-aligned).

x@

( oaddr -- o )

Fetch octlet from an octlet aligned address.

x!

( o oaddr -- )

Store octlet to an octlet aligned address.

xbflips

( oaddr len -- )

Reverse the bytes within each octlet in the given region.The behavior is undefined if len is not a multiple of /x .

xlflips

( oaddr len -- )

Reverse the quadlets within each octlet in the given region. The bytes within each quadlet are not reversed. The behavior is undefined if len is not a multiple of /x .

xwflips

( oaddr len -- )

Reverse the doublets within each octlet in the given region. The bytes within each doublet are not reversed. The behavior is undefined if len is not a multiple of /x .



Memory Mapping Commands
TABLE I-18 Memory Mapping Commands

Command

Stack Diagram

Description

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 .

map?

( virt -- )

Display memory map information for the virtual address.



Defining Words
TABLE I-19 Defining Words

Command

Stack Diagram

Description

: new-name

( -- )
(E: ... -- ??? )

Start a new colon definition of the word new-name .

;

( -- )

End a colon definition.

alias new-name old-name

( -- )
(E: ... -- ??? )

Create new-name with the same behavior as old-name .

buffer: name

( size -- )
(E: -- a-addr )

Create a named array in temporary storage.

constant name

( n -- )
(E: -- n )

Define a constant (for example, 3 constant bar ).

2constant name

( n1 n2 -- )
(E: -- n1 n2 )

Define a 2-number constant.

create name

( -- )
(E: -- a-addr )

Generic defining word.

defer name

( -- )
(E: ... -- ??? )

Define a word for forward references or execution vectors using execution token.

does>

( ... -- ... a-addr )

(E: ... -- ??? )

Start the run-time clause for defining words.

field name

( offset size -- offset+size )
(E: addr -- addr+offset )

Create a named offset pointer.

struct

( -- 0 )

Initialize for field creation.

value name

( n -- )
(E: -- n )

Create a changeable, named quantity.

variable name

( -- )
(E: -- a-addr )

Define a variable.



Dictionary Searching Commands
TABLE I-20 Dictionary Searching Commands

Command

Stack Diagram

Description

' name

( -- xt )

Find the named word in the dictionary.
Returns the execution token. Use outside definitions.

['] name

( -- xt )

Similar to ' but is used either inside or outside definitions.

.calls

( xt -- )

Display a list of all words that call the word whose execution token is xt .

$find

( str len -- str len false | xt true )

Search for word named by str,len. If found, leave xt and true on stack. If not found, leave name string and false on stack.

find

( pstr -- pstr false | xt n )

Search for word named by pstr. If found, leave xt and true on stack. If not found, leave name string and false on stack.

(Recommend using $find to avoid use of packed string.)

see thisword

( -- )

Decompile the named command.

(see)

( xt -- )

Decompile the word indicated by the execution token.

sift

( pstr -- )

Display names of all dictionary entries containing the string pointed to by pstr .

sifting ccc

( -- )

Display names of all dictionary entries containing the sequence of characters. ccc contains no spaces.

words

( -- )

Display all visible words in the dictionary.



Dictionary Compilation Commands
TABLE I-21 Dictionary Compilation Commands

Command

Stack Diagram

Description

,

( 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,

( quad -- )

Place a 32-bit number in the dictionary.

[

( -- )

Enter interpretation state.

]

( -- )

End interpreting, enter compilation state.

allot

( n -- )

Allocate n bytes in the dictionary.

>body

( xt -- a-addr )

Find the data field address from the execution token.

body>

( a-addr -- xt )

Find the execution token from the data field address.

compile

( -- )

Compile the next word at run time. (Recommend using postpone instead.)

[compile] name

( -- )

Compile the next (immediate) word. (Recommend using postpone instead.)

forget name

( -- )

Remove word from dictionary and all subsequent words.

here

( -- addr )

Address of top of dictionary.

immediate

( -- )

Mark the last definition as immediate.

to name

( n -- )

Install a new action in a defer word or value .

literal

( n -- )

Compile a number.

origin

( -- addr )

Return the address of the start of the Forth system.

patch new-word old-word word-to-patch

( -- )

Replace old-word with new-word in word-to-patch .

(patch)

( new-n old-n xt -- )

Replace old-n with new-n in word indicated
by xt .

postpone name

( -- )

Delay the execution of the word name.

recursive

( -- )

Make the name of the colon definition being compiled visible in the dictionary, and thus allow the name of the word to be used recursively in its own definition.

state

( -- addr )

Variable that is non-zero in compile state.



Assembly Language Programming
TABLE I-22 Assembly Language Programming

Command

Stack Diagram

Description

code name

( -- code-sys )

(E: ... -- ??? )

Begin the creation of an assembly language routine called name . Commands that follow are interpreted as assembler mnemonics. Note that if the assembler is not installed, code is still present, except that machine code must be entered numerically (for example, in hex) with ",".

c;

( code-sys -- )

End the creation of an assembly language routine. Automatically assemble the Forth interpreter "next" function so that the created assembly-code word, when executed, returns control to the calling routine as usual.

label name

( -- code-sys )

(E: -- a-addr )

Begin the creation of an assembly language routine called name . Words created with label leave the address of the code on the stack when executed. The commands that follow are interpreted as assembler mnemonics. As with code , label is present even if the assembler is not installed.

end-code

( code-sys -- )

End the assembly language patch started with label .



Basic Number Display
TABLE I-23 Basic Number Display

Command

Stack Diagram

Description

.

( n -- )

Display a number in the current base.

.r

( n size -- )

Display a number in a fixed width field.

.s

( -- )

Display contents of data stack.

showstack

( -- )

Execute .s automatically before each ok prompt.

noshowstack

( -- )

Turn off automatic display of the stack before each ok prompt.

u.

( u -- )

Display an unsigned number.

u.r

( u size -- )

Display an unsigned number in a fixed width field.



Changing the Number Base
TABLE I-24 Changing the Number Base

Command

Stack Diagram

Description

.d

( n -- )

Display n in decimal without changing base.

.h

( n -- )

Display n in hex without changing base.

base

( -- addr )

Variable containing number base.

decimal

( -- )

Set the number base to 10.

d# number

( -- n )

Interpret number in decimal; base is unchanged.

hex

( -- )

Set the number base to 16.

h# number

( -- n )

Interpret number in hex; base is unchanged.



Numeric Output Word Primitives
TABLE I-25 Numeric Output Word Primitives

Command

Stack Diagram

Description

#

( +l1 -- +l2 )

Convert a digit in pictured numeric output.

#>

( l-- addr +n )

End pictured numeric output.

<#

( -- )

Initialize pictured numeric output.

(.)

( n -- )

Convert a number to a string.

(u.)

( -- addr len )

Convert unsigned to string.

digit

( char base -- digit true | char false )

Convert a character to a digit.

hold

( char -- )

Insert the char in the pictured numeric output string.

$number

( addr len -- true | n false )

Convert a string to a number.

#s

( l -- 0 )

Convert the rest of the digits in pictured numeric output.

sign

( n -- )

Set sign of pictured output.



Controlling Text Input
TABLE I-26 Controlling Text Input

Command

Stack Diagram

Description

( ccc )

( -- )

Begin a comment.

\ rest-of-line

( -- )

Skip the rest of the line.

ascii ccc

( -- char )

Get numerical value of first ASCII character of next word.

accept

( addr len1 -- len2 )

Get a line of edited input from the console input device; store at addr .len1 is the maximum allowed length. len2 is the actual length received.

expect

( addr len -- )

Get and display a line of input from the console; store at addr . (Recommend using accept instead.)

key

( -- char )

Read a character from the console input device.

key?

( -- flag )

True if a key has been typed on the console input device.

parse

( char -- str len )

Parse text from the input buffer delimited by char.

parse-word

( -- str len )

Skip leading spaces and parse text from the input buffer delimited by white space.

safe-parse-word

( -- str len )

Similar to parse-word but intended for use in cases where the null string as input is indicative of an error.

word

( char -- pstr )

Collect a string delimited by char from the input buffer and place it as a packed string in memory at pstr . (Recommend using parse instead.)



Displaying Text Output
TABLE I-27 Displaying Text Output

Command

Stack Diagram

Description

." ccc "

( -- )

Compile a string for later display.

(cr

( -- )

Move the output cursor back to the beginning of the current line.

cr

( -- )

Terminate a line on the display and go to the next line.

emit

( char -- )

Display the character.

exit?

( -- flag )

Enable the scrolling control prompt: More [<space>,<cr>,q] ?

The return flag is true if the user wants the output to be terminated.

space

( -- )

Display a space character.

spaces

( +n -- )

Display +n spaces.

type

( addr +n -- )

Display n characters.



Formatted Output
TABLE I-28 Formatted Output

Command

Stack Diagram

Description

#lines

( -- rows )

Value holding the number of lines on the output device.

#out

( -- a-addr )

Variable holding the column number on the output device.



Manipulating Text Strings
TABLE I-29 Manipulating Text Strings

Command

Stack Diagram

Description

",

( addr len -- )

Compile an array of bytes from addr of length len , at the top of the dictionary as a packed string.

" ccc "

( -- addr len )

Collect an input stream string, either interpreted or compiled. Within the string, "(00,ff...) can be used to include arbitrary byte values.

.( ccc )

( -- )

Display a string immediately.

-trailing

( addr +n1 -- addr +n2 )

Remove trailing spaces.

bl

( -- char )

ASCII code for the space character; decimal 32.

count

( pstr -- addr +n )

Unpack a packed string.

lcc

( char -- lowercase-char )

Convert a character to lowercase.

left-parse-string

( addr len char -- addrR lenR addrL lenL )

Split a string at char (which is discarded).

pack

( addr len pstr -- pstr )

Make a packed string from addr len ; place it at pstr .

p" ccc "

( -- pstr )

Collect a string from the input stream; store as a packed string.

upc

( char -- uppercase-char )

Convert a character to uppercase.



I/O Redirection Commands
TABLE I-30 I/O Redirection Commands

Command

Stack Diagram

Description

input

( device -- )

Select device ( keyboard , or device-specifier ) for subsequent input.

io

( device -- )

Select device for subsequent input and output.

output

( device -- )

Select device ( screen , or device-specifier ) for subsequent output.



ASCII Constants
TABLE I-31 ASCII Constants

Command

Stack Diagram

Description

bell

( -- n )

ASCII code for the bell character; decimal 7.

bs

( -- n )

ASCII code for the backspace character; decimal 8.



Command Line Editor Keystroke Commands
TABLE I-32 Command Line Editor Keystroke Commands

Keystroke

Description

Control-B

Moves backward one character.

Escape B

Moves backward one word.

Control-F

Moves forward one character.

Escape F

Moves forward one word.

Control-A

Moves backward to beginning of line.

Control-E

Moves forward to end of line.

Delete

Erases previous character.

Backspace

Erases previous character.

Control-H

Erases previous character.

Escape H

Erases from beginning of word to just before the cursor, storing erased characters in a save buffer.

Control-W

Erases from beginning of word to just before the cursor, storing erased characters in a save buffer.

Control-D

Erases next character.

Escape D

Erases from cursor to end of the word, storing erased characters in a save buffer.

Control-K

Erases from cursor to end of line, storing erased characters in a save buffer.

Control-U

Erases entire line, storing erased characters in a save buffer.

Control-R

Retypes the line.

Control-Q

Quotes next character (allows you to insert control characters).

Control-Y

Inserts the contents of the save buffer before the cursor.

Control-P

Selects and displays the previous line for subsequent editing.

Control-N

Selects and displays the next line for subsequent editing.

Control-L

Displays the entire contents of the editing buffer.



Command Completion Keystroke Commands
TABLE I-33 Command Completion Keystroke Commands

Keystroke

Description

Control-Space

Complete the name of the current word.

Control-/

Display all possible matches for the current word.



Comparison Commands
TABLE I-34 Comparison Commands

Command

Stack Diagram

Description

<

( n1 n2 -- flag )

True if n1 < n2 .

<=

( n1 n2 -- flag )

True if n1 <= n2 .

<>

( n1 n2 -- flag )

True if n1 is not equal to n2 .

=

( n1 n2 -- flag )

True if n1 = n2 .

>

( n1 n2 -- flag )

True if n1 > n2 .

>=

( n1 n2 -- flag )

True if n1 >= n2 .

0<

( n -- flag )

True if n < 0.

0<=

( n -- flag )

True if n <= 0.

0<>

( n -- flag )

True if n <> 0.

0=

( n -- flag )

True if n = 0 (also inverts any flag).

0>

( n -- flag )

True if n > 0.

0>=

( n -- flag )

True if n >= 0.

between

( n min max -- flag )

True if min <= n <= max .

false

( -- 0 )

The value FALSE , which is 0.

true

( -- -1 )

The value TRUE , which is -1.

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-else-then Commands
TABLE I-35 if-else-then Commands

Command

Stack Diagram

Description

if

( flag -- )

Execute the following code when flag is true .

else

( -- )

Execute the following code when flag is false .

then

( -- )

Terminate if...then...else .



case Statement Commands
TABLE I-36 case Statement Commands

Command

Stack Diagram

Description

case

( selector -- selector )

Begin a case...endcase conditional.

endcase

( selector | {empty} -- )

Terminate a case...endcase conditional.

endof

( -- )

Terminate an of...endof clause within a case...endcase

of

( selector test-value -- selector | {empty} )

Begin an of...endof clause within a case conditional.



begin (Conditional) Loop Commands
TABLE I-37 begin (Conditional) Loop Commands

Command

Stack Diagram

Description

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 Commands
TABLE I-38 do (Counted) Loop Commands

Command

Stack Diagram

Description

+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.

?leave

( flag -- )

Exit from a do...loop if flag is non-zero.

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 )

Leaves the loop index on the stack.

j

( -- n )

Leaves the loop index for next outer enclosing loop.

leave

( -- )

Exit from do...loop .

loop

( -- )

End of do...loop .



Program Execution Control Commands
TABLE I-39 Program Execution Control Commands

Command

Stack Diagram

Description

abort

( -- )

Abort current execution and interpret keyboard commands.

abort " ccc "

( abort? -- )

If abort? is true, abort and display message.

eval

( ... str len -- ??? )

Synonym for evaluate .

evaluate

( ... str len -- ??? )

Interpret Forth source text from the specified string.

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.



File Loading Commands
TABLE I-40 File Loading Commands

Command

Stack Diagram

Description

?go

( -- )

Execute Forth, FCode, or binary programs.

boot [specifiers] -h

( -- )

Load file from specified source.

byte-load

( addr span -- )

Interpret 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

( addr -- )

Load the specified file over Ethernet at the given address.

eval

( addr len -- )

Interpret loaded Forth text file.

go

( -- )

Begin executing a previously-loaded binary program, or resume executing an interrupted program.

init-program

( -- )

Initialize to execute a binary file.

load device-specifier argument

( -- )

Load data from specified device into memory at the address given by load-base .

load-base

( -- addr )

Address at which load places the data it reads from a device.



Disassembler Commands
TABLE I-41 Disassembler Commands

Command

Stack Diagram

Description

+dis

( -- )

Continue disassembling where the last disassembly left off.

dis

( addr -- )

Begin disassembling at the specified address.



Breakpoint Commands
TABLE I-42 Breakpoint Commands

Command

Stack Diagram

Description

+bp

( addr -- )

Add a breakpoint at the given address.

-bp

( addr -- )

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. This word can be altered to perform any desired action. For example, to display registers at every breakpoint, type: ['] .registers is .breakpoint . The default behavior is .instruction . To perform multiple behaviors, create a single definition which calls all desired behaviors, then load that word into .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.) Treat 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

( addr -- )

Execute until the given address is encountered. Equivalent to +bp go .



Forth Source-level Debugger Commands
TABLE I-43 Forth Source-level Debugger Commands

Command

Description

c

"Continue". Switch from stepping to tracing, thus tracing the remainder of the execution of the word being debugged.

d

"Down a level". Mark for debugging the word whose name was just displayed, then execute it.

u

"Up a level". Un-mark the word being debugged, mark its caller for debugging, and finish executing the word that was previously being debugged.

f

Start a subordinate Forth interpreter. When that interpreter exits (with resume ), control returns to the debugger at the place where the f command was executed.

g

"Go." Turn off the debugger and continue execution.

q

"Quit". Abort the execution of the word being debugged and all its callers and return to the command interpreter.

s

"see". Decompile the word being debugged.

$

Display the address,len on top of the stack as a text string.

h

"Help". Display symbolic debugger documentation.

?

"Short Help". Display brief symbolic debugger documentation.

debug name

Mark the specified Forth word for debugging. Enter the Forth Source-level Debugger on all subsequent attempts to execute name. After executing debug , the execution speed of the system may decrease until debugging is turned off with debug-off . (Do not debug basic Forth words such as " dup " .)

(debug

Like debug except that (debug takes an execution token from the stack instead of a name from the input stream.

debug-off

Turn off the Forth Source-level Debugger so that no word is being debugged.

resume

Exit from a subordinate interpreter, and go back to the stepper (See the f command in this table.)

stepping

Set step mode for the Forth Source-level Debugger, allowing the interactive, step-by-step execution of the word being debugged. Step mode is the default.

tracing

Set trace mode for the Forth Source-level Debugger. Tracing enables the execution of the word being debugged, while showing the name and stack contents for each word called by that word.

<space-bar>

Execute the word just displayed and proceed to the next word.



Time Utilities
TABLE I-44 Time Utilities

Command

Stack Diagram

Description

get-msecs

( -- ms )

Return the approximate current time in milliseconds.

ms

( n -- )

Delay for n milliseconds. Resolution is 1 millisecond.



Miscellaneous Operations
TABLE I-45 Miscellaneous Operations

Command

Stack Diagram

Description

callback string

( value -- )

Call Solaris with the given value and string.

catch

( ... xt -- ??? error-code | ??? false )

Execute xt ; return throw error code or 0 if throw is not called.

eject-floppy

( -- )

Eject the diskette from the floppy drive.

firmware-version

(-- n )

Return major/minor CPU firmware version
(that is, 0x00030001 = firmware version 3.1).

forth

( -- )

Restore main Forth vocabulary to top of search order.

ftrace

( -- )

Show calling sequence when exception occurred.

noop

( -- )

Do nothing.

reset-all

( -- )

Reset the entire system (similar to a power-cycle).

sync

( -- )

Call the operating system to write any pending information to the hard disk. Also boot after sync-ing file systems.

throw

( error-code -- )

Return given error code to catch.



Multiprocessor Commands
TABLE I-46 Multiprocessor Commands

Command

Stack Diagram

Description

switch-cpu

( cpu# -- )

Switch to indicated CPU.



Memory Mapping Commands
TABLE I-47 Memory Mapping Commands

Command

Stack Diagram

Description

map?

( virt -- )

Display memory map information for the virtual address.

memmap

( phys space size -- virt )

Map a region of physical addresses; return the allocated virtual address. Unmap with free-virtual .

obio

( -- space )

Specify the device address space for mapping.

obmem

( -- space )

Specify the onboard memory address space for mapping.

sbus

( -- space )

Specify the SBus address space for mapping.



Memory Mapping Primitives
TABLE I-48 Memory Mapping Primitives

Command

Stack Diagram

Description

iomap?

( virt -- )

Display IOMMU page map entry for the virtual address.

iomap-page

( phys space virt -- )

Map physical page given by phys and space to the virtual address.

iomap-pages

( phys space virt size -- )

Perform consecutive iomap-page s to map a region of memory given by size .

iopgmap@

( virt -- pte | 0 )

Return IOMMU page map entry for the virtual address.

iopgmap!

( pte virt -- )

Store a new page map entry for the virtual address.

map-page

( phys space virt -- )

Map one page of memory starting at address phys on to virtual address virt in the specified address space . All addresses are truncated to lie on a page boundary.

map-pages

( phys space virt size -- )

Perform consecutive map-page s to map a region of memory to the specified size .

map-region

( region# virt -- )

Map a region.

map-segments

( smentry virt len -- )

Perform consecutive smap! operations to map a region of memory.

pgmap!

( pmentry virt -- )

Store a new page map entry for the virtual address.

pgmap?

( virt -- )

Display the page map entry (decoded and in English) corresponding to the virtual address.

pgmap@

( virt -- pmentry )

Return the page map entry for the virtual address.

pagesize

( -- size )

Return the size of a page.

rmap!

( rmentry virt -- )

Store a new region map entry for the virtual address.

rmap@

( virt -- rmentry )

Return the region map entry for the virtual address.

segmentsize

( -- size )

Return the size of a segment.

smap!

( smentry virt -- )

Store a new segment map entry for the virtual address.

smap?

( virt -- )

Formatted display of the segment map entry for the virtual address.

smap@

( virt -- smentry )

Return the segment map entry for the virtual address.



Cache Manipulation Commands
TABLE I-49 Cache Manipulation Commands

Command

Stack Diagram

Description

clear-cache

( -- )

Invalidate all cache entries.

cache-off

( -- )

Disable the cache.

cache-on

( -- )

Enable the cache.

ecdata!

( data offset -- )

Store the data at the cache offset .

ecdata@

( offset -- data )

Fetch (return) data from the cache offset .

ectag!

( value offset -- )

Store the tag value at the cache offset .

ectag@

( offset -- value )

Return the tag value at the cache offset .

flush-cache

( -- )

Write back any pending data from the cache.



Reading/Writing Machine Registers in Sun-4u Machines
TABLE I-50 Reading/Writing Machine Registers in Sun-4u Machines

Command

Stack Diagram

Description

aux!

( data -- )

Write auxiliary register.

aux@

( -- data )

Read auxiliary register.



Alternate Address Space Access Commands
TABLE I-51 Alternate Address Space Access Commands

Command

Stack Diagram

Description

spacec!

( byte addr asi -- )

Store the byte in asi at addr .

spacec?

( addr asi -- )

Display the byte in asi at addr .

spacec@

( addr asi -- byte )

Fetch the byte from asi at addr .

spaced!

( quad1 quad2 addr asi -- )

Store the two quadlets in asi at addr . Order is implementation-dependent.

spaced?

( addr asi -- )

Display the two quadlets in asi at addr . Order is implementation-dependent.

spaced@

( addr asi -- quad1 quad2 )

Fetch the two quadlets from asi at addr . Order is implementation-dependent.

spacel!

( quad addr asi -- )

Store the quadlet in asi at addr .

spacel?

( addr asi -- )

Display the quadlet in asi at addr .

spacel@

( addr asi -- quad )

Fetch the quadlet from asi at addr .

spacew!

( w addr asi -- )

Store the doublet in asi at addr .

spacew?

( addr asi -- )

Display the doublet in asi at addr .

spacew@

( addr asi -- w )

Fetch the doublet from asi at addr .

spacex!

( x addr asi -- )

Store the number in asi at addr .

spacex?

( addr asi -- )

Display the word in asi at addr .

spacex@

( addr asi -- x )

Fetch the word from asi at addr.



SPARC Register Commands
TABLE I-52 SPARC Register Commands

Command

Stack Diagram

Description

%g0 through %g7

( -- value )

Return the value in the specified global register.

%i0 through %i7

( -- value )

Return the value in the specified input register.

%l0 through %l7

( -- value )

Return the value in the specified local register.

%o0 through %o7

( -- value )

Return the value in the specified output register.

%pc %npc %y

( -- value )

Return the value in the specified register.

%f0 through %f31

( -- value )

Return the value in the specified floating point register.

.fregisters

( -- )

Display the values in %f0 through %f31 .

.locals

( -- )

Display the values in the i , l and o registers.

.registers

( -- )

Display values in processor registers.

.window

( window# -- )

Same as w .locals ; display the desired window.

ctrace

( -- )

Display the return stack showing C subroutines.

set-pc

( new-value -- )

Set %pc to new-value, and set %npc to (new-value+4).

to regname

( new-value -- )

Change the value stored in any of the above registers.
Use in the form: new-value to regname.

w

( window# -- )

Set the current window for displaying %i x, %l x, or %o x.



SPARC V9 Register Commands
TABLE I-53 SPARC V9 Register Commands

Command

Stack Diagram

Description

%fprs

%asi

%pstate

%tl-c

%pil

%tstate

%tt

%tba

%cwp

%cansave

%canrestore

%otherwin

%wstate

%cleanwin

( -- value )

Return the value in the specified register.

.pstate

( -- )

Formatted display of the processor state register.

.ver

( -- )

Formatted display of the version register.

.ccr

( -- )

Formatted display of the ccr register.

.trap-registers

( -- )

Display trap-related registers.



Emergency Keyboard Commands
TABLE I-54 Emergency Keyboard Commands

Command

Description

Stop

Bypass POST. This command does not depend on security-mode. (Note: some systems bypass POST as a default; in such cases, use Stop-D to start POST.)

Stop-A

Abort.

Stop-D

Enter diagnostic mode (set diag-switch? to true ).

Stop-F

Enter Forth on TTYA instead of probing. Use fexit to continue with the initialization sequence. Useful if hardware is broken.

Stop-N

Reset NVRAM contents to default values.


Copyright © 2001, Sun Microsystems, Inc. All rights reserved.