1070af384SBlue Swirl /* 2070af384SBlue Swirl * Helpers for CWP and PSTATE handling 3070af384SBlue Swirl * 4070af384SBlue Swirl * Copyright (c) 2003-2005 Fabrice Bellard 5070af384SBlue Swirl * 6070af384SBlue Swirl * This library is free software; you can redistribute it and/or 7070af384SBlue Swirl * modify it under the terms of the GNU Lesser General Public 8070af384SBlue Swirl * License as published by the Free Software Foundation; either 9070af384SBlue Swirl * version 2 of the License, or (at your option) any later version. 10070af384SBlue Swirl * 11070af384SBlue Swirl * This library is distributed in the hope that it will be useful, 12070af384SBlue Swirl * but WITHOUT ANY WARRANTY; without even the implied warranty of 13070af384SBlue Swirl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14070af384SBlue Swirl * Lesser General Public License for more details. 15070af384SBlue Swirl * 16070af384SBlue Swirl * You should have received a copy of the GNU Lesser General Public 17070af384SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18070af384SBlue Swirl */ 19070af384SBlue Swirl 20db5ebe5fSPeter Maydell #include "qemu/osdep.h" 21070af384SBlue Swirl #include "cpu.h" 222f9d35fcSRichard Henderson #include "exec/exec-all.h" 232ef6175aSRichard Henderson #include "exec/helper-proto.h" 24870be6adSBlue Swirl #include "trace.h" 25070af384SBlue Swirl 26070af384SBlue Swirl static inline void memcpy32(target_ulong *dst, const target_ulong *src) 27070af384SBlue Swirl { 28070af384SBlue Swirl dst[0] = src[0]; 29070af384SBlue Swirl dst[1] = src[1]; 30070af384SBlue Swirl dst[2] = src[2]; 31070af384SBlue Swirl dst[3] = src[3]; 32070af384SBlue Swirl dst[4] = src[4]; 33070af384SBlue Swirl dst[5] = src[5]; 34070af384SBlue Swirl dst[6] = src[6]; 35070af384SBlue Swirl dst[7] = src[7]; 36070af384SBlue Swirl } 37070af384SBlue Swirl 38c5f9864eSAndreas Färber void cpu_set_cwp(CPUSPARCState *env, int new_cwp) 39070af384SBlue Swirl { 40070af384SBlue Swirl /* put the modified wrap registers at their proper location */ 41070af384SBlue Swirl if (env->cwp == env->nwindows - 1) { 42070af384SBlue Swirl memcpy32(env->regbase, env->regbase + env->nwindows * 16); 43070af384SBlue Swirl } 44070af384SBlue Swirl env->cwp = new_cwp; 45070af384SBlue Swirl 46070af384SBlue Swirl /* put the wrap registers at their temporary location */ 47070af384SBlue Swirl if (new_cwp == env->nwindows - 1) { 48070af384SBlue Swirl memcpy32(env->regbase + env->nwindows * 16, env->regbase); 49070af384SBlue Swirl } 50070af384SBlue Swirl env->regwptr = env->regbase + (new_cwp * 16); 51070af384SBlue Swirl } 52070af384SBlue Swirl 53c5f9864eSAndreas Färber target_ulong cpu_get_psr(CPUSPARCState *env) 54070af384SBlue Swirl { 55070af384SBlue Swirl helper_compute_psr(env); 56070af384SBlue Swirl 57070af384SBlue Swirl #if !defined(TARGET_SPARC64) 58070af384SBlue Swirl return env->version | (env->psr & PSR_ICC) | 59070af384SBlue Swirl (env->psref ? PSR_EF : 0) | 60070af384SBlue Swirl (env->psrpil << 8) | 61070af384SBlue Swirl (env->psrs ? PSR_S : 0) | 62070af384SBlue Swirl (env->psrps ? PSR_PS : 0) | 63070af384SBlue Swirl (env->psret ? PSR_ET : 0) | env->cwp; 64070af384SBlue Swirl #else 65070af384SBlue Swirl return env->psr & PSR_ICC; 66070af384SBlue Swirl #endif 67070af384SBlue Swirl } 68070af384SBlue Swirl 694552a09dSPeter Maydell void cpu_put_psr_raw(CPUSPARCState *env, target_ulong val) 70070af384SBlue Swirl { 71070af384SBlue Swirl env->psr = val & PSR_ICC; 72070af384SBlue Swirl #if !defined(TARGET_SPARC64) 73070af384SBlue Swirl env->psref = (val & PSR_EF) ? 1 : 0; 74070af384SBlue Swirl env->psrpil = (val & PSR_PIL) >> 8; 75070af384SBlue Swirl env->psrs = (val & PSR_S) ? 1 : 0; 76070af384SBlue Swirl env->psrps = (val & PSR_PS) ? 1 : 0; 77070af384SBlue Swirl env->psret = (val & PSR_ET) ? 1 : 0; 78070af384SBlue Swirl #endif 79070af384SBlue Swirl env->cc_op = CC_OP_FLAGS; 804552a09dSPeter Maydell #if !defined(TARGET_SPARC64) 814552a09dSPeter Maydell cpu_set_cwp(env, val & PSR_CWP); 824552a09dSPeter Maydell #endif 834552a09dSPeter Maydell } 844552a09dSPeter Maydell 854552a09dSPeter Maydell void cpu_put_psr(CPUSPARCState *env, target_ulong val) 864552a09dSPeter Maydell { 874552a09dSPeter Maydell cpu_put_psr_raw(env, val); 884552a09dSPeter Maydell #if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY)) 894552a09dSPeter Maydell cpu_check_irqs(env); 904552a09dSPeter Maydell #endif 91070af384SBlue Swirl } 92070af384SBlue Swirl 93c5f9864eSAndreas Färber int cpu_cwp_inc(CPUSPARCState *env, int cwp) 94070af384SBlue Swirl { 95070af384SBlue Swirl if (unlikely(cwp >= env->nwindows)) { 96070af384SBlue Swirl cwp -= env->nwindows; 97070af384SBlue Swirl } 98070af384SBlue Swirl return cwp; 99070af384SBlue Swirl } 100070af384SBlue Swirl 101c5f9864eSAndreas Färber int cpu_cwp_dec(CPUSPARCState *env, int cwp) 102070af384SBlue Swirl { 103070af384SBlue Swirl if (unlikely(cwp < 0)) { 104070af384SBlue Swirl cwp += env->nwindows; 105070af384SBlue Swirl } 106070af384SBlue Swirl return cwp; 107070af384SBlue Swirl } 108070af384SBlue Swirl 109070af384SBlue Swirl #ifndef TARGET_SPARC64 110c5f9864eSAndreas Färber void helper_rett(CPUSPARCState *env) 111070af384SBlue Swirl { 112070af384SBlue Swirl unsigned int cwp; 113070af384SBlue Swirl 114070af384SBlue Swirl if (env->psret == 1) { 1152f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC()); 116070af384SBlue Swirl } 117070af384SBlue Swirl 118070af384SBlue Swirl env->psret = 1; 119063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1) ; 120070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1212f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC()); 122070af384SBlue Swirl } 123063c3675SBlue Swirl cpu_set_cwp(env, cwp); 124070af384SBlue Swirl env->psrs = env->psrps; 125070af384SBlue Swirl } 126070af384SBlue Swirl 127070af384SBlue Swirl /* XXX: use another pointer for %iN registers to avoid slow wrapping 128070af384SBlue Swirl handling ? */ 129c5f9864eSAndreas Färber void helper_save(CPUSPARCState *env) 130070af384SBlue Swirl { 131070af384SBlue Swirl uint32_t cwp; 132070af384SBlue Swirl 133063c3675SBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 134070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1352f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_OVF, GETPC()); 136070af384SBlue Swirl } 137063c3675SBlue Swirl cpu_set_cwp(env, cwp); 138070af384SBlue Swirl } 139070af384SBlue Swirl 140c5f9864eSAndreas Färber void helper_restore(CPUSPARCState *env) 141070af384SBlue Swirl { 142070af384SBlue Swirl uint32_t cwp; 143070af384SBlue Swirl 144063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1); 145070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1462f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC()); 147070af384SBlue Swirl } 148063c3675SBlue Swirl cpu_set_cwp(env, cwp); 149070af384SBlue Swirl } 150070af384SBlue Swirl 151c5f9864eSAndreas Färber void helper_wrpsr(CPUSPARCState *env, target_ulong new_psr) 152070af384SBlue Swirl { 153070af384SBlue Swirl if ((new_psr & PSR_CWP) >= env->nwindows) { 1542f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC()); 155070af384SBlue Swirl } else { 156070af384SBlue Swirl cpu_put_psr(env, new_psr); 157070af384SBlue Swirl } 158070af384SBlue Swirl } 159070af384SBlue Swirl 160c5f9864eSAndreas Färber target_ulong helper_rdpsr(CPUSPARCState *env) 161070af384SBlue Swirl { 162063c3675SBlue Swirl return cpu_get_psr(env); 163070af384SBlue Swirl } 164070af384SBlue Swirl 165070af384SBlue Swirl #else 166070af384SBlue Swirl /* XXX: use another pointer for %iN registers to avoid slow wrapping 167070af384SBlue Swirl handling ? */ 168c5f9864eSAndreas Färber void helper_save(CPUSPARCState *env) 169070af384SBlue Swirl { 170070af384SBlue Swirl uint32_t cwp; 171070af384SBlue Swirl 172063c3675SBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 173070af384SBlue Swirl if (env->cansave == 0) { 1742f9d35fcSRichard Henderson int tt = TT_SPILL | (env->otherwin != 0 1752f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 1762f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 1772f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 178070af384SBlue Swirl } else { 179070af384SBlue Swirl if (env->cleanwin - env->canrestore == 0) { 180070af384SBlue Swirl /* XXX Clean windows without trap */ 1812f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_CLRWIN, GETPC()); 182070af384SBlue Swirl } else { 183070af384SBlue Swirl env->cansave--; 184070af384SBlue Swirl env->canrestore++; 185063c3675SBlue Swirl cpu_set_cwp(env, cwp); 186070af384SBlue Swirl } 187070af384SBlue Swirl } 188070af384SBlue Swirl } 189070af384SBlue Swirl 190c5f9864eSAndreas Färber void helper_restore(CPUSPARCState *env) 191070af384SBlue Swirl { 192070af384SBlue Swirl uint32_t cwp; 193070af384SBlue Swirl 194063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1); 195070af384SBlue Swirl if (env->canrestore == 0) { 1962f9d35fcSRichard Henderson int tt = TT_FILL | (env->otherwin != 0 1972f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 1982f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 1992f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 200070af384SBlue Swirl } else { 201070af384SBlue Swirl env->cansave++; 202070af384SBlue Swirl env->canrestore--; 203063c3675SBlue Swirl cpu_set_cwp(env, cwp); 204070af384SBlue Swirl } 205070af384SBlue Swirl } 206070af384SBlue Swirl 207c5f9864eSAndreas Färber void helper_flushw(CPUSPARCState *env) 208070af384SBlue Swirl { 209070af384SBlue Swirl if (env->cansave != env->nwindows - 2) { 2102f9d35fcSRichard Henderson int tt = TT_SPILL | (env->otherwin != 0 2112f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 2122f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 2132f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 214070af384SBlue Swirl } 215070af384SBlue Swirl } 216070af384SBlue Swirl 217c5f9864eSAndreas Färber void helper_saved(CPUSPARCState *env) 218070af384SBlue Swirl { 219070af384SBlue Swirl env->cansave++; 220070af384SBlue Swirl if (env->otherwin == 0) { 221070af384SBlue Swirl env->canrestore--; 222070af384SBlue Swirl } else { 223070af384SBlue Swirl env->otherwin--; 224070af384SBlue Swirl } 225070af384SBlue Swirl } 226070af384SBlue Swirl 227c5f9864eSAndreas Färber void helper_restored(CPUSPARCState *env) 228070af384SBlue Swirl { 229070af384SBlue Swirl env->canrestore++; 230070af384SBlue Swirl if (env->cleanwin < env->nwindows - 1) { 231070af384SBlue Swirl env->cleanwin++; 232070af384SBlue Swirl } 233070af384SBlue Swirl if (env->otherwin == 0) { 234070af384SBlue Swirl env->cansave--; 235070af384SBlue Swirl } else { 236070af384SBlue Swirl env->otherwin--; 237070af384SBlue Swirl } 238070af384SBlue Swirl } 239070af384SBlue Swirl 240c5f9864eSAndreas Färber target_ulong cpu_get_ccr(CPUSPARCState *env) 241070af384SBlue Swirl { 242070af384SBlue Swirl target_ulong psr; 243070af384SBlue Swirl 244063c3675SBlue Swirl psr = cpu_get_psr(env); 245070af384SBlue Swirl 246070af384SBlue Swirl return ((env->xcc >> 20) << 4) | ((psr & PSR_ICC) >> 20); 247070af384SBlue Swirl } 248070af384SBlue Swirl 249c5f9864eSAndreas Färber void cpu_put_ccr(CPUSPARCState *env, target_ulong val) 250070af384SBlue Swirl { 251070af384SBlue Swirl env->xcc = (val >> 4) << 20; 252070af384SBlue Swirl env->psr = (val & 0xf) << 20; 253070af384SBlue Swirl CC_OP = CC_OP_FLAGS; 254070af384SBlue Swirl } 255070af384SBlue Swirl 256c5f9864eSAndreas Färber target_ulong cpu_get_cwp64(CPUSPARCState *env) 257070af384SBlue Swirl { 258070af384SBlue Swirl return env->nwindows - 1 - env->cwp; 259070af384SBlue Swirl } 260070af384SBlue Swirl 261c5f9864eSAndreas Färber void cpu_put_cwp64(CPUSPARCState *env, int cwp) 262070af384SBlue Swirl { 263070af384SBlue Swirl if (unlikely(cwp >= env->nwindows || cwp < 0)) { 264070af384SBlue Swirl cwp %= env->nwindows; 265070af384SBlue Swirl } 266063c3675SBlue Swirl cpu_set_cwp(env, env->nwindows - 1 - cwp); 267070af384SBlue Swirl } 268070af384SBlue Swirl 269c5f9864eSAndreas Färber target_ulong helper_rdccr(CPUSPARCState *env) 270070af384SBlue Swirl { 271063c3675SBlue Swirl return cpu_get_ccr(env); 272070af384SBlue Swirl } 273070af384SBlue Swirl 274c5f9864eSAndreas Färber void helper_wrccr(CPUSPARCState *env, target_ulong new_ccr) 275070af384SBlue Swirl { 276063c3675SBlue Swirl cpu_put_ccr(env, new_ccr); 277070af384SBlue Swirl } 278070af384SBlue Swirl 279070af384SBlue Swirl /* CWP handling is reversed in V9, but we still use the V8 register 280070af384SBlue Swirl order. */ 281c5f9864eSAndreas Färber target_ulong helper_rdcwp(CPUSPARCState *env) 282070af384SBlue Swirl { 283063c3675SBlue Swirl return cpu_get_cwp64(env); 284070af384SBlue Swirl } 285070af384SBlue Swirl 286c5f9864eSAndreas Färber void helper_wrcwp(CPUSPARCState *env, target_ulong new_cwp) 287070af384SBlue Swirl { 288063c3675SBlue Swirl cpu_put_cwp64(env, new_cwp); 289070af384SBlue Swirl } 290070af384SBlue Swirl 291c5f9864eSAndreas Färber static inline uint64_t *get_gregset(CPUSPARCState *env, uint32_t pstate) 292070af384SBlue Swirl { 293*cbc3a6a4SArtyom Tarasenko if (env->def->features & CPU_FEATURE_GL) { 294*cbc3a6a4SArtyom Tarasenko return env->glregs + (env->gl & 7) * 8; 295*cbc3a6a4SArtyom Tarasenko } 296*cbc3a6a4SArtyom Tarasenko 297070af384SBlue Swirl switch (pstate) { 298070af384SBlue Swirl default: 299870be6adSBlue Swirl trace_win_helper_gregset_error(pstate); 300070af384SBlue Swirl /* pass through to normal set of global registers */ 301070af384SBlue Swirl case 0: 302070af384SBlue Swirl return env->bgregs; 303070af384SBlue Swirl case PS_AG: 304070af384SBlue Swirl return env->agregs; 305070af384SBlue Swirl case PS_MG: 306070af384SBlue Swirl return env->mgregs; 307070af384SBlue Swirl case PS_IG: 308070af384SBlue Swirl return env->igregs; 309070af384SBlue Swirl } 310070af384SBlue Swirl } 311070af384SBlue Swirl 312*cbc3a6a4SArtyom Tarasenko static inline uint64_t *get_gl_gregset(CPUSPARCState *env, uint32_t gl) 313*cbc3a6a4SArtyom Tarasenko { 314*cbc3a6a4SArtyom Tarasenko return env->glregs + (gl & 7) * 8; 315*cbc3a6a4SArtyom Tarasenko } 316*cbc3a6a4SArtyom Tarasenko 317*cbc3a6a4SArtyom Tarasenko /* Switch global register bank */ 318*cbc3a6a4SArtyom Tarasenko void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl) 319*cbc3a6a4SArtyom Tarasenko { 320*cbc3a6a4SArtyom Tarasenko uint64_t *src, *dst; 321*cbc3a6a4SArtyom Tarasenko src = get_gl_gregset(env, new_gl); 322*cbc3a6a4SArtyom Tarasenko dst = get_gl_gregset(env, env->gl); 323*cbc3a6a4SArtyom Tarasenko 324*cbc3a6a4SArtyom Tarasenko if (src != dst) { 325*cbc3a6a4SArtyom Tarasenko memcpy32(dst, env->gregs); 326*cbc3a6a4SArtyom Tarasenko memcpy32(env->gregs, src); 327*cbc3a6a4SArtyom Tarasenko } 328*cbc3a6a4SArtyom Tarasenko } 329*cbc3a6a4SArtyom Tarasenko 330*cbc3a6a4SArtyom Tarasenko void helper_wrgl(CPUSPARCState *env, target_ulong new_gl) 331*cbc3a6a4SArtyom Tarasenko { 332*cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl & 7); 333*cbc3a6a4SArtyom Tarasenko env->gl = new_gl & 7; 334*cbc3a6a4SArtyom Tarasenko } 335*cbc3a6a4SArtyom Tarasenko 336c5f9864eSAndreas Färber void cpu_change_pstate(CPUSPARCState *env, uint32_t new_pstate) 337070af384SBlue Swirl { 338070af384SBlue Swirl uint32_t pstate_regs, new_pstate_regs; 339070af384SBlue Swirl uint64_t *src, *dst; 340070af384SBlue Swirl 341070af384SBlue Swirl if (env->def->features & CPU_FEATURE_GL) { 342*cbc3a6a4SArtyom Tarasenko /* PS_AG, IG and MG are not implemented in this case */ 343*cbc3a6a4SArtyom Tarasenko new_pstate &= ~(PS_AG | PS_IG | PS_MG); 344*cbc3a6a4SArtyom Tarasenko env->pstate = new_pstate; 345*cbc3a6a4SArtyom Tarasenko return; 346070af384SBlue Swirl } 347070af384SBlue Swirl 348070af384SBlue Swirl pstate_regs = env->pstate & 0xc01; 349070af384SBlue Swirl new_pstate_regs = new_pstate & 0xc01; 350070af384SBlue Swirl 351070af384SBlue Swirl if (new_pstate_regs != pstate_regs) { 352870be6adSBlue Swirl trace_win_helper_switch_pstate(pstate_regs, new_pstate_regs); 353870be6adSBlue Swirl 354070af384SBlue Swirl /* Switch global register bank */ 355063c3675SBlue Swirl src = get_gregset(env, new_pstate_regs); 356063c3675SBlue Swirl dst = get_gregset(env, pstate_regs); 357070af384SBlue Swirl memcpy32(dst, env->gregs); 358070af384SBlue Swirl memcpy32(env->gregs, src); 359070af384SBlue Swirl } else { 360870be6adSBlue Swirl trace_win_helper_no_switch_pstate(new_pstate_regs); 361070af384SBlue Swirl } 362070af384SBlue Swirl env->pstate = new_pstate; 363070af384SBlue Swirl } 364070af384SBlue Swirl 365c5f9864eSAndreas Färber void helper_wrpstate(CPUSPARCState *env, target_ulong new_state) 366070af384SBlue Swirl { 367063c3675SBlue Swirl cpu_change_pstate(env, new_state & 0xf3f); 368070af384SBlue Swirl 369070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 370070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 371070af384SBlue Swirl cpu_check_irqs(env); 372070af384SBlue Swirl } 373070af384SBlue Swirl #endif 374070af384SBlue Swirl } 375070af384SBlue Swirl 376c5f9864eSAndreas Färber void helper_wrpil(CPUSPARCState *env, target_ulong new_pil) 377070af384SBlue Swirl { 378070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 379870be6adSBlue Swirl trace_win_helper_wrpil(env->psrpil, (uint32_t)new_pil); 380070af384SBlue Swirl 381070af384SBlue Swirl env->psrpil = new_pil; 382070af384SBlue Swirl 383070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 384070af384SBlue Swirl cpu_check_irqs(env); 385070af384SBlue Swirl } 386070af384SBlue Swirl #endif 387070af384SBlue Swirl } 388070af384SBlue Swirl 389c5f9864eSAndreas Färber void helper_done(CPUSPARCState *env) 390070af384SBlue Swirl { 391070af384SBlue Swirl trap_state *tsptr = cpu_tsptr(env); 392070af384SBlue Swirl 393070af384SBlue Swirl env->pc = tsptr->tnpc; 394070af384SBlue Swirl env->npc = tsptr->tnpc + 4; 395063c3675SBlue Swirl cpu_put_ccr(env, tsptr->tstate >> 32); 396070af384SBlue Swirl env->asi = (tsptr->tstate >> 24) & 0xff; 397063c3675SBlue Swirl cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); 398063c3675SBlue Swirl cpu_put_cwp64(env, tsptr->tstate & 0xff); 3996e040755SArtyom Tarasenko if (cpu_has_hypervisor(env)) { 400*cbc3a6a4SArtyom Tarasenko uint32_t new_gl = (tsptr->tstate >> 40) & 7; 4016e040755SArtyom Tarasenko env->hpstate = env->htstate[env->tl]; 402*cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl); 403*cbc3a6a4SArtyom Tarasenko env->gl = new_gl; 4046e040755SArtyom Tarasenko } 405070af384SBlue Swirl env->tl--; 406070af384SBlue Swirl 407870be6adSBlue Swirl trace_win_helper_done(env->tl); 408070af384SBlue Swirl 409070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 410070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 411070af384SBlue Swirl cpu_check_irqs(env); 412070af384SBlue Swirl } 413070af384SBlue Swirl #endif 414070af384SBlue Swirl } 415070af384SBlue Swirl 416c5f9864eSAndreas Färber void helper_retry(CPUSPARCState *env) 417070af384SBlue Swirl { 418070af384SBlue Swirl trap_state *tsptr = cpu_tsptr(env); 419070af384SBlue Swirl 420070af384SBlue Swirl env->pc = tsptr->tpc; 421070af384SBlue Swirl env->npc = tsptr->tnpc; 422063c3675SBlue Swirl cpu_put_ccr(env, tsptr->tstate >> 32); 423070af384SBlue Swirl env->asi = (tsptr->tstate >> 24) & 0xff; 424063c3675SBlue Swirl cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); 425063c3675SBlue Swirl cpu_put_cwp64(env, tsptr->tstate & 0xff); 4266e040755SArtyom Tarasenko if (cpu_has_hypervisor(env)) { 427*cbc3a6a4SArtyom Tarasenko uint32_t new_gl = (tsptr->tstate >> 40) & 7; 4286e040755SArtyom Tarasenko env->hpstate = env->htstate[env->tl]; 429*cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl); 430*cbc3a6a4SArtyom Tarasenko env->gl = new_gl; 4316e040755SArtyom Tarasenko } 432070af384SBlue Swirl env->tl--; 433070af384SBlue Swirl 434870be6adSBlue Swirl trace_win_helper_retry(env->tl); 435070af384SBlue Swirl 436070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 437070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 438070af384SBlue Swirl cpu_check_irqs(env); 439070af384SBlue Swirl } 440070af384SBlue Swirl #endif 441070af384SBlue Swirl } 442070af384SBlue Swirl #endif 443