OpenBoot 2.x Command Reference Manual

Accessing Memory

The User Interface provides interactive commands for examining and setting memory. Use the User Interface to:

Memory operators let you read from and write to any memory location. All memory addresses shown in the examples that follow are virtual addresses.

A variety of 8-bit, 16-bit, and 32-bit operations are provided. In general, a c (character) prefix indicates an 8-bit (one byte) operation; a w (word) prefix indicates a 16-bit (two byte) operation; and an l (longword) prefix indicates a 32-bit (four byte) operation.


Note -

"l" is sometimes printed in uppercase to avoid confusion with 1 (the number one).


waddr, qaddr, and addr64 indicate addresses with alignment restrictions. For example, qaddr indicates 32-bit (4 byte) alignment; so this address must be evenly divisible by 4, as shown in the following example:


ok 4028 L@ 
ok 4029 L@ 
Memory address not aligned 
ok 

The Forth interpreter implemented in OpenBoot adheres closely to the ANS Forth Standard. If you explicitly want a 16-bit fetch or a 32-bit fetch, use w@ or L@ instead of @. Other commands also follow this convention.

Table 4-5 lists the commands used to access memory.

Table 4-5 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.

<w@

( waddr -- n ) 

Fetch doublet w from waddr, sign-extended.

@

( 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 space (decimal 32).

c!

(byte addr -- ) 

Store byte at addr.

c@

( addr -- byte ) 

Fetch a byte from addr.

cmove

( addr1 addr2 u -- ) 

Copy u bytes from addr1 to addr2, starting at low byte.

cmove>

( addr1 addr2 u -- ) 

Copy u bytes from addr1 to addr2, starting at high byte.

cpeek

( addr -- false | byte true ) 

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? ) 

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? = 0 if arrays are identical, diff? = -1 if first byte that is different is lesser in string at addr1,

diff? = 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!

( n 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 ) 

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? ) 

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.

wbflips

( waddr len -- ) 

Swap the bytes within each doublet in the specified region. 

wpeek

( waddr -- false | w true ) 

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? ) 

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

The dump command is particularly useful. It displays a region of memory as both bytes and ASCII values. The example below displays the contents of 20 bytes of memory starting at virtual address 10000. It also shows you how to read from and write to a memory location.


ok 10000 20 dump   
(Display 20 bytes of memory starting at virtual address
10000) 
      \/ 1  2  3  4  5  6  7   8  9  a  b  c  d  e  f  v123456789abcdef 
10000 05 75 6e 74 69 6c 00 40  4e d4 00 00 da 18 00 00 .until.@NT..Z...
10010 ce da 00 00 f4 f4 00 00  fe dc 00 00 d3 0c 00 00 NZ..tt..~\..S...
ok 22 10004 c!   (Change
8-bit byte at location 10004 to 22) 
ok

If you try (with @, for example) to access an invalid memory location, the operation immediately aborts and the PROM displays an error message, such as Data Access Exception or Bus Error.

Table 4-6 lists memory mapping commands.

Table 4-6 Memory Mapping Commands

Command 

Stack Diagram 

Description 

alloc-mem

( size -- virt ) 

Allocate and map size bytes of available memory; return the virtual address.

free-mem

( virt size -- ) 

Free memory allocated by alloc-mem.

free-virtual

( virt size -- ) 

Undo mappings created with memmap.

The following screen is an example of the use of alloc-mem and free-mem.

An example of using memmap is shown below.


ok 200.0000 sbus 1000 memmap ( virt ) 
ok