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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
25 #ifndef CONFIG_USER_ONLY
27 #define MMUSUFFIX _mmu
30 #include "softmmu_template.h"
33 #include "softmmu_template.h"
36 #include "softmmu_template.h"
39 #include "softmmu_template.h"
41 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
48 /* XXX: hack to restore env in all cases, even if not called from
52 ret
= cpu_sh4_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
55 /* now we have a real cpu fault */
56 pc
= (unsigned long) retaddr
;
59 /* the PC is inside the translated code. It means that we have
60 a virtual CPU fault */
61 cpu_restore_state(tb
, env
, pc
, NULL
);
71 void helper_ldtlb(void)
73 #ifdef CONFIG_USER_ONLY
81 void helper_raise_illegal_instruction(void)
83 env
->exception_index
= 0x180;
87 void helper_raise_slot_illegal_instruction(void)
89 env
->exception_index
= 0x1a0;
93 void helper_raise_fpu_disable(void)
95 env
->exception_index
= 0x800;
99 void helper_raise_slot_fpu_disable(void)
101 env
->exception_index
= 0x820;
105 void helper_debug(void)
107 env
->exception_index
= EXCP_DEBUG
;
111 void helper_sleep(uint32_t next_pc
)
114 env
->exception_index
= EXCP_HLT
;
119 void helper_trapa(uint32_t tra
)
122 env
->exception_index
= 0x160;
126 void helper_movcal(uint32_t address
, uint32_t value
)
128 if (cpu_sh4_is_cached (env
, address
))
130 memory_content
*r
= malloc (sizeof(memory_content
));
131 r
->address
= address
;
135 *(env
->movcal_backup_tail
) = r
;
136 env
->movcal_backup_tail
= &(r
->next
);
140 void helper_discard_movcal_backup(void)
142 memory_content
*current
= env
->movcal_backup
;
146 memory_content
*next
= current
->next
;
148 env
->movcal_backup
= current
= next
;
150 env
->movcal_backup_tail
= &(env
->movcal_backup
);
154 void helper_ocbi(uint32_t address
)
156 memory_content
**current
= &(env
->movcal_backup
);
159 uint32_t a
= (*current
)->address
;
160 if ((a
& ~0x1F) == (address
& ~0x1F))
162 memory_content
*next
= (*current
)->next
;
163 stl(a
, (*current
)->value
);
167 env
->movcal_backup_tail
= current
;
177 uint32_t helper_addc(uint32_t arg0
, uint32_t arg1
)
183 arg1
= tmp1
+ (env
->sr
& 1);
193 uint32_t helper_addv(uint32_t arg0
, uint32_t arg1
)
195 uint32_t dest
, src
, ans
;
197 if ((int32_t) arg1
>= 0)
201 if ((int32_t) arg0
>= 0)
207 if ((int32_t) arg1
>= 0)
212 if (src
== 0 || src
== 2) {
222 #define T (env->sr & SR_T)
223 #define Q (env->sr & SR_Q ? 1 : 0)
224 #define M (env->sr & SR_M ? 1 : 0)
225 #define SETT env->sr |= SR_T
226 #define CLRT env->sr &= ~SR_T
227 #define SETQ env->sr |= SR_Q
228 #define CLRQ env->sr &= ~SR_Q
229 #define SETM env->sr |= SR_M
230 #define CLRM env->sr &= ~SR_M
232 uint32_t helper_div1(uint32_t arg0
, uint32_t arg1
)
235 uint8_t old_q
, tmp1
= 0xff;
237 //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T);
239 if ((0x80000000 & arg1
) != 0)
336 //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T);
340 void helper_macl(uint32_t arg0
, uint32_t arg1
)
344 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
345 res
+= (int64_t) (int32_t) arg0
*(int64_t) (int32_t) arg1
;
346 env
->mach
= (res
>> 32) & 0xffffffff;
347 env
->macl
= res
& 0xffffffff;
348 if (env
->sr
& SR_S
) {
350 env
->mach
|= 0xffff0000;
352 env
->mach
&= 0x00007fff;
356 void helper_macw(uint32_t arg0
, uint32_t arg1
)
360 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
361 res
+= (int64_t) (int16_t) arg0
*(int64_t) (int16_t) arg1
;
362 env
->mach
= (res
>> 32) & 0xffffffff;
363 env
->macl
= res
& 0xffffffff;
364 if (env
->sr
& SR_S
) {
365 if (res
< -0x80000000) {
367 env
->macl
= 0x80000000;
368 } else if (res
> 0x000000007fffffff) {
370 env
->macl
= 0x7fffffff;
375 uint32_t helper_negc(uint32_t arg
)
380 arg
= temp
- (env
->sr
& SR_T
);
390 uint32_t helper_subc(uint32_t arg0
, uint32_t arg1
)
396 arg1
= tmp1
- (env
->sr
& SR_T
);
406 uint32_t helper_subv(uint32_t arg0
, uint32_t arg1
)
408 int32_t dest
, src
, ans
;
410 if ((int32_t) arg1
>= 0)
414 if ((int32_t) arg0
>= 0)
420 if ((int32_t) arg1
>= 0)
435 static inline void set_t(void)
440 static inline void clr_t(void)
445 void helper_ld_fpscr(uint32_t val
)
447 env
->fpscr
= val
& 0x003fffff;
449 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
451 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
454 uint32_t helper_fabs_FT(uint32_t t0
)
458 f
.f
= float32_abs(f
.f
);
462 uint64_t helper_fabs_DT(uint64_t t0
)
466 d
.d
= float64_abs(d
.d
);
470 uint32_t helper_fadd_FT(uint32_t t0
, uint32_t t1
)
475 f0
.f
= float32_add(f0
.f
, f1
.f
, &env
->fp_status
);
479 uint64_t helper_fadd_DT(uint64_t t0
, uint64_t t1
)
484 d0
.d
= float64_add(d0
.d
, d1
.d
, &env
->fp_status
);
488 void helper_fcmp_eq_FT(uint32_t t0
, uint32_t t1
)
494 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 0)
500 void helper_fcmp_eq_DT(uint64_t t0
, uint64_t t1
)
506 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 0)
512 void helper_fcmp_gt_FT(uint32_t t0
, uint32_t t1
)
518 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 1)
524 void helper_fcmp_gt_DT(uint64_t t0
, uint64_t t1
)
530 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 1)
536 uint64_t helper_fcnvsd_FT_DT(uint32_t t0
)
541 d
.d
= float32_to_float64(f
.f
, &env
->fp_status
);
545 uint32_t helper_fcnvds_DT_FT(uint64_t t0
)
550 f
.f
= float64_to_float32(d
.d
, &env
->fp_status
);
554 uint32_t helper_fdiv_FT(uint32_t t0
, uint32_t t1
)
559 f0
.f
= float32_div(f0
.f
, f1
.f
, &env
->fp_status
);
563 uint64_t helper_fdiv_DT(uint64_t t0
, uint64_t t1
)
568 d0
.d
= float64_div(d0
.d
, d1
.d
, &env
->fp_status
);
572 uint32_t helper_float_FT(uint32_t t0
)
575 f
.f
= int32_to_float32(t0
, &env
->fp_status
);
579 uint64_t helper_float_DT(uint32_t t0
)
582 d
.d
= int32_to_float64(t0
, &env
->fp_status
);
586 uint32_t helper_fmac_FT(uint32_t t0
, uint32_t t1
, uint32_t t2
)
588 CPU_FloatU f0
, f1
, f2
;
592 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
593 f0
.f
= float32_add(f0
.f
, f2
.f
, &env
->fp_status
);
597 uint32_t helper_fmul_FT(uint32_t t0
, uint32_t t1
)
602 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
606 uint64_t helper_fmul_DT(uint64_t t0
, uint64_t t1
)
611 d0
.d
= float64_mul(d0
.d
, d1
.d
, &env
->fp_status
);
615 uint32_t helper_fneg_T(uint32_t t0
)
619 f
.f
= float32_chs(f
.f
);
623 uint32_t helper_fsqrt_FT(uint32_t t0
)
627 f
.f
= float32_sqrt(f
.f
, &env
->fp_status
);
631 uint64_t helper_fsqrt_DT(uint64_t t0
)
635 d
.d
= float64_sqrt(d
.d
, &env
->fp_status
);
639 uint32_t helper_fsub_FT(uint32_t t0
, uint32_t t1
)
644 f0
.f
= float32_sub(f0
.f
, f1
.f
, &env
->fp_status
);
648 uint64_t helper_fsub_DT(uint64_t t0
, uint64_t t1
)
653 d0
.d
= float64_sub(d0
.d
, d1
.d
, &env
->fp_status
);
657 uint32_t helper_ftrc_FT(uint32_t t0
)
661 return float32_to_int32_round_to_zero(f
.f
, &env
->fp_status
);
664 uint32_t helper_ftrc_DT(uint64_t t0
)
668 return float64_to_int32_round_to_zero(d
.d
, &env
->fp_status
);