1986fd29aSsetje\
2986fd29aSsetje\ CDDL HEADER START
3986fd29aSsetje\
4986fd29aSsetje\ The contents of this file are subject to the terms of the
5986fd29aSsetje\ Common Development and Distribution License (the "License").
6986fd29aSsetje\ You may not use this file except in compliance with the License.
7986fd29aSsetje\
8986fd29aSsetje\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9986fd29aSsetje\ or http://www.opensolaris.org/os/licensing.
10986fd29aSsetje\ See the License for the specific language governing permissions
11986fd29aSsetje\ and limitations under the License.
12986fd29aSsetje\
13986fd29aSsetje\ When distributing Covered Code, include this CDDL HEADER in each
14986fd29aSsetje\ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15986fd29aSsetje\ If applicable, add the following below this CDDL HEADER, with the
16986fd29aSsetje\ fields enclosed by brackets "[]" replaced with your own identifying
17986fd29aSsetje\ information: Portions Copyright [yyyy] [name of copyright owner]
18986fd29aSsetje\
19986fd29aSsetje\ CDDL HEADER END
20986fd29aSsetje\
21986fd29aSsetje\
22*c713350eSJohn Johnson\ Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23986fd29aSsetje\ Use is subject to license terms.
24986fd29aSsetje\
25986fd29aSsetje
26986fd29aSsetjepurpose: utility words
27*c713350eSJohn Johnsoncopyright: Copyright 2009 Sun Microsystems, Inc. All Rights Reserved
28986fd29aSsetje
29986fd29aSsetje
30986fd29aSsetjed# 256  constant  /buf-len
31986fd29aSsetje
32986fd29aSsetje\
33986fd29aSsetje\	useful counting words
34986fd29aSsetje\
35986fd29aSsetje: roundup ( x y -- x' )  1- tuck +  swap invert and  ;
36986fd29aSsetje
37986fd29aSsetje
38986fd29aSsetje\
39986fd29aSsetje\	various useful string manipulation words
40986fd29aSsetje\
41986fd29aSsetje
42986fd29aSsetje: cstrlen ( cstr -- len )
43986fd29aSsetje   dup begin
44986fd29aSsetje      dup c@
45986fd29aSsetje   while
46986fd29aSsetje      char+
47986fd29aSsetje   repeat swap -
48986fd29aSsetje;
49986fd29aSsetje
50986fd29aSsetje: cscount ( cstr -- adr,len )  dup cstrlen  ;
51986fd29aSsetje
52986fd29aSsetje\ Append str1 to the end of str2
53986fd29aSsetje: $append ( adr,len1 adr,len2 -- )
54986fd29aSsetje   2over 2over  ca+ swap move   ( adr,len1 adr,len2 )
55986fd29aSsetje   rot + ca+ 0 swap c!  drop    (  )
56986fd29aSsetje;
57986fd29aSsetje
58986fd29aSsetje: $=  ( str1$ str2$ -- same? )
59986fd29aSsetje   rot tuck <>  if
60986fd29aSsetje      3drop false exit
61986fd29aSsetje   then  comp 0=
62986fd29aSsetje;
63986fd29aSsetje
64986fd29aSsetje\ advance str by 1
65986fd29aSsetje: str++  ( adr len --  adr' len' )
66986fd29aSsetje   swap 1+  swap 1-
67986fd29aSsetje;
68986fd29aSsetje
69e7cbe64fSgw: die  ( str -- )
70e7cbe64fSgw   cr  type  cr abort
71e7cbe64fSgw;
72e7cbe64fSgw
73986fd29aSsetje: diag-cr?  ( -- )  diagnostic-mode?  if  cr  then  ;
74986fd29aSsetje
75986fd29aSsetje
76986fd29aSsetje: find-abort ( name$ -- )
77e7cbe64fSgw   cr  ." Can't find " type  cr abort
78986fd29aSsetje;
79986fd29aSsetje
80986fd29aSsetje: get-package ( pkg$ -- ph )
81986fd29aSsetje   2dup  find-package 0=  if
82986fd29aSsetje      find-abort
83986fd29aSsetje   then                       ( pkg$ ph )
84986fd29aSsetje   nip nip                    ( ph )
85986fd29aSsetje;
86986fd29aSsetje
87986fd29aSsetje
88986fd29aSsetje\
89986fd29aSsetje\	CIF words for I/O and memory
90986fd29aSsetje\
91986fd29aSsetje" /openprom/client-services" get-package  constant cif-ph
92986fd29aSsetje
93986fd29aSsetjeinstance defer cif-open     ( dev$ -- ihandle|0 )
94986fd29aSsetjeinstance defer cif-close    ( ihandle -- )
95986fd29aSsetjeinstance defer cif-read     ( len adr ihandle -- #read )
96986fd29aSsetjeinstance defer cif-seek     ( low high ihandle -- -1|0|1 )
97986fd29aSsetjeinstance defer cif-release  ( size virt -- )
98986fd29aSsetje
99986fd29aSsetje: find-cif-method ( adr,len -- acf )
100986fd29aSsetje   2dup  cif-ph find-method 0=  if    ( adr,len )
101986fd29aSsetje      find-abort
102986fd29aSsetje   then                               ( adr,len acf )
103986fd29aSsetje   nip nip                            ( acf )
104986fd29aSsetje;
105986fd29aSsetje
106986fd29aSsetje" open"     find-cif-method to cif-open
107986fd29aSsetje" close"    find-cif-method to cif-close
108986fd29aSsetje" read"     find-cif-method to cif-read
109986fd29aSsetje" seek"     find-cif-method to cif-seek
110986fd29aSsetje" release"  find-cif-method to cif-release
111986fd29aSsetje
112986fd29aSsetje
113986fd29aSsetje" /chosen" get-package  constant chosen-ph
114986fd29aSsetje
115986fd29aSsetje: get-property  ( name$ ph -- prop$ )
116986fd29aSsetje   >r 2dup  r>  get-package-property  if   ( name$ )
117986fd29aSsetje      find-abort
118986fd29aSsetje   then                                    ( name$ prop$ )
119986fd29aSsetje   2swap  2drop                            ( prop$ )
120986fd29aSsetje;
121986fd29aSsetje
122986fd29aSsetje: get-string-prop  ( name$ ph -- val$ )
123986fd29aSsetje   get-property decode-string            ( prop$' val$ )
124986fd29aSsetje   2swap 2drop                           ( val$ )
125986fd29aSsetje;
126986fd29aSsetje
127986fd29aSsetje: get-int-prop  ( name$ ph -- n )
128986fd29aSsetje   get-property decode-int               ( prop$' n )
129986fd29aSsetje   nip nip                               ( n )
130986fd29aSsetje;
131986fd29aSsetje
132986fd29aSsetje\
133986fd29aSsetje\	memory allocation
134986fd29aSsetje\	we bypass cif claim so we can do large page
135986fd29aSsetje\	allocations like promif can
136986fd29aSsetje\
137986fd29aSsetje
138986fd29aSsetje" mmu"    chosen-ph  get-int-prop  constant mmu-ih
139986fd29aSsetje
140986fd29aSsetje" memory" chosen-ph  get-int-prop  constant mem-ih
141