OFW FAQ: Difference between revisions

From OLPC
Jump to navigation Jump to search
m (Added showstack)
No edit summary
Line 30: Line 30:
rdmsr ( addr -- value.low value.high )
rdmsr ( addr -- value.low value.high )
wrmsr ( value.low value.high addr -- )
wrmsr ( value.low value.high addr -- )

for example: 10 rdmsr .u .u reads and prints the x86 time stamp counter (MSR 0x10)


=== How do I enter numbers? ===
=== How do I enter numbers? ===
Line 44: Line 46:
port
port


=== I read some MSRs and "." printed tham as signed. Is there a better way to print? ===
=== I read some MSRs and "." printed them as signed. Is there a better way to print? ===


'''.''' pops stack and displays signed number in default radix.
'''.''' pops stack and displays signed number in default radix.

Revision as of 04:46, 30 October 2006

What is Forth stack notation?

The stack effect of a Forth word - i.e. the arguments it pops from the stack and the results is pushes back - is conventionally described as follows:

foo ( a b c -- d e )

means that the word "foo" pops three arguments (numbers) from the stack (c from the top of stack), and pushes two results back (e on the top).

The item names (a, b, etc) are clues about what kind of number it is, e.g. 'adr' for address, 'n' for number, 'b' for 8-bit number, 'w' for 16-bit number, 'l' for 32-bit number, 'flag' for boolean result. For multiple items of the same type the convention is "( n1 n2 -- n3 )".

How do I do x86 I/O port accesses in the OFW interpreter?

pc@ ( port# -- byte )  \ Read from an 8-bit I/O port
pw@ ( port# -- word )  \ Read from a 16-bit I/O port
pl@ ( port# -- long )  \ Read from a 32-bit I/O port
pc! ( byte port# -- )  \ Write to an 8-bit I/O port
pw! ( word port# -- )  \ Write to a 16-bit I/O port
pl! ( long port# -- )  \ Write to a 32-bit I/O port

c is byte, w is short, l is long.

@ is conventional notation for read, takes port# from stack and leaves value on stack

! is convetnional notation for write, takes port# from top of stack and value from underneath that.

for example: 45 66 pc! writes 0x45 to port 0x66 as a byte

How do I do Geode MSR accesses in the ofw interpreter?

 rdmsr ( addr -- value.low value.high )
 wrmsr ( value.low value.high addr -- )

for example: 10 rdmsr .u .u reads and prints the x86 time stamp counter (MSR 0x10)

How do I enter numbers?

Typing a number pushes it on the stack.

OFW defaults to hex radix. If you want a decimal number, precede it with "d# ", as in "d# 99". You can also say "h# 12ab" if you want to be explicit about the hex radix.

For clarity, you can embed punctuation in numbers. I usually write long hex numbers with a period at position 4, e.g. "c000.2001" so I don't have to count 0's when looking at the number. You can also embed ',' e.g "d# 1,000,000". I usually use comma every third position for decimal numbers.

What does the "p" stand for in I/O access words (e.g. pc@ )?

port

I read some MSRs and "." printed them as signed. Is there a better way to print?

. pops stack and displays signed number in default radix.

u. displays unsigned.

.x or .h displays in hex.

.d displays in decimal.

How can I watch what's on the stack?

 showstack   \ Turns on show stack mode
 noshowstack \ Turns off show stack mode

In show stack mode, the Forth interpreter shows you what's on the stack before every prompt. For example:

 123 ffab0012 34 ok

That means that there are currently 3 numbers on the stack. The 34 is on top.