2007-10-26 01:35:50 +04:00
|
|
|
/*
|
|
|
|
* PowerPC emulation special registers manipulation helpers for qemu.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2009-07-17 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-10-26 01:35:50 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(__HELPER_REGS_H__)
|
|
|
|
#define __HELPER_REGS_H__
|
|
|
|
|
|
|
|
/* Swap temporary saved registers with GPRs */
|
2009-08-16 13:06:54 +04:00
|
|
|
static inline void hreg_swap_gpr_tgpr(CPUPPCState *env)
|
2007-10-26 01:35:50 +04:00
|
|
|
{
|
2008-09-04 09:26:09 +04:00
|
|
|
target_ulong tmp;
|
2007-10-26 01:35:50 +04:00
|
|
|
|
|
|
|
tmp = env->gpr[0];
|
|
|
|
env->gpr[0] = env->tgpr[0];
|
|
|
|
env->tgpr[0] = tmp;
|
|
|
|
tmp = env->gpr[1];
|
|
|
|
env->gpr[1] = env->tgpr[1];
|
|
|
|
env->tgpr[1] = tmp;
|
|
|
|
tmp = env->gpr[2];
|
|
|
|
env->gpr[2] = env->tgpr[2];
|
|
|
|
env->tgpr[2] = tmp;
|
|
|
|
tmp = env->gpr[3];
|
|
|
|
env->gpr[3] = env->tgpr[3];
|
|
|
|
env->tgpr[3] = tmp;
|
|
|
|
}
|
|
|
|
|
2009-08-16 13:06:54 +04:00
|
|
|
static inline void hreg_compute_mem_idx(CPUPPCState *env)
|
2007-11-04 05:55:33 +03:00
|
|
|
{
|
|
|
|
/* Precompute MMU index */
|
2007-11-18 00:14:09 +03:00
|
|
|
if (msr_pr == 0 && msr_hv != 0) {
|
2007-11-04 05:55:33 +03:00
|
|
|
env->mmu_idx = 2;
|
2007-11-18 00:14:09 +03:00
|
|
|
} else {
|
2007-11-04 05:55:33 +03:00
|
|
|
env->mmu_idx = 1 - msr_pr;
|
2007-11-18 00:14:09 +03:00
|
|
|
}
|
2007-11-04 05:55:33 +03:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:06:54 +04:00
|
|
|
static inline void hreg_compute_hflags(CPUPPCState *env)
|
2007-10-26 01:35:50 +04:00
|
|
|
{
|
|
|
|
target_ulong hflags_mask;
|
|
|
|
|
|
|
|
/* We 'forget' FE0 & FE1: we'll never generate imprecise exceptions */
|
|
|
|
hflags_mask = (1 << MSR_VR) | (1 << MSR_AP) | (1 << MSR_SA) |
|
|
|
|
(1 << MSR_PR) | (1 << MSR_FP) | (1 << MSR_SE) | (1 << MSR_BE) |
|
2013-12-18 12:21:02 +04:00
|
|
|
(1 << MSR_LE) | (1 << MSR_VSX);
|
2007-11-18 00:14:09 +03:00
|
|
|
hflags_mask |= (1ULL << MSR_CM) | (1ULL << MSR_SF) | MSR_HVB;
|
2007-11-04 05:55:33 +03:00
|
|
|
hreg_compute_mem_idx(env);
|
2007-10-26 01:35:50 +04:00
|
|
|
env->hflags = env->msr & hflags_mask;
|
2007-11-04 05:55:33 +03:00
|
|
|
/* Merge with hflags coming from other registers */
|
|
|
|
env->hflags |= env->hflags_nmsr;
|
2007-10-26 01:35:50 +04:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:06:54 +04:00
|
|
|
static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
|
|
|
|
int alter_hv)
|
2007-10-26 01:35:50 +04:00
|
|
|
{
|
2007-10-26 03:14:50 +04:00
|
|
|
int excp;
|
2013-01-17 21:51:17 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
|
|
|
#endif
|
2007-10-26 01:35:50 +04:00
|
|
|
|
|
|
|
excp = 0;
|
|
|
|
value &= env->msr_mask;
|
2013-01-17 21:51:17 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2007-11-18 00:14:09 +03:00
|
|
|
if (!alter_hv) {
|
|
|
|
/* mtmsr cannot alter the hypervisor state */
|
|
|
|
value &= ~MSR_HVB;
|
|
|
|
value |= env->msr & MSR_HVB;
|
|
|
|
}
|
2007-10-26 01:35:50 +04:00
|
|
|
if (((value >> MSR_IR) & 1) != msr_ir ||
|
|
|
|
((value >> MSR_DR) & 1) != msr_dr) {
|
|
|
|
/* Flush all tlb when changing translation mode */
|
|
|
|
tlb_flush(env, 1);
|
|
|
|
excp = POWERPC_EXCP_NONE;
|
2013-01-17 21:51:17 +04:00
|
|
|
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
2007-10-26 01:35:50 +04:00
|
|
|
}
|
|
|
|
if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
|
|
|
|
((value ^ env->msr) & (1 << MSR_TGPR)))) {
|
|
|
|
/* Swap temporary saved registers with GPRs */
|
|
|
|
hreg_swap_gpr_tgpr(env);
|
|
|
|
}
|
|
|
|
if (unlikely((value >> MSR_EP) & 1) != msr_ep) {
|
|
|
|
/* Change the exception prefix on PowerPC 601 */
|
|
|
|
env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
env->msr = value;
|
|
|
|
hreg_compute_hflags(env);
|
2013-01-17 21:51:17 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2007-10-26 01:35:50 +04:00
|
|
|
if (unlikely(msr_pow == 1)) {
|
2007-10-26 03:14:50 +04:00
|
|
|
if ((*env->check_pow)(env)) {
|
2013-01-17 21:51:17 +04:00
|
|
|
cs->halted = 1;
|
2007-10-26 01:35:50 +04:00
|
|
|
excp = EXCP_HALTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return excp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(__HELPER_REGS_H__) */
|