j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 1 | /* |
| 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 Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #if !defined(__HELPER_REGS_H__) |
| 21 | #define __HELPER_REGS_H__ |
| 22 | |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 23 | /* Swap temporary saved registers with GPRs */ |
Blue Swirl | 636aa20 | 2009-08-16 09:06:54 +0000 | [diff] [blame] | 24 | static inline void hreg_swap_gpr_tgpr(CPUPPCState *env) |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 25 | { |
aurel32 | bd7d9a6 | 2008-09-04 05:26:09 +0000 | [diff] [blame] | 26 | target_ulong tmp; |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 27 | |
| 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 Swirl | 636aa20 | 2009-08-16 09:06:54 +0000 | [diff] [blame] | 42 | static inline void hreg_compute_mem_idx(CPUPPCState *env) |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 43 | { |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 44 | /* Precompute MMU index */ |
j_mayer | a4f3071 | 2007-11-17 21:14:09 +0000 | [diff] [blame] | 45 | if (msr_pr == 0 && msr_hv != 0) { |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 46 | env->mmu_idx = 2; |
j_mayer | a4f3071 | 2007-11-17 21:14:09 +0000 | [diff] [blame] | 47 | } else { |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 48 | env->mmu_idx = 1 - msr_pr; |
j_mayer | a4f3071 | 2007-11-17 21:14:09 +0000 | [diff] [blame] | 49 | } |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Blue Swirl | 636aa20 | 2009-08-16 09:06:54 +0000 | [diff] [blame] | 52 | static inline void hreg_compute_hflags(CPUPPCState *env) |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 53 | { |
| 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) | |
| 59 | (1 << MSR_LE); |
j_mayer | a4f3071 | 2007-11-17 21:14:09 +0000 | [diff] [blame] | 60 | hflags_mask |= (1ULL << MSR_CM) | (1ULL << MSR_SF) | MSR_HVB; |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 61 | hreg_compute_mem_idx(env); |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 62 | env->hflags = env->msr & hflags_mask; |
j_mayer | 056401e | 2007-11-04 02:55:33 +0000 | [diff] [blame] | 63 | /* Merge with hflags coming from other registers */ |
| 64 | env->hflags |= env->hflags_nmsr; |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Blue Swirl | 636aa20 | 2009-08-16 09:06:54 +0000 | [diff] [blame] | 67 | static inline int hreg_store_msr(CPUPPCState *env, target_ulong value, |
| 68 | int alter_hv) |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 69 | { |
j_mayer | 2f46281 | 2007-10-25 23:14:50 +0000 | [diff] [blame] | 70 | int excp; |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 71 | |
| 72 | excp = 0; |
| 73 | value &= env->msr_mask; |
| 74 | #if !defined (CONFIG_USER_ONLY) |
j_mayer | a4f3071 | 2007-11-17 21:14:09 +0000 | [diff] [blame] | 75 | if (!alter_hv) { |
| 76 | /* mtmsr cannot alter the hypervisor state */ |
| 77 | value &= ~MSR_HVB; |
| 78 | value |= env->msr & MSR_HVB; |
| 79 | } |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 80 | if (((value >> MSR_IR) & 1) != msr_ir || |
| 81 | ((value >> MSR_DR) & 1) != msr_dr) { |
| 82 | /* Flush all tlb when changing translation mode */ |
| 83 | tlb_flush(env, 1); |
| 84 | excp = POWERPC_EXCP_NONE; |
| 85 | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
| 86 | } |
| 87 | if (unlikely((env->flags & POWERPC_FLAG_TGPR) && |
| 88 | ((value ^ env->msr) & (1 << MSR_TGPR)))) { |
| 89 | /* Swap temporary saved registers with GPRs */ |
| 90 | hreg_swap_gpr_tgpr(env); |
| 91 | } |
| 92 | if (unlikely((value >> MSR_EP) & 1) != msr_ep) { |
| 93 | /* Change the exception prefix on PowerPC 601 */ |
| 94 | env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000; |
| 95 | } |
| 96 | #endif |
| 97 | env->msr = value; |
| 98 | hreg_compute_hflags(env); |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 99 | #if !defined (CONFIG_USER_ONLY) |
| 100 | if (unlikely(msr_pow == 1)) { |
j_mayer | 2f46281 | 2007-10-25 23:14:50 +0000 | [diff] [blame] | 101 | if ((*env->check_pow)(env)) { |
j_mayer | 0411a97 | 2007-10-25 21:35:50 +0000 | [diff] [blame] | 102 | env->halted = 1; |
| 103 | excp = EXCP_HALTED; |
| 104 | } |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | return excp; |
| 109 | } |
| 110 | |
| 111 | #endif /* !defined(__HELPER_REGS_H__) */ |