Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: clntmem.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: @(#)clntmem.fth 1.18 03/07/15 | |
43 | purpose: Implements client interface "claim" and "release" | |
44 | copyright: Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | variable memory-node | |
49 | variable mmu-node | |
50 | headers | |
51 | ' memory-node " memory" chosen-variable | |
52 | ' mmu-node " mmu" chosen-variable | |
53 | ||
54 | headerless | |
55 | ||
56 | \ Build the memory and mmu node allocation and mapping methods using | |
57 | \ a method builder that saves the ihandle, crash acf and method name at | |
58 | \ compile time. The runtime behavior finds the crash acf on the first | |
59 | \ call, does a lookup of the method with the ihandle and replaces | |
60 | \ the crash acf with the method acf. Future calls then use the cached | |
61 | \ acf for faster performance. | |
62 | \ | |
63 | \ the basic layout is: | |
64 | \ [n0] variable containing ihandle for node | |
65 | \ [n1] ['] crash for lookup else method acf | |
66 | \ [n2]+ method$ name | |
67 | ||
68 | transient | |
69 | : (method-builder) | |
70 | create | |
71 | token, \ save the variable | |
72 | ['] crash token, \ not referenced yet | |
73 | parse-word ", \ save the string | |
74 | ; | |
75 | resident headerless | |
76 | ||
77 | \ this routine is never going to be used at runtime because the defining | |
78 | \ words have been disposed, only the does> clause matters. | |
79 | : (method:) ( acf -- ) | |
80 | does> | |
81 | >r ( ?? ) | |
82 | r@ token@ execute @ ( ?? ihandle ) | |
83 | r@ ta1+ token@ dup ['] crash = if ( ?? acf ) | |
84 | drop dup ( ?? ihandle ihandle ) | |
85 | r@ 2 ta+ count ( ?? ihandle ihandle method$ ) | |
86 | rot ihandle>phandle find-method ( ?? ihandle,acf,true | ihandle,0 ) | |
87 | 0= abort" FATAL: lookup failed" ( ?? ) | |
88 | dup r@ ta1+ token! ( ?? ) | |
89 | then ( ?? ihandle acf ) | |
90 | r> drop swap call-package ( ?? ) | |
91 | ; | |
92 | ||
93 | transient | |
94 | : mem-method: \ method-name method | |
95 | ['] memory-node (method-builder) (method:) | |
96 | ; | |
97 | ||
98 | : mmu-method: \ method-name method | |
99 | ['] mmu-node (method-builder) (method:) | |
100 | ; | |
101 | resident | |
102 | ||
103 | \ mem-claim ( [ phys.lo phys.hi ] size align -- base.lo base.hi ) | |
104 | mem-method: mem-claim claim | |
105 | ||
106 | \ mem-release ( phys.lo phys.hi size -- ) | |
107 | mem-method: mem-release release | |
108 | ||
109 | \ mem-mode ( -- mode ) | |
110 | mem-method: mem-mode mode | |
111 | ||
112 | \ mmu-map ( phys-lo phys-hi virt size mode -- ) | |
113 | mmu-method: mmu-map map | |
114 | ||
115 | \ mmu-claim ( [ virt ] size align -- base ) | |
116 | mmu-method: mmu-claim claim | |
117 | ||
118 | \ mmu-release ( virt size -- ) | |
119 | mmu-method: mmu-release release | |
120 | ||
121 | \ mmu-unmap ( virt size -- ) | |
122 | mmu-method: mmu-unmap unmap | |
123 | ||
124 | \ mmu-translate ( virt -- false | phys-lo phys-hi mode true ) | |
125 | mmu-method: mmu-translate translate | |
126 | ||
127 | \ mmu-pagesize ( -- n ) | |
128 | \ mmu-method: mmu-pagesize pagesize | |
129 | alias mmu-pagesize pagesize | |
130 | ||
131 | : mmu-lowbits ( adr1 -- lowbits ) mmu-pagesize 1- and ; | |
132 | : mmu-highbits ( adr1 -- highbits ) mmu-pagesize 1- invert and ; | |
133 | ||
134 | : (map) ( size phys space virthint mode -- virtual ) | |
135 | >r ( size phys space virtual ) ( r: mode ) | |
136 | ?dup if ( size phys space virtual ) ( r: mode ) | |
137 | 2 pick mmu-lowbits over mmu-lowbits | |
138 | <> abort" Inconsistent page offsets" | |
139 | 3 pick 0 mmu-claim ( size phys space virtual ) ( r: mode ) | |
140 | else ( size phys space ) ( r: mode ) | |
141 | over mmu-lowbits 3 pick + ( size phys space size' ) ( r: mode ) | |
142 | mmu-pagesize mmu-claim ( size phys space virtual ) ( r: mode ) | |
143 | then ( size phys space virtual ) ( r: mode ) | |
144 | ||
145 | 2 pick mmu-lowbits ( size phys space virtual offset ) ( r: mode ) | |
146 | over mmu-highbits + ( size phys space virtual virtual' ) ( r: mode ) | |
147 | r> swap >r ( size phys space virtual mode ) ( r: virtual' ) | |
148 | 4 roll swap mmu-map ( ) ( r: virtual' ) | |
149 | r> ( virtual' ) | |
150 | ; | |
151 | ||
152 | : (allocate-aligned) ( alignment size virthint mode -- virtual ) | |
153 | 2 pick 0= if 2drop 2drop 0 exit then | |
154 | >r rot >r ( size virthint ) ( r: mode align ) | |
155 | 2dup mmu-lowbits + ( size virthint size' ) ( r: mode align ) | |
156 | dup r> 1 max ( size virthint size' size' align ) ( r: mode) | |
157 | mem-claim ( size virthint size' p.lo p.hi ) ( r: mode ) | |
158 | ||
159 | \ Now we map in the allocated memory | |
160 | rot r> 2over swap ( size virthint p.lo p.hi size' mode p.hi p.lo ) | |
161 | rot 2swap 2>r 2>r ( size virthint p.lo,hi ) ( r: size' p.hi,lo md ) | |
162 | ||
163 | -rot over mmu-lowbits + ( size p.hi virthint p.lo ) ( r: " ) | |
164 | -rot ( size p.lo' p.hi virthint ) ( r: " ) | |
165 | ||
166 | r> ['] (map) catch ?dup if ( 4*x error-code ) ( r: size' p.hi,lo) | |
167 | ||
168 | \ If the mapping operation fails, we give back the | |
169 | \ physical memory that we have already allocated. | |
170 | ||
171 | nip nip nip nip ( error-code ) | |
172 | r> r> r> mem-release ( error-code ) | |
173 | throw \ Propagate the error | |
174 | ||
175 | then ( virtual ) ( r: size p.hi,lo ) | |
176 | r> r> r> 3drop ( virtual ) | |
177 | ; | |
178 | : allocate-aligned ( alignment size virthint -- virtual ) | |
179 | mem-mode ['] (allocate-aligned) catch if 3drop 0 then | |
180 | ; | |
181 | ||
182 | headers | |
183 | ||
184 | cif: claim ( align size virt -- base ) | |
185 | rot dup if ( size virt align ) | |
186 | nip swap 0 ( align size 0 ) | |
187 | else | |
188 | drop 1 -rot ( size virt ) | |
189 | then ( align size virthint ) | |
190 | allocate-aligned ( base ) | |
191 | ; | |
192 | cif: release ( size virt -- ) | |
193 | swap >r dup mmu-translate if ( virt phys.lo phys.hi mode ) ( r: size ) | |
194 | drop 2dup memory? if ( virt phys.lo phys.hi ) ( r: size ) | |
195 | r@ mem-release ( virt ) ( r: size ) | |
196 | else ( virt phys.lo phys.hi ) ( r: size ) | |
197 | 2drop ( virt ) ( r: size ) | |
198 | then r> ( virt size ) | |
199 | then 2dup mmu-unmap mmu-release ( ) | |
200 | ; | |
201 | ||
202 | ||
203 | headerless | |
204 | also client-services | |
205 | alias cif-release release | |
206 | alias cif-claim claim | |
207 | previous | |
208 | ||
209 | headers |