[OpenBIOS] [RFC v2] Pretty-print reg property
Segher Boessenkool
segher at kernel.crashing.org
Thu Nov 4 05:05:58 CET 2010
> +\ Helpers: Convert number of cells into number of bytes
> +\ TODO honor cell size, currently assumes 4 (wrong for sparc64)
> +: my-#acellbytes ( -- #bytes)
> + my-#acells 4 *
> +;
Device tree property "cells" aren't Forth cells; that's why the
documentation always talks about "integer as encoded with encode-int",
i.e., four bytes big-endian twos' complement.
> +: .p-reg ( data len -- )
> + swap >r 0
> + begin 2dup > while
> + dup r@ + c@
> + ( len n ch )
> + pocket tohexstr dup 2 <> if ." 0" then type
: 0.r ( u minlen -- ) 0 swap <# 1 ?DO # LOOP #s #> type ;
and then you can use here:
2 0.r
> + 1+
> + dup my-#acellbytes my-#scellbytes + mod my-#acellbytes = if
It is very expensive to use the tree queries in the loop.
> + ." "
> + then
> + dup my-#acellbytes my-#scellbytes + mod 0= if
> + 2dup <> if
> + cr 0 begin ." " 1+ dup d# 26 >= until drop
26? Why that?
> + then
> + then
> + repeat
> + 2drop r> drop
> +;
Maybe something like this:
: .p-reg ( prop len -- )
>r >r my-#scells my-#acells dup r> r> bounds ?DO
2dup = IF cr THEN \ start of line
dup 0= IF 2 spaces THEN \ start of "size" part
dup 3 and 0= IF space THEN \ make numbers more readable
i c@ 2 0.r \ print byte
1- 3dup nip + 0= IF drop dup THEN \ update counter
LOOP ;
(untested, mind the bogons).
> +\ HELPER: get #size-cells value (from parent)
> +\ Legal values are 1..4 (we may optionally support longer addresses)
> +: my-#scells ( -- #size-cells )
> + my-self ?dup if >in.device-node @ else active-package then
> + ?dup if >dn.parent @ then
> + ?dup if
> + " #size-cells" rot get-package-property if 2 exit then
> + \ we don't have to support more than 4 (and 0 is illegal)
> + decode-int nip nip 4 min 1 max
> + else
> + 2
> + then
> +;
Default for #size-cells is 1, not 2.
Segher
More information about the OpenBIOS
mailing list