Executing .properties for, e.g., the /memory node would print the "reg" property as a series of bytes.
Visualize the "reg" format as a table, with address and size columns.
v5: * Drop the upper limit for my-#scells, suggested by Segher. * Fix indentation.
v4: * Fix my-#scells to allow 0 return value. * Pass #address-cells and #size-cells as arguments. * Add some more comments.
v3: * Optimization, based on code suggested by Segher.
v2: * Use my-#acells for address size. * Introduce my-#scells for size size.
Cc: Segher Boessenkool segher@kernel.crashing.org Signed-off-by: Andreas Färber andreas.faerber@web.de --- forth/admin/devices.fs | 27 +++++++++++++++++++++++++++ forth/device/property.fs | 14 ++++++++++++++ 2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/forth/admin/devices.fs b/forth/admin/devices.fs index 91fbde5..7313a35 100644 --- a/forth/admin/devices.fs +++ b/forth/admin/devices.fs @@ -304,8 +304,35 @@ 2drop ." <unimplemented type>" ;
+\ Print the value of a property in "reg" format +: .p-reg ( #acells #scells data len -- ) + 2dup + -rot ( #acells #scells data+len data len ) + >r >r -rot ( data+len #acells #scells R: len data ) + 4 * swap 4 * dup r> r> ( data+len #sbytes #abytes #abytes data len ) + bounds ( data+len #sbytes #abytes #abytes data+len data ) ?do + dup 0= if 2 spaces then \ start of "size" part + 2dup <> if \ non-first byte in row + dup 3 and 0= if space then \ make numbers more readable + then + i c@ 2 0.r \ print byte + 1- 3dup nip + 0= if \ end of row + 3 pick i 1+ > if \ non-last byte + cr \ start new line + d# 26 spaces \ indentation + then + drop dup \ update counter + then + loop + 3drop drop +; + \ This function hardwires data formats to particular node properties : (.property-by-name) ( name-str name-len data len -- ) + 2over " reg" strcmp 0= if + my-#acells my-#scells 2swap .p-reg + 2drop exit + then + 2swap 2drop ( data len ) (.property) ; diff --git a/forth/device/property.fs b/forth/device/property.fs index 285113b..4479e6e 100644 --- a/forth/device/property.fs +++ b/forth/device/property.fs @@ -157,6 +157,20 @@ then ;
+\ HELPER: get #size-cells value (from parent) +\ Legal values are >= 0 +: 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 1 exit then + \ we don't have to support more than 4 + decode-int nip nip 0 max + else + 1 + then +; + : decode-string ( prop-addr1 prop-len1 -- prop-addr2 prop-len2 str len ) dup 0> if 2dup bounds \ check property for 0 bytes