4 \ The contents of this file are subject to the terms of the
5 \ Common Development and Distribution License (the "License").
6 \ You may not use this file except in compliance with the License.
8 \ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 \ or http://www.opensolaris.org/os/licensing.
10 \ See the License for the specific language governing permissions
11 \ and limitations under the License.
13 \ When distributing Covered Code, include this CDDL HEADER in each
14 \ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 \ If applicable, add the following below this CDDL HEADER, with the
16 \ fields enclosed by brackets "[]" replaced with your own identifying
17 \ information: Portions Copyright [yyyy] [name of copyright owner]
22 \ Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 \ Use is subject to license terms.
26 purpose: utility words
27 copyright: Copyright 2009 Sun Microsystems, Inc. All Rights Reserved
30 d# 256 constant /buf-len
33 \ useful counting words
35 : roundup ( x y -- x' ) 1- tuck + swap invert and ;
39 \ various useful string manipulation words
42 : cstrlen ( cstr -- len )
50 : cscount ( cstr -- adr,len ) dup cstrlen ;
52 \ Append str1 to the end of str2
53 : $append ( adr,len1 adr,len2 -- )
54 2over 2over ca+ swap move ( adr,len1 adr,len2 )
55 rot + ca+ 0 swap c! drop ( )
58 : $= ( str1$ str2$ -- same? )
65 : str++ ( adr len -- adr' len' )
73 : diag-cr? ( -- ) diagnostic-mode? if cr then ;
76 : find-abort ( name$ -- )
77 cr ." Can't find " type cr abort
80 : get-package ( pkg$ -- ph )
81 2dup find-package 0= if
89 \ CIF words for I/O and memory
91 " /openprom/client-services" get-package constant cif-ph
93 instance defer cif-open ( dev$ -- ihandle|0 )
94 instance defer cif-close ( ihandle -- )
95 instance defer cif-read ( len adr ihandle -- #read )
96 instance defer cif-seek ( low high ihandle -- -1|0|1 )
97 instance defer cif-release ( size virt -- )
99 : find-cif-method ( adr,len -- acf )
100 2dup cif-ph find-method 0= if ( adr,len )
106 " open" find-cif-method to cif-open
107 " close" find-cif-method to cif-close
108 " read" find-cif-method to cif-read
109 " seek" find-cif-method to cif-seek
110 " release" find-cif-method to cif-release
113 " /chosen" get-package constant chosen-ph
115 : get-property ( name$ ph -- prop$ )
116 >r 2dup r> get-package-property if ( name$ )
119 2swap 2drop ( prop$ )
122 : get-string-prop ( name$ ph -- val$ )
123 get-property decode-string ( prop$' val$ )
127 : get-int-prop ( name$ ph -- n )
128 get-property decode-int ( prop$' n )
134 \ we bypass cif claim so we can do large page
135 \ allocations like promif can
138 " mmu" chosen-ph get-int-prop constant mmu-ih
140 " memory" chosen-ph get-int-prop constant mem-ih
142 : mmu-claim ( [ virt ] size align -- base )
143 " claim" mmu-ih $call-method
146 : mmu-map ( phys.lo phys.hi virt size -- )
147 -1 " map" mmu-ih $call-method
150 : mem-claim ( size align -- phys.lo phys.hi )
151 " claim" mem-ih $call-method
154 : (mem-alloc) ( size virt align -- virt )
155 \ claim memory first since it may throw if fragmented
156 rot 2dup swap mem-claim ( virt align size phys.lo phys.hi )
157 >r >r rot ?dup if ( align size virt r: phys.lo phys.hi )
158 \ we picked virt - zero alignment
159 over 0 mmu-claim ( align size virt r: phys.lo phys.hi )
160 else ( align size r: phys.lo phys.hi )
161 \ OBP picks virt - pass alignment
162 2dup swap mmu-claim ( align size virt r: phys.lo phys.hi )
163 then ( align size virt r: phys.lo phys.hi )
164 r> r> 2over swap mmu-map ( align size virt )
168 : vmem-alloc ( size virt -- virt )
169 swap h# 2000 roundup swap
173 : mem-alloc ( size -- virt )
178 : mem-free ( virt size -- )
185 \ put ramdisk fcode 256 bytes from end of bootblk
186 \ (currently 244 bytes in size)
187 d# 256 constant /rd-fcode
188 d# 8192 /rd-fcode - constant rd-offset
190 : open-abort ( file$ -- )
191 cr ." Can't open " type cr abort
194 /buf-len buffer: open-cstr
196 : dev-open ( dev$ -- ih | 0 )
197 \ copy to C string for open
198 0 over open-cstr + c!
203 : dev-close ( ih -- )
207 : read-disk ( adr len off ih -- )
208 dup >r 0 swap cif-seek if ( adr len r: ih )
212 tuck swap r> cif-read <> if ( )