OFW FAQ

From OLPC
Revision as of 04:23, 30 October 2006 by Wmb@firmworks.com (talk | contribs) (Typo)
Jump to navigation Jump to search

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 from the stack (c from the top of stack), and pushes two values back (e on the top).

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

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 MSR, and "." printed tham 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.