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.
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
Acked-by: Segher Boessenkool segher@kernel.crashing.org
(assuming you tested it :-) )
forth/admin/devices.fs | 24 ++++++++++++++++++++++++ forth/device/property.fs | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/forth/admin/devices.fs b/forth/admin/devices.fs index 33ad0de..93f306c 100644 --- a/forth/admin/devices.fs +++ b/forth/admin/devices.fs @@ -304,8 +304,32 @@ 2drop ." <unimplemented type>" ;
+\ Print the value of a property in "reg" format +: .p-reg ( data len -- )
- 2dup + -rot ( data+len data len )
r >r my-#scells 4 * my-#acells 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
dup 3 and 0= if space then \ make numbers more readable
- then
- i c@ 2 0.r \ print byte
- 1- 3dup nip ( data+len #sbytes #abytes n #sbytes n ) + 0= if
3 pick i 1+ > if
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 .p-reg 2drop exit then
- 2swap 2drop ( data len ) (.property)
; diff --git a/forth/device/property.fs b/forth/device/property.fs index 285113b..fb529a5 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 1..4 (we may optionally support larger sizes) +: 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 (and 0 is illegal)
- decode-int nip nip 4 min 1 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 -- 1.7.3