6 " client-services" device
-name
8 active
-package
to ciface-ph
10 \
-------------------------------------------------------------
12 \
-------------------------------------------------------------
16 variable
callback-function
18 : ?phandle
( phandle
-- phandle
)
19 dup
0= if ." NULL phandle" -1 throw
then
21 : ?ihandle
( ihandle
-- ihandle
)
22 dup
0= if ." NULL ihandle" -2 throw
then
25 \ copy
and null terminate return
string
26 : ci
-strcpy
( buf buflen str len
-- len
)
28 ( str buf buflen buflen
R: len
)
30 ( str buf n buflen
R: len
)
42 " /chosen" find
-device
44 " mmu" active
-package
get-package
-property
0= if
45 decode
-int nip nip to mmu-ih
48 " memory" active
-package
get-package
-property
0= if
49 decode
-int nip nip to memory-ih
55 ." <" dup cstrlen
dup 20 < if type else 2drop ." BAD" then ." >"
58 \
-------------------------------------------------------------
60 \
-------------------------------------------------------------
64 \
-------------------------------------------------------------
65 \
6.3.2.1 Client interface
66 \
-------------------------------------------------------------
68 \ returns
-1 if missing
69 : test
( name
-- 0|-1 )
70 dup cstrlen
ciface-ph find
-method
71 if drop
0 else -1 then
74 \
-------------------------------------------------------------
76 \
-------------------------------------------------------------
82 : getproplen
( name
phandle -- len
|-1 )
84 ?phandle get-package
-property
88 : getprop
( buflen buf name
phandle -- size
|-1 )
89 \ detect
phandle == -1
94 \ return
-1 if phandle is 0 (MacOS actually does
this)
95 ?dup 0= if drop
2drop -1 exit
then
98 ?phandle get-package
-property
if 2drop -1 exit
then
99 ( buflen buf prop proplen
)
101 ( prop buf buflen proplen
)
105 \
1 OK, 0 no more
prop, -1 prev invalid
106 : nextprop
( buf prev
phandle -- 1|0|-1 )
108 dup 0= if 0 else dup cstrlen
then
110 ( buf prev prev_len
)
113 \ verify that
prev exists
(overkill
...)
115 2dup r@ get-package
-property
if
116 r> 2drop 2drop -1 exit
122 ( buf
prev prev_len
)
125 ( buf name
name_len )
126 dup 1+ -rot
ci-strcpy drop
1
133 : setprop
( len buf name
phandle -- size
)
135 >r >r swap encode
-bytes \
( prop-addr
prop-len
R: phandle name )
141 : finddevice
( dev_spec
-- phandle|-1 )
143 \
." FIND-DEVICE " 2dup type
144 find
-dev
0= if -1 then
148 : instance
-to-package
( ihandle
-- phandle )
149 ?ihandle
ihandle>phandle
152 : package
-to-path
( buflen buf
phandle -- length
)
153 \
XXX improve
error checking
154 dup 0= if 3drop -1 exit
then
157 ( buf buflen str len
)
161 : canon
( buflen buf dev_specifier
-- len
)
162 dup cstrlen find
-dev
if
163 ( buflen buf
phandle )
170 : instance
-to-path
( buflen buf
ihandle -- length
)
171 \
XXX improve
error checking
172 dup 0= if 3drop -1 exit
then
175 \
." INSTANCE: " 2dup type cr dup .
176 ( buf buflen str len
)
180 : instance
-to-interposed
-path
( buflen buf
ihandle -- length
)
181 \
XXX improve
error checking
182 dup 0= if 3drop -1 exit
then
184 get-instance
-interposed
-path
185 ( buf buflen str len
)
189 : call
-method
( ihandle method -- xxxx catch
-result
)
190 dup 0= if ." call of null method" -1 exit
then
193 \
." call-method " 2dup type cr
194 rot
?ihandle ['] $call-method catch dup if
195 \ not necessary an error but very useful for debugging...
196 ." call-method " r@ dup cstrlen type ." : exception " dup . cr
202 \ -------------------------------------------------------------
204 \ -------------------------------------------------------------
206 : open ( dev_spec -- ihandle|0 )
210 : close ( ihandle -- )
214 : read ( len addr ihandle -- actual )
216 dup ihandle>phandle " read" rot find-method
217 if swap call-package else 3drop -1 then
220 : write ( len addr ihandle -- actual )
222 dup ihandle>phandle " write" rot find-method
223 if swap call-package else 3drop -1 then
226 : seek ( pos_lo pos_hi ihandle -- status )
227 dup ihandle>phandle " seek" rot find-method
228 if swap call-package else 3drop -1 then
232 \ -------------------------------------------------------------
234 \ -------------------------------------------------------------
236 : claim ( align size virt -- baseaddr|-1 )
238 ciface-ph " cif-claim" rot find-method
239 if execute else 3drop -1 then
242 : release ( size virt -- )
244 ciface-ph " cif-release" rot find-method
245 if execute else 2drop -1 then
248 \ -------------------------------------------------------------
249 \ 6.3.2.5 Control transfer
250 \ -------------------------------------------------------------
252 : boot ( bootspec -- )
260 \ exit ( -- ) is defined later (clashes with builtin exit)
262 : chain ( virt size entry args len -- )
266 \ -------------------------------------------------------------
267 \ 6.3.2.6 User interface
268 \ -------------------------------------------------------------
270 : interpret ( xxx cmdstring -- ??? catch-reult )
272 \ ." INTERPRETE: --- " 2dup type
273 ['] evaluate
catch dup if
274 \
this is not
necessary an
error...
275 ." interpret: exception " dup . ." caught" cr
277 \
Force back to interpret
state on
error, otherwise
the next
call to
278 \ interpret
gets confused
if the error occurred
in compile
mode
284 : set
-callback ( newfunc
-- oldfunc
)
290 \
: set
-symbol
-lookup
( sym
-to-value
-- value
-to-sym
) ;
293 \
-------------------------------------------------------------
295 \
-------------------------------------------------------------
297 \
: milliseconds
( -- ms
) ;
300 \
-------------------------------------------------------------
302 \
-------------------------------------------------------------
304 : start
-cpu
( xxx xxx xxx
--- )
305 ." Start CPU unimplemented" cr
309 \
-------------------------------------------------------------
311 \
-------------------------------------------------------------
319 \
PowerPC Microprocessor CHRP binding
320 \
10.5.2. Client Interface
322 ( cstring
-method phandle -- missing
)
326 find-method 0= if -1 else drop 0 then
334 \
-------------------------------------------------------------
336 \
-------------------------------------------------------------
338 : client
-iface
( [args
] name len -- [args
] -1 | [rets
] 0 )
339 ciface-ph
find-method 0= if -1 exit
then
341 cr ." Unexpected client interface exception: " . -2 cr exit
346 : client
-call-iface
( [args
] name len -- [args
] -1 | [rets
] 0 )
347 ciface-ph
find-method 0= if -1 exit
then