1 \ -------------------------------------------------------------------------
2 \ SBus encode/decode unit
3 \ -------------------------------------------------------------------------
5 : decode-unit-sbus ( str len -- id lun )
7 ( addr-R len-R addr-L len-L )
13 : encode-unit-sbus ( id lun -- str len)
16 " ," pocket tmpstrcat >r
17 rot pocket tohexstr r> tmpstrcat drop
20 \ Convert sbus unit (from decode-unit) to physical address using
21 \ sbus node ranges property
23 : sbus-unit>addr ( phys.lo phys.hi -- phys.lo phys.hi -1 | 0 )
24 " ranges" my-self ihandle>phandle
25 get-package-property 0= if ( phys.lo phys.hi prop prop-len )
27 2over swap drop 0 swap \ force phys.lo to zero for matching
28 2swap ( unit.phys.lo unit.phys.hi 0 phys.hi res prop prop-len )
29 0 -rot ( unit.phys.lo unit.phys.hi res prop prop-len )
31 decode-int -rot >r >r ( unit.phys.lo unit.phys.hi res phys.x -- R: prop-len prop )
32 rot ( unit.phys.lo res phys.x phys.hi )
35 then ( unit.phys.lo res )
36 r> r> ( unit.phys.lo res prop prop-len )
38 rot ( prop prop-len res )
39 2 = if \ did we match the unit address? if so, return the physical address
40 decode-phys 2swap 2drop 2swap ( unit.phys.lo unit.phys.hi phys.lo phys.hi )
41 drop 0 d+ \ force unit.phys.hi to zero and add address for final offset
44 decode-phys 2drop decode-int drop \ drop the size and carry on
51 : map-in-sbus ( phys.lo phys.hi size )
53 r@ " map-in" $call-parent
58 : map-out-sbus ( virt size )
59 " map-out" $call-parent
62 \ -------------------------------------------------------------------------
64 \ -------------------------------------------------------------------------
66 : probe-self-sbus ( arg-adr arg-len reg-adr reg-len fcode-adr fcode-len -- )
70 ['] decode-unit-sbus catch if
71 2drop 2drop 2drop 2drop
78 dup h# f1 = swap h# fd = or if
87 ." Invalid FCode start byte" cr