[OpenBIOS] [RFC v2] Pretty-print reg property
Andreas Färber
andreas.faerber at web.de
Thu Nov 4 21:05:52 CET 2010
Am 04.11.2010 um 05:05 schrieb Segher Boessenkool:
>> +\ 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.
Thanks for clarifying.
>> +: .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?
Indentation of non-first line, adapted from .properties.
>> + 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).
Leads to:
0 > dev /memory ok
0 > .properties
name "memory"
device_type "memory"
reg
00 00
00 00
40 00
00 00
N?!H -- 5 : 4e 80 04 21 48
available
00 00
40 00
3f bd
40 00
<empty>
ok
My patch did:
0 > dev /memory ok
0 > .properties
name "memory"
device_type "memory"
reg 00000000 40000000
available 00004000 3fbd4000
ok
Any hint? My code may have been inefficient but better unstandable for
a Forth newbie...
>> +\ 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.
Copied from my-#acells. Is it wrong for #address-cells, too?
Andreas
More information about the OpenBIOS
mailing list