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
24 #ifndef CONFIG_USER_ONLY
26 #define MMUSUFFIX _mmu
29 #include "softmmu_template.h"
32 #include "softmmu_template.h"
35 #include "softmmu_template.h"
38 #include "softmmu_template.h"
40 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
47 /* XXX: hack to restore env in all cases, even if not called from
51 ret
= cpu_sh4_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
54 /* now we have a real cpu fault */
55 pc
= (unsigned long) retaddr
;
58 /* the PC is inside the translated code. It means that we have
59 a virtual CPU fault */
60 cpu_restore_state(tb
, env
, pc
, NULL
);
70 void helper_ldtlb(void)
72 #ifdef CONFIG_USER_ONLY
80 void helper_raise_illegal_instruction(void)
82 env
->exception_index
= 0x180;
86 void helper_raise_slot_illegal_instruction(void)
88 env
->exception_index
= 0x1a0;
92 void helper_debug(void)
94 env
->exception_index
= EXCP_DEBUG
;
98 void helper_sleep(uint32_t next_pc
)
101 env
->exception_index
= EXCP_HLT
;
106 void helper_trapa(uint32_t tra
)
109 env
->exception_index
= 0x160;
113 uint32_t helper_addc(uint32_t arg0
, uint32_t arg1
)
119 arg1
= tmp1
+ (env
->sr
& 1);
129 uint32_t helper_addv(uint32_t arg0
, uint32_t arg1
)
131 uint32_t dest
, src
, ans
;
133 if ((int32_t) arg1
>= 0)
137 if ((int32_t) arg0
>= 0)
143 if ((int32_t) arg1
>= 0)
148 if (src
== 0 || src
== 2) {
158 #define T (env->sr & SR_T)
159 #define Q (env->sr & SR_Q ? 1 : 0)
160 #define M (env->sr & SR_M ? 1 : 0)
161 #define SETT env->sr |= SR_T
162 #define CLRT env->sr &= ~SR_T
163 #define SETQ env->sr |= SR_Q
164 #define CLRQ env->sr &= ~SR_Q
165 #define SETM env->sr |= SR_M
166 #define CLRM env->sr &= ~SR_M
168 uint32_t helper_div1(uint32_t arg0
, uint32_t arg1
)
171 uint8_t old_q
, tmp1
= 0xff;
173 //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T);
175 if ((0x80000000 & arg1
) != 0)
272 //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T);
276 void helper_macl(uint32_t arg0
, uint32_t arg1
)
280 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
281 res
+= (int64_t) (int32_t) arg0
*(int64_t) (int32_t) arg1
;
282 env
->mach
= (res
>> 32) & 0xffffffff;
283 env
->macl
= res
& 0xffffffff;
284 if (env
->sr
& SR_S
) {
286 env
->mach
|= 0xffff0000;
288 env
->mach
&= 0x00007fff;
292 void helper_macw(uint32_t arg0
, uint32_t arg1
)
296 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
297 res
+= (int64_t) (int16_t) arg0
*(int64_t) (int16_t) arg1
;
298 env
->mach
= (res
>> 32) & 0xffffffff;
299 env
->macl
= res
& 0xffffffff;
300 if (env
->sr
& SR_S
) {
301 if (res
< -0x80000000) {
303 env
->macl
= 0x80000000;
304 } else if (res
> 0x000000007fffffff) {
306 env
->macl
= 0x7fffffff;
311 uint32_t helper_negc(uint32_t arg
)
316 arg
= temp
- (env
->sr
& SR_T
);
326 uint32_t helper_subc(uint32_t arg0
, uint32_t arg1
)
332 arg1
= tmp1
- (env
->sr
& SR_T
);
342 uint32_t helper_subv(uint32_t arg0
, uint32_t arg1
)
344 int32_t dest
, src
, ans
;
346 if ((int32_t) arg1
>= 0)
350 if ((int32_t) arg0
>= 0)
356 if ((int32_t) arg1
>= 0)
371 static inline void set_t(void)
376 static inline void clr_t(void)
381 void helper_ld_fpscr(uint32_t val
)
383 env
->fpscr
= val
& 0x003fffff;
385 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
387 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
390 uint32_t helper_fabs_FT(uint32_t t0
)
394 f
.f
= float32_abs(f
.f
);
398 uint64_t helper_fabs_DT(uint64_t t0
)
402 d
.d
= float64_abs(d
.d
);
406 uint32_t helper_fadd_FT(uint32_t t0
, uint32_t t1
)
411 f0
.f
= float32_add(f0
.f
, f1
.f
, &env
->fp_status
);
415 uint64_t helper_fadd_DT(uint64_t t0
, uint64_t t1
)
420 d0
.d
= float64_add(d0
.d
, d1
.d
, &env
->fp_status
);
424 void helper_fcmp_eq_FT(uint32_t t0
, uint32_t t1
)
430 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 0)
436 void helper_fcmp_eq_DT(uint64_t t0
, uint64_t t1
)
442 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 0)
448 void helper_fcmp_gt_FT(uint32_t t0
, uint32_t t1
)
454 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 1)
460 void helper_fcmp_gt_DT(uint64_t t0
, uint64_t t1
)
466 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 1)
472 uint64_t helper_fcnvsd_FT_DT(uint32_t t0
)
477 d
.d
= float32_to_float64(f
.f
, &env
->fp_status
);
481 uint32_t helper_fcnvds_DT_FT(uint64_t t0
)
486 f
.f
= float64_to_float32(d
.d
, &env
->fp_status
);
490 uint32_t helper_fdiv_FT(uint32_t t0
, uint32_t t1
)
495 f0
.f
= float32_div(f0
.f
, f1
.f
, &env
->fp_status
);
499 uint64_t helper_fdiv_DT(uint64_t t0
, uint64_t t1
)
504 d0
.d
= float64_div(d0
.d
, d1
.d
, &env
->fp_status
);
508 uint32_t helper_float_FT(uint32_t t0
)
511 f
.f
= int32_to_float32(t0
, &env
->fp_status
);
515 uint64_t helper_float_DT(uint32_t t0
)
518 d
.d
= int32_to_float64(t0
, &env
->fp_status
);
522 uint32_t helper_fmul_FT(uint32_t t0
, uint32_t t1
)
527 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
531 uint64_t helper_fmul_DT(uint64_t t0
, uint64_t t1
)
536 d0
.d
= float64_mul(d0
.d
, d1
.d
, &env
->fp_status
);
540 uint32_t helper_fneg_T(uint32_t t0
)
544 f
.f
= float32_chs(f
.f
);
548 uint32_t helper_fsqrt_FT(uint32_t t0
)
552 f
.f
= float32_sqrt(f
.f
, &env
->fp_status
);
556 uint64_t helper_fsqrt_DT(uint64_t t0
)
560 d
.d
= float64_sqrt(d
.d
, &env
->fp_status
);
564 uint32_t helper_fsub_FT(uint32_t t0
, uint32_t t1
)
569 f0
.f
= float32_sub(f0
.f
, f1
.f
, &env
->fp_status
);
573 uint64_t helper_fsub_DT(uint64_t t0
, uint64_t t1
)
578 d0
.d
= float64_sub(d0
.d
, d1
.d
, &env
->fp_status
);
582 uint32_t helper_ftrc_FT(uint32_t t0
)
586 return float32_to_int32_round_to_zero(f
.f
, &env
->fp_status
);
589 uint32_t helper_ftrc_DT(uint64_t t0
)
593 return float64_to_int32_round_to_zero(d
.d
, &env
->fp_status
);