18a05fd9aSRichard Henderson /*
28a05fd9aSRichard Henderson * PowerPC emulation special registers manipulation helpers for qemu.
38a05fd9aSRichard Henderson *
48a05fd9aSRichard Henderson * Copyright (c) 2003-2007 Jocelyn Mayer
58a05fd9aSRichard Henderson *
68a05fd9aSRichard Henderson * This library is free software; you can redistribute it and/or
78a05fd9aSRichard Henderson * modify it under the terms of the GNU Lesser General Public
88a05fd9aSRichard Henderson * License as published by the Free Software Foundation; either
98a05fd9aSRichard Henderson * version 2.1 of the License, or (at your option) any later version.
108a05fd9aSRichard Henderson *
118a05fd9aSRichard Henderson * This library is distributed in the hope that it will be useful,
128a05fd9aSRichard Henderson * but WITHOUT ANY WARRANTY; without even the implied warranty of
138a05fd9aSRichard Henderson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
148a05fd9aSRichard Henderson * Lesser General Public License for more details.
158a05fd9aSRichard Henderson *
168a05fd9aSRichard Henderson * You should have received a copy of the GNU Lesser General Public
178a05fd9aSRichard Henderson * License along with this library; if not, see <http://www.gnu.org/licenses/>.
188a05fd9aSRichard Henderson */
198a05fd9aSRichard Henderson
208a05fd9aSRichard Henderson #include "qemu/osdep.h"
212df4fe7aSRichard Henderson #include "cpu.h"
228a05fd9aSRichard Henderson #include "qemu/main-loop.h"
238a05fd9aSRichard Henderson #include "exec/exec-all.h"
248a05fd9aSRichard Henderson #include "sysemu/kvm.h"
2503ac0a0cSRichard Henderson #include "sysemu/tcg.h"
268a05fd9aSRichard Henderson #include "helper_regs.h"
2746d396bdSDaniel Henrique Barboza #include "power8-pmu.h"
2865e0446cSFabiano Rosas #include "cpu-models.h"
2965e0446cSFabiano Rosas #include "spr_common.h"
308a05fd9aSRichard Henderson
318a05fd9aSRichard Henderson /* Swap temporary saved registers with GPRs */
hreg_swap_gpr_tgpr(CPUPPCState * env)328a05fd9aSRichard Henderson void hreg_swap_gpr_tgpr(CPUPPCState *env)
338a05fd9aSRichard Henderson {
348a05fd9aSRichard Henderson target_ulong tmp;
358a05fd9aSRichard Henderson
368a05fd9aSRichard Henderson tmp = env->gpr[0];
378a05fd9aSRichard Henderson env->gpr[0] = env->tgpr[0];
388a05fd9aSRichard Henderson env->tgpr[0] = tmp;
398a05fd9aSRichard Henderson tmp = env->gpr[1];
408a05fd9aSRichard Henderson env->gpr[1] = env->tgpr[1];
418a05fd9aSRichard Henderson env->tgpr[1] = tmp;
428a05fd9aSRichard Henderson tmp = env->gpr[2];
438a05fd9aSRichard Henderson env->gpr[2] = env->tgpr[2];
448a05fd9aSRichard Henderson env->tgpr[2] = tmp;
458a05fd9aSRichard Henderson tmp = env->gpr[3];
468a05fd9aSRichard Henderson env->gpr[3] = env->tgpr[3];
478a05fd9aSRichard Henderson env->tgpr[3] = tmp;
488a05fd9aSRichard Henderson }
498a05fd9aSRichard Henderson
50a7138e28SGlenn Miles #if defined(TARGET_PPC64)
hreg_check_bhrb_enable(CPUPPCState * env)51a7138e28SGlenn Miles static bool hreg_check_bhrb_enable(CPUPPCState *env)
52a7138e28SGlenn Miles {
53a7138e28SGlenn Miles bool pr = !!(env->msr & (1 << MSR_PR));
54a7138e28SGlenn Miles target_long mmcr0;
55a7138e28SGlenn Miles bool fcp;
56a7138e28SGlenn Miles bool hv;
57a7138e28SGlenn Miles
58a7138e28SGlenn Miles /* ISA 3.1 adds the PMCRA[BRHBRD] and problem state checks */
59a7138e28SGlenn Miles if ((env->insns_flags2 & PPC2_ISA310) &&
60a7138e28SGlenn Miles ((env->spr[SPR_POWER_MMCRA] & MMCRA_BHRBRD) || !pr)) {
61a7138e28SGlenn Miles return false;
62a7138e28SGlenn Miles }
63a7138e28SGlenn Miles
64a7138e28SGlenn Miles /* Check for BHRB "frozen" conditions */
65a7138e28SGlenn Miles mmcr0 = env->spr[SPR_POWER_MMCR0];
66a7138e28SGlenn Miles fcp = !!(mmcr0 & MMCR0_FCP);
67a7138e28SGlenn Miles if (mmcr0 & MMCR0_FCPC) {
68a7138e28SGlenn Miles hv = !!(env->msr & (1ull << MSR_HV));
69a7138e28SGlenn Miles if (fcp) {
70a7138e28SGlenn Miles if (hv && pr) {
71a7138e28SGlenn Miles return false;
72a7138e28SGlenn Miles }
73a7138e28SGlenn Miles } else if (!hv && pr) {
74a7138e28SGlenn Miles return false;
75a7138e28SGlenn Miles }
76a7138e28SGlenn Miles } else if (fcp && pr) {
77a7138e28SGlenn Miles return false;
78a7138e28SGlenn Miles }
79a7138e28SGlenn Miles return true;
80a7138e28SGlenn Miles }
81a7138e28SGlenn Miles #endif
82a7138e28SGlenn Miles
hreg_compute_pmu_hflags_value(CPUPPCState * env)836494d2c1SNicholas Piggin static uint32_t hreg_compute_pmu_hflags_value(CPUPPCState *env)
846494d2c1SNicholas Piggin {
856494d2c1SNicholas Piggin uint32_t hflags = 0;
866494d2c1SNicholas Piggin #if defined(TARGET_PPC64)
87052af14eSHarsh Prateek Bora target_ulong mmcr0 = env->spr[SPR_POWER_MMCR0];
88052af14eSHarsh Prateek Bora
89052af14eSHarsh Prateek Bora if (mmcr0 & MMCR0_PMCC0) {
906494d2c1SNicholas Piggin hflags |= 1 << HFLAGS_PMCC0;
916494d2c1SNicholas Piggin }
92052af14eSHarsh Prateek Bora if (mmcr0 & MMCR0_PMCC1) {
936494d2c1SNicholas Piggin hflags |= 1 << HFLAGS_PMCC1;
946494d2c1SNicholas Piggin }
95052af14eSHarsh Prateek Bora if (mmcr0 & MMCR0_PMCjCE) {
966494d2c1SNicholas Piggin hflags |= 1 << HFLAGS_PMCJCE;
976494d2c1SNicholas Piggin }
98a7138e28SGlenn Miles if (hreg_check_bhrb_enable(env)) {
99a7138e28SGlenn Miles hflags |= 1 << HFLAGS_BHRB_ENABLE;
100a7138e28SGlenn Miles }
1016494d2c1SNicholas Piggin
1026494d2c1SNicholas Piggin #ifndef CONFIG_USER_ONLY
1036494d2c1SNicholas Piggin if (env->pmc_ins_cnt) {
1046494d2c1SNicholas Piggin hflags |= 1 << HFLAGS_INSN_CNT;
1056494d2c1SNicholas Piggin if (env->pmc_ins_cnt & 0x1e) {
1066494d2c1SNicholas Piggin hflags |= 1 << HFLAGS_PMC_OTHER;
1076494d2c1SNicholas Piggin }
108*7e806070SHarsh Prateek Bora }
1096494d2c1SNicholas Piggin #endif
1106494d2c1SNicholas Piggin #endif
1116494d2c1SNicholas Piggin
1126494d2c1SNicholas Piggin return hflags;
1136494d2c1SNicholas Piggin }
1146494d2c1SNicholas Piggin
1156494d2c1SNicholas Piggin /* Mask of all PMU hflags */
hreg_compute_pmu_hflags_mask(CPUPPCState * env)1166494d2c1SNicholas Piggin static uint32_t hreg_compute_pmu_hflags_mask(CPUPPCState *env)
1176494d2c1SNicholas Piggin {
1186494d2c1SNicholas Piggin uint32_t hflags_mask = 0;
1196494d2c1SNicholas Piggin #if defined(TARGET_PPC64)
1206494d2c1SNicholas Piggin hflags_mask |= 1 << HFLAGS_PMCC0;
1216494d2c1SNicholas Piggin hflags_mask |= 1 << HFLAGS_PMCC1;
1226494d2c1SNicholas Piggin hflags_mask |= 1 << HFLAGS_PMCJCE;
1236494d2c1SNicholas Piggin hflags_mask |= 1 << HFLAGS_INSN_CNT;
1246494d2c1SNicholas Piggin hflags_mask |= 1 << HFLAGS_PMC_OTHER;
125a7138e28SGlenn Miles hflags_mask |= 1 << HFLAGS_BHRB_ENABLE;
1266494d2c1SNicholas Piggin #endif
1276494d2c1SNicholas Piggin return hflags_mask;
1286494d2c1SNicholas Piggin }
1296494d2c1SNicholas Piggin
hreg_compute_hflags_value(CPUPPCState * env)1302da8a6bcSRichard Henderson static uint32_t hreg_compute_hflags_value(CPUPPCState *env)
1318a05fd9aSRichard Henderson {
1322df4fe7aSRichard Henderson target_ulong msr = env->msr;
1332df4fe7aSRichard Henderson uint32_t ppc_flags = env->flags;
1342df4fe7aSRichard Henderson uint32_t hflags = 0;
1352df4fe7aSRichard Henderson uint32_t msr_mask;
1368a05fd9aSRichard Henderson
1372df4fe7aSRichard Henderson /* Some bits come straight across from MSR. */
1382df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_LE != HFLAGS_LE);
1392df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_PR != HFLAGS_PR);
1402df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_DR != HFLAGS_DR);
1412df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_FP != HFLAGS_FP);
1422df4fe7aSRichard Henderson msr_mask = ((1 << MSR_LE) | (1 << MSR_PR) |
143d764184dSRichard Henderson (1 << MSR_DR) | (1 << MSR_FP));
14418285046SRichard Henderson
1457da31f26SRichard Henderson if (ppc_flags & POWERPC_FLAG_DE) {
1467da31f26SRichard Henderson target_ulong dbcr0 = env->spr[SPR_BOOKE_DBCR0];
1472bbddc08SHarsh Prateek Bora if ((dbcr0 & DBCR0_ICMP) && FIELD_EX64(msr, MSR, DE)) {
1487da31f26SRichard Henderson hflags |= 1 << HFLAGS_SE;
1497da31f26SRichard Henderson }
1502bbddc08SHarsh Prateek Bora if ((dbcr0 & DBCR0_BRT) && FIELD_EX64(msr, MSR, DE)) {
1517da31f26SRichard Henderson hflags |= 1 << HFLAGS_BE;
1527da31f26SRichard Henderson }
1537da31f26SRichard Henderson } else {
1542df4fe7aSRichard Henderson if (ppc_flags & POWERPC_FLAG_BE) {
1552df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_BE != HFLAGS_BE);
1562df4fe7aSRichard Henderson msr_mask |= 1 << MSR_BE;
1572df4fe7aSRichard Henderson }
1582df4fe7aSRichard Henderson if (ppc_flags & POWERPC_FLAG_SE) {
1592df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_SE != HFLAGS_SE);
1602df4fe7aSRichard Henderson msr_mask |= 1 << MSR_SE;
1612df4fe7aSRichard Henderson }
1627da31f26SRichard Henderson }
1632df4fe7aSRichard Henderson
1642df4fe7aSRichard Henderson if (msr_is_64bit(env, msr)) {
1652df4fe7aSRichard Henderson hflags |= 1 << HFLAGS_64;
1662df4fe7aSRichard Henderson }
1672df4fe7aSRichard Henderson if ((ppc_flags & POWERPC_FLAG_SPE) && (msr & (1 << MSR_SPE))) {
1682df4fe7aSRichard Henderson hflags |= 1 << HFLAGS_SPE;
1692df4fe7aSRichard Henderson }
1702df4fe7aSRichard Henderson if (ppc_flags & POWERPC_FLAG_VRE) {
1712df4fe7aSRichard Henderson QEMU_BUILD_BUG_ON(MSR_VR != HFLAGS_VR);
1722df4fe7aSRichard Henderson msr_mask |= 1 << MSR_VR;
1732df4fe7aSRichard Henderson }
1740e6bac3eSRichard Henderson if (ppc_flags & POWERPC_FLAG_VSX) {
1750e6bac3eSRichard Henderson QEMU_BUILD_BUG_ON(MSR_VSX != HFLAGS_VSX);
1760e6bac3eSRichard Henderson msr_mask |= 1 << MSR_VSX;
1772df4fe7aSRichard Henderson }
1782df4fe7aSRichard Henderson if ((ppc_flags & POWERPC_FLAG_TM) && (msr & (1ull << MSR_TM))) {
1792df4fe7aSRichard Henderson hflags |= 1 << HFLAGS_TM;
1802df4fe7aSRichard Henderson }
181f03de3b4SRichard Henderson if (env->spr[SPR_LPCR] & LPCR_GTSE) {
182f03de3b4SRichard Henderson hflags |= 1 << HFLAGS_GTSE;
183f03de3b4SRichard Henderson }
1841db3632aSMatheus Ferst if (env->spr[SPR_LPCR] & LPCR_HR) {
1851db3632aSMatheus Ferst hflags |= 1 << HFLAGS_HR;
1861db3632aSMatheus Ferst }
1872df4fe7aSRichard Henderson
1882df4fe7aSRichard Henderson #ifndef CONFIG_USER_ONLY
1892df4fe7aSRichard Henderson if (!env->has_hv_mode || (msr & (1ull << MSR_HV))) {
1902df4fe7aSRichard Henderson hflags |= 1 << HFLAGS_HV;
1912df4fe7aSRichard Henderson }
192d764184dSRichard Henderson
193d764184dSRichard Henderson /*
194d764184dSRichard Henderson * This is our encoding for server processors. The architecture
195d764184dSRichard Henderson * specifies that there is no such thing as userspace with
196d764184dSRichard Henderson * translation off, however it appears that MacOS does it and some
197d764184dSRichard Henderson * 32-bit CPUs support it. Weird...
198d764184dSRichard Henderson *
199d764184dSRichard Henderson * 0 = Guest User space virtual mode
200d764184dSRichard Henderson * 1 = Guest Kernel space virtual mode
201d764184dSRichard Henderson * 2 = Guest User space real mode
202d764184dSRichard Henderson * 3 = Guest Kernel space real mode
203d764184dSRichard Henderson * 4 = HV User space virtual mode
204d764184dSRichard Henderson * 5 = HV Kernel space virtual mode
205d764184dSRichard Henderson * 6 = HV User space real mode
206d764184dSRichard Henderson * 7 = HV Kernel space real mode
207d764184dSRichard Henderson *
208d764184dSRichard Henderson * For BookE, we need 8 MMU modes as follow:
209d764184dSRichard Henderson *
210d764184dSRichard Henderson * 0 = AS 0 HV User space
211d764184dSRichard Henderson * 1 = AS 0 HV Kernel space
212d764184dSRichard Henderson * 2 = AS 1 HV User space
213d764184dSRichard Henderson * 3 = AS 1 HV Kernel space
214d764184dSRichard Henderson * 4 = AS 0 Guest User space
215d764184dSRichard Henderson * 5 = AS 0 Guest Kernel space
216d764184dSRichard Henderson * 6 = AS 1 Guest User space
217d764184dSRichard Henderson * 7 = AS 1 Guest Kernel space
218d764184dSRichard Henderson */
219d764184dSRichard Henderson unsigned immu_idx, dmmu_idx;
220d764184dSRichard Henderson dmmu_idx = msr & (1 << MSR_PR) ? 0 : 1;
22163f38cc3SCédric Le Goater if (env->mmu_model == POWERPC_MMU_BOOKE ||
22263f38cc3SCédric Le Goater env->mmu_model == POWERPC_MMU_BOOKE206) {
223d764184dSRichard Henderson dmmu_idx |= msr & (1 << MSR_GS) ? 4 : 0;
224d764184dSRichard Henderson immu_idx = dmmu_idx;
225d764184dSRichard Henderson immu_idx |= msr & (1 << MSR_IS) ? 2 : 0;
226d764184dSRichard Henderson dmmu_idx |= msr & (1 << MSR_DS) ? 2 : 0;
227d764184dSRichard Henderson } else {
228d764184dSRichard Henderson dmmu_idx |= msr & (1ull << MSR_HV) ? 4 : 0;
229d764184dSRichard Henderson immu_idx = dmmu_idx;
230d764184dSRichard Henderson immu_idx |= msr & (1 << MSR_IR) ? 0 : 2;
231d764184dSRichard Henderson dmmu_idx |= msr & (1 << MSR_DR) ? 0 : 2;
232d764184dSRichard Henderson }
233d764184dSRichard Henderson hflags |= immu_idx << HFLAGS_IMMU_IDX;
234d764184dSRichard Henderson hflags |= dmmu_idx << HFLAGS_DMMU_IDX;
2352df4fe7aSRichard Henderson #endif
2362df4fe7aSRichard Henderson
2376494d2c1SNicholas Piggin hflags |= hreg_compute_pmu_hflags_value(env);
2386494d2c1SNicholas Piggin
2392da8a6bcSRichard Henderson return hflags | (msr & msr_mask);
2408a05fd9aSRichard Henderson }
2418a05fd9aSRichard Henderson
hreg_compute_hflags(CPUPPCState * env)2422da8a6bcSRichard Henderson void hreg_compute_hflags(CPUPPCState *env)
2432da8a6bcSRichard Henderson {
2442da8a6bcSRichard Henderson env->hflags = hreg_compute_hflags_value(env);
2452da8a6bcSRichard Henderson }
2462da8a6bcSRichard Henderson
2476494d2c1SNicholas Piggin /*
2486494d2c1SNicholas Piggin * This can be used as a lighter-weight alternative to hreg_compute_hflags
2496494d2c1SNicholas Piggin * when PMU MMCR0 or pmc_ins_cnt changes. pmc_ins_cnt is changed by
2506494d2c1SNicholas Piggin * pmu_update_summaries.
2516494d2c1SNicholas Piggin */
hreg_update_pmu_hflags(CPUPPCState * env)2526494d2c1SNicholas Piggin void hreg_update_pmu_hflags(CPUPPCState *env)
2536494d2c1SNicholas Piggin {
2546494d2c1SNicholas Piggin env->hflags &= ~hreg_compute_pmu_hflags_mask(env);
2556494d2c1SNicholas Piggin env->hflags |= hreg_compute_pmu_hflags_value(env);
2566494d2c1SNicholas Piggin }
2576494d2c1SNicholas Piggin
2582da8a6bcSRichard Henderson #ifdef CONFIG_DEBUG_TCG
cpu_get_tb_cpu_state(CPUPPCState * env,vaddr * pc,uint64_t * cs_base,uint32_t * flags)259bb5de525SAnton Johansson void cpu_get_tb_cpu_state(CPUPPCState *env, vaddr *pc,
260bb5de525SAnton Johansson uint64_t *cs_base, uint32_t *flags)
2612da8a6bcSRichard Henderson {
2622da8a6bcSRichard Henderson uint32_t hflags_current = env->hflags;
2632da8a6bcSRichard Henderson uint32_t hflags_rebuilt;
2642da8a6bcSRichard Henderson
2652da8a6bcSRichard Henderson *pc = env->nip;
2662da8a6bcSRichard Henderson *cs_base = 0;
2672da8a6bcSRichard Henderson *flags = hflags_current;
2682da8a6bcSRichard Henderson
2692da8a6bcSRichard Henderson hflags_rebuilt = hreg_compute_hflags_value(env);
2702da8a6bcSRichard Henderson if (unlikely(hflags_current != hflags_rebuilt)) {
2712da8a6bcSRichard Henderson cpu_abort(env_cpu(env),
2722da8a6bcSRichard Henderson "TCG hflags mismatch (current:0x%08x rebuilt:0x%08x)\n",
2732da8a6bcSRichard Henderson hflags_current, hflags_rebuilt);
2742da8a6bcSRichard Henderson }
2752da8a6bcSRichard Henderson }
2762da8a6bcSRichard Henderson #endif
2772da8a6bcSRichard Henderson
cpu_interrupt_exittb(CPUState * cs)2788a05fd9aSRichard Henderson void cpu_interrupt_exittb(CPUState *cs)
2798a05fd9aSRichard Henderson {
2800c0aac01SDaniel Henrique Barboza /*
2810c0aac01SDaniel Henrique Barboza * We don't need to worry about translation blocks
28203ac0a0cSRichard Henderson * unless running with TCG.
2830c0aac01SDaniel Henrique Barboza */
28403ac0a0cSRichard Henderson if (tcg_enabled()) {
28532ead8e6SStefan Hajnoczi BQL_LOCK_GUARD();
2868a05fd9aSRichard Henderson cpu_interrupt(cs, CPU_INTERRUPT_EXITTB);
2878a05fd9aSRichard Henderson }
2888a05fd9aSRichard Henderson }
2898a05fd9aSRichard Henderson
hreg_store_msr(CPUPPCState * env,target_ulong value,int alter_hv)2908a05fd9aSRichard Henderson int hreg_store_msr(CPUPPCState *env, target_ulong value, int alter_hv)
2918a05fd9aSRichard Henderson {
2928a05fd9aSRichard Henderson int excp;
2938a05fd9aSRichard Henderson #if !defined(CONFIG_USER_ONLY)
2948a05fd9aSRichard Henderson CPUState *cs = env_cpu(env);
2958a05fd9aSRichard Henderson #endif
2968a05fd9aSRichard Henderson
2978a05fd9aSRichard Henderson excp = 0;
2988a05fd9aSRichard Henderson value &= env->msr_mask;
2998a05fd9aSRichard Henderson #if !defined(CONFIG_USER_ONLY)
3008a05fd9aSRichard Henderson /* Neither mtmsr nor guest state can alter HV */
3018a05fd9aSRichard Henderson if (!alter_hv || !(env->msr & MSR_HVB)) {
3028a05fd9aSRichard Henderson value &= ~MSR_HVB;
3038a05fd9aSRichard Henderson value |= env->msr & MSR_HVB;
3048a05fd9aSRichard Henderson }
305678b6f1aSNicholas Piggin /* Attempt to modify MSR[ME] in guest state is ignored */
306678b6f1aSNicholas Piggin if (is_book3s_arch2x(env) && !(env->msr & MSR_HVB)) {
307678b6f1aSNicholas Piggin value &= ~(1 << MSR_ME);
308678b6f1aSNicholas Piggin value |= env->msr & (1 << MSR_ME);
309678b6f1aSNicholas Piggin }
310e4eea6efSVíctor Colombo if ((value ^ env->msr) & (R_MSR_IR_MASK | R_MSR_DR_MASK)) {
3118a05fd9aSRichard Henderson cpu_interrupt_exittb(cs);
3128a05fd9aSRichard Henderson }
31363f38cc3SCédric Le Goater if ((env->mmu_model == POWERPC_MMU_BOOKE ||
31463f38cc3SCédric Le Goater env->mmu_model == POWERPC_MMU_BOOKE206) &&
31510b2b373SVíctor Colombo ((value ^ env->msr) & R_MSR_GS_MASK)) {
3168a05fd9aSRichard Henderson cpu_interrupt_exittb(cs);
3178a05fd9aSRichard Henderson }
3188a05fd9aSRichard Henderson if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
3198a05fd9aSRichard Henderson ((value ^ env->msr) & (1 << MSR_TGPR)))) {
3208a05fd9aSRichard Henderson /* Swap temporary saved registers with GPRs */
3218a05fd9aSRichard Henderson hreg_swap_gpr_tgpr(env);
3228a05fd9aSRichard Henderson }
32350242330SVíctor Colombo if (unlikely((value ^ env->msr) & R_MSR_EP_MASK)) {
32450242330SVíctor Colombo env->excp_prefix = FIELD_EX64(value, MSR, EP) * 0xFFF00000;
3258a05fd9aSRichard Henderson }
3268a05fd9aSRichard Henderson /*
3278a05fd9aSRichard Henderson * If PR=1 then EE, IR and DR must be 1
3288a05fd9aSRichard Henderson *
3298a05fd9aSRichard Henderson * Note: We only enforce this on 64-bit server processors.
3308a05fd9aSRichard Henderson * It appears that:
3318a05fd9aSRichard Henderson * - 32-bit implementations supports PR=1 and EE/DR/IR=0 and MacOS
3328a05fd9aSRichard Henderson * exploits it.
3338a05fd9aSRichard Henderson * - 64-bit embedded implementations do not need any operation to be
3348a05fd9aSRichard Henderson * performed when PR is set.
3358a05fd9aSRichard Henderson */
3368a05fd9aSRichard Henderson if (is_book3s_arch2x(env) && ((value >> MSR_PR) & 1)) {
3378a05fd9aSRichard Henderson value |= (1 << MSR_EE) | (1 << MSR_DR) | (1 << MSR_IR);
3388a05fd9aSRichard Henderson }
3398a05fd9aSRichard Henderson #endif
3408a05fd9aSRichard Henderson env->msr = value;
3418a05fd9aSRichard Henderson hreg_compute_hflags(env);
3428a05fd9aSRichard Henderson #if !defined(CONFIG_USER_ONLY)
3432fdedcbcSMatheus Ferst ppc_maybe_interrupt(env);
3442fdedcbcSMatheus Ferst
3458e54ad65SVíctor Colombo if (unlikely(FIELD_EX64(env->msr, MSR, POW))) {
3468a05fd9aSRichard Henderson if (!env->pending_interrupts && (*env->check_pow)(env)) {
3478a05fd9aSRichard Henderson cs->halted = 1;
3488a05fd9aSRichard Henderson excp = EXCP_HALTED;
3498a05fd9aSRichard Henderson }
3508a05fd9aSRichard Henderson }
3518a05fd9aSRichard Henderson #endif
3528a05fd9aSRichard Henderson
3538a05fd9aSRichard Henderson return excp;
3548a05fd9aSRichard Henderson }
3558a05fd9aSRichard Henderson
356227776b7SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
store_40x_sler(CPUPPCState * env,uint32_t val)357c06ba892SLucas Mateus Castro (alqotel) void store_40x_sler(CPUPPCState *env, uint32_t val)
358c06ba892SLucas Mateus Castro (alqotel) {
359c06ba892SLucas Mateus Castro (alqotel) /* XXX: TO BE FIXED */
360c06ba892SLucas Mateus Castro (alqotel) if (val != 0x00000000) {
361c06ba892SLucas Mateus Castro (alqotel) cpu_abort(env_cpu(env),
362c06ba892SLucas Mateus Castro (alqotel) "Little-endian regions are not supported by now\n");
363c06ba892SLucas Mateus Castro (alqotel) }
364c06ba892SLucas Mateus Castro (alqotel) env->spr[SPR_405_SLER] = val;
365c06ba892SLucas Mateus Castro (alqotel) }
366c06ba892SLucas Mateus Castro (alqotel)
check_tlb_flush(CPUPPCState * env,bool global)3678a05fd9aSRichard Henderson void check_tlb_flush(CPUPPCState *env, bool global)
3688a05fd9aSRichard Henderson {
3698a05fd9aSRichard Henderson CPUState *cs = env_cpu(env);
3708a05fd9aSRichard Henderson
3718a05fd9aSRichard Henderson /* Handle global flushes first */
3728a05fd9aSRichard Henderson if (global && (env->tlb_need_flush & TLB_NEED_GLOBAL_FLUSH)) {
3738a05fd9aSRichard Henderson env->tlb_need_flush &= ~TLB_NEED_GLOBAL_FLUSH;
3748a05fd9aSRichard Henderson env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
37582676f1fSNicholas Piggin tlb_flush_all_cpus_synced(cs);
3768a05fd9aSRichard Henderson return;
3778a05fd9aSRichard Henderson }
3788a05fd9aSRichard Henderson
3798a05fd9aSRichard Henderson /* Then handle local ones */
3808a05fd9aSRichard Henderson if (env->tlb_need_flush & TLB_NEED_LOCAL_FLUSH) {
3818a05fd9aSRichard Henderson env->tlb_need_flush &= ~TLB_NEED_LOCAL_FLUSH;
3828a05fd9aSRichard Henderson tlb_flush(cs);
3838a05fd9aSRichard Henderson }
3848a05fd9aSRichard Henderson }
385227776b7SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
38665e0446cSFabiano Rosas
38765e0446cSFabiano Rosas /**
38865e0446cSFabiano Rosas * _spr_register
38965e0446cSFabiano Rosas *
39065e0446cSFabiano Rosas * Register an SPR with all the callbacks required for tcg,
39165e0446cSFabiano Rosas * and the ID number for KVM.
39265e0446cSFabiano Rosas *
39365e0446cSFabiano Rosas * The reason for the conditional compilation is that the tcg functions
39465e0446cSFabiano Rosas * may be compiled out, and the system kvm header may not be available
39565e0446cSFabiano Rosas * for supplying the ID numbers. This is ugly, but the best we can do.
39665e0446cSFabiano Rosas */
_spr_register(CPUPPCState * env,int num,const char * name,USR_ARG (spr_callback * uea_read)USR_ARG (spr_callback * uea_write)SYS_ARG (spr_callback * oea_read)SYS_ARG (spr_callback * oea_write)SYS_ARG (spr_callback * hea_read)SYS_ARG (spr_callback * hea_write)KVM_ARG (uint64_t one_reg_id)target_ulong initial_value)39765e0446cSFabiano Rosas void _spr_register(CPUPPCState *env, int num, const char *name,
39865e0446cSFabiano Rosas USR_ARG(spr_callback *uea_read)
39965e0446cSFabiano Rosas USR_ARG(spr_callback *uea_write)
40065e0446cSFabiano Rosas SYS_ARG(spr_callback *oea_read)
40165e0446cSFabiano Rosas SYS_ARG(spr_callback *oea_write)
40265e0446cSFabiano Rosas SYS_ARG(spr_callback *hea_read)
40365e0446cSFabiano Rosas SYS_ARG(spr_callback *hea_write)
40465e0446cSFabiano Rosas KVM_ARG(uint64_t one_reg_id)
40565e0446cSFabiano Rosas target_ulong initial_value)
40665e0446cSFabiano Rosas {
40765e0446cSFabiano Rosas ppc_spr_t *spr = &env->spr_cb[num];
40865e0446cSFabiano Rosas
40965e0446cSFabiano Rosas /* No SPR should be registered twice. */
41065e0446cSFabiano Rosas assert(spr->name == NULL);
41165e0446cSFabiano Rosas assert(name != NULL);
41265e0446cSFabiano Rosas
41365e0446cSFabiano Rosas spr->name = name;
41465e0446cSFabiano Rosas spr->default_value = initial_value;
41565e0446cSFabiano Rosas env->spr[num] = initial_value;
41665e0446cSFabiano Rosas
41765e0446cSFabiano Rosas #ifdef CONFIG_TCG
41865e0446cSFabiano Rosas spr->uea_read = uea_read;
41965e0446cSFabiano Rosas spr->uea_write = uea_write;
42065e0446cSFabiano Rosas # ifndef CONFIG_USER_ONLY
42165e0446cSFabiano Rosas spr->oea_read = oea_read;
42265e0446cSFabiano Rosas spr->oea_write = oea_write;
42365e0446cSFabiano Rosas spr->hea_read = hea_read;
42465e0446cSFabiano Rosas spr->hea_write = hea_write;
42565e0446cSFabiano Rosas # endif
42665e0446cSFabiano Rosas #endif
42765e0446cSFabiano Rosas #ifdef CONFIG_KVM
42865e0446cSFabiano Rosas spr->one_reg_id = one_reg_id;
42965e0446cSFabiano Rosas #endif
43065e0446cSFabiano Rosas }
43165e0446cSFabiano Rosas
43265e0446cSFabiano Rosas /* Generic PowerPC SPRs */
register_generic_sprs(PowerPCCPU * cpu)43365e0446cSFabiano Rosas void register_generic_sprs(PowerPCCPU *cpu)
43465e0446cSFabiano Rosas {
43565e0446cSFabiano Rosas PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
43665e0446cSFabiano Rosas CPUPPCState *env = &cpu->env;
43765e0446cSFabiano Rosas
43865e0446cSFabiano Rosas /* Integer processing */
43965e0446cSFabiano Rosas spr_register(env, SPR_XER, "XER",
44065e0446cSFabiano Rosas &spr_read_xer, &spr_write_xer,
44165e0446cSFabiano Rosas &spr_read_xer, &spr_write_xer,
44265e0446cSFabiano Rosas 0x00000000);
44365e0446cSFabiano Rosas /* Branch control */
44465e0446cSFabiano Rosas spr_register(env, SPR_LR, "LR",
44565e0446cSFabiano Rosas &spr_read_lr, &spr_write_lr,
44665e0446cSFabiano Rosas &spr_read_lr, &spr_write_lr,
44765e0446cSFabiano Rosas 0x00000000);
44865e0446cSFabiano Rosas spr_register(env, SPR_CTR, "CTR",
44965e0446cSFabiano Rosas &spr_read_ctr, &spr_write_ctr,
45065e0446cSFabiano Rosas &spr_read_ctr, &spr_write_ctr,
45165e0446cSFabiano Rosas 0x00000000);
45265e0446cSFabiano Rosas /* Interrupt processing */
45365e0446cSFabiano Rosas spr_register(env, SPR_SRR0, "SRR0",
45465e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
45565e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
45665e0446cSFabiano Rosas 0x00000000);
45765e0446cSFabiano Rosas spr_register(env, SPR_SRR1, "SRR1",
45865e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
45965e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
46065e0446cSFabiano Rosas 0x00000000);
46165e0446cSFabiano Rosas /* Processor control */
46265e0446cSFabiano Rosas spr_register(env, SPR_SPRG0, "SPRG0",
46365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
46465e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
46565e0446cSFabiano Rosas 0x00000000);
46665e0446cSFabiano Rosas spr_register(env, SPR_SPRG1, "SPRG1",
46765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
46865e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
46965e0446cSFabiano Rosas 0x00000000);
47065e0446cSFabiano Rosas spr_register(env, SPR_SPRG2, "SPRG2",
47165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
47265e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
47365e0446cSFabiano Rosas 0x00000000);
47465e0446cSFabiano Rosas spr_register(env, SPR_SPRG3, "SPRG3",
47565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
47665e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
47765e0446cSFabiano Rosas 0x00000000);
47865e0446cSFabiano Rosas
47965e0446cSFabiano Rosas spr_register(env, SPR_PVR, "PVR",
48065e0446cSFabiano Rosas /* Linux permits userspace to read PVR */
48165e0446cSFabiano Rosas #if defined(CONFIG_LINUX_USER)
48265e0446cSFabiano Rosas &spr_read_generic,
48365e0446cSFabiano Rosas #else
48465e0446cSFabiano Rosas SPR_NOACCESS,
48565e0446cSFabiano Rosas #endif
48665e0446cSFabiano Rosas SPR_NOACCESS,
48765e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
48865e0446cSFabiano Rosas pcc->pvr);
48965e0446cSFabiano Rosas
49065e0446cSFabiano Rosas /* Register SVR if it's defined to anything else than POWERPC_SVR_NONE */
49165e0446cSFabiano Rosas if (pcc->svr != POWERPC_SVR_NONE) {
49265e0446cSFabiano Rosas if (pcc->svr & POWERPC_SVR_E500) {
49365e0446cSFabiano Rosas spr_register(env, SPR_E500_SVR, "SVR",
49465e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
49565e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
49665e0446cSFabiano Rosas pcc->svr & ~POWERPC_SVR_E500);
49765e0446cSFabiano Rosas } else {
49865e0446cSFabiano Rosas spr_register(env, SPR_SVR, "SVR",
49965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
50065e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
50165e0446cSFabiano Rosas pcc->svr);
50265e0446cSFabiano Rosas }
50365e0446cSFabiano Rosas }
50465e0446cSFabiano Rosas
50565e0446cSFabiano Rosas /* Time base */
50619e81ce5SNicholas Piggin #if defined(TARGET_PPC64)
50780e28a41SNicholas Piggin spr_register(env, SPR_TBL, "TB",
50819e81ce5SNicholas Piggin #else
50980e28a41SNicholas Piggin spr_register(env, SPR_TBL, "TBL",
51019e81ce5SNicholas Piggin #endif
51165e0446cSFabiano Rosas &spr_read_tbl, SPR_NOACCESS,
51265e0446cSFabiano Rosas &spr_read_tbl, SPR_NOACCESS,
51365e0446cSFabiano Rosas 0x00000000);
51480e28a41SNicholas Piggin spr_register(env, SPR_TBU, "TBU",
51565e0446cSFabiano Rosas &spr_read_tbu, SPR_NOACCESS,
51665e0446cSFabiano Rosas &spr_read_tbu, SPR_NOACCESS,
51765e0446cSFabiano Rosas 0x00000000);
518f6940474SNicholas Piggin #ifndef CONFIG_USER_ONLY
519f6940474SNicholas Piggin if (env->has_hv_mode) {
520f6940474SNicholas Piggin spr_register_hv(env, SPR_WR_TBL, "TBL",
521f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
522f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
523f6940474SNicholas Piggin SPR_NOACCESS, &spr_write_tbl,
52465e0446cSFabiano Rosas 0x00000000);
525f6940474SNicholas Piggin spr_register_hv(env, SPR_WR_TBU, "TBU",
526f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
527f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
528f6940474SNicholas Piggin SPR_NOACCESS, &spr_write_tbu,
529f6940474SNicholas Piggin 0x00000000);
530f6940474SNicholas Piggin } else {
531f6940474SNicholas Piggin spr_register(env, SPR_WR_TBL, "TBL",
532f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
533f6940474SNicholas Piggin SPR_NOACCESS, &spr_write_tbl,
534f6940474SNicholas Piggin 0x00000000);
535f6940474SNicholas Piggin spr_register(env, SPR_WR_TBU, "TBU",
536f6940474SNicholas Piggin SPR_NOACCESS, SPR_NOACCESS,
537f6940474SNicholas Piggin SPR_NOACCESS, &spr_write_tbu,
538f6940474SNicholas Piggin 0x00000000);
539f6940474SNicholas Piggin }
540f6940474SNicholas Piggin #endif
54165e0446cSFabiano Rosas }
54265e0446cSFabiano Rosas
register_non_embedded_sprs(CPUPPCState * env)54365e0446cSFabiano Rosas void register_non_embedded_sprs(CPUPPCState *env)
54465e0446cSFabiano Rosas {
54565e0446cSFabiano Rosas /* Exception processing */
54665e0446cSFabiano Rosas spr_register_kvm(env, SPR_DSISR, "DSISR",
54765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
548fbda88f7SNicholas Piggin &spr_read_generic, &spr_write_generic32,
54965e0446cSFabiano Rosas KVM_REG_PPC_DSISR, 0x00000000);
55065e0446cSFabiano Rosas spr_register_kvm(env, SPR_DAR, "DAR",
55165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
55265e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
55365e0446cSFabiano Rosas KVM_REG_PPC_DAR, 0x00000000);
55465e0446cSFabiano Rosas /* Timer */
555a5116b95SNicholas Piggin spr_register(env, SPR_DECR, "DEC",
55665e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
55765e0446cSFabiano Rosas &spr_read_decr, &spr_write_decr,
55865e0446cSFabiano Rosas 0x00000000);
55965e0446cSFabiano Rosas }
56065e0446cSFabiano Rosas
56165e0446cSFabiano Rosas /* Storage Description Register 1 */
register_sdr1_sprs(CPUPPCState * env)56265e0446cSFabiano Rosas void register_sdr1_sprs(CPUPPCState *env)
56365e0446cSFabiano Rosas {
56465e0446cSFabiano Rosas #ifndef CONFIG_USER_ONLY
56565e0446cSFabiano Rosas if (env->has_hv_mode) {
56665e0446cSFabiano Rosas /*
56765e0446cSFabiano Rosas * SDR1 is a hypervisor resource on CPUs which have a
56865e0446cSFabiano Rosas * hypervisor mode
56965e0446cSFabiano Rosas */
57065e0446cSFabiano Rosas spr_register_hv(env, SPR_SDR1, "SDR1",
57165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
57265e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
57365e0446cSFabiano Rosas &spr_read_generic, &spr_write_sdr1,
57465e0446cSFabiano Rosas 0x00000000);
57565e0446cSFabiano Rosas } else {
57665e0446cSFabiano Rosas spr_register(env, SPR_SDR1, "SDR1",
57765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
57865e0446cSFabiano Rosas &spr_read_generic, &spr_write_sdr1,
57965e0446cSFabiano Rosas 0x00000000);
58065e0446cSFabiano Rosas }
58165e0446cSFabiano Rosas #endif
58265e0446cSFabiano Rosas }
58365e0446cSFabiano Rosas
58465e0446cSFabiano Rosas /* BATs 0-3 */
register_low_BATs(CPUPPCState * env)58565e0446cSFabiano Rosas void register_low_BATs(CPUPPCState *env)
58665e0446cSFabiano Rosas {
58765e0446cSFabiano Rosas #if !defined(CONFIG_USER_ONLY)
58865e0446cSFabiano Rosas spr_register(env, SPR_IBAT0U, "IBAT0U",
58965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
59065e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatu,
59165e0446cSFabiano Rosas 0x00000000);
59265e0446cSFabiano Rosas spr_register(env, SPR_IBAT0L, "IBAT0L",
59365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
59465e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatl,
59565e0446cSFabiano Rosas 0x00000000);
59665e0446cSFabiano Rosas spr_register(env, SPR_IBAT1U, "IBAT1U",
59765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
59865e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatu,
59965e0446cSFabiano Rosas 0x00000000);
60065e0446cSFabiano Rosas spr_register(env, SPR_IBAT1L, "IBAT1L",
60165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
60265e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatl,
60365e0446cSFabiano Rosas 0x00000000);
60465e0446cSFabiano Rosas spr_register(env, SPR_IBAT2U, "IBAT2U",
60565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
60665e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatu,
60765e0446cSFabiano Rosas 0x00000000);
60865e0446cSFabiano Rosas spr_register(env, SPR_IBAT2L, "IBAT2L",
60965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
61065e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatl,
61165e0446cSFabiano Rosas 0x00000000);
61265e0446cSFabiano Rosas spr_register(env, SPR_IBAT3U, "IBAT3U",
61365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
61465e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatu,
61565e0446cSFabiano Rosas 0x00000000);
61665e0446cSFabiano Rosas spr_register(env, SPR_IBAT3L, "IBAT3L",
61765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
61865e0446cSFabiano Rosas &spr_read_ibat, &spr_write_ibatl,
61965e0446cSFabiano Rosas 0x00000000);
62065e0446cSFabiano Rosas spr_register(env, SPR_DBAT0U, "DBAT0U",
62165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
62265e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatu,
62365e0446cSFabiano Rosas 0x00000000);
62465e0446cSFabiano Rosas spr_register(env, SPR_DBAT0L, "DBAT0L",
62565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
62665e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatl,
62765e0446cSFabiano Rosas 0x00000000);
62865e0446cSFabiano Rosas spr_register(env, SPR_DBAT1U, "DBAT1U",
62965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
63065e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatu,
63165e0446cSFabiano Rosas 0x00000000);
63265e0446cSFabiano Rosas spr_register(env, SPR_DBAT1L, "DBAT1L",
63365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
63465e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatl,
63565e0446cSFabiano Rosas 0x00000000);
63665e0446cSFabiano Rosas spr_register(env, SPR_DBAT2U, "DBAT2U",
63765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
63865e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatu,
63965e0446cSFabiano Rosas 0x00000000);
64065e0446cSFabiano Rosas spr_register(env, SPR_DBAT2L, "DBAT2L",
64165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
64265e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatl,
64365e0446cSFabiano Rosas 0x00000000);
64465e0446cSFabiano Rosas spr_register(env, SPR_DBAT3U, "DBAT3U",
64565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
64665e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatu,
64765e0446cSFabiano Rosas 0x00000000);
64865e0446cSFabiano Rosas spr_register(env, SPR_DBAT3L, "DBAT3L",
64965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
65065e0446cSFabiano Rosas &spr_read_dbat, &spr_write_dbatl,
65165e0446cSFabiano Rosas 0x00000000);
65265e0446cSFabiano Rosas env->nb_BATs += 4;
65365e0446cSFabiano Rosas #endif
65465e0446cSFabiano Rosas }
65565e0446cSFabiano Rosas
65665e0446cSFabiano Rosas /* BATs 4-7 */
register_high_BATs(CPUPPCState * env)65765e0446cSFabiano Rosas void register_high_BATs(CPUPPCState *env)
65865e0446cSFabiano Rosas {
65965e0446cSFabiano Rosas #if !defined(CONFIG_USER_ONLY)
66065e0446cSFabiano Rosas spr_register(env, SPR_IBAT4U, "IBAT4U",
66165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
66265e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatu_h,
66365e0446cSFabiano Rosas 0x00000000);
66465e0446cSFabiano Rosas spr_register(env, SPR_IBAT4L, "IBAT4L",
66565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
66665e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatl_h,
66765e0446cSFabiano Rosas 0x00000000);
66865e0446cSFabiano Rosas spr_register(env, SPR_IBAT5U, "IBAT5U",
66965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
67065e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatu_h,
67165e0446cSFabiano Rosas 0x00000000);
67265e0446cSFabiano Rosas spr_register(env, SPR_IBAT5L, "IBAT5L",
67365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
67465e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatl_h,
67565e0446cSFabiano Rosas 0x00000000);
67665e0446cSFabiano Rosas spr_register(env, SPR_IBAT6U, "IBAT6U",
67765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
67865e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatu_h,
67965e0446cSFabiano Rosas 0x00000000);
68065e0446cSFabiano Rosas spr_register(env, SPR_IBAT6L, "IBAT6L",
68165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
68265e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatl_h,
68365e0446cSFabiano Rosas 0x00000000);
68465e0446cSFabiano Rosas spr_register(env, SPR_IBAT7U, "IBAT7U",
68565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
68665e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatu_h,
68765e0446cSFabiano Rosas 0x00000000);
68865e0446cSFabiano Rosas spr_register(env, SPR_IBAT7L, "IBAT7L",
68965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
69065e0446cSFabiano Rosas &spr_read_ibat_h, &spr_write_ibatl_h,
69165e0446cSFabiano Rosas 0x00000000);
69265e0446cSFabiano Rosas spr_register(env, SPR_DBAT4U, "DBAT4U",
69365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
69465e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatu_h,
69565e0446cSFabiano Rosas 0x00000000);
69665e0446cSFabiano Rosas spr_register(env, SPR_DBAT4L, "DBAT4L",
69765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
69865e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatl_h,
69965e0446cSFabiano Rosas 0x00000000);
70065e0446cSFabiano Rosas spr_register(env, SPR_DBAT5U, "DBAT5U",
70165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
70265e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatu_h,
70365e0446cSFabiano Rosas 0x00000000);
70465e0446cSFabiano Rosas spr_register(env, SPR_DBAT5L, "DBAT5L",
70565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
70665e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatl_h,
70765e0446cSFabiano Rosas 0x00000000);
70865e0446cSFabiano Rosas spr_register(env, SPR_DBAT6U, "DBAT6U",
70965e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
71065e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatu_h,
71165e0446cSFabiano Rosas 0x00000000);
71265e0446cSFabiano Rosas spr_register(env, SPR_DBAT6L, "DBAT6L",
71365e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
71465e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatl_h,
71565e0446cSFabiano Rosas 0x00000000);
71665e0446cSFabiano Rosas spr_register(env, SPR_DBAT7U, "DBAT7U",
71765e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
71865e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatu_h,
71965e0446cSFabiano Rosas 0x00000000);
72065e0446cSFabiano Rosas spr_register(env, SPR_DBAT7L, "DBAT7L",
72165e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
72265e0446cSFabiano Rosas &spr_read_dbat_h, &spr_write_dbatl_h,
72365e0446cSFabiano Rosas 0x00000000);
72465e0446cSFabiano Rosas env->nb_BATs += 4;
72565e0446cSFabiano Rosas #endif
72665e0446cSFabiano Rosas }
72765e0446cSFabiano Rosas
72865e0446cSFabiano Rosas /* Softare table search registers */
register_6xx_7xx_soft_tlb(CPUPPCState * env,int nb_tlbs,int nb_ways)72965e0446cSFabiano Rosas void register_6xx_7xx_soft_tlb(CPUPPCState *env, int nb_tlbs, int nb_ways)
73065e0446cSFabiano Rosas {
73165e0446cSFabiano Rosas #if !defined(CONFIG_USER_ONLY)
73265e0446cSFabiano Rosas env->nb_tlb = nb_tlbs;
73365e0446cSFabiano Rosas env->nb_ways = nb_ways;
73465e0446cSFabiano Rosas env->tlb_type = TLB_6XX;
73565e0446cSFabiano Rosas spr_register(env, SPR_DMISS, "DMISS",
73665e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
73765e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
73865e0446cSFabiano Rosas 0x00000000);
73965e0446cSFabiano Rosas spr_register(env, SPR_DCMP, "DCMP",
74065e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
74165e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
74265e0446cSFabiano Rosas 0x00000000);
74365e0446cSFabiano Rosas spr_register(env, SPR_HASH1, "HASH1",
74465e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
74565e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
74665e0446cSFabiano Rosas 0x00000000);
74765e0446cSFabiano Rosas spr_register(env, SPR_HASH2, "HASH2",
74865e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
74965e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
75065e0446cSFabiano Rosas 0x00000000);
75165e0446cSFabiano Rosas spr_register(env, SPR_IMISS, "IMISS",
75265e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
75365e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
75465e0446cSFabiano Rosas 0x00000000);
75565e0446cSFabiano Rosas spr_register(env, SPR_ICMP, "ICMP",
75665e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
75765e0446cSFabiano Rosas &spr_read_generic, SPR_NOACCESS,
75865e0446cSFabiano Rosas 0x00000000);
75965e0446cSFabiano Rosas spr_register(env, SPR_RPA, "RPA",
76065e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
76165e0446cSFabiano Rosas &spr_read_generic, &spr_write_generic,
76265e0446cSFabiano Rosas 0x00000000);
76365e0446cSFabiano Rosas #endif
76465e0446cSFabiano Rosas }
76565e0446cSFabiano Rosas
register_thrm_sprs(CPUPPCState * env)76665e0446cSFabiano Rosas void register_thrm_sprs(CPUPPCState *env)
76765e0446cSFabiano Rosas {
76865e0446cSFabiano Rosas /* Thermal management */
76965e0446cSFabiano Rosas spr_register(env, SPR_THRM1, "THRM1",
77065e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
77165e0446cSFabiano Rosas &spr_read_thrm, &spr_write_generic,
77265e0446cSFabiano Rosas 0x00000000);
77365e0446cSFabiano Rosas
77465e0446cSFabiano Rosas spr_register(env, SPR_THRM2, "THRM2",
77565e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
77665e0446cSFabiano Rosas &spr_read_thrm, &spr_write_generic,
77765e0446cSFabiano Rosas 0x00000000);
77865e0446cSFabiano Rosas
77965e0446cSFabiano Rosas spr_register(env, SPR_THRM3, "THRM3",
78065e0446cSFabiano Rosas SPR_NOACCESS, SPR_NOACCESS,
78165e0446cSFabiano Rosas &spr_read_thrm, &spr_write_generic,
78265e0446cSFabiano Rosas 0x00000000);
78365e0446cSFabiano Rosas }
78465e0446cSFabiano Rosas
register_usprgh_sprs(CPUPPCState * env)78565e0446cSFabiano Rosas void register_usprgh_sprs(CPUPPCState *env)
78665e0446cSFabiano Rosas {
78765e0446cSFabiano Rosas spr_register(env, SPR_USPRG4, "USPRG4",
78865e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
78965e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
79065e0446cSFabiano Rosas 0x00000000);
79165e0446cSFabiano Rosas spr_register(env, SPR_USPRG5, "USPRG5",
79265e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
79365e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
79465e0446cSFabiano Rosas 0x00000000);
79565e0446cSFabiano Rosas spr_register(env, SPR_USPRG6, "USPRG6",
79665e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
79765e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
79865e0446cSFabiano Rosas 0x00000000);
79965e0446cSFabiano Rosas spr_register(env, SPR_USPRG7, "USPRG7",
80065e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
80165e0446cSFabiano Rosas &spr_read_ureg, SPR_NOACCESS,
80265e0446cSFabiano Rosas 0x00000000);
80365e0446cSFabiano Rosas }
804