root / target-ppc / helper_regs.h @ be94c952
History | View | Annotate | Download (3.4 kB)
1 | 0411a972 | j_mayer | /*
|
---|---|---|---|
2 | 0411a972 | j_mayer | * PowerPC emulation special registers manipulation helpers for qemu.
|
3 | 0411a972 | j_mayer | *
|
4 | 0411a972 | j_mayer | * Copyright (c) 2003-2007 Jocelyn Mayer
|
5 | 0411a972 | j_mayer | *
|
6 | 0411a972 | j_mayer | * This library is free software; you can redistribute it and/or
|
7 | 0411a972 | j_mayer | * modify it under the terms of the GNU Lesser General Public
|
8 | 0411a972 | j_mayer | * License as published by the Free Software Foundation; either
|
9 | 0411a972 | j_mayer | * version 2 of the License, or (at your option) any later version.
|
10 | 0411a972 | j_mayer | *
|
11 | 0411a972 | j_mayer | * This library is distributed in the hope that it will be useful,
|
12 | 0411a972 | j_mayer | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 0411a972 | j_mayer | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 0411a972 | j_mayer | * Lesser General Public License for more details.
|
15 | 0411a972 | j_mayer | *
|
16 | 0411a972 | j_mayer | * You should have received a copy of the GNU Lesser General Public
|
17 | 0411a972 | j_mayer | * License along with this library; if not, write to the Free Software
|
18 | 0411a972 | j_mayer | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 0411a972 | j_mayer | */
|
20 | 0411a972 | j_mayer | |
21 | 0411a972 | j_mayer | #if !defined(__HELPER_REGS_H__)
|
22 | 0411a972 | j_mayer | #define __HELPER_REGS_H__
|
23 | 0411a972 | j_mayer | |
24 | 0411a972 | j_mayer | /* Swap temporary saved registers with GPRs */
|
25 | 0411a972 | j_mayer | static always_inline void hreg_swap_gpr_tgpr (CPUPPCState *env) |
26 | 0411a972 | j_mayer | { |
27 | bd7d9a6d | aurel32 | target_ulong tmp; |
28 | 0411a972 | j_mayer | |
29 | 0411a972 | j_mayer | tmp = env->gpr[0];
|
30 | 0411a972 | j_mayer | env->gpr[0] = env->tgpr[0]; |
31 | 0411a972 | j_mayer | env->tgpr[0] = tmp;
|
32 | 0411a972 | j_mayer | tmp = env->gpr[1];
|
33 | 0411a972 | j_mayer | env->gpr[1] = env->tgpr[1]; |
34 | 0411a972 | j_mayer | env->tgpr[1] = tmp;
|
35 | 0411a972 | j_mayer | tmp = env->gpr[2];
|
36 | 0411a972 | j_mayer | env->gpr[2] = env->tgpr[2]; |
37 | 0411a972 | j_mayer | env->tgpr[2] = tmp;
|
38 | 0411a972 | j_mayer | tmp = env->gpr[3];
|
39 | 0411a972 | j_mayer | env->gpr[3] = env->tgpr[3]; |
40 | 0411a972 | j_mayer | env->tgpr[3] = tmp;
|
41 | 0411a972 | j_mayer | } |
42 | 0411a972 | j_mayer | |
43 | 056401ea | j_mayer | static always_inline void hreg_compute_mem_idx (CPUPPCState *env) |
44 | 056401ea | j_mayer | { |
45 | 056401ea | j_mayer | /* Precompute MMU index */
|
46 | a4f30719 | j_mayer | if (msr_pr == 0 && msr_hv != 0) { |
47 | 056401ea | j_mayer | env->mmu_idx = 2;
|
48 | a4f30719 | j_mayer | } else {
|
49 | 056401ea | j_mayer | env->mmu_idx = 1 - msr_pr;
|
50 | a4f30719 | j_mayer | } |
51 | 056401ea | j_mayer | } |
52 | 056401ea | j_mayer | |
53 | 0411a972 | j_mayer | static always_inline void hreg_compute_hflags (CPUPPCState *env) |
54 | 0411a972 | j_mayer | { |
55 | 0411a972 | j_mayer | target_ulong hflags_mask; |
56 | 0411a972 | j_mayer | |
57 | 0411a972 | j_mayer | /* We 'forget' FE0 & FE1: we'll never generate imprecise exceptions */
|
58 | 0411a972 | j_mayer | hflags_mask = (1 << MSR_VR) | (1 << MSR_AP) | (1 << MSR_SA) | |
59 | 0411a972 | j_mayer | (1 << MSR_PR) | (1 << MSR_FP) | (1 << MSR_SE) | (1 << MSR_BE) | |
60 | 0411a972 | j_mayer | (1 << MSR_LE);
|
61 | a4f30719 | j_mayer | hflags_mask |= (1ULL << MSR_CM) | (1ULL << MSR_SF) | MSR_HVB; |
62 | 056401ea | j_mayer | hreg_compute_mem_idx(env); |
63 | 0411a972 | j_mayer | env->hflags = env->msr & hflags_mask; |
64 | 056401ea | j_mayer | /* Merge with hflags coming from other registers */
|
65 | 056401ea | j_mayer | env->hflags |= env->hflags_nmsr; |
66 | 0411a972 | j_mayer | } |
67 | 0411a972 | j_mayer | |
68 | a4f30719 | j_mayer | static always_inline int hreg_store_msr (CPUPPCState *env, target_ulong value, |
69 | a4f30719 | j_mayer | int alter_hv)
|
70 | 0411a972 | j_mayer | { |
71 | 2f462816 | j_mayer | int excp;
|
72 | 0411a972 | j_mayer | |
73 | 0411a972 | j_mayer | excp = 0;
|
74 | 0411a972 | j_mayer | value &= env->msr_mask; |
75 | 0411a972 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
76 | a4f30719 | j_mayer | if (!alter_hv) {
|
77 | a4f30719 | j_mayer | /* mtmsr cannot alter the hypervisor state */
|
78 | a4f30719 | j_mayer | value &= ~MSR_HVB; |
79 | a4f30719 | j_mayer | value |= env->msr & MSR_HVB; |
80 | a4f30719 | j_mayer | } |
81 | 0411a972 | j_mayer | if (((value >> MSR_IR) & 1) != msr_ir || |
82 | 0411a972 | j_mayer | ((value >> MSR_DR) & 1) != msr_dr) {
|
83 | 0411a972 | j_mayer | /* Flush all tlb when changing translation mode */
|
84 | 0411a972 | j_mayer | tlb_flush(env, 1);
|
85 | 0411a972 | j_mayer | excp = POWERPC_EXCP_NONE; |
86 | 0411a972 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
87 | 0411a972 | j_mayer | } |
88 | 0411a972 | j_mayer | if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
|
89 | 0411a972 | j_mayer | ((value ^ env->msr) & (1 << MSR_TGPR)))) {
|
90 | 0411a972 | j_mayer | /* Swap temporary saved registers with GPRs */
|
91 | 0411a972 | j_mayer | hreg_swap_gpr_tgpr(env); |
92 | 0411a972 | j_mayer | } |
93 | 0411a972 | j_mayer | if (unlikely((value >> MSR_EP) & 1) != msr_ep) { |
94 | 0411a972 | j_mayer | /* Change the exception prefix on PowerPC 601 */
|
95 | 0411a972 | j_mayer | env->excp_prefix = ((value >> MSR_EP) & 1) * 0xFFF00000; |
96 | 0411a972 | j_mayer | } |
97 | 0411a972 | j_mayer | #endif
|
98 | 0411a972 | j_mayer | env->msr = value; |
99 | 0411a972 | j_mayer | hreg_compute_hflags(env); |
100 | 0411a972 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
101 | 0411a972 | j_mayer | if (unlikely(msr_pow == 1)) { |
102 | 2f462816 | j_mayer | if ((*env->check_pow)(env)) {
|
103 | 0411a972 | j_mayer | env->halted = 1;
|
104 | 0411a972 | j_mayer | excp = EXCP_HALTED; |
105 | 0411a972 | j_mayer | } |
106 | 0411a972 | j_mayer | } |
107 | 0411a972 | j_mayer | #endif
|
108 | 0411a972 | j_mayer | |
109 | 0411a972 | j_mayer | return excp;
|
110 | 0411a972 | j_mayer | } |
111 | 0411a972 | j_mayer | |
112 | 0411a972 | j_mayer | #endif /* !defined(__HELPER_REGS_H__) */ |