Executing .properties for, e.g., the /memory node would print the "reg" property as a series of bytes. Modify the .properties and (.property) words to special-case property display based on property name.
Visualize the "reg" format as a table.
v2: * Use my-#acells for address size. * Introduce my-#scells for size size. * Confine special-handling of "available" to /memory and MMU.
Signed-off-by: Andreas Färber andreas.faerber@web.de --- forth/admin/devices.fs | 60 +++++++++++++++++++++++++++++++++++++++++++-- forth/device/property.fs | 16 +++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/forth/admin/devices.fs b/forth/admin/devices.fs index dbb4646..6662a7e 100644 --- a/forth/admin/devices.fs +++ b/forth/admin/devices.fs @@ -289,9 +289,63 @@ 2drop r> drop 1 ;
+\ 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 * +; + +: my-#scellbytes ( -- #bytes) + my-#scells 4 * +; + +: .p-reg ( data len -- ) + swap >r 0 + begin 2dup > while + dup r@ + c@ + ( len n ch ) + pocket tohexstr dup 2 <> if ." 0" then type + 1+ + dup my-#acellbytes my-#scellbytes + mod my-#acellbytes = if + ." " + then + dup my-#acellbytes my-#scellbytes + mod 0= if + 2dup <> if + cr 0 begin ." " 1+ dup d# 26 >= until drop + then + then + repeat + 2drop r> drop +; + \ this function tries to heuristically determine the data format -: (.property) ( data len -- ) - dup 0= if 2drop ." <empty>" exit then +: (.property) ( name-str name-len data len -- ) + dup 0= if 2drop 2drop ." <empty>" exit then + + 2over + ( name-str name-len data len name-str name-len ) + " reg" strcmp 0= if .p-reg 2drop exit then + ( name-str name-len data len ) + " name" active-package get-package-property 0= if + drop + ( name-str name-len data len prop-name ) + " memory" comp0 0= if + 2over + " available" strcmp 0= if .p-reg 2drop exit then + then + then + ( name-str name-len data len ) + " device_type" active-package get-package-property 0= if + drop + ( name-str name-len data len prop-name ) + " cpu" comp0 0= if + 2over + " available" strcmp 0= if .p-reg 2drop exit then + then + then + ( name-str name-len data len ) + 2swap 2drop + ( data len )
.p-string? if exit then .p-int? if exit then @@ -307,7 +361,7 @@ while cr 2dup dup -rot type begin ." " 1+ dup d# 26 >= until drop - 2dup active-package get-package-property drop (.property) + 2dup 2dup active-package get-package-property drop (.property) repeat then r> drop diff --git a/forth/device/property.fs b/forth/device/property.fs index 285113b..d0a46a0 100644 --- a/forth/device/property.fs +++ b/forth/device/property.fs @@ -143,7 +143,7 @@ then ;
-\ HELPER: get #address-cell value (from parent) +\ HELPER: get #address-cells value (from parent) \ Legal values are 1..4 (we may optionally support longer addresses) : my-#acells ( -- #address-cells ) my-self ?dup if >in.device-node @ else active-package then @@ -157,6 +157,20 @@ then ;
+\ 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 +; + : decode-string ( prop-addr1 prop-len1 -- prop-addr2 prop-len2 str len ) dup 0> if 2dup bounds \ check property for 0 bytes