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 9*5650b549SChetan Pant * version 2.1 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" 215ee59930SAlex Bennée #include "qemu/main-loop.h" 22070af384SBlue Swirl #include "cpu.h" 232f9d35fcSRichard Henderson #include "exec/exec-all.h" 242ef6175aSRichard Henderson #include "exec/helper-proto.h" 25870be6adSBlue Swirl #include "trace.h" 26070af384SBlue Swirl 27070af384SBlue Swirl static inline void memcpy32(target_ulong *dst, const target_ulong *src) 28070af384SBlue Swirl { 29070af384SBlue Swirl dst[0] = src[0]; 30070af384SBlue Swirl dst[1] = src[1]; 31070af384SBlue Swirl dst[2] = src[2]; 32070af384SBlue Swirl dst[3] = src[3]; 33070af384SBlue Swirl dst[4] = src[4]; 34070af384SBlue Swirl dst[5] = src[5]; 35070af384SBlue Swirl dst[6] = src[6]; 36070af384SBlue Swirl dst[7] = src[7]; 37070af384SBlue Swirl } 38070af384SBlue Swirl 39c5f9864eSAndreas Färber void cpu_set_cwp(CPUSPARCState *env, int new_cwp) 40070af384SBlue Swirl { 41070af384SBlue Swirl /* put the modified wrap registers at their proper location */ 42070af384SBlue Swirl if (env->cwp == env->nwindows - 1) { 43070af384SBlue Swirl memcpy32(env->regbase, env->regbase + env->nwindows * 16); 44070af384SBlue Swirl } 45070af384SBlue Swirl env->cwp = new_cwp; 46070af384SBlue Swirl 47070af384SBlue Swirl /* put the wrap registers at their temporary location */ 48070af384SBlue Swirl if (new_cwp == env->nwindows - 1) { 49070af384SBlue Swirl memcpy32(env->regbase + env->nwindows * 16, env->regbase); 50070af384SBlue Swirl } 51070af384SBlue Swirl env->regwptr = env->regbase + (new_cwp * 16); 52070af384SBlue Swirl } 53070af384SBlue Swirl 54c5f9864eSAndreas Färber target_ulong cpu_get_psr(CPUSPARCState *env) 55070af384SBlue Swirl { 56070af384SBlue Swirl helper_compute_psr(env); 57070af384SBlue Swirl 58070af384SBlue Swirl #if !defined(TARGET_SPARC64) 59070af384SBlue Swirl return env->version | (env->psr & PSR_ICC) | 60070af384SBlue Swirl (env->psref ? PSR_EF : 0) | 61070af384SBlue Swirl (env->psrpil << 8) | 62070af384SBlue Swirl (env->psrs ? PSR_S : 0) | 63070af384SBlue Swirl (env->psrps ? PSR_PS : 0) | 64070af384SBlue Swirl (env->psret ? PSR_ET : 0) | env->cwp; 65070af384SBlue Swirl #else 66070af384SBlue Swirl return env->psr & PSR_ICC; 67070af384SBlue Swirl #endif 68070af384SBlue Swirl } 69070af384SBlue Swirl 704552a09dSPeter Maydell void cpu_put_psr_raw(CPUSPARCState *env, target_ulong val) 71070af384SBlue Swirl { 72070af384SBlue Swirl env->psr = val & PSR_ICC; 73070af384SBlue Swirl #if !defined(TARGET_SPARC64) 74070af384SBlue Swirl env->psref = (val & PSR_EF) ? 1 : 0; 75070af384SBlue Swirl env->psrpil = (val & PSR_PIL) >> 8; 76070af384SBlue Swirl env->psrs = (val & PSR_S) ? 1 : 0; 77070af384SBlue Swirl env->psrps = (val & PSR_PS) ? 1 : 0; 78070af384SBlue Swirl env->psret = (val & PSR_ET) ? 1 : 0; 79070af384SBlue Swirl #endif 80070af384SBlue Swirl env->cc_op = CC_OP_FLAGS; 814552a09dSPeter Maydell #if !defined(TARGET_SPARC64) 824552a09dSPeter Maydell cpu_set_cwp(env, val & PSR_CWP); 834552a09dSPeter Maydell #endif 844552a09dSPeter Maydell } 854552a09dSPeter Maydell 865ee59930SAlex Bennée /* Called with BQL held */ 874552a09dSPeter Maydell void cpu_put_psr(CPUSPARCState *env, target_ulong val) 884552a09dSPeter Maydell { 894552a09dSPeter Maydell cpu_put_psr_raw(env, val); 904552a09dSPeter Maydell #if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY)) 914552a09dSPeter Maydell cpu_check_irqs(env); 924552a09dSPeter Maydell #endif 93070af384SBlue Swirl } 94070af384SBlue Swirl 95c5f9864eSAndreas Färber int cpu_cwp_inc(CPUSPARCState *env, int cwp) 96070af384SBlue Swirl { 97070af384SBlue Swirl if (unlikely(cwp >= env->nwindows)) { 98070af384SBlue Swirl cwp -= env->nwindows; 99070af384SBlue Swirl } 100070af384SBlue Swirl return cwp; 101070af384SBlue Swirl } 102070af384SBlue Swirl 103c5f9864eSAndreas Färber int cpu_cwp_dec(CPUSPARCState *env, int cwp) 104070af384SBlue Swirl { 105070af384SBlue Swirl if (unlikely(cwp < 0)) { 106070af384SBlue Swirl cwp += env->nwindows; 107070af384SBlue Swirl } 108070af384SBlue Swirl return cwp; 109070af384SBlue Swirl } 110070af384SBlue Swirl 111070af384SBlue Swirl #ifndef TARGET_SPARC64 112c5f9864eSAndreas Färber void helper_rett(CPUSPARCState *env) 113070af384SBlue Swirl { 114070af384SBlue Swirl unsigned int cwp; 115070af384SBlue Swirl 116070af384SBlue Swirl if (env->psret == 1) { 1172f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC()); 118070af384SBlue Swirl } 119070af384SBlue Swirl 120070af384SBlue Swirl env->psret = 1; 121063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1) ; 122070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1232f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC()); 124070af384SBlue Swirl } 125063c3675SBlue Swirl cpu_set_cwp(env, cwp); 126070af384SBlue Swirl env->psrs = env->psrps; 127070af384SBlue Swirl } 128070af384SBlue Swirl 129070af384SBlue Swirl /* XXX: use another pointer for %iN registers to avoid slow wrapping 130070af384SBlue Swirl handling ? */ 131c5f9864eSAndreas Färber void helper_save(CPUSPARCState *env) 132070af384SBlue Swirl { 133070af384SBlue Swirl uint32_t cwp; 134070af384SBlue Swirl 135063c3675SBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 136070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1372f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_OVF, GETPC()); 138070af384SBlue Swirl } 139063c3675SBlue Swirl cpu_set_cwp(env, cwp); 140070af384SBlue Swirl } 141070af384SBlue Swirl 142c5f9864eSAndreas Färber void helper_restore(CPUSPARCState *env) 143070af384SBlue Swirl { 144070af384SBlue Swirl uint32_t cwp; 145070af384SBlue Swirl 146063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1); 147070af384SBlue Swirl if (env->wim & (1 << cwp)) { 1482f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC()); 149070af384SBlue Swirl } 150063c3675SBlue Swirl cpu_set_cwp(env, cwp); 151070af384SBlue Swirl } 152070af384SBlue Swirl 153c5f9864eSAndreas Färber void helper_wrpsr(CPUSPARCState *env, target_ulong new_psr) 154070af384SBlue Swirl { 155070af384SBlue Swirl if ((new_psr & PSR_CWP) >= env->nwindows) { 1562f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC()); 157070af384SBlue Swirl } else { 1585ee59930SAlex Bennée /* cpu_put_psr may trigger interrupts, hence BQL */ 1595ee59930SAlex Bennée qemu_mutex_lock_iothread(); 160070af384SBlue Swirl cpu_put_psr(env, new_psr); 1615ee59930SAlex Bennée qemu_mutex_unlock_iothread(); 162070af384SBlue Swirl } 163070af384SBlue Swirl } 164070af384SBlue Swirl 165c5f9864eSAndreas Färber target_ulong helper_rdpsr(CPUSPARCState *env) 166070af384SBlue Swirl { 167063c3675SBlue Swirl return cpu_get_psr(env); 168070af384SBlue Swirl } 169070af384SBlue Swirl 170070af384SBlue Swirl #else 171070af384SBlue Swirl /* XXX: use another pointer for %iN registers to avoid slow wrapping 172070af384SBlue Swirl handling ? */ 173c5f9864eSAndreas Färber void helper_save(CPUSPARCState *env) 174070af384SBlue Swirl { 175070af384SBlue Swirl uint32_t cwp; 176070af384SBlue Swirl 177063c3675SBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 178070af384SBlue Swirl if (env->cansave == 0) { 1792f9d35fcSRichard Henderson int tt = TT_SPILL | (env->otherwin != 0 1802f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 1812f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 1822f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 183070af384SBlue Swirl } else { 184070af384SBlue Swirl if (env->cleanwin - env->canrestore == 0) { 185070af384SBlue Swirl /* XXX Clean windows without trap */ 1862f9d35fcSRichard Henderson cpu_raise_exception_ra(env, TT_CLRWIN, GETPC()); 187070af384SBlue Swirl } else { 188070af384SBlue Swirl env->cansave--; 189070af384SBlue Swirl env->canrestore++; 190063c3675SBlue Swirl cpu_set_cwp(env, cwp); 191070af384SBlue Swirl } 192070af384SBlue Swirl } 193070af384SBlue Swirl } 194070af384SBlue Swirl 195c5f9864eSAndreas Färber void helper_restore(CPUSPARCState *env) 196070af384SBlue Swirl { 197070af384SBlue Swirl uint32_t cwp; 198070af384SBlue Swirl 199063c3675SBlue Swirl cwp = cpu_cwp_inc(env, env->cwp + 1); 200070af384SBlue Swirl if (env->canrestore == 0) { 2012f9d35fcSRichard Henderson int tt = TT_FILL | (env->otherwin != 0 2022f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 2032f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 2042f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 205070af384SBlue Swirl } else { 206070af384SBlue Swirl env->cansave++; 207070af384SBlue Swirl env->canrestore--; 208063c3675SBlue Swirl cpu_set_cwp(env, cwp); 209070af384SBlue Swirl } 210070af384SBlue Swirl } 211070af384SBlue Swirl 212c5f9864eSAndreas Färber void helper_flushw(CPUSPARCState *env) 213070af384SBlue Swirl { 214070af384SBlue Swirl if (env->cansave != env->nwindows - 2) { 2152f9d35fcSRichard Henderson int tt = TT_SPILL | (env->otherwin != 0 2162f9d35fcSRichard Henderson ? (TT_WOTHER | ((env->wstate & 0x38) >> 1)) 2172f9d35fcSRichard Henderson : ((env->wstate & 0x7) << 2)); 2182f9d35fcSRichard Henderson cpu_raise_exception_ra(env, tt, GETPC()); 219070af384SBlue Swirl } 220070af384SBlue Swirl } 221070af384SBlue Swirl 222c5f9864eSAndreas Färber void helper_saved(CPUSPARCState *env) 223070af384SBlue Swirl { 224070af384SBlue Swirl env->cansave++; 225070af384SBlue Swirl if (env->otherwin == 0) { 226070af384SBlue Swirl env->canrestore--; 227070af384SBlue Swirl } else { 228070af384SBlue Swirl env->otherwin--; 229070af384SBlue Swirl } 230070af384SBlue Swirl } 231070af384SBlue Swirl 232c5f9864eSAndreas Färber void helper_restored(CPUSPARCState *env) 233070af384SBlue Swirl { 234070af384SBlue Swirl env->canrestore++; 235070af384SBlue Swirl if (env->cleanwin < env->nwindows - 1) { 236070af384SBlue Swirl env->cleanwin++; 237070af384SBlue Swirl } 238070af384SBlue Swirl if (env->otherwin == 0) { 239070af384SBlue Swirl env->cansave--; 240070af384SBlue Swirl } else { 241070af384SBlue Swirl env->otherwin--; 242070af384SBlue Swirl } 243070af384SBlue Swirl } 244070af384SBlue Swirl 245c5f9864eSAndreas Färber target_ulong cpu_get_ccr(CPUSPARCState *env) 246070af384SBlue Swirl { 247070af384SBlue Swirl target_ulong psr; 248070af384SBlue Swirl 249063c3675SBlue Swirl psr = cpu_get_psr(env); 250070af384SBlue Swirl 251070af384SBlue Swirl return ((env->xcc >> 20) << 4) | ((psr & PSR_ICC) >> 20); 252070af384SBlue Swirl } 253070af384SBlue Swirl 254c5f9864eSAndreas Färber void cpu_put_ccr(CPUSPARCState *env, target_ulong val) 255070af384SBlue Swirl { 256070af384SBlue Swirl env->xcc = (val >> 4) << 20; 257070af384SBlue Swirl env->psr = (val & 0xf) << 20; 258070af384SBlue Swirl CC_OP = CC_OP_FLAGS; 259070af384SBlue Swirl } 260070af384SBlue Swirl 261c5f9864eSAndreas Färber target_ulong cpu_get_cwp64(CPUSPARCState *env) 262070af384SBlue Swirl { 263070af384SBlue Swirl return env->nwindows - 1 - env->cwp; 264070af384SBlue Swirl } 265070af384SBlue Swirl 266c5f9864eSAndreas Färber void cpu_put_cwp64(CPUSPARCState *env, int cwp) 267070af384SBlue Swirl { 268070af384SBlue Swirl if (unlikely(cwp >= env->nwindows || cwp < 0)) { 269070af384SBlue Swirl cwp %= env->nwindows; 270070af384SBlue Swirl } 271063c3675SBlue Swirl cpu_set_cwp(env, env->nwindows - 1 - cwp); 272070af384SBlue Swirl } 273070af384SBlue Swirl 274c5f9864eSAndreas Färber target_ulong helper_rdccr(CPUSPARCState *env) 275070af384SBlue Swirl { 276063c3675SBlue Swirl return cpu_get_ccr(env); 277070af384SBlue Swirl } 278070af384SBlue Swirl 279c5f9864eSAndreas Färber void helper_wrccr(CPUSPARCState *env, target_ulong new_ccr) 280070af384SBlue Swirl { 281063c3675SBlue Swirl cpu_put_ccr(env, new_ccr); 282070af384SBlue Swirl } 283070af384SBlue Swirl 284070af384SBlue Swirl /* CWP handling is reversed in V9, but we still use the V8 register 285070af384SBlue Swirl order. */ 286c5f9864eSAndreas Färber target_ulong helper_rdcwp(CPUSPARCState *env) 287070af384SBlue Swirl { 288063c3675SBlue Swirl return cpu_get_cwp64(env); 289070af384SBlue Swirl } 290070af384SBlue Swirl 291c5f9864eSAndreas Färber void helper_wrcwp(CPUSPARCState *env, target_ulong new_cwp) 292070af384SBlue Swirl { 293063c3675SBlue Swirl cpu_put_cwp64(env, new_cwp); 294070af384SBlue Swirl } 295070af384SBlue Swirl 296c5f9864eSAndreas Färber static inline uint64_t *get_gregset(CPUSPARCState *env, uint32_t pstate) 297070af384SBlue Swirl { 298576e1c4cSIgor Mammedov if (env->def.features & CPU_FEATURE_GL) { 299cbc3a6a4SArtyom Tarasenko return env->glregs + (env->gl & 7) * 8; 300cbc3a6a4SArtyom Tarasenko } 301cbc3a6a4SArtyom Tarasenko 302070af384SBlue Swirl switch (pstate) { 303070af384SBlue Swirl default: 304870be6adSBlue Swirl trace_win_helper_gregset_error(pstate); 305070af384SBlue Swirl /* pass through to normal set of global registers */ 306070af384SBlue Swirl case 0: 307070af384SBlue Swirl return env->bgregs; 308070af384SBlue Swirl case PS_AG: 309070af384SBlue Swirl return env->agregs; 310070af384SBlue Swirl case PS_MG: 311070af384SBlue Swirl return env->mgregs; 312070af384SBlue Swirl case PS_IG: 313070af384SBlue Swirl return env->igregs; 314070af384SBlue Swirl } 315070af384SBlue Swirl } 316070af384SBlue Swirl 317cbc3a6a4SArtyom Tarasenko static inline uint64_t *get_gl_gregset(CPUSPARCState *env, uint32_t gl) 318cbc3a6a4SArtyom Tarasenko { 319cbc3a6a4SArtyom Tarasenko return env->glregs + (gl & 7) * 8; 320cbc3a6a4SArtyom Tarasenko } 321cbc3a6a4SArtyom Tarasenko 322cbc3a6a4SArtyom Tarasenko /* Switch global register bank */ 323cbc3a6a4SArtyom Tarasenko void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl) 324cbc3a6a4SArtyom Tarasenko { 325cbc3a6a4SArtyom Tarasenko uint64_t *src, *dst; 326cbc3a6a4SArtyom Tarasenko src = get_gl_gregset(env, new_gl); 327cbc3a6a4SArtyom Tarasenko dst = get_gl_gregset(env, env->gl); 328cbc3a6a4SArtyom Tarasenko 329cbc3a6a4SArtyom Tarasenko if (src != dst) { 330cbc3a6a4SArtyom Tarasenko memcpy32(dst, env->gregs); 331cbc3a6a4SArtyom Tarasenko memcpy32(env->gregs, src); 332cbc3a6a4SArtyom Tarasenko } 333cbc3a6a4SArtyom Tarasenko } 334cbc3a6a4SArtyom Tarasenko 335cbc3a6a4SArtyom Tarasenko void helper_wrgl(CPUSPARCState *env, target_ulong new_gl) 336cbc3a6a4SArtyom Tarasenko { 337cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl & 7); 338cbc3a6a4SArtyom Tarasenko env->gl = new_gl & 7; 339cbc3a6a4SArtyom Tarasenko } 340cbc3a6a4SArtyom Tarasenko 341c5f9864eSAndreas Färber void cpu_change_pstate(CPUSPARCState *env, uint32_t new_pstate) 342070af384SBlue Swirl { 343070af384SBlue Swirl uint32_t pstate_regs, new_pstate_regs; 344070af384SBlue Swirl uint64_t *src, *dst; 345070af384SBlue Swirl 346576e1c4cSIgor Mammedov if (env->def.features & CPU_FEATURE_GL) { 347cbc3a6a4SArtyom Tarasenko /* PS_AG, IG and MG are not implemented in this case */ 348cbc3a6a4SArtyom Tarasenko new_pstate &= ~(PS_AG | PS_IG | PS_MG); 349cbc3a6a4SArtyom Tarasenko env->pstate = new_pstate; 350cbc3a6a4SArtyom Tarasenko return; 351070af384SBlue Swirl } 352070af384SBlue Swirl 353070af384SBlue Swirl pstate_regs = env->pstate & 0xc01; 354070af384SBlue Swirl new_pstate_regs = new_pstate & 0xc01; 355070af384SBlue Swirl 356070af384SBlue Swirl if (new_pstate_regs != pstate_regs) { 357870be6adSBlue Swirl trace_win_helper_switch_pstate(pstate_regs, new_pstate_regs); 358870be6adSBlue Swirl 359070af384SBlue Swirl /* Switch global register bank */ 360063c3675SBlue Swirl src = get_gregset(env, new_pstate_regs); 361063c3675SBlue Swirl dst = get_gregset(env, pstate_regs); 362070af384SBlue Swirl memcpy32(dst, env->gregs); 363070af384SBlue Swirl memcpy32(env->gregs, src); 364070af384SBlue Swirl } else { 365870be6adSBlue Swirl trace_win_helper_no_switch_pstate(new_pstate_regs); 366070af384SBlue Swirl } 367070af384SBlue Swirl env->pstate = new_pstate; 368070af384SBlue Swirl } 369070af384SBlue Swirl 370c5f9864eSAndreas Färber void helper_wrpstate(CPUSPARCState *env, target_ulong new_state) 371070af384SBlue Swirl { 372063c3675SBlue Swirl cpu_change_pstate(env, new_state & 0xf3f); 373070af384SBlue Swirl 374070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 375070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 3765ee59930SAlex Bennée qemu_mutex_lock_iothread(); 377070af384SBlue Swirl cpu_check_irqs(env); 3785ee59930SAlex Bennée qemu_mutex_unlock_iothread(); 379070af384SBlue Swirl } 380070af384SBlue Swirl #endif 381070af384SBlue Swirl } 382070af384SBlue Swirl 383c5f9864eSAndreas Färber void helper_wrpil(CPUSPARCState *env, target_ulong new_pil) 384070af384SBlue Swirl { 385070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 386870be6adSBlue Swirl trace_win_helper_wrpil(env->psrpil, (uint32_t)new_pil); 387070af384SBlue Swirl 388070af384SBlue Swirl env->psrpil = new_pil; 389070af384SBlue Swirl 390070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 3915ee59930SAlex Bennée qemu_mutex_lock_iothread(); 392070af384SBlue Swirl cpu_check_irqs(env); 3935ee59930SAlex Bennée qemu_mutex_unlock_iothread(); 394070af384SBlue Swirl } 395070af384SBlue Swirl #endif 396070af384SBlue Swirl } 397070af384SBlue Swirl 398c5f9864eSAndreas Färber void helper_done(CPUSPARCState *env) 399070af384SBlue Swirl { 400070af384SBlue Swirl trap_state *tsptr = cpu_tsptr(env); 401070af384SBlue Swirl 402070af384SBlue Swirl env->pc = tsptr->tnpc; 403070af384SBlue Swirl env->npc = tsptr->tnpc + 4; 404063c3675SBlue Swirl cpu_put_ccr(env, tsptr->tstate >> 32); 405070af384SBlue Swirl env->asi = (tsptr->tstate >> 24) & 0xff; 406063c3675SBlue Swirl cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); 407063c3675SBlue Swirl cpu_put_cwp64(env, tsptr->tstate & 0xff); 4086e040755SArtyom Tarasenko if (cpu_has_hypervisor(env)) { 409cbc3a6a4SArtyom Tarasenko uint32_t new_gl = (tsptr->tstate >> 40) & 7; 4106e040755SArtyom Tarasenko env->hpstate = env->htstate[env->tl]; 411cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl); 412cbc3a6a4SArtyom Tarasenko env->gl = new_gl; 4136e040755SArtyom Tarasenko } 414070af384SBlue Swirl env->tl--; 415070af384SBlue Swirl 416870be6adSBlue Swirl trace_win_helper_done(env->tl); 417070af384SBlue Swirl 418070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 419070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 4205ee59930SAlex Bennée qemu_mutex_lock_iothread(); 421070af384SBlue Swirl cpu_check_irqs(env); 4225ee59930SAlex Bennée qemu_mutex_unlock_iothread(); 423070af384SBlue Swirl } 424070af384SBlue Swirl #endif 425070af384SBlue Swirl } 426070af384SBlue Swirl 427c5f9864eSAndreas Färber void helper_retry(CPUSPARCState *env) 428070af384SBlue Swirl { 429070af384SBlue Swirl trap_state *tsptr = cpu_tsptr(env); 430070af384SBlue Swirl 431070af384SBlue Swirl env->pc = tsptr->tpc; 432070af384SBlue Swirl env->npc = tsptr->tnpc; 433063c3675SBlue Swirl cpu_put_ccr(env, tsptr->tstate >> 32); 434070af384SBlue Swirl env->asi = (tsptr->tstate >> 24) & 0xff; 435063c3675SBlue Swirl cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f); 436063c3675SBlue Swirl cpu_put_cwp64(env, tsptr->tstate & 0xff); 4376e040755SArtyom Tarasenko if (cpu_has_hypervisor(env)) { 438cbc3a6a4SArtyom Tarasenko uint32_t new_gl = (tsptr->tstate >> 40) & 7; 4396e040755SArtyom Tarasenko env->hpstate = env->htstate[env->tl]; 440cbc3a6a4SArtyom Tarasenko cpu_gl_switch_gregs(env, new_gl); 441cbc3a6a4SArtyom Tarasenko env->gl = new_gl; 4426e040755SArtyom Tarasenko } 443070af384SBlue Swirl env->tl--; 444070af384SBlue Swirl 445870be6adSBlue Swirl trace_win_helper_retry(env->tl); 446070af384SBlue Swirl 447070af384SBlue Swirl #if !defined(CONFIG_USER_ONLY) 448070af384SBlue Swirl if (cpu_interrupts_enabled(env)) { 4495ee59930SAlex Bennée qemu_mutex_lock_iothread(); 450070af384SBlue Swirl cpu_check_irqs(env); 4515ee59930SAlex Bennée qemu_mutex_unlock_iothread(); 452070af384SBlue Swirl } 453070af384SBlue Swirl #endif 454070af384SBlue Swirl } 455070af384SBlue Swirl #endif 456