xref: /qemu/target/mips/tcg/op_helper.c (revision 4c44a980)
1a2b0a27dSPhilippe Mathieu-Daudé /*
2a2b0a27dSPhilippe Mathieu-Daudé  *  MIPS emulation helpers for qemu.
3a2b0a27dSPhilippe Mathieu-Daudé  *
4a2b0a27dSPhilippe Mathieu-Daudé  *  Copyright (c) 2004-2005 Jocelyn Mayer
5a2b0a27dSPhilippe Mathieu-Daudé  *
6a2b0a27dSPhilippe Mathieu-Daudé  * This library is free software; you can redistribute it and/or
7a2b0a27dSPhilippe Mathieu-Daudé  * modify it under the terms of the GNU Lesser General Public
8a2b0a27dSPhilippe Mathieu-Daudé  * License as published by the Free Software Foundation; either
9a2b0a27dSPhilippe Mathieu-Daudé  * version 2.1 of the License, or (at your option) any later version.
10a2b0a27dSPhilippe Mathieu-Daudé  *
11a2b0a27dSPhilippe Mathieu-Daudé  * This library is distributed in the hope that it will be useful,
12a2b0a27dSPhilippe Mathieu-Daudé  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13a2b0a27dSPhilippe Mathieu-Daudé  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14a2b0a27dSPhilippe Mathieu-Daudé  * Lesser General Public License for more details.
15a2b0a27dSPhilippe Mathieu-Daudé  *
16a2b0a27dSPhilippe Mathieu-Daudé  * You should have received a copy of the GNU Lesser General Public
17a2b0a27dSPhilippe Mathieu-Daudé  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18a2b0a27dSPhilippe Mathieu-Daudé  *
19a2b0a27dSPhilippe Mathieu-Daudé  */
20a2b0a27dSPhilippe Mathieu-Daudé 
21a2b0a27dSPhilippe Mathieu-Daudé #include "qemu/osdep.h"
22a2b0a27dSPhilippe Mathieu-Daudé #include "cpu.h"
23a2b0a27dSPhilippe Mathieu-Daudé #include "internal.h"
24a2b0a27dSPhilippe Mathieu-Daudé #include "exec/helper-proto.h"
25a2b0a27dSPhilippe Mathieu-Daudé #include "exec/exec-all.h"
26a2b0a27dSPhilippe Mathieu-Daudé #include "exec/memop.h"
27a2b0a27dSPhilippe Mathieu-Daudé #include "fpu_helper.h"
28a2b0a27dSPhilippe Mathieu-Daudé 
bitswap(target_ulong v)29a2b0a27dSPhilippe Mathieu-Daudé static inline target_ulong bitswap(target_ulong v)
30a2b0a27dSPhilippe Mathieu-Daudé {
31a2b0a27dSPhilippe Mathieu-Daudé     v = ((v >> 1) & (target_ulong)0x5555555555555555ULL) |
32a2b0a27dSPhilippe Mathieu-Daudé               ((v & (target_ulong)0x5555555555555555ULL) << 1);
33a2b0a27dSPhilippe Mathieu-Daudé     v = ((v >> 2) & (target_ulong)0x3333333333333333ULL) |
34a2b0a27dSPhilippe Mathieu-Daudé               ((v & (target_ulong)0x3333333333333333ULL) << 2);
35a2b0a27dSPhilippe Mathieu-Daudé     v = ((v >> 4) & (target_ulong)0x0F0F0F0F0F0F0F0FULL) |
36a2b0a27dSPhilippe Mathieu-Daudé               ((v & (target_ulong)0x0F0F0F0F0F0F0F0FULL) << 4);
37a2b0a27dSPhilippe Mathieu-Daudé     return v;
38a2b0a27dSPhilippe Mathieu-Daudé }
39a2b0a27dSPhilippe Mathieu-Daudé 
40a2b0a27dSPhilippe Mathieu-Daudé #ifdef TARGET_MIPS64
helper_dbitswap(target_ulong rt)41a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_dbitswap(target_ulong rt)
42a2b0a27dSPhilippe Mathieu-Daudé {
43a2b0a27dSPhilippe Mathieu-Daudé     return bitswap(rt);
44a2b0a27dSPhilippe Mathieu-Daudé }
45a2b0a27dSPhilippe Mathieu-Daudé #endif
46a2b0a27dSPhilippe Mathieu-Daudé 
helper_bitswap(target_ulong rt)47a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_bitswap(target_ulong rt)
48a2b0a27dSPhilippe Mathieu-Daudé {
49a2b0a27dSPhilippe Mathieu-Daudé     return (int32_t)bitswap(rt);
50a2b0a27dSPhilippe Mathieu-Daudé }
51a2b0a27dSPhilippe Mathieu-Daudé 
helper_rotx(target_ulong rs,uint32_t shift,uint32_t shiftx,uint32_t stripe)52a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rotx(target_ulong rs, uint32_t shift, uint32_t shiftx,
53a2b0a27dSPhilippe Mathieu-Daudé                         uint32_t stripe)
54a2b0a27dSPhilippe Mathieu-Daudé {
55a2b0a27dSPhilippe Mathieu-Daudé     int i;
56a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp0 = ((uint64_t)rs) << 32 | ((uint64_t)rs & 0xffffffff);
57a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp1 = tmp0;
58a2b0a27dSPhilippe Mathieu-Daudé     for (i = 0; i <= 46; i++) {
59a2b0a27dSPhilippe Mathieu-Daudé         int s;
60a2b0a27dSPhilippe Mathieu-Daudé         if (i & 0x8) {
61a2b0a27dSPhilippe Mathieu-Daudé             s = shift;
62a2b0a27dSPhilippe Mathieu-Daudé         } else {
63a2b0a27dSPhilippe Mathieu-Daudé             s = shiftx;
64a2b0a27dSPhilippe Mathieu-Daudé         }
65a2b0a27dSPhilippe Mathieu-Daudé 
66a2b0a27dSPhilippe Mathieu-Daudé         if (stripe != 0 && !(i & 0x4)) {
67a2b0a27dSPhilippe Mathieu-Daudé             s = ~s;
68a2b0a27dSPhilippe Mathieu-Daudé         }
69a2b0a27dSPhilippe Mathieu-Daudé         if (s & 0x10) {
70a2b0a27dSPhilippe Mathieu-Daudé             if (tmp0 & (1LL << (i + 16))) {
71a2b0a27dSPhilippe Mathieu-Daudé                 tmp1 |= 1LL << i;
72a2b0a27dSPhilippe Mathieu-Daudé             } else {
73a2b0a27dSPhilippe Mathieu-Daudé                 tmp1 &= ~(1LL << i);
74a2b0a27dSPhilippe Mathieu-Daudé             }
75a2b0a27dSPhilippe Mathieu-Daudé         }
76a2b0a27dSPhilippe Mathieu-Daudé     }
77a2b0a27dSPhilippe Mathieu-Daudé 
78a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp2 = tmp1;
79a2b0a27dSPhilippe Mathieu-Daudé     for (i = 0; i <= 38; i++) {
80a2b0a27dSPhilippe Mathieu-Daudé         int s;
81a2b0a27dSPhilippe Mathieu-Daudé         if (i & 0x4) {
82a2b0a27dSPhilippe Mathieu-Daudé             s = shift;
83a2b0a27dSPhilippe Mathieu-Daudé         } else {
84a2b0a27dSPhilippe Mathieu-Daudé             s = shiftx;
85a2b0a27dSPhilippe Mathieu-Daudé         }
86a2b0a27dSPhilippe Mathieu-Daudé 
87a2b0a27dSPhilippe Mathieu-Daudé         if (s & 0x8) {
88a2b0a27dSPhilippe Mathieu-Daudé             if (tmp1 & (1LL << (i + 8))) {
89a2b0a27dSPhilippe Mathieu-Daudé                 tmp2 |= 1LL << i;
90a2b0a27dSPhilippe Mathieu-Daudé             } else {
91a2b0a27dSPhilippe Mathieu-Daudé                 tmp2 &= ~(1LL << i);
92a2b0a27dSPhilippe Mathieu-Daudé             }
93a2b0a27dSPhilippe Mathieu-Daudé         }
94a2b0a27dSPhilippe Mathieu-Daudé     }
95a2b0a27dSPhilippe Mathieu-Daudé 
96a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp3 = tmp2;
97a2b0a27dSPhilippe Mathieu-Daudé     for (i = 0; i <= 34; i++) {
98a2b0a27dSPhilippe Mathieu-Daudé         int s;
99a2b0a27dSPhilippe Mathieu-Daudé         if (i & 0x2) {
100a2b0a27dSPhilippe Mathieu-Daudé             s = shift;
101a2b0a27dSPhilippe Mathieu-Daudé         } else {
102a2b0a27dSPhilippe Mathieu-Daudé             s = shiftx;
103a2b0a27dSPhilippe Mathieu-Daudé         }
104a2b0a27dSPhilippe Mathieu-Daudé         if (s & 0x4) {
105a2b0a27dSPhilippe Mathieu-Daudé             if (tmp2 & (1LL << (i + 4))) {
106a2b0a27dSPhilippe Mathieu-Daudé                 tmp3 |= 1LL << i;
107a2b0a27dSPhilippe Mathieu-Daudé             } else {
108a2b0a27dSPhilippe Mathieu-Daudé                 tmp3 &= ~(1LL << i);
109a2b0a27dSPhilippe Mathieu-Daudé             }
110a2b0a27dSPhilippe Mathieu-Daudé         }
111a2b0a27dSPhilippe Mathieu-Daudé     }
112a2b0a27dSPhilippe Mathieu-Daudé 
113a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp4 = tmp3;
114a2b0a27dSPhilippe Mathieu-Daudé     for (i = 0; i <= 32; i++) {
115a2b0a27dSPhilippe Mathieu-Daudé         int s;
116a2b0a27dSPhilippe Mathieu-Daudé         if (i & 0x1) {
117a2b0a27dSPhilippe Mathieu-Daudé             s = shift;
118a2b0a27dSPhilippe Mathieu-Daudé         } else {
119a2b0a27dSPhilippe Mathieu-Daudé             s = shiftx;
120a2b0a27dSPhilippe Mathieu-Daudé         }
121a2b0a27dSPhilippe Mathieu-Daudé         if (s & 0x2) {
122a2b0a27dSPhilippe Mathieu-Daudé             if (tmp3 & (1LL << (i + 2))) {
123a2b0a27dSPhilippe Mathieu-Daudé                 tmp4 |= 1LL << i;
124a2b0a27dSPhilippe Mathieu-Daudé             } else {
125a2b0a27dSPhilippe Mathieu-Daudé                 tmp4 &= ~(1LL << i);
126a2b0a27dSPhilippe Mathieu-Daudé             }
127a2b0a27dSPhilippe Mathieu-Daudé         }
128a2b0a27dSPhilippe Mathieu-Daudé     }
129a2b0a27dSPhilippe Mathieu-Daudé 
130a2b0a27dSPhilippe Mathieu-Daudé     uint64_t tmp5 = tmp4;
131a2b0a27dSPhilippe Mathieu-Daudé     for (i = 0; i <= 31; i++) {
132a2b0a27dSPhilippe Mathieu-Daudé         int s;
133a2b0a27dSPhilippe Mathieu-Daudé         s = shift;
134a2b0a27dSPhilippe Mathieu-Daudé         if (s & 0x1) {
135a2b0a27dSPhilippe Mathieu-Daudé             if (tmp4 & (1LL << (i + 1))) {
136a2b0a27dSPhilippe Mathieu-Daudé                 tmp5 |= 1LL << i;
137a2b0a27dSPhilippe Mathieu-Daudé             } else {
138a2b0a27dSPhilippe Mathieu-Daudé                 tmp5 &= ~(1LL << i);
139a2b0a27dSPhilippe Mathieu-Daudé             }
140a2b0a27dSPhilippe Mathieu-Daudé         }
141a2b0a27dSPhilippe Mathieu-Daudé     }
142a2b0a27dSPhilippe Mathieu-Daudé 
143a2b0a27dSPhilippe Mathieu-Daudé     return (int64_t)(int32_t)(uint32_t)tmp5;
144a2b0a27dSPhilippe Mathieu-Daudé }
145a2b0a27dSPhilippe Mathieu-Daudé 
helper_fork(target_ulong arg1,target_ulong arg2)146a2b0a27dSPhilippe Mathieu-Daudé void helper_fork(target_ulong arg1, target_ulong arg2)
147a2b0a27dSPhilippe Mathieu-Daudé {
148a2b0a27dSPhilippe Mathieu-Daudé     /*
149a2b0a27dSPhilippe Mathieu-Daudé      * arg1 = rt, arg2 = rs
150a2b0a27dSPhilippe Mathieu-Daudé      * TODO: store to TC register
151a2b0a27dSPhilippe Mathieu-Daudé      */
152a2b0a27dSPhilippe Mathieu-Daudé }
153a2b0a27dSPhilippe Mathieu-Daudé 
helper_yield(CPUMIPSState * env,target_ulong arg)154a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_yield(CPUMIPSState *env, target_ulong arg)
155a2b0a27dSPhilippe Mathieu-Daudé {
156a2b0a27dSPhilippe Mathieu-Daudé     target_long arg1 = arg;
157a2b0a27dSPhilippe Mathieu-Daudé 
158a2b0a27dSPhilippe Mathieu-Daudé     if (arg1 < 0) {
159a2b0a27dSPhilippe Mathieu-Daudé         /* No scheduling policy implemented. */
160a2b0a27dSPhilippe Mathieu-Daudé         if (arg1 != -2) {
161a2b0a27dSPhilippe Mathieu-Daudé             if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
162a2b0a27dSPhilippe Mathieu-Daudé                 env->active_tc.CP0_TCStatus & (1 << CP0TCSt_DT)) {
163a2b0a27dSPhilippe Mathieu-Daudé                 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
164a2b0a27dSPhilippe Mathieu-Daudé                 env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
165a2b0a27dSPhilippe Mathieu-Daudé                 do_raise_exception(env, EXCP_THREAD, GETPC());
166a2b0a27dSPhilippe Mathieu-Daudé             }
167a2b0a27dSPhilippe Mathieu-Daudé         }
168a2b0a27dSPhilippe Mathieu-Daudé     } else if (arg1 == 0) {
169a2b0a27dSPhilippe Mathieu-Daudé         if (0) {
170a2b0a27dSPhilippe Mathieu-Daudé             /* TODO: TC underflow */
171a2b0a27dSPhilippe Mathieu-Daudé             env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
172a2b0a27dSPhilippe Mathieu-Daudé             do_raise_exception(env, EXCP_THREAD, GETPC());
173a2b0a27dSPhilippe Mathieu-Daudé         } else {
174a2b0a27dSPhilippe Mathieu-Daudé             /* TODO: Deallocate TC */
175a2b0a27dSPhilippe Mathieu-Daudé         }
176a2b0a27dSPhilippe Mathieu-Daudé     } else if (arg1 > 0) {
177a2b0a27dSPhilippe Mathieu-Daudé         /* Yield qualifier inputs not implemented. */
178a2b0a27dSPhilippe Mathieu-Daudé         env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
179a2b0a27dSPhilippe Mathieu-Daudé         env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
180a2b0a27dSPhilippe Mathieu-Daudé         do_raise_exception(env, EXCP_THREAD, GETPC());
181a2b0a27dSPhilippe Mathieu-Daudé     }
182a2b0a27dSPhilippe Mathieu-Daudé     return env->CP0_YQMask;
183a2b0a27dSPhilippe Mathieu-Daudé }
184a2b0a27dSPhilippe Mathieu-Daudé 
check_hwrena(CPUMIPSState * env,int reg,uintptr_t pc)185a2b0a27dSPhilippe Mathieu-Daudé static inline void check_hwrena(CPUMIPSState *env, int reg, uintptr_t pc)
186a2b0a27dSPhilippe Mathieu-Daudé {
187a2b0a27dSPhilippe Mathieu-Daudé     if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << reg))) {
188a2b0a27dSPhilippe Mathieu-Daudé         return;
189a2b0a27dSPhilippe Mathieu-Daudé     }
190a2b0a27dSPhilippe Mathieu-Daudé     do_raise_exception(env, EXCP_RI, pc);
191a2b0a27dSPhilippe Mathieu-Daudé }
192a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_cpunum(CPUMIPSState * env)193a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_cpunum(CPUMIPSState *env)
194a2b0a27dSPhilippe Mathieu-Daudé {
195a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 0, GETPC());
196a2b0a27dSPhilippe Mathieu-Daudé     return env->CP0_EBase & 0x3ff;
197a2b0a27dSPhilippe Mathieu-Daudé }
198a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_synci_step(CPUMIPSState * env)199a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
200a2b0a27dSPhilippe Mathieu-Daudé {
201a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 1, GETPC());
202a2b0a27dSPhilippe Mathieu-Daudé     return env->SYNCI_Step;
203a2b0a27dSPhilippe Mathieu-Daudé }
204a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_cc(CPUMIPSState * env)205a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_cc(CPUMIPSState *env)
206a2b0a27dSPhilippe Mathieu-Daudé {
207a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 2, GETPC());
208a2b0a27dSPhilippe Mathieu-Daudé #ifdef CONFIG_USER_ONLY
209a2b0a27dSPhilippe Mathieu-Daudé     return env->CP0_Count;
210a2b0a27dSPhilippe Mathieu-Daudé #else
211a2b0a27dSPhilippe Mathieu-Daudé     return (int32_t)cpu_mips_get_count(env);
212a2b0a27dSPhilippe Mathieu-Daudé #endif
213a2b0a27dSPhilippe Mathieu-Daudé }
214a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_ccres(CPUMIPSState * env)215a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_ccres(CPUMIPSState *env)
216a2b0a27dSPhilippe Mathieu-Daudé {
217a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 3, GETPC());
218a2b0a27dSPhilippe Mathieu-Daudé     return env->CCRes;
219a2b0a27dSPhilippe Mathieu-Daudé }
220a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_performance(CPUMIPSState * env)221a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_performance(CPUMIPSState *env)
222a2b0a27dSPhilippe Mathieu-Daudé {
223a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 4, GETPC());
224a2b0a27dSPhilippe Mathieu-Daudé     return env->CP0_Performance0;
225a2b0a27dSPhilippe Mathieu-Daudé }
226a2b0a27dSPhilippe Mathieu-Daudé 
helper_rdhwr_xnp(CPUMIPSState * env)227a2b0a27dSPhilippe Mathieu-Daudé target_ulong helper_rdhwr_xnp(CPUMIPSState *env)
228a2b0a27dSPhilippe Mathieu-Daudé {
229a2b0a27dSPhilippe Mathieu-Daudé     check_hwrena(env, 5, GETPC());
230a2b0a27dSPhilippe Mathieu-Daudé     return (env->CP0_Config5 >> CP0C5_XNP) & 1;
231a2b0a27dSPhilippe Mathieu-Daudé }
232a2b0a27dSPhilippe Mathieu-Daudé 
helper_pmon(CPUMIPSState * env,int function)233a2b0a27dSPhilippe Mathieu-Daudé void helper_pmon(CPUMIPSState *env, int function)
234a2b0a27dSPhilippe Mathieu-Daudé {
235a2b0a27dSPhilippe Mathieu-Daudé     function /= 2;
236a2b0a27dSPhilippe Mathieu-Daudé     switch (function) {
237a2b0a27dSPhilippe Mathieu-Daudé     case 2: /* TODO: char inbyte(int waitflag); */
238a2b0a27dSPhilippe Mathieu-Daudé         if (env->active_tc.gpr[4] == 0) {
239a2b0a27dSPhilippe Mathieu-Daudé             env->active_tc.gpr[2] = -1;
240a2b0a27dSPhilippe Mathieu-Daudé         }
241a2b0a27dSPhilippe Mathieu-Daudé         /* Fall through */
242a2b0a27dSPhilippe Mathieu-Daudé     case 11: /* TODO: char inbyte (void); */
243a2b0a27dSPhilippe Mathieu-Daudé         env->active_tc.gpr[2] = -1;
244a2b0a27dSPhilippe Mathieu-Daudé         break;
245a2b0a27dSPhilippe Mathieu-Daudé     case 3:
246a2b0a27dSPhilippe Mathieu-Daudé     case 12:
247a2b0a27dSPhilippe Mathieu-Daudé         printf("%c", (char)(env->active_tc.gpr[4] & 0xFF));
248a2b0a27dSPhilippe Mathieu-Daudé         break;
249a2b0a27dSPhilippe Mathieu-Daudé     case 17:
250a2b0a27dSPhilippe Mathieu-Daudé         break;
251a2b0a27dSPhilippe Mathieu-Daudé     case 158:
252a2b0a27dSPhilippe Mathieu-Daudé         {
253a2b0a27dSPhilippe Mathieu-Daudé             unsigned char *fmt = (void *)(uintptr_t)env->active_tc.gpr[4];
254a2b0a27dSPhilippe Mathieu-Daudé             printf("%s", fmt);
255a2b0a27dSPhilippe Mathieu-Daudé         }
256a2b0a27dSPhilippe Mathieu-Daudé         break;
257a2b0a27dSPhilippe Mathieu-Daudé     }
258a2b0a27dSPhilippe Mathieu-Daudé }
259a2b0a27dSPhilippe Mathieu-Daudé 
26003afdc28SJiaxun Yang #ifdef TARGET_MIPS64
helper_lcsr_cpucfg(CPUMIPSState * env,target_ulong rs)26103afdc28SJiaxun Yang target_ulong helper_lcsr_cpucfg(CPUMIPSState *env, target_ulong rs)
26203afdc28SJiaxun Yang {
26303afdc28SJiaxun Yang     switch (rs) {
26403afdc28SJiaxun Yang     case 0:
26503afdc28SJiaxun Yang         return env->CP0_PRid;
26603afdc28SJiaxun Yang     case 1:
26703afdc28SJiaxun Yang         return env->lcsr_cpucfg1;
26803afdc28SJiaxun Yang     case 2:
26903afdc28SJiaxun Yang         return env->lcsr_cpucfg2;
27003afdc28SJiaxun Yang     default:
27103afdc28SJiaxun Yang         return 0;
27203afdc28SJiaxun Yang     }
27303afdc28SJiaxun Yang }
27403afdc28SJiaxun Yang #endif
27503afdc28SJiaxun Yang 
276a2b0a27dSPhilippe Mathieu-Daudé #if !defined(CONFIG_USER_ONLY)
277a2b0a27dSPhilippe Mathieu-Daudé 
mips_cpu_do_unaligned_access(CPUState * cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)278a2b0a27dSPhilippe Mathieu-Daudé void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
279a2b0a27dSPhilippe Mathieu-Daudé                                   MMUAccessType access_type,
280a2b0a27dSPhilippe Mathieu-Daudé                                   int mmu_idx, uintptr_t retaddr)
281a2b0a27dSPhilippe Mathieu-Daudé {
2824c44a980SPhilippe Mathieu-Daudé     CPUMIPSState *env = cpu_env(cs);
283a2b0a27dSPhilippe Mathieu-Daudé     int error_code = 0;
284a2b0a27dSPhilippe Mathieu-Daudé     int excp;
285a2b0a27dSPhilippe Mathieu-Daudé 
286a2b0a27dSPhilippe Mathieu-Daudé     if (!(env->hflags & MIPS_HFLAG_DM)) {
287a2b0a27dSPhilippe Mathieu-Daudé         env->CP0_BadVAddr = addr;
288a2b0a27dSPhilippe Mathieu-Daudé     }
289a2b0a27dSPhilippe Mathieu-Daudé 
290a2b0a27dSPhilippe Mathieu-Daudé     if (access_type == MMU_DATA_STORE) {
291a2b0a27dSPhilippe Mathieu-Daudé         excp = EXCP_AdES;
292a2b0a27dSPhilippe Mathieu-Daudé     } else {
293a2b0a27dSPhilippe Mathieu-Daudé         excp = EXCP_AdEL;
294a2b0a27dSPhilippe Mathieu-Daudé         if (access_type == MMU_INST_FETCH) {
295a2b0a27dSPhilippe Mathieu-Daudé             error_code |= EXCP_INST_NOTAVAIL;
296a2b0a27dSPhilippe Mathieu-Daudé         }
297a2b0a27dSPhilippe Mathieu-Daudé     }
298a2b0a27dSPhilippe Mathieu-Daudé 
299a2b0a27dSPhilippe Mathieu-Daudé     do_raise_exception_err(env, excp, error_code, retaddr);
300a2b0a27dSPhilippe Mathieu-Daudé }
301a2b0a27dSPhilippe Mathieu-Daudé 
mips_cpu_do_transaction_failed(CPUState * cs,hwaddr physaddr,vaddr addr,unsigned size,MMUAccessType access_type,int mmu_idx,MemTxAttrs attrs,MemTxResult response,uintptr_t retaddr)302a2b0a27dSPhilippe Mathieu-Daudé void mips_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
303a2b0a27dSPhilippe Mathieu-Daudé                                     vaddr addr, unsigned size,
304a2b0a27dSPhilippe Mathieu-Daudé                                     MMUAccessType access_type,
305a2b0a27dSPhilippe Mathieu-Daudé                                     int mmu_idx, MemTxAttrs attrs,
306a2b0a27dSPhilippe Mathieu-Daudé                                     MemTxResult response, uintptr_t retaddr)
307a2b0a27dSPhilippe Mathieu-Daudé {
3084c44a980SPhilippe Mathieu-Daudé     MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cs);
3094c44a980SPhilippe Mathieu-Daudé     CPUMIPSState *env = cpu_env(cs);
310a2b0a27dSPhilippe Mathieu-Daudé 
311a2b0a27dSPhilippe Mathieu-Daudé     if (access_type == MMU_INST_FETCH) {
312a2b0a27dSPhilippe Mathieu-Daudé         do_raise_exception(env, EXCP_IBE, retaddr);
3133803b6b4SRichard Henderson     } else if (!mcc->no_data_aborts) {
314a2b0a27dSPhilippe Mathieu-Daudé         do_raise_exception(env, EXCP_DBE, retaddr);
315a2b0a27dSPhilippe Mathieu-Daudé     }
316a2b0a27dSPhilippe Mathieu-Daudé }
317a2b0a27dSPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
318