Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: methods.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)methods.fth 1.1 06/02/16 | |
43 | purpose: | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headers | |
48 | " block" device-type | |
49 | ||
50 | headerless | |
51 | 0 instance value offset-low \ Offset to start of partition | |
52 | 0 instance value offset-high | |
53 | ||
54 | 0 instance value label-package | |
55 | 0 instance value deblocker | |
56 | ||
57 | : init-deblocker ( -- okay? ) | |
58 | " " " deblocker" $open-package to deblocker | |
59 | deblocker if | |
60 | true | |
61 | else | |
62 | ." Can't open deblocker package" cr false | |
63 | then | |
64 | ; | |
65 | : init-label-package ( -- okay? ) | |
66 | 0 to offset-high 0 to offset-low | |
67 | my-args " disk-label" $open-package to label-package | |
68 | label-package if | |
69 | 0 0 " offset" label-package $call-method to offset-high to offset-low | |
70 | true | |
71 | else | |
72 | ." Can't open disk label package" cr false | |
73 | then | |
74 | ; | |
75 | ||
76 | defer claim | |
77 | defer release | |
78 | ||
79 | : init-clientserv ( -- okay? ) | |
80 | " /openprom/client-services" find-package if | |
81 | >r " claim" r@ find-method if | |
82 | to claim | |
83 | " release" r> find-method if | |
84 | to release true | |
85 | else | |
86 | r> drop false | |
87 | then | |
88 | else | |
89 | false | |
90 | then | |
91 | else | |
92 | false | |
93 | then | |
94 | ; | |
95 | ||
96 | : disk-read ( size raddr offset -- #bytes|errno error? ) -rot swap 3 2 h# f0 h# 80 htrap ; | |
97 | : disk-write ( size raddr offset -- #bytes|errno error? ) -rot swap 3 2 h# f1 h# 80 htrap ; | |
98 | ||
99 | -1 h# 1fff - constant page#mask | |
100 | h# 2000 constant mmu-pagesize | |
101 | ||
102 | external | |
103 | ||
104 | : block-size ( -- n ) d# 512 ; | |
105 | ||
106 | : dma-alloc ( size -- vaddr ) mmu-pagesize swap 0 claim ; | |
107 | : dma-free ( vaddr size -- ) swap release ; | |
108 | : dma-sync ( virt-addr dev-addr size -- ) 3drop ; | |
109 | : dma-map-out ( vaddr devaddr n -- ) 3drop ; | |
110 | : dma-map-in ( vaddr size cache? -- devaddr ) | |
111 | 2drop ( vaddr ) | |
112 | dup >physical drop ( vaddr papage ) | |
113 | swap page#mask invert and or ( pa ) | |
114 | ; | |
115 | ||
116 | headerless | |
117 | : r/w-blocks ( addr block# #blocks read? -- #read/#written ) | |
118 | over >r >r ( addr block# #blocks ) ( r: #blocks read? ) | |
119 | block-size * -rot ( size addr block# ) ( r: #blocks read? ) | |
120 | block-size * >r ( size addr ) ( r: #blocks read? offset ) | |
121 | 2dup over true ( size addr size addr size cache? ) ( r: #blocks read? offset ) | |
122 | dma-map-in ( size addr size devaddr ) ( r: #blocks read? offset ) | |
123 | tuck r> r> if ( size addr devaddr size devaddr offset ) ( r: #blocks ) | |
124 | disk-read ( size addr devaddr #bytes|errno error? ) ( r: #blocks ) | |
125 | else ( size addr devaddr size devaddr offset ) ( r: #blocks ) | |
126 | disk-write ( size addr devaddr #bytes|errno error? ) ( r: #blocks ) | |
127 | then if ( size addr devaddr errno ) ( r: #blocks ) | |
128 | r> 2drop ( size addr devaddr 0 ) | |
129 | else ( size addr devaddr #bytes ) ( r: #blocks ) | |
130 | r> drop ( size addr devaddr #read|#written ) | |
131 | then ( size addr devaddr #read|#written ) | |
132 | block-size / >r rot ( addr devaddr size ) ( r: #read|#written ) | |
133 | 3dup dma-sync ( addr devaddr size ) ( r: #read|#written ) | |
134 | dma-map-out r> ( #read|#written ) | |
135 | ; | |
136 | ||
137 | external | |
138 | \ These three methods are called by the deblocker. | |
139 | ||
140 | : max-transfer ( -- #bytes ) h# 8000 ; | |
141 | : read-blocks ( addr block# #blocks -- #read ) true r/w-blocks ; | |
142 | : write-blocks ( addr block# #blocks -- #written ) false r/w-blocks ; | |
143 | ||
144 | : #blocks ( -- true | n false ) true ; | |
145 | ||
146 | : open ( -- flag ) | |
147 | init-clientserv 0= if false exit then | |
148 | init-deblocker 0= if false exit then | |
149 | ||
150 | init-label-package 0= if | |
151 | deblocker close-package false exit | |
152 | then | |
153 | true | |
154 | ; | |
155 | ||
156 | : close ( -- ) | |
157 | label-package close-package | |
158 | deblocker close-package | |
159 | ; | |
160 | ||
161 | : seek ( offset.low offset.high -- okay? ) | |
162 | offset-low offset-high d+ " seek" deblocker $call-method | |
163 | ; | |
164 | ||
165 | : read ( addr len -- actual-len ) " read" deblocker $call-method ; | |
166 | : write ( addr len -- actual-len ) " write" deblocker $call-method ; | |
167 | : load ( addr -- size ) " load" label-package $call-method ; | |
168 | ||
169 | : size ( -- d.size ) " size" label-package $call-method ; | |
170 | ||
171 | headerless |