Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: trans.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: @(#)trans.fth 1.22 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 | headerless | |
48 | : (initial-memory) ( -- phys.lo phys.hi len ) | |
49 | hi-memory-base @ pageshift lshift obmem | |
50 | hi-memory-size @ pageshift lshift | |
51 | ; | |
52 | ' (initial-memory) to initial-memory | |
53 | ||
54 | : (.trans) ( ?? va len tte -- ?? ) | |
55 | push-hex | |
56 | .vpt space swap | |
57 | d# 12 .r | |
58 | d# 9 .r cr | |
59 | pop-base | |
60 | ; | |
61 | ||
62 | headers | |
63 | : .trans ( -- ) ['] (.trans) vpt-walker ; | |
64 | ||
65 | headerless | |
66 | ||
67 | \ The "translations" property is generated on-demand by walking | |
68 | \ the vpt and saving the valid translations in a buffer. | |
69 | \ The last-translation-buffer is used to store the last set of | |
70 | \ translations retrieved. Once the client takes over the tba | |
71 | \ obp will return what is stored in the last-translation-buffer. | |
72 | \ Since the last-translation-buffer is fixed if the number of | |
73 | \ translations exceeds its size they are clipped. | |
74 | \ | |
75 | \ If a client makes a request via a cif call, we use the client's | |
76 | \ buffer to store the translations. This handles cases where the | |
77 | \ number of translations overflows the buffer allocated for the | |
78 | \ last-translation-buffer. If the client request is simply for | |
79 | \ the length of the translations property, we only count them. | |
80 | \ For client requests we rely on the cif-buf indicating if its | |
81 | \ a getprop or getproplen request. | |
82 | \ | |
83 | \ last-translation-buffer = adr,len of the translations buffer | |
84 | \ trans-max = max # translations that fit in allocated buffer | |
85 | \ trans-cur = current count of translations while walking vpt | |
86 | \ /trans-entry = # bytes for translation made up of va,size,tte | |
87 | ||
88 | h# 8010 constant trans-max | |
89 | h# 18 constant /trans-entry | |
90 | variable trans-cur 0 trans-cur ! | |
91 | 2variable last-translation-buffer 0 0 last-translation-buffer 2! | |
92 | ||
93 | : alloc-trans-buf ( -- ) | |
94 | trans-max alloc-mem | |
95 | 0 last-translation-buffer 2! | |
96 | ; | |
97 | ||
98 | \ vpt-walker calls with each valid mapping to count # translations | |
99 | : count-translations ( adr,len va len tte -- adr,len' ) | |
100 | 3drop /trans-entry + | |
101 | ; | |
102 | ||
103 | \ vpt-walker calls with each valid mapping to save in buffer | |
104 | : save-all-translations ( adr,len va len tte -- adr',len' ) | |
105 | >r >r 2 pick 2 pick + tuck x! | |
106 | 8 + r> over x! | |
107 | 8 + r> swap x! | |
108 | /trans-entry + | |
109 | ; | |
110 | ||
111 | \ vpt-walker calls with each valid mapping to save until buffer full | |
112 | : save-clip-translations ( adr,len va len tte -- adr',len' ) | |
113 | /trans-entry trans-cur +! | |
114 | trans-cur @ trans-max <= if | |
115 | >r >r 2 pick 2 pick + tuck x! | |
116 | 8 + r> over x! | |
117 | 8 + r> swap x! | |
118 | /trans-entry + | |
119 | else | |
120 | 3drop | |
121 | then | |
122 | ; | |
123 | ||
124 | \ called to generate "translations" property on-the-fly | |
125 | \ once client takes over the trap table there will be no additional | |
126 | \ mappings in the vpt so we return the last saved translations | |
127 | \ (assumes translations property is retrieved at least once before TBA set) | |
128 | : make-translations ( -- xdr,len ) | |
129 | obp-control-relinquished? if | |
130 | last-translation-buffer 2@ ( xdr,len ) | |
131 | else | |
132 | \ if cif-buf has non-zero len then this is cif request | |
133 | \ if non-zero adr then this is a getprop call, otherwise its getproplen | |
134 | [ also client-services ] cif-buf [ previous ] ( cifbuf ) | |
135 | 2@ dup if ( xdr,len ) | |
136 | over if ( xdr,len ) | |
137 | drop 0 ( xdr,0 ) | |
138 | ['] save-all-translations vpt-walker ( xdr,len ) | |
139 | 2dup last-translation-buffer ( xdr,len xdr,len last ) | |
140 | 2@ over swap erase ( xdr,len xdr,len buf ) | |
141 | swap trans-max min ( xdr,len xdr buf len' ) | |
142 | 2dup last-translation-buffer 2! ( xdr,len xdr buf len' ) | |
143 | cmove ( xdr,len ) | |
144 | else | |
145 | drop 0 ['] count-translations vpt-walker ( xdr,len ) | |
146 | then | |
147 | else | |
148 | 2drop last-translation-buffer 2@ ( xdr,len ) | |
149 | over swap erase 0 ( xdr,0 ) | |
150 | 0 trans-cur ! | |
151 | ['] save-clip-translations vpt-walker ( xdr,len ) | |
152 | 2dup last-translation-buffer 2! | |
153 | then | |
154 | then | |
155 | ; | |
156 | ||
157 | : (allocate-page ( -- pa-lo pa-hi ) | |
158 | mmu-pagesize dup mem-claim | |
159 | ; | |
160 | ' (allocate-page is allocate-page | |
161 | ||
162 | create err-invalid-index ," Index must be in the range: 7 < index < 64" | |
163 | ||
164 | 5 actions | |
165 | action: drop make-translations ; ( ) | |
166 | action: drop 2drop ; | |
167 | action: ; | |
168 | action: drop ; | |
169 | action: drop ; | |
170 | ||
171 | headers | |
172 | ||
173 | " /virtual-memory" find-device | |
174 | ||
175 | " translations" make-property-name use-actions | |
176 | ||
177 | : open ( -- ok? ) | |
178 | 0 memrange ! \ Clear free list | |
179 | d# 20 memrange more-nodes \ Get enough nodes "forever" | |
180 | ||
181 | \ Create the available memory list from which the firmware is allowed | |
182 | \ to dynamically allocate virtual memory. | |
183 | ||
184 | monvirtbase monvirtsize set-node fwvirt insert-after | |
185 | ||
186 | monvirtbase dictionary-top over - claim-virtual drop | |
187 | RAMbase RAMsize claim-virtual drop | |
188 | mondvmabase mondvmasize claim-virtual drop | |
189 | ||
190 | \ Create the available memory list from which the firmware | |
191 | \ is not allowed to dynamically allocate virtual memory. | |
192 | ||
193 | 0 monvirtbase add-os-piece | |
194 | monvirtbase monvirtsize + 1.0000.0000 add-os-piece | |
195 | ||
196 | \ Allocate ffff.e000 -> ffff.ffff for safety | |
197 | -1 n->l 1 claim-virtual drop | |
198 | ||
199 | \ virtual address hole on ultrasparc I/II due to 44 bit MMU support | |
200 | \ don't want to add this range to the free list so skip over it | |
201 | [ifexist] hole-start | |
202 | h# 1.0000.0000 hole-start over - noreclaim-free-virtual | |
203 | hole-end dup 0 swap - vpt-size - noreclaim-free-virtual | |
204 | [else] | |
205 | h# 1.0000.0000 0 over - noreclaim-free-virtual | |
206 | [then] | |
207 | ||
208 | true | |
209 | ; | |
210 | caps @ caps off | |
211 | : SUNW,itlb-load ( index tte-data vaddr -- ) | |
212 | rot dup 8 0 #itlb-entries within if ( tte-data vaddr index ) | |
213 | -rot mmu-highbits tuck ( index tag tte-data tag ) | |
214 | over tte>size bounds ?do ( index tte-tag tte-data ) | |
215 | i h# 20 or demap-itlb ( index tte-tag tte-data ) | |
216 | mmu-pagesize +loop ( index tte-tag tte-data ) | |
217 | -rot 0 swap ( tte-data index 0 tte-tag ) | |
218 | pil@ >r itlb-tar-data! r> pil! ( ) | |
219 | else ( tte-data vaddr index ) | |
220 | err-invalid-index throw | |
221 | then ( ) | |
222 | ; | |
223 | : SUNW,dtlb-load ( index tte-data vaddr -- ) | |
224 | rot dup 8 0 #dtlb-entries within if ( tte-data vaddr index ) | |
225 | -rot mmu-highbits tuck ( index tag tte-data tag ) | |
226 | over tte>size bounds ?do ( index tte-tag tte-data ) | |
227 | i h# 20 or demap-dtlb ( index tte-tag tte-data ) | |
228 | mmu-pagesize +loop ( index tte-tag tte-data ) | |
229 | -rot 0 swap ( tte-data index 0 tte-tag ) | |
230 | pil@ >r dtlb-tar-data! r> pil! ( ) | |
231 | else ( tte-data vaddr index ) | |
232 | err-invalid-index throw | |
233 | then ( ) | |
234 | ; | |
235 | caps ! | |
236 | device-end | |
237 | ||
238 | stand-init: Allocate translations buffer | |
239 | alloc-trans-buf | |
240 | ; | |
241 | ||
242 | headers |