2011-08-01 13:03:20 +04:00
|
|
|
/*
|
|
|
|
* Helpers for CWP and PSTATE handling
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:42:35 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-08-01 13:03:20 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:16:59 +03:00
|
|
|
#include "qemu/osdep.h"
|
2017-03-01 16:20:02 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2011-08-01 13:03:20 +04:00
|
|
|
#include "cpu.h"
|
2016-07-12 23:12:50 +03:00
|
|
|
#include "exec/exec-all.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2011-09-11 19:53:35 +04:00
|
|
|
#include "trace.h"
|
2011-08-01 13:03:20 +04:00
|
|
|
|
|
|
|
static inline void memcpy32(target_ulong *dst, const target_ulong *src)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
dst[4] = src[4];
|
|
|
|
dst[5] = src[5];
|
|
|
|
dst[6] = src[6];
|
|
|
|
dst[7] = src[7];
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void cpu_set_cwp(CPUSPARCState *env, int new_cwp)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
/* put the modified wrap registers at their proper location */
|
|
|
|
if (env->cwp == env->nwindows - 1) {
|
|
|
|
memcpy32(env->regbase, env->regbase + env->nwindows * 16);
|
|
|
|
}
|
|
|
|
env->cwp = new_cwp;
|
|
|
|
|
|
|
|
/* put the wrap registers at their temporary location */
|
|
|
|
if (new_cwp == env->nwindows - 1) {
|
|
|
|
memcpy32(env->regbase + env->nwindows * 16, env->regbase);
|
|
|
|
}
|
|
|
|
env->regwptr = env->regbase + (new_cwp * 16);
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong cpu_get_psr(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2023-10-15 04:24:19 +03:00
|
|
|
target_ulong icc = 0;
|
|
|
|
|
|
|
|
icc |= ((int32_t)env->cc_N < 0) << PSR_NEG_SHIFT;
|
|
|
|
icc |= ((int32_t)env->cc_V < 0) << PSR_OVF_SHIFT;
|
|
|
|
icc |= ((int32_t)env->icc_Z == 0) << PSR_ZERO_SHIFT;
|
|
|
|
if (TARGET_LONG_BITS == 64) {
|
|
|
|
icc |= extract64(env->icc_C, 32, 1) << PSR_CARRY_SHIFT;
|
|
|
|
} else {
|
|
|
|
icc |= env->icc_C << PSR_CARRY_SHIFT;
|
|
|
|
}
|
|
|
|
|
2011-08-01 13:03:20 +04:00
|
|
|
#if !defined(TARGET_SPARC64)
|
2023-10-15 04:24:19 +03:00
|
|
|
return env->version | icc |
|
2011-08-01 13:03:20 +04:00
|
|
|
(env->psref ? PSR_EF : 0) |
|
|
|
|
(env->psrpil << 8) |
|
|
|
|
(env->psrs ? PSR_S : 0) |
|
|
|
|
(env->psrps ? PSR_PS : 0) |
|
|
|
|
(env->psret ? PSR_ET : 0) | env->cwp;
|
|
|
|
#else
|
2023-10-15 04:24:19 +03:00
|
|
|
return icc;
|
2011-08-01 13:03:20 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-10-15 00:01:08 +03:00
|
|
|
void cpu_put_psr_icc(CPUSPARCState *env, target_ulong val)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2023-10-15 04:24:19 +03:00
|
|
|
if (TARGET_LONG_BITS == 64) {
|
|
|
|
/* Do not clobber xcc.[NV] */
|
|
|
|
env->cc_N = deposit64(env->cc_N, 0, 32, -(val & PSR_NEG));
|
|
|
|
env->cc_V = deposit64(env->cc_V, 0, 32, -(val & PSR_OVF));
|
|
|
|
env->icc_C = -(val & PSR_CARRY);
|
|
|
|
} else {
|
|
|
|
env->cc_N = -(val & PSR_NEG);
|
|
|
|
env->cc_V = -(val & PSR_OVF);
|
|
|
|
env->icc_C = (val >> PSR_CARRY_SHIFT) & 1;
|
|
|
|
}
|
|
|
|
env->icc_Z = ~val & PSR_ZERO;
|
2023-10-15 00:01:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_put_psr_raw(CPUSPARCState *env, target_ulong val)
|
|
|
|
{
|
|
|
|
cpu_put_psr_icc(env, val);
|
2011-08-01 13:03:20 +04:00
|
|
|
#if !defined(TARGET_SPARC64)
|
|
|
|
env->psref = (val & PSR_EF) ? 1 : 0;
|
|
|
|
env->psrpil = (val & PSR_PIL) >> 8;
|
|
|
|
env->psrs = (val & PSR_S) ? 1 : 0;
|
|
|
|
env->psrps = (val & PSR_PS) ? 1 : 0;
|
|
|
|
env->psret = (val & PSR_ET) ? 1 : 0;
|
|
|
|
#endif
|
2016-01-11 15:40:24 +03:00
|
|
|
#if !defined(TARGET_SPARC64)
|
|
|
|
cpu_set_cwp(env, val & PSR_CWP);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-01 16:20:02 +03:00
|
|
|
/* Called with BQL held */
|
2016-01-11 15:40:24 +03:00
|
|
|
void cpu_put_psr(CPUSPARCState *env, target_ulong val)
|
|
|
|
{
|
|
|
|
cpu_put_psr_raw(env, val);
|
|
|
|
#if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
|
|
|
|
cpu_check_irqs(env);
|
|
|
|
#endif
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
int cpu_cwp_inc(CPUSPARCState *env, int cwp)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
if (unlikely(cwp >= env->nwindows)) {
|
|
|
|
cwp -= env->nwindows;
|
|
|
|
}
|
|
|
|
return cwp;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
int cpu_cwp_dec(CPUSPARCState *env, int cwp)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
if (unlikely(cwp < 0)) {
|
|
|
|
cwp += env->nwindows;
|
|
|
|
}
|
|
|
|
return cwp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TARGET_SPARC64
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_rett(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
unsigned int cwp;
|
|
|
|
|
|
|
|
if (env->psret == 1) {
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
env->psret = 1;
|
2011-07-04 01:01:59 +04:00
|
|
|
cwp = cpu_cwp_inc(env, env->cwp + 1) ;
|
2011-08-01 13:03:20 +04:00
|
|
|
if (env->wim & (1 << cwp)) {
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
env->psrs = env->psrps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: use another pointer for %iN registers to avoid slow wrapping
|
|
|
|
handling ? */
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_save(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
uint32_t cwp;
|
|
|
|
|
2011-07-04 01:01:59 +04:00
|
|
|
cwp = cpu_cwp_dec(env, env->cwp - 1);
|
2011-08-01 13:03:20 +04:00
|
|
|
if (env->wim & (1 << cwp)) {
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_WIN_OVF, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_restore(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
uint32_t cwp;
|
|
|
|
|
2011-07-04 01:01:59 +04:00
|
|
|
cwp = cpu_cwp_inc(env, env->cwp + 1);
|
2011-08-01 13:03:20 +04:00
|
|
|
if (env->wim & (1 << cwp)) {
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_WIN_UNF, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_wrpsr(CPUSPARCState *env, target_ulong new_psr)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
if ((new_psr & PSR_CWP) >= env->nwindows) {
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
} else {
|
2017-03-01 16:20:02 +03:00
|
|
|
/* cpu_put_psr may trigger interrupts, hence BQL */
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_lock();
|
2011-08-01 13:03:20 +04:00
|
|
|
cpu_put_psr(env, new_psr);
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_unlock();
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong helper_rdpsr(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
return cpu_get_psr(env);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* XXX: use another pointer for %iN registers to avoid slow wrapping
|
|
|
|
handling ? */
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_save(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
uint32_t cwp;
|
|
|
|
|
2011-07-04 01:01:59 +04:00
|
|
|
cwp = cpu_cwp_dec(env, env->cwp - 1);
|
2011-08-01 13:03:20 +04:00
|
|
|
if (env->cansave == 0) {
|
2016-07-12 23:12:50 +03:00
|
|
|
int tt = TT_SPILL | (env->otherwin != 0
|
|
|
|
? (TT_WOTHER | ((env->wstate & 0x38) >> 1))
|
|
|
|
: ((env->wstate & 0x7) << 2));
|
|
|
|
cpu_raise_exception_ra(env, tt, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
} else {
|
|
|
|
if (env->cleanwin - env->canrestore == 0) {
|
|
|
|
/* XXX Clean windows without trap */
|
2016-07-12 23:12:50 +03:00
|
|
|
cpu_raise_exception_ra(env, TT_CLRWIN, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
} else {
|
|
|
|
env->cansave--;
|
|
|
|
env->canrestore++;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_restore(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
uint32_t cwp;
|
|
|
|
|
2011-07-04 01:01:59 +04:00
|
|
|
cwp = cpu_cwp_inc(env, env->cwp + 1);
|
2011-08-01 13:03:20 +04:00
|
|
|
if (env->canrestore == 0) {
|
2016-07-12 23:12:50 +03:00
|
|
|
int tt = TT_FILL | (env->otherwin != 0
|
|
|
|
? (TT_WOTHER | ((env->wstate & 0x38) >> 1))
|
|
|
|
: ((env->wstate & 0x7) << 2));
|
|
|
|
cpu_raise_exception_ra(env, tt, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
} else {
|
|
|
|
env->cansave++;
|
|
|
|
env->canrestore--;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_flushw(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
if (env->cansave != env->nwindows - 2) {
|
2016-07-12 23:12:50 +03:00
|
|
|
int tt = TT_SPILL | (env->otherwin != 0
|
|
|
|
? (TT_WOTHER | ((env->wstate & 0x38) >> 1))
|
|
|
|
: ((env->wstate & 0x7) << 2));
|
|
|
|
cpu_raise_exception_ra(env, tt, GETPC());
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_saved(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
env->cansave++;
|
|
|
|
if (env->otherwin == 0) {
|
|
|
|
env->canrestore--;
|
|
|
|
} else {
|
|
|
|
env->otherwin--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_restored(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
env->canrestore++;
|
|
|
|
if (env->cleanwin < env->nwindows - 1) {
|
|
|
|
env->cleanwin++;
|
|
|
|
}
|
|
|
|
if (env->otherwin == 0) {
|
|
|
|
env->cansave--;
|
|
|
|
} else {
|
|
|
|
env->otherwin--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong cpu_get_ccr(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2023-10-15 04:24:19 +03:00
|
|
|
target_ulong ccr = 0;
|
|
|
|
|
|
|
|
ccr |= (env->icc_C >> 32) & 1;
|
|
|
|
ccr |= ((int32_t)env->cc_V < 0) << 1;
|
|
|
|
ccr |= ((int32_t)env->icc_Z == 0) << 2;
|
|
|
|
ccr |= ((int32_t)env->cc_N < 0) << 3;
|
2011-08-01 13:03:20 +04:00
|
|
|
|
2023-10-15 04:24:19 +03:00
|
|
|
ccr |= env->xcc_C << 4;
|
|
|
|
ccr |= (env->cc_V < 0) << 5;
|
|
|
|
ccr |= (env->xcc_Z == 0) << 6;
|
|
|
|
ccr |= (env->cc_N < 0) << 7;
|
|
|
|
|
|
|
|
return ccr;
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void cpu_put_ccr(CPUSPARCState *env, target_ulong val)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2023-10-15 04:24:19 +03:00
|
|
|
env->cc_N = deposit64(-(val & 0x08), 32, 32, -(val & 0x80));
|
|
|
|
env->cc_V = deposit64(-(val & 0x02), 32, 32, -(val & 0x20));
|
|
|
|
env->icc_C = (uint64_t)val << 32;
|
|
|
|
env->xcc_C = (val >> 4) & 1;
|
|
|
|
env->icc_Z = ~val & 0x04;
|
|
|
|
env->xcc_Z = ~val & 0x40;
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong cpu_get_cwp64(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
return env->nwindows - 1 - env->cwp;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void cpu_put_cwp64(CPUSPARCState *env, int cwp)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
if (unlikely(cwp >= env->nwindows || cwp < 0)) {
|
|
|
|
cwp %= env->nwindows;
|
|
|
|
}
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_set_cwp(env, env->nwindows - 1 - cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong helper_rdccr(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
return cpu_get_ccr(env);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_wrccr(CPUSPARCState *env, target_ulong new_ccr)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_put_ccr(env, new_ccr);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CWP handling is reversed in V9, but we still use the V8 register
|
|
|
|
order. */
|
2012-03-14 04:38:22 +04:00
|
|
|
target_ulong helper_rdcwp(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
return cpu_get_cwp64(env);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_wrcwp(CPUSPARCState *env, target_ulong new_cwp)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_put_cwp64(env, new_cwp);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static inline uint64_t *get_gregset(CPUSPARCState *env, uint32_t pstate)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2017-08-24 19:31:26 +03:00
|
|
|
if (env->def.features & CPU_FEATURE_GL) {
|
2016-06-07 19:34:49 +03:00
|
|
|
return env->glregs + (env->gl & 7) * 8;
|
|
|
|
}
|
|
|
|
|
2011-08-01 13:03:20 +04:00
|
|
|
switch (pstate) {
|
|
|
|
default:
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_gregset_error(pstate);
|
2020-12-11 18:24:23 +03:00
|
|
|
/* fall through to normal set of global registers */
|
2011-08-01 13:03:20 +04:00
|
|
|
case 0:
|
|
|
|
return env->bgregs;
|
|
|
|
case PS_AG:
|
|
|
|
return env->agregs;
|
|
|
|
case PS_MG:
|
|
|
|
return env->mgregs;
|
|
|
|
case PS_IG:
|
|
|
|
return env->igregs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:34:49 +03:00
|
|
|
static inline uint64_t *get_gl_gregset(CPUSPARCState *env, uint32_t gl)
|
|
|
|
{
|
|
|
|
return env->glregs + (gl & 7) * 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Switch global register bank */
|
|
|
|
void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl)
|
|
|
|
{
|
|
|
|
uint64_t *src, *dst;
|
|
|
|
src = get_gl_gregset(env, new_gl);
|
|
|
|
dst = get_gl_gregset(env, env->gl);
|
|
|
|
|
|
|
|
if (src != dst) {
|
|
|
|
memcpy32(dst, env->gregs);
|
|
|
|
memcpy32(env->gregs, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_wrgl(CPUSPARCState *env, target_ulong new_gl)
|
|
|
|
{
|
|
|
|
cpu_gl_switch_gregs(env, new_gl & 7);
|
|
|
|
env->gl = new_gl & 7;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void cpu_change_pstate(CPUSPARCState *env, uint32_t new_pstate)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
uint32_t pstate_regs, new_pstate_regs;
|
|
|
|
uint64_t *src, *dst;
|
|
|
|
|
2017-08-24 19:31:26 +03:00
|
|
|
if (env->def.features & CPU_FEATURE_GL) {
|
2016-06-07 19:34:49 +03:00
|
|
|
/* PS_AG, IG and MG are not implemented in this case */
|
|
|
|
new_pstate &= ~(PS_AG | PS_IG | PS_MG);
|
|
|
|
env->pstate = new_pstate;
|
|
|
|
return;
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pstate_regs = env->pstate & 0xc01;
|
|
|
|
new_pstate_regs = new_pstate & 0xc01;
|
|
|
|
|
|
|
|
if (new_pstate_regs != pstate_regs) {
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_switch_pstate(pstate_regs, new_pstate_regs);
|
|
|
|
|
2011-08-01 13:03:20 +04:00
|
|
|
/* Switch global register bank */
|
2011-07-04 01:01:59 +04:00
|
|
|
src = get_gregset(env, new_pstate_regs);
|
|
|
|
dst = get_gregset(env, pstate_regs);
|
2011-08-01 13:03:20 +04:00
|
|
|
memcpy32(dst, env->gregs);
|
|
|
|
memcpy32(env->gregs, src);
|
|
|
|
} else {
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_no_switch_pstate(new_pstate_regs);
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
env->pstate = new_pstate;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_wrpstate(CPUSPARCState *env, target_ulong new_state)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_change_pstate(env, new_state & 0xf3f);
|
2011-08-01 13:03:20 +04:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (cpu_interrupts_enabled(env)) {
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_lock();
|
2011-08-01 13:03:20 +04:00
|
|
|
cpu_check_irqs(env);
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_unlock();
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_wrpil(CPUSPARCState *env, target_ulong new_pil)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_wrpil(env->psrpil, (uint32_t)new_pil);
|
2011-08-01 13:03:20 +04:00
|
|
|
|
|
|
|
env->psrpil = new_pil;
|
|
|
|
|
|
|
|
if (cpu_interrupts_enabled(env)) {
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_lock();
|
2011-08-01 13:03:20 +04:00
|
|
|
cpu_check_irqs(env);
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_unlock();
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_done(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
trap_state *tsptr = cpu_tsptr(env);
|
|
|
|
|
|
|
|
env->pc = tsptr->tnpc;
|
|
|
|
env->npc = tsptr->tnpc + 4;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_put_ccr(env, tsptr->tstate >> 32);
|
2011-08-01 13:03:20 +04:00
|
|
|
env->asi = (tsptr->tstate >> 24) & 0xff;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f);
|
|
|
|
cpu_put_cwp64(env, tsptr->tstate & 0xff);
|
2016-06-07 19:33:53 +03:00
|
|
|
if (cpu_has_hypervisor(env)) {
|
2016-06-07 19:34:49 +03:00
|
|
|
uint32_t new_gl = (tsptr->tstate >> 40) & 7;
|
2016-06-07 19:33:53 +03:00
|
|
|
env->hpstate = env->htstate[env->tl];
|
2016-06-07 19:34:49 +03:00
|
|
|
cpu_gl_switch_gregs(env, new_gl);
|
|
|
|
env->gl = new_gl;
|
2016-06-07 19:33:53 +03:00
|
|
|
}
|
2011-08-01 13:03:20 +04:00
|
|
|
env->tl--;
|
|
|
|
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_done(env->tl);
|
2011-08-01 13:03:20 +04:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (cpu_interrupts_enabled(env)) {
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_lock();
|
2011-08-01 13:03:20 +04:00
|
|
|
cpu_check_irqs(env);
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_unlock();
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
void helper_retry(CPUSPARCState *env)
|
2011-08-01 13:03:20 +04:00
|
|
|
{
|
|
|
|
trap_state *tsptr = cpu_tsptr(env);
|
|
|
|
|
|
|
|
env->pc = tsptr->tpc;
|
|
|
|
env->npc = tsptr->tnpc;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_put_ccr(env, tsptr->tstate >> 32);
|
2011-08-01 13:03:20 +04:00
|
|
|
env->asi = (tsptr->tstate >> 24) & 0xff;
|
2011-07-04 01:01:59 +04:00
|
|
|
cpu_change_pstate(env, (tsptr->tstate >> 8) & 0xf3f);
|
|
|
|
cpu_put_cwp64(env, tsptr->tstate & 0xff);
|
2016-06-07 19:33:53 +03:00
|
|
|
if (cpu_has_hypervisor(env)) {
|
2016-06-07 19:34:49 +03:00
|
|
|
uint32_t new_gl = (tsptr->tstate >> 40) & 7;
|
2016-06-07 19:33:53 +03:00
|
|
|
env->hpstate = env->htstate[env->tl];
|
2016-06-07 19:34:49 +03:00
|
|
|
cpu_gl_switch_gregs(env, new_gl);
|
|
|
|
env->gl = new_gl;
|
2016-06-07 19:33:53 +03:00
|
|
|
}
|
2011-08-01 13:03:20 +04:00
|
|
|
env->tl--;
|
|
|
|
|
2011-09-11 19:53:35 +04:00
|
|
|
trace_win_helper_retry(env->tl);
|
2011-08-01 13:03:20 +04:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (cpu_interrupts_enabled(env)) {
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_lock();
|
2011-08-01 13:03:20 +04:00
|
|
|
cpu_check_irqs(env);
|
2024-01-02 18:35:25 +03:00
|
|
|
bql_unlock();
|
2011-08-01 13:03:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|