3 \ this
code implements
IEEE 1275-1994 ch
. 5.3.4
5 \
Copyright (C) 2003 Stefan Reinauer
7 \
See the file
"COPYING" for further information about
8 \
the copyright and warranty status
of this
work.
11 \ variable
last-package
0 last-package
!
12 \
0 value
active-package
13 : current
-device
active-package
;
16 \
5.3.4.1 Open/Close packages (part
1)
19 \
0 value
my-self
( -- ihandle
)
21 my-self dup
0= abort
" no current instance."
24 : my-parent
( -- ihandle
)
25 ?my-self
>in.my-parent
@
28 : ihandle
>non
-interposed
-phandle
( ihandle
-- phandle
)
29 begin dup
>in.interposed
@ while
35 : ihandle
>phandle
( ihandle
-- phandle
)
41 \ defined
in property
.c
43 : peer
( phandle
-- phandle
.sibling
)
51 : child
( phandle
.parent
-- phandle
.child
)
57 \
5.3.4.2 Call methods from other
packages
60 : find
-method
( method
-str method
-len phandle
-- false | xt true )
61 \ should we
search the private wordlist
too? I don
't think so...
62 >dn.methods @ find-wordlist if
69 : call-package ( ... xt ihandle -- ??? )
77 : $call-method ( ... method-str method-len ihandle -- ??? )
78 dup >r >in.device-node @ find-method if
85 : $call-parent ( ... method-str method-len -- ??? )
86 my-parent $call-method
91 \ 5.3.4.1 Open/Close packages (part 2)
94 \ find-dev ( dev-str dev-len -- false | phandle true )
95 \ find-rel-dev ( dev-str dev-len phandle -- false | phandle true )
97 \ These function works just like find-device but without
98 \ any side effects (or exceptions).
102 : find-rel-dev ( dev-str dev-len phandle -- false | phandle true )
103 active-package >r active-package!
108 : find-package ( name-str name-len -- false | phandle true )
109 \ Locate the support package named by name string.
110 \ If the package can be located, return its phandle and true; otherwise,
112 \ Interpret the name in name string relative to the "packages" device node.
113 \ If there are multiple packages with the same name (within the "packages"
114 \ node), return the phandle for the most recently created one.
116 \ This does the full path resolution stuff (including
117 \ alias expansion. If we don't
want that
, then we
should just
118 \ iterade
the children
of /packages.
119 " /packages" find-dev
0= if 2drop false exit then
120 find-rel
-dev
0= if false exit then
125 : open-package ( arg
-str arg
-len
phandle -- ihandle | 0 )
126 \
Open the package indicated by
phandle.
127 \
Create an instance of the package identified by
phandle, save
in that
128 \
instance the instance-argument
specified by arg
-string and invoke
the
129 \
package's open method.
130 \ Return the instance handle ihandle of the new instance, or 0 if the package
131 \ could not be opened. This could occur either because that package has no
132 \ open method, or because its open method returned false, indicating an error.
133 \ The parent instance of the new instance is the instance that invoked
134 \ open-package. The current instance is not changed.
136 create-instance dup 0= if
142 strdup r@ >in.arguments 2!
145 " open" r@ ['] $call
-method catch
if 3drop false then
149 r
> destroy
-instance false
154 : $
open-package ( arg-str
arg-len name
-str name
-len
-- ihandle | 0 )
155 \
Open the support package named by name
string.
164 : close
-package ( ihandle -- )
165 \
Close the instance identified by
ihandle by calling
the package's close
166 \ method and then destroying the instance.
167 dup " close" rot ['] $call
-method catch
if 3drop then
172 \
5.3.4.3 Get local arguments
175 : my-address
( -- phys
.lo
... )
176 ?my-self
>in.device
-node @
178 my-#acells tuck /l* + swap 1- 0
185 : my-space
( -- phys
.hi
)
186 ?my-self
>in.device
-node @
190 : my-unit ( -- phys
.lo
... phys
.hi
)
192 my-#acells tuck /l* + swap 0 ?do
198 : my-args
( -- arg-str
arg-len
)
199 ?my-self
>in.arguments
2@
202 \ char
is not included
. If char
is not found
, then R-len
is zero
203 : left
-parse
-string ( str len char
-- R-str
R-len
L-str
L-len
)
207 \ parse
ints "hi,...,lo" separated
by comma
208 : parse
-ints ( str len num
-- val.lo
.. val.hi
)
211 rot
1- -rot
2 pick
0>=
214 2dup ascii
, strchr
?dup if
217 2 pick
2 pick
- ( num n p str len len1
+1 )
218 dup -rot
- ( num n p str len1
+1 len2
)
219 -rot
1- ( num n p len2 str len1
)
228 begin 1- dup 0>= while r> swap repeat
232 : parse
-2int ( str len
-- val.lo
val.hi
)
238 \
5.3.4.4 Mapping tools
241 : map
-low
( phys
.lo
... size
-- virt
)
242 my-space
swap s
" map-in" $call
-parent
245 : free
-virtual
( virt
size -- )
246 over s
" address" get
-my-property
0= if
247 decode
-int -rot
2drop = if
248 s
" address" delete
-property
253 s
" map-out" $call
-parent
257 \
Deprecated functions
(required
for compatibility
with older loaders
)
259 variable
package-stack
-pos
0 package-stack
-pos
!
260 create
package-stack
8 cells
allot
262 : push
-package ( phandle -- )
263 \
Throw an error
if we
attempt to push a
full stack
264 package-stack-pos
@ 8 >= if
265 ." cannot push-package onto full stack" cr
269 package-stack-pos
@ /n
* package-stack + !
270 package-stack-pos
@ 1 + package-stack-pos
!
275 \
Throw an error
if we
attempt to pop
an empty
stack
276 package-stack-pos
@ 0 = if
277 ." cannot pop-package from empty stack" cr
280 package-stack-pos
@ 1 - package-stack-pos
!
281 package-stack-pos
@ /n
* package-stack + @