[OpenBIOS] [RFC v2] WIP fix for /memory reg property
Andreas Färber
andreas.faerber at web.de
Thu Nov 4 01:25:06 CET 2010
v2:
* Use my-#acells for address size.
* Introduce my-#scells for size size.
* Confine special-handling of "available" to /memory and MMU.
---
Hi,
How can we determine the cell size within Forth?
64bit? wouldn't work as criteria for ppc64.
Is an explicit [IFDEF] CONFIG_{SPARC64,PPC64} the only way here?
Thanks,
Andreas
arch/ppc/qemu/init.c | 14 +++++++++-----
forth/admin/devices.fs | 40 +++++++++++++++++++++++++++++++++-------
forth/device/property.fs | 16 +++++++++++++++-
3 files changed, 57 insertions(+), 13 deletions(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
index 08eb59c..d7ebc15 100644
--- a/arch/ppc/qemu/init.c
+++ b/arch/ppc/qemu/init.c
@@ -774,15 +774,19 @@ arch_of_init( void )
/* all memory */
- PUSH(ram_size >> 32);
- fword("encode-int");
- PUSH(ram_size & 0xffffffff);
- fword("encode-int");
+ PUSH(0);
+ fword("encode-phys");
+#if 0
fword("encode+");
PUSH(0);
fword("encode-int");
fword("encode+");
- PUSH(0);
+#endif
+#if 0
+ PUSH(ram_size >> 32);
+ fword("encode-int");
+#endif
+ PUSH(ram_size & 0xffffffff);
fword("encode-int");
fword("encode+");
push_str("reg");
diff --git a/forth/admin/devices.fs b/forth/admin/devices.fs
index 4c72cbb..6662a7e 100644
--- a/forth/admin/devices.fs
+++ b/forth/admin/devices.fs
@@ -289,18 +289,27 @@
2drop r> drop 1
;
-\ TODO honor #address-cells and #size-cells
-: (.p-reg) ( data len -- )
+\ 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 8 mod 4 = if
+ dup my-#acellbytes my-#scellbytes + mod my-#acellbytes = if
." "
then
- dup 8 mod 0 = if
+ dup my-#acellbytes my-#scellbytes + mod 0= if
2dup <> if
cr 0 begin ." " 1+ dup d# 26 >= until drop
then
@@ -315,10 +324,27 @@
2over
( name-str name-len data len name-str name-len )
- s" reg" strcmp 0= if (.p-reg) 2drop exit then
+ " 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 )
- \ TODO this should be limited to /memory device
- 2swap s" available" strcmp 0= if (.p-reg) exit then
+ 2swap 2drop
( data len )
.p-string? if exit then
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
--
1.7.3
More information about the OpenBIOS
mailing list