Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: xcall.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: @(#)xcall.fth 1.2 07/04/27 | |
43 | purpose: | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headers | |
48 | ||
49 | 3 h# 40 * buffer: xcall-buffer | |
50 | 0 value xcall-cpulist | |
51 | 0 value xcall-cpuargs | |
52 | 0 value xcall-cpulist-pa | |
53 | 0 value xcall-cpuargs-pa | |
54 | d# 1000 value cpu-mondo-timeout \ in msecs, 1 sec by default | |
55 | ||
56 | \ htrap function number | |
57 | h# 42 constant api-cpu-mondo-send | |
58 | ||
59 | \ Get cpu-mondo-timeout value from MD. If it is not available in MD then use | |
60 | \ the default value. See FWARC/2006/545 for the MD node prop description | |
61 | stand-init: setup 4v xcall buffer | |
62 | 0 " platform" md-find-node ?dup if ( node | ) | |
63 | " inter-cpu-latency" ascii v md-find-prop ?dup if ( prop | ) | |
64 | md-decode-prop drop ( data ) | |
65 | d# 1000000 / is cpu-mondo-timeout ( ) \ Convert from nano-secs | |
66 | then \ to milli-secs, and set | |
67 | then \ time-out variable | |
68 | xcall-buffer ( va ) | |
69 | h# 40 round-up ( va' ) | |
70 | dup is xcall-cpulist ( va' ) | |
71 | dup >physical drop is xcall-cpulist-pa ( va' ) | |
72 | h# 40 + ( va'' ) | |
73 | dup is xcall-cpuargs ( va'' ) | |
74 | >physical drop is xcall-cpuargs-pa ( ) | |
75 | ; | |
76 | ||
77 | \ Hypervisor call | |
78 | 1 3 api-cpu-mondo-send fast-trap# | |
79 | hypercall: api-send-mondo ( cpu-args cpu-list-pa n -- status ) | |
80 | ||
81 | ||
82 | : xcall-cpus ( n -- failed? ) | |
83 | get-msecs cpu-mondo-timeout + >r ( n ) ( r: msecs ) | |
84 | begin ( n ) ( r: msecs ) | |
85 | dup xcall-cpuargs-pa xcall-cpulist-pa rot ( n cpu-args cpu-list-pa n ) | |
86 | api-send-mondo ( n status ) ( r: msecs ) | |
87 | dup HV-EOK = if ( n status ) ( r: msecs ) | |
88 | r> 3drop false exit ( false ) | |
89 | then | |
90 | HV-EWOULDBLOCK <> if ( n ) ( r: msecs ) | |
91 | r> 2drop true exit ( true ) | |
92 | then | |
93 | get-msecs r@ > ( n true|false ) ( r: msecs ) | |
94 | until ( n ) ( r: msecs ) | |
95 | r> 2drop true ( true ) | |
96 | ; | |
97 | ||
98 | : xcall-cpu ( arg1 arg0 pc mid -- failed? ) | |
99 | >r r@ xcall-cpulist w! ( arg1 arg0 pc ) ( r: mid ) | |
100 | xcall-cpuargs ( arg1 arg0 pc va ) | |
101 | tuck x! /x + ( arg1 arg0 n' ) | |
102 | tuck x! /x + ( arg1 n' ) | |
103 | x! ( ) | |
104 | 1 xcall-cpus dup if ( failed? ) | |
105 | r> cmn-warn[ " Failed to send Mondo to CPU# %x" ]cmn-end | |
106 | else | |
107 | r> drop | |
108 | then | |
109 | ; | |
110 | ||
111 | headerless | |
112 | hidden also definitions | |
113 | ||
114 | label bounce | |
115 | \ TL = 1 | |
116 | \ %g1 = function @ TL=0 | |
117 | \ %g2 = arg0 | |
118 | \ %g7 + 8 = Return address | |
119 | ||
120 | %g1 %g3 move | |
121 | %g2 %o0 move | |
122 | ||
123 | \ %o0 = Arg0 | |
124 | \ %g3 = PC @ TL=0 | |
125 | ||
126 | %o1 rdtpc | |
127 | %o2 rdtnpc | |
128 | ||
129 | %g3 0 wrtpc | |
130 | %g3 4 %g3 add | |
131 | %g3 0 wrtnpc | |
132 | ||
133 | \ TPC = PC of Function @ TL=0 | |
134 | \ TnPC = nPC of Function @ TL=0 | |
135 | \ %o0 = Arg0 of Function @ TL=0 | |
136 | \ %o1 = Return PC of Function @ TL=0 | |
137 | \ %o2 = Return nPC of Function @ TL=0 | |
138 | \ %g7 + 8 = Return address | |
139 | retry | |
140 | end-code | |
141 | ||
142 | label start-cpu ( -- ) | |
143 | \ %TL = 1 | |
144 | \ %g1 = PC | |
145 | \ %g2 = Arg0 | |
146 | \ %g7 + 8 = Return address | |
147 | ||
148 | \ Setup %tpc and %tnpc | |
149 | %g1 0 wrtpc | |
150 | %g1 4 %g1 add | |
151 | %g1 0 wrtnpc | |
152 | ||
153 | \ %g2 = Arg0 | |
154 | \ %g7 + 8 = Return address | |
155 | \ Setup the arguments | |
156 | %g2 %o0 move %g0 %o1 move | |
157 | %g0 %o2 move %g0 %o3 move | |
158 | %g0 %o4 move %g0 %o5 move | |
159 | ||
160 | ||
161 | \ %g7 + 8 = Return address | |
162 | \ Set the base register | |
163 | base rdpc | |
164 | here 4 - origin - %g4 set | |
165 | base %g4 base sub | |
166 | ||
167 | \ %g7 + 8 = Return address | |
168 | \ Setup cpu-state variables | |
169 | prom-main-task %g4 up setx \ Set User Area Pointer | |
170 | up %g4 %g6 get-cpu-struct | |
171 | CPU-STARTED %g4 %g1 %g6 mark-cpu-state | |
172 | ||
173 | \ %g7 + 8 = Return address | |
174 | %g0 1 %g1 sub | |
175 | %g1 %g6 offset-of %restartable? nput \ Set restartable? | |
176 | %g0 %g6 offset-of last-trap# nput \ Clear last-trap# | |
177 | %g0 %g6 offset-of %state-valid nput \ Unlock Per CPU state | |
178 | ||
179 | retry | |
180 | end-code | |
181 | ||
182 | label goto-cpu ( -- ) | |
183 | \ %TL = 1 | |
184 | \ %g1 = PC | |
185 | \ %g2 = Arg0 | |
186 | \ %g7 + 8 = Return address | |
187 | ||
188 | \ Setup %tpc and %tnpc | |
189 | %g1 0 wrtpc | |
190 | %g1 4 %g1 add | |
191 | %g1 0 wrtnpc | |
192 | ||
193 | \ %g7 + 8 = Return address | |
194 | \ Setup the arguments | |
195 | %g2 %o0 move %g0 %o1 move | |
196 | %g0 %o2 move %g0 %o3 move | |
197 | %g0 %o4 move %g0 %o5 move | |
198 | ||
199 | \ %g7 + 8 = Return address | |
200 | retry | |
201 | end-code | |
202 | ||
203 | 0 value idle-pc | |
204 | ||
205 | label get-pc ( -- ) | |
206 | \ %TL = 1 | |
207 | \ %g7 + 8= return address | |
208 | ||
209 | \ Set User Area Pointer | |
210 | prom-main-task %g4 up setx | |
211 | ||
212 | \ up = user area | |
213 | 'user# idle-pc %g4 set | |
214 | %g5 rdtpc | |
215 | %g5 up %g4 nput | |
216 | ||
217 | retry | |
218 | end-code | |
219 | ||
220 | label exec-cpu ( -- ) | |
221 | \ %o0 = acf | |
222 | ||
223 | \ Set the up register | |
224 | prom-main-task %g4 up setx \ Set User Area Pointer | |
225 | ||
226 | \ Set the base register | |
227 | base rdpc | |
228 | here 4 - origin - tos set | |
229 | base tos base sub | |
230 | ||
231 | \ Establish the Data and Return stacks | |
232 | up rp ip get-cpu-struct \ ip = cpu-struct base | |
233 | 0 >stack-fence? tos set | |
234 | ip tos tos ldx \ stacks-fenced? | |
235 | tos %g0 %g0 subcc | |
236 | 0= if nop | |
237 | 0 >cpu-rp0 tos set | |
238 | 0 >cpu-sp0 sp set | |
239 | else nop | |
240 | 0 >cpu-rp0-fence tos set | |
241 | 0 >cpu-sp0-fence sp set | |
242 | then | |
243 | ip tos rp ldx \ Get RP | |
244 | ip sp sp ldx \ Get SP | |
245 | sp /n sp add \ Account for TOS. | |
246 | ||
247 | \dtc %o0 ip move | |
248 | \dtc ip %g0 %g0 jmpl nop | |
249 | \itc %o0 sc1 move | |
250 | \itc sc1 %g0 scr rtget | |
251 | \itc scr base %g0 jmpl nop | |
252 | c; | |
253 | ||
254 | also forth definitions | |
255 | ||
256 | headers | |
257 | ||
258 | : xcall-get-pc ( cpu# -- true | pc false ) | |
259 | true to idle-pc | |
260 | >r 0 0 get-pc r> xcall-cpu if | |
261 | true | |
262 | else | |
263 | d# 10000 0 do idle-pc true <> if leave then loop | |
264 | idle-pc false | |
265 | then | |
266 | ; | |
267 | ||
268 | : xcall-start-cpu ( arg0 pc mid -- failed? ) | |
269 | start-cpu swap xcall-cpu | |
270 | ; | |
271 | : xcall-execute ( acf cpu# -- failed? ) | |
272 | exec-cpu goto-cpu rot xcall-cpu ( fail? ) | |
273 | ; | |
274 | headerless | |
275 | : xcall-idle-cpu ( cpu# -- failed? ) | |
276 | >r 0 0 slave-save-state r> xcall-cpu | |
277 | ; | |
278 | : xcall-resume-cpu ( cpu# -- failed? ) | |
279 | ['] restart-slave ( cpu# xt ) | |
280 | swap xcall-execute | |
281 | ; | |
282 | headers |