4 * Copyright (c) 2005 Samuel Tardieu
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 void do_raise_exception(void)
28 #ifndef CONFIG_USER_ONLY
30 #define MMUSUFFIX _mmu
31 #define GETPC() (__builtin_return_address(0))
34 #include "softmmu_template.h"
37 #include "softmmu_template.h"
40 #include "softmmu_template.h"
43 #include "softmmu_template.h"
45 void tlb_fill(target_ulong addr
, int is_write
, int is_user
, void *retaddr
)
52 /* XXX: hack to restore env in all cases, even if not called from
56 ret
= cpu_sh4_handle_mmu_fault(env
, addr
, is_write
, is_user
, 1);
59 /* now we have a real cpu fault */
60 pc
= (unsigned long) retaddr
;
63 /* the PC is inside the translated code. It means that we have
64 a virtual CPU fault */
65 cpu_restore_state(tb
, env
, pc
, NULL
);
75 void helper_addc_T0_T1(void)
81 T1
= tmp1
+ (env
->sr
& 1);
90 void helper_addv_T0_T1(void)
92 uint32_t dest
, src
, ans
;
94 if ((int32_t) T1
>= 0)
98 if ((int32_t) T0
>= 0)
104 if ((int32_t) T1
>= 0)
109 if (src
== 0 || src
== 2) {
118 #define T (env->sr & SR_T)
119 #define Q (env->sr & SR_Q ? 1 : 0)
120 #define M (env->sr & SR_M ? 1 : 0)
121 #define SETT env->sr |= SR_T
122 #define CLRT env->sr &= ~SR_T
123 #define SETQ env->sr |= SR_Q
124 #define CLRQ env->sr &= ~SR_Q
125 #define SETM env->sr |= SR_M
126 #define CLRM env->sr &= ~SR_M
128 void helper_div1_T0_T1(void)
131 uint8_t old_q
, tmp1
= 0xff;
133 //printf("div1 T0=0x%08x T1=0x%08x M=%d Q=%d T=%d\n", T0, T1, M, Q, T);
135 if ((0x80000000 & T1
) != 0)
232 //printf("Output: T1=0x%08x M=%d Q=%d T=%d\n", T1, M, Q, T);
235 void helper_dmulsl_T0_T1()
239 res
= (int64_t) (int32_t) T0
*(int64_t) (int32_t) T1
;
240 env
->mach
= (res
>> 32) & 0xffffffff;
241 env
->macl
= res
& 0xffffffff;
244 void helper_dmulul_T0_T1()
248 res
= (uint64_t) (uint32_t) T0
*(uint64_t) (uint32_t) T1
;
249 env
->mach
= (res
>> 32) & 0xffffffff;
250 env
->macl
= res
& 0xffffffff;
253 void helper_macl_T0_T1()
257 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
258 res
+= (int64_t) (int32_t) T0
*(int64_t) (int32_t) T1
;
259 env
->mach
= (res
>> 32) & 0xffffffff;
260 env
->macl
= res
& 0xffffffff;
261 if (env
->sr
& SR_S
) {
263 env
->mach
|= 0xffff0000;
265 env
->mach
&= 0x00007fff;
269 void helper_macw_T0_T1()
273 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
274 res
+= (int64_t) (int16_t) T0
*(int64_t) (int16_t) T1
;
275 env
->mach
= (res
>> 32) & 0xffffffff;
276 env
->macl
= res
& 0xffffffff;
277 if (env
->sr
& SR_S
) {
278 if (res
< -0x80000000) {
280 env
->macl
= 0x80000000;
281 } else if (res
> 0x000000007fffffff) {
283 env
->macl
= 0x7fffffff;
288 void helper_negc_T0()
293 T0
= temp
- (env
->sr
& SR_T
);
302 void helper_subc_T0_T1()
308 T1
= tmp1
- (env
->sr
& SR_T
);
317 void helper_subv_T0_T1()
319 int32_t dest
, src
, ans
;
321 if ((int32_t) T1
>= 0)
325 if ((int32_t) T0
>= 0)
331 if ((int32_t) T1
>= 0)
345 void helper_rotcl(uint32_t * addr
)
349 new = (*addr
<< 1) | (env
->sr
& SR_T
);
350 if (*addr
& 0x80000000)
357 void helper_rotcr(uint32_t * addr
)
361 new = (*addr
>> 1) | ((env
->sr
& SR_T
) ? 0x80000000 : 0);