Branch
Hash :
1a08f436
Author :
Date :
2010-08-25T09:23:17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
\ ========== Copyright Header Begin ==========================================
\
\ Hypervisor Software File: savecpu.fth
\
\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
\
\ - Do no alter or remove copyright notices
\
\ - Redistribution and use of this software in source and binary forms, with
\ or without modification, are permitted provided that the following
\ conditions are met:
\
\ - Redistribution of source code must retain the above copyright notice,
\ this list of conditions and the following disclaimer.
\
\ - Redistribution in binary form must reproduce the above copyright notice,
\ this list of conditions and the following disclaimer in the
\ documentation and/or other materials provided with the distribution.
\
\ Neither the name of Sun Microsystems, Inc. or the names of contributors
\ may be used to endorse or promote products derived from this software
\ without specific prior written permission.
\
\ This software is provided "AS IS," without a warranty of any kind.
\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\
\ You acknowledge that this software is not designed, licensed or
\ intended for use in the design, construction, operation or maintenance of
\ any nuclear facility.
\
\ ========== Copyright Header End ============================================
id: @(#)savecpu.fth 1.1 06/02/16
purpose:
copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
copyright: Use is subject to license terms.
transient
also assembler definitions
: save-reg ( reg offset -- ) \ where?
postpone offset-of %asi stxa
;
: load-reg ( area reg -- ) \ where?
>r postpone offset-of %asi r> ldxa
;
: write-reg ( reg area offset -- ) %asi stxa ;
: read-reg ( area offset reg -- ) >r %asi r> ldxa ;
previous definitions
resident
headers
\ %g5 = save area
\ %g4 = <exit type>
\ = 0, restore, retry
\ = 1, restore, done
\ else, restore, jmpl %g7
\
label restore-cpu-state ( -- )
%g0 memory-asi wrasi
%g5 %g1 load-reg %cwp %g1 0 wrcwp \ EARLY!!!
%g5 %l5 move
%g4 %l4 move
%g7 %l7 move
%g0 2 wrtl
%l5 %g1 load-reg %tpc-2 %g1 0 wrtpc
%l5 %g1 load-reg %tnpc-2 %g1 0 wrtnpc
%l5 %g1 load-reg %tstate-2 %g1 0 wrtstate
%l5 %g1 load-reg %tt-2 %g1 0 wrtt
%g0 1 wrtl
%l5 %g1 load-reg %tpc-1 %g1 0 wrtpc
%l5 %g1 load-reg %tnpc-1 %g1 0 wrtnpc
%l5 %g1 load-reg %tstate-1 %g1 0 wrtstate
%l5 %g1 load-reg %tt-1 %g1 0 wrtt
\ Now restore original state..
%l5 %g1 load-reg %tl-c %g1 0 cmp \ TL=0??
0= if
%g1 0 wrtl \ Restore
%g0 1 wrtl \ Force to 1.
then
%l5 %g1 load-reg %pc %g1 0 wrtpc
%l5 %g1 load-reg %npc %g1 0 wrtnpc
%l5 %g1 load-reg %tstate-c %g1 0 wrtstate
%l5 %g1 load-reg %y %g1 0 wry
%l5 %g1 load-reg %pil %g1 0 wrpil
%l5 %g1 load-reg %cansave %g1 0 wrcansave
%l5 %g1 load-reg %canrestore %g1 0 wrcanrestore
%l5 %g1 load-reg %cleanwin %g1 0 wrcleanwin
%l5 %g1 load-reg %otherwin %g1 0 wrotherwin
%l5 %g1 load-reg %wstate %g1 0 wrwstate
%l5 %g1 load-reg %fprs %g1 0 wrfprs
[ifdef] SUN4V
%g0 0 wrgl 8 0 do %l5 offset-of %g0 i /x* + %g0 i + read-reg loop
%g0 1 wrgl 8 0 do %l5 offset-of %a0 i /x* + %g0 i + read-reg loop
%g0 2 wrgl
[then]
%l5 %g5 move
%l4 %g4 move
%l7 %g7 move
\ Restore locals, Ins Outs
\ Address of window regs.
%l5 window-registers %g6 add
8 0 do %g6 i /x* %o0 i + read-reg loop \ %o0-%o7
%g6 8 /n* %g6 add
%g5 %g1 load-reg full-save?
%g1 %g0 cmp
0<> if
nop
%g5 %g1 load-reg %pcontext
%g0 h# 08 %g2 add
%g1 %g0 %g2 h# 21 stxa
%g5 %g1 load-reg %scontext
%g0 h# 10 %g2 add
%g1 %g0 %g2 h# 21 stxa
#sync membar
%g5 %g1 load-reg %tba
%g1 0 wrtba
\ recover how many we saved
%g5 %g1 load-reg %nwins
%g2 rdcwp
begin
%g2 0 wrcwp
8 0 do %g6 i /x* %l0 i + read-reg loop \ %l0-%l7
%g6 8 /n* %g6 add
8 0 do %g6 i /x* %i0 i + read-reg loop \ %i0-%i7
%g6 8 /n* %g6 add
%g2 1 %g2 sub
%g2 0 wrcwp
%g1 1 %g1 subcc
0= until
%g2 rdcwp
%g5 %g1 load-reg %cwp
%g1 0 wrcwp
else
nop
8 0 do %g6 i /x* %l0 i + read-reg loop \ %l0-%l7
%g6 8 /n* %g6 add
8 0 do %g6 i /x* %i0 i + read-reg loop \ %i0-%i7
%g6 8 /n* %g6 add
then
%g4 %g0 cmp
0<> if
%g4 1 cmp
0= if
nop
done
then
\ copy the state we destroy into TL=2 equivs.
%g0 1 wrtl
%g7 4 %g7 add
%g7 0 wrtpc
%g7 4 %g7 add
%g7 0 wrtnpc
then
retry
end-code
\ In: any GL
\ %g4 = <preserved>
\ %g5 = save area
\ %g6 = full_save?
\ %g7 = pc to jump to after save, cwp=0, gl=0, tl=0, ie=1
\
\ %g1 trashed
\ %g2 trashed
\ %g3 trashed
\ %g6 trashed once used
\
\ Out: GL=0, run (%g7)
\
label save-cpu-state ( -- )
%g0 memory-asi wrasi
%g1 rdtl %g1 %g5 save-reg %tl-c
%g1 rdtpc %g1 %g5 save-reg %tpc-c
%g1 %g5 save-reg %pc
%g1 rdtnpc %g1 %g5 save-reg %tnpc-c
%g1 %g5 save-reg %npc
%g1 rdtstate %g1 %g5 save-reg %tstate-c
%g1 rdy %g1 %g5 save-reg %y
%g1 rdpil %g1 %g5 save-reg %pil
%g1 rdcwp %g1 %g5 save-reg %cwp
%g1 rdcansave %g1 %g5 save-reg %cansave
%g1 rdcanrestore %g1 %g5 save-reg %canrestore
%g1 rdcleanwin %g1 %g5 save-reg %cleanwin
%g1 rdotherwin %g1 %g5 save-reg %otherwin
%g1 rdwstate %g1 %g5 save-reg %wstate
%g1 rdfprs %g1 %g5 save-reg %fprs
%g6 %g5 save-reg full-save?
[ifdef] SUN4V
%g1 rdgl %g1 %g5 save-reg %gl
[then]
%g1 rdtt %g1 %g5 save-reg %tt-c
%g0 2 wrtl
%g1 rdtpc %g1 %g5 save-reg %tpc-2
%g1 rdtnpc %g1 %g5 save-reg %tnpc-2
%g1 rdtstate %g1 %g5 save-reg %tstate-2
%g1 rdtt %g1 %g5 save-reg %tt-2
%g0 1 wrtl
%g1 rdtpc %g1 %g5 save-reg %tpc-1
%g1 rdtnpc %g1 %g5 save-reg %tnpc-1
%g1 rdtstate %g1 %g5 save-reg %tstate-1
%g1 rdtt %g1 %g5 save-reg %tt-1
\ Address of window regs.
%g5 window-registers %g6 add
8 0 do %o0 i + %g6 i /x* write-reg loop \ %o0-%o7
%g6 8 /n* %g6 add
\ Full save or partial?
%g5 %g1 load-reg full-save?
%g1 %g0 cmp
0<> if
%g1 rdtba
%g1 %g5 save-reg %tba
%g0 h# 08 %g2 add
%g0 %g2 h# 21 %g1 ldxa
%g1 %g5 save-reg %pcontext
%g0 h# 10 %g1 add
%g0 %g1 h# 21 %g1 ldxa
%g1 %g5 save-reg %scontext
%g0 %g0 %g2 h# 21 stxa \ Set Primary context to 0
#sync membar
\ Rebuild %PSTATE, %CCR, %ASI from %TSTATE and save them
%g1 rdtstate
%g1 d# 08 %g2 sll
%g2 d# 16 %g2 srl
%g2 %g5 save-reg %pstate
%g1 d# 63 d# 39 - %g2 sllx
%g2 d# 32 %g2 srlx
%g2 %g5 save-reg %ccr
%g1 d# 24 %g2 srl
%g2 %g5 save-reg %asi
%g2 rdcwp
%g2 %g3 move
%g0 %g1 move
begin
%g3 0 wrcwp
8 0 do %l0 i + %g6 i /x* write-reg loop \ %l0-%l7
%g6 8 /n* %g6 add
8 0 do %i0 i + %g6 i /x* write-reg loop \ %i0-%i7
%g3 1 %g3 sub
%g3 0 wrcwp
%g3 rdcwp
%g2 %g3 %g0 subcc
%g1 1 %g1 add
= until
%g6 8 /n* %g6 add
%g1 %g5 save-reg %nwins \ How many?
else
nop
8 0 do %l0 i + %g6 i /x* write-reg loop \ %l0-%l7
%g6 8 /n* %g6 add
8 0 do %i0 i + %g6 i /x* write-reg loop \ %i0-%i7
%g6 8 /n* %g6 add
then
%g5 %g1 load-reg %cwp %g1 0 wrcwp
%g4 %l4 move
%g5 %l5 move
%g7 %l7 move
[ifdef] SUN4V
\ Save current GLs
%g0 1 wrgl 8 0 do %g0 i + %l5 offset-of %a0 i /x* + write-reg loop
%g0 0 wrgl 8 0 do %g0 i + %l5 offset-of %g0 i /x* + write-reg loop
[then]
%g1 rdpstate
%g1 2 %g1 andn
%g1 0 wrpstate
%l7 4 %g0 jmpl
%g0 0 wrtl
end-code
\ %l0 = stack base
\ %l4 = TOS (VA)
\ %l7 = IP to run
label setup-small-forth-engine
prom-main-task %g5 up setx \ Set User Pointer
up sp %g1 get-cpu-struct
%g1 %l0 %g1 add \ CPU Save Area VA
%g1 /min-cpu-save %g1 add
%g1 /fth-exception-stack sp add \ Data Stack set
%g1 /fth-exception-stack 2/ rp add
rombase base set \ set base
%l7 base ip add
%l4 tos move \ VA
next
end-code
[ifdef] WOULD-BE-NICE-TO-HAVE-HERE
\
\ We cant put this here because it has a fwd ref to save state
\ we also depends upon this code. So its [ifdef]d out and left for
\ reference.
\
\ %gl = 2
\ %g1 is the structure offset
label small-forth-save-state
\ OK, we have to switch to the original fault-tl and tpc, tnpc
\ we got here from the restore which does a retry at tl=1 having
\ setup the tpc, tnpc to 'return', everything else should be restored
%g0 2 wrtl
%g0 h# 38 %g2 add
%g2 %g0 h# 20 %g5 ldxa \ CPU struct PA
%g5 %g1 %g5 add \ CPU save area
%g7 rdasi
%g0 memory-asi wrasi
%g5 %g1 load-reg %tpc-1
%g5 %g2 load-reg %tnpc-1
%g5 %g3 load-reg %tl-c
%g0 1 wrtl
%g0 %g1 wrtpc
%g0 %g2 wrtnpc
%g0 %g7 wrasi
save-state always brif
%g0 %g3 wrtl
end-code
[then]