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_raise_fpu_disable(void)
94 env
->exception_index
= 0x800;
98 void helper_raise_slot_fpu_disable(void)
100 env
->exception_index
= 0x820;
104 void helper_debug(void)
106 env
->exception_index
= EXCP_DEBUG
;
110 void helper_sleep(uint32_t next_pc
)
113 env
->exception_index
= EXCP_HLT
;
118 void helper_trapa(uint32_t tra
)
121 env
->exception_index
= 0x160;
125 uint32_t helper_addc(uint32_t arg0
, uint32_t arg1
)
131 arg1
= tmp1
+ (env
->sr
& 1);
141 uint32_t helper_addv(uint32_t arg0
, uint32_t arg1
)
143 uint32_t dest
, src
, ans
;
145 if ((int32_t) arg1
>= 0)
149 if ((int32_t) arg0
>= 0)
155 if ((int32_t) arg1
>= 0)
160 if (src
== 0 || src
== 2) {
170 #define T (env->sr & SR_T)
171 #define Q (env->sr & SR_Q ? 1 : 0)
172 #define M (env->sr & SR_M ? 1 : 0)
173 #define SETT env->sr |= SR_T
174 #define CLRT env->sr &= ~SR_T
175 #define SETQ env->sr |= SR_Q
176 #define CLRQ env->sr &= ~SR_Q
177 #define SETM env->sr |= SR_M
178 #define CLRM env->sr &= ~SR_M
180 uint32_t helper_div1(uint32_t arg0
, uint32_t arg1
)
183 uint8_t old_q
, tmp1
= 0xff;
185 //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T);
187 if ((0x80000000 & arg1
) != 0)
284 //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T);
288 void helper_macl(uint32_t arg0
, uint32_t arg1
)
292 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
293 res
+= (int64_t) (int32_t) arg0
*(int64_t) (int32_t) arg1
;
294 env
->mach
= (res
>> 32) & 0xffffffff;
295 env
->macl
= res
& 0xffffffff;
296 if (env
->sr
& SR_S
) {
298 env
->mach
|= 0xffff0000;
300 env
->mach
&= 0x00007fff;
304 void helper_macw(uint32_t arg0
, uint32_t arg1
)
308 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
309 res
+= (int64_t) (int16_t) arg0
*(int64_t) (int16_t) arg1
;
310 env
->mach
= (res
>> 32) & 0xffffffff;
311 env
->macl
= res
& 0xffffffff;
312 if (env
->sr
& SR_S
) {
313 if (res
< -0x80000000) {
315 env
->macl
= 0x80000000;
316 } else if (res
> 0x000000007fffffff) {
318 env
->macl
= 0x7fffffff;
323 uint32_t helper_negc(uint32_t arg
)
328 arg
= temp
- (env
->sr
& SR_T
);
338 uint32_t helper_subc(uint32_t arg0
, uint32_t arg1
)
344 arg1
= tmp1
- (env
->sr
& SR_T
);
354 uint32_t helper_subv(uint32_t arg0
, uint32_t arg1
)
356 int32_t dest
, src
, ans
;
358 if ((int32_t) arg1
>= 0)
362 if ((int32_t) arg0
>= 0)
368 if ((int32_t) arg1
>= 0)
383 static inline void set_t(void)
388 static inline void clr_t(void)
393 void helper_ld_fpscr(uint32_t val
)
395 env
->fpscr
= val
& 0x003fffff;
397 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
399 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
402 uint32_t helper_fabs_FT(uint32_t t0
)
406 f
.f
= float32_abs(f
.f
);
410 uint64_t helper_fabs_DT(uint64_t t0
)
414 d
.d
= float64_abs(d
.d
);
418 uint32_t helper_fadd_FT(uint32_t t0
, uint32_t t1
)
423 f0
.f
= float32_add(f0
.f
, f1
.f
, &env
->fp_status
);
427 uint64_t helper_fadd_DT(uint64_t t0
, uint64_t t1
)
432 d0
.d
= float64_add(d0
.d
, d1
.d
, &env
->fp_status
);
436 void helper_fcmp_eq_FT(uint32_t t0
, uint32_t t1
)
442 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 0)
448 void helper_fcmp_eq_DT(uint64_t t0
, uint64_t t1
)
454 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 0)
460 void helper_fcmp_gt_FT(uint32_t t0
, uint32_t t1
)
466 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 1)
472 void helper_fcmp_gt_DT(uint64_t t0
, uint64_t t1
)
478 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 1)
484 uint64_t helper_fcnvsd_FT_DT(uint32_t t0
)
489 d
.d
= float32_to_float64(f
.f
, &env
->fp_status
);
493 uint32_t helper_fcnvds_DT_FT(uint64_t t0
)
498 f
.f
= float64_to_float32(d
.d
, &env
->fp_status
);
502 uint32_t helper_fdiv_FT(uint32_t t0
, uint32_t t1
)
507 f0
.f
= float32_div(f0
.f
, f1
.f
, &env
->fp_status
);
511 uint64_t helper_fdiv_DT(uint64_t t0
, uint64_t t1
)
516 d0
.d
= float64_div(d0
.d
, d1
.d
, &env
->fp_status
);
520 uint32_t helper_float_FT(uint32_t t0
)
523 f
.f
= int32_to_float32(t0
, &env
->fp_status
);
527 uint64_t helper_float_DT(uint32_t t0
)
530 d
.d
= int32_to_float64(t0
, &env
->fp_status
);
534 uint32_t helper_fmul_FT(uint32_t t0
, uint32_t t1
)
539 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
543 uint64_t helper_fmul_DT(uint64_t t0
, uint64_t t1
)
548 d0
.d
= float64_mul(d0
.d
, d1
.d
, &env
->fp_status
);
552 uint32_t helper_fneg_T(uint32_t t0
)
556 f
.f
= float32_chs(f
.f
);
560 uint32_t helper_fsqrt_FT(uint32_t t0
)
564 f
.f
= float32_sqrt(f
.f
, &env
->fp_status
);
568 uint64_t helper_fsqrt_DT(uint64_t t0
)
572 d
.d
= float64_sqrt(d
.d
, &env
->fp_status
);
576 uint32_t helper_fsub_FT(uint32_t t0
, uint32_t t1
)
581 f0
.f
= float32_sub(f0
.f
, f1
.f
, &env
->fp_status
);
585 uint64_t helper_fsub_DT(uint64_t t0
, uint64_t t1
)
590 d0
.d
= float64_sub(d0
.d
, d1
.d
, &env
->fp_status
);
594 uint32_t helper_ftrc_FT(uint32_t t0
)
598 return float32_to_int32_round_to_zero(f
.f
, &env
->fp_status
);
601 uint32_t helper_ftrc_DT(uint64_t t0
)
605 return float64_to_int32_round_to_zero(d
.d
, &env
->fp_status
);