blob: 271fddf17f0aa4862ef6503f679bf35c0b3c4315 [file] [log] [blame]
j_mayer0411a972007-10-25 21:35:50 +00001/*
2 * PowerPC emulation special registers manipulation helpers for qemu.
3 *
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
j_mayer0411a972007-10-25 21:35:50 +000018 */
19
20#if !defined(__HELPER_REGS_H__)
21#define __HELPER_REGS_H__
22
j_mayer0411a972007-10-25 21:35:50 +000023/* Swap temporary saved registers with GPRs */
Blue Swirl636aa202009-08-16 09:06:54 +000024static inline void hreg_swap_gpr_tgpr(CPUPPCState *env)
j_mayer0411a972007-10-25 21:35:50 +000025{
aurel32bd7d9a62008-09-04 05:26:09 +000026 target_ulong tmp;
j_mayer0411a972007-10-25 21:35:50 +000027
28 tmp = env->gpr[0];
29 env->gpr[0] = env->tgpr[0];
30 env->tgpr[0] = tmp;
31 tmp = env->gpr[1];
32 env->gpr[1] = env->tgpr[1];
33 env->tgpr[1] = tmp;
34 tmp = env->gpr[2];
35 env->gpr[2] = env->tgpr[2];
36 env->tgpr[2] = tmp;
37 tmp = env->gpr[3];
38 env->gpr[3] = env->tgpr[3];
39 env->tgpr[3] = tmp;
40}
41
Blue Swirl636aa202009-08-16 09:06:54 +000042static inline void hreg_compute_mem_idx(CPUPPCState *env)
j_mayer056401e2007-11-04 02:55:33 +000043{
j_mayer056401e2007-11-04 02:55:33 +000044 /* Precompute MMU index */
j_mayera4f30712007-11-17 21:14:09 +000045 if (msr_pr == 0 && msr_hv != 0) {
j_mayer056401e2007-11-04 02:55:33 +000046 env->mmu_idx = 2;
j_mayera4f30712007-11-17 21:14:09 +000047 } else {
j_mayer056401e2007-11-04 02:55:33 +000048 env->mmu_idx = 1 - msr_pr;
j_mayera4f30712007-11-17 21:14:09 +000049 }
j_mayer056401e2007-11-04 02:55:33 +000050}
51
Blue Swirl636aa202009-08-16 09:06:54 +000052static inline void hreg_compute_hflags(CPUPPCState *env)
j_mayer0411a972007-10-25 21:35:50 +000053{
54 target_ulong hflags_mask;
55
56 /* We 'forget' FE0 & FE1: we'll never generate imprecise exceptions */
57 hflags_mask = (1 << MSR_VR) | (1 << MSR_AP) | (1 << MSR_SA) |
58 (1 << MSR_PR) | (1 << MSR_FP) | (1 << MSR_SE) | (1 << MSR_BE) |
Alexander Grafc2b63f02013-12-18 09:21:02 +010059 (1 << MSR_LE) | (1 << MSR_VSX);
j_mayera4f30712007-11-17 21:14:09 +000060 hflags_mask |= (1ULL << MSR_CM) | (1ULL << MSR_SF) | MSR_HVB;
j_mayer056401e2007-11-04 02:55:33 +000061 hreg_compute_mem_idx(env);
j_mayer0411a972007-10-25 21:35:50 +000062 env->hflags = env->msr & hflags_mask;
j_mayer056401e2007-11-04 02:55:33 +000063 /* Merge with hflags coming from other registers */
64 env->hflags |= env->hflags_nmsr;
j_mayer0411a972007-10-25 21:35:50 +000065}
66
Blue Swirl636aa202009-08-16 09:06:54 +000067static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
68 int alter_hv)
j_mayer0411a972007-10-25 21:35:50 +000069{
j_mayer2f462812007-10-25 23:14:50 +000070 int excp;
Andreas Färber259186a2013-01-17 18:51:17 +010071#if !defined(CONFIG_USER_ONLY)
72 CPUState *cs = CPU(ppc_env_get_cpu(env));
73#endif
j_mayer0411a972007-10-25 21:35:50 +000074
75 excp = 0;
76 value &= env->msr_mask;
Andreas Färber259186a2013-01-17 18:51:17 +010077#if !defined(CONFIG_USER_ONLY)
j_mayera4f30712007-11-17 21:14:09 +000078 if (!alter_hv) {
79 /* mtmsr cannot alter the hypervisor state */
80 value &= ~MSR_HVB;
81 value |= env->msr & MSR_HVB;
82 }
j_mayer0411a972007-10-25 21:35:50 +000083 if (((value >> MSR_IR) & 1) != msr_ir ||
84 ((value >> MSR_DR) & 1) != msr_dr) {
85 /* Flush all tlb when changing translation mode */
Andreas Färber00c8cb02013-09-04 02:19:44 +020086 tlb_flush(cs, 1);
j_mayer0411a972007-10-25 21:35:50 +000087 excp = POWERPC_EXCP_NONE;
Andreas Färber259186a2013-01-17 18:51:17 +010088 cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
j_mayer0411a972007-10-25 21:35:50 +000089 }
90 if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
91 ((value ^ env->msr) & (1 << MSR_TGPR)))) {
92 /* Swap temporary saved registers with GPRs */
93 hreg_swap_gpr_tgpr(env);
94 }
95 if (unlikely((value >> MSR_EP) & 1) != msr_ep) {
96 /* Change the exception prefix on PowerPC 601 */
97 env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000;
98 }
99#endif
100 env->msr = value;
101 hreg_compute_hflags(env);
Andreas Färber259186a2013-01-17 18:51:17 +0100102#if !defined(CONFIG_USER_ONLY)
j_mayer0411a972007-10-25 21:35:50 +0000103 if (unlikely(msr_pow == 1)) {
Alexander Graf05edc262014-04-06 22:40:47 +0200104 if (!env->pending_interrupts && (*env->check_pow)(env)) {
Andreas Färber259186a2013-01-17 18:51:17 +0100105 cs->halted = 1;
j_mayer0411a972007-10-25 21:35:50 +0000106 excp = EXCP_HALTED;
107 }
108 }
109#endif
110
111 return excp;
112}
113
114#endif /* !defined(__HELPER_REGS_H__) */