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, see <http://www.gnu.org/licenses/>.
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
74 cpu_abort(env
, "Unhandled ldtlb");
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 void helper_movcal(uint32_t address
, uint32_t value
)
127 if (cpu_sh4_is_cached (env
, address
))
129 memory_content
*r
= malloc (sizeof(memory_content
));
130 r
->address
= address
;
134 *(env
->movcal_backup_tail
) = r
;
135 env
->movcal_backup_tail
= &(r
->next
);
139 void helper_discard_movcal_backup(void)
141 memory_content
*current
= env
->movcal_backup
;
145 memory_content
*next
= current
->next
;
147 env
->movcal_backup
= current
= next
;
149 env
->movcal_backup_tail
= &(env
->movcal_backup
);
153 void helper_ocbi(uint32_t address
)
155 memory_content
**current
= &(env
->movcal_backup
);
158 uint32_t a
= (*current
)->address
;
159 if ((a
& ~0x1F) == (address
& ~0x1F))
161 memory_content
*next
= (*current
)->next
;
162 stl(a
, (*current
)->value
);
166 env
->movcal_backup_tail
= current
;
176 uint32_t helper_addc(uint32_t arg0
, uint32_t arg1
)
182 arg1
= tmp1
+ (env
->sr
& 1);
192 uint32_t helper_addv(uint32_t arg0
, uint32_t arg1
)
194 uint32_t dest
, src
, ans
;
196 if ((int32_t) arg1
>= 0)
200 if ((int32_t) arg0
>= 0)
206 if ((int32_t) arg1
>= 0)
211 if (src
== 0 || src
== 2) {
221 #define T (env->sr & SR_T)
222 #define Q (env->sr & SR_Q ? 1 : 0)
223 #define M (env->sr & SR_M ? 1 : 0)
224 #define SETT env->sr |= SR_T
225 #define CLRT env->sr &= ~SR_T
226 #define SETQ env->sr |= SR_Q
227 #define CLRQ env->sr &= ~SR_Q
228 #define SETM env->sr |= SR_M
229 #define CLRM env->sr &= ~SR_M
231 uint32_t helper_div1(uint32_t arg0
, uint32_t arg1
)
234 uint8_t old_q
, tmp1
= 0xff;
236 //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T);
238 if ((0x80000000 & arg1
) != 0)
335 //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T);
339 void helper_macl(uint32_t arg0
, uint32_t arg1
)
343 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
344 res
+= (int64_t) (int32_t) arg0
*(int64_t) (int32_t) arg1
;
345 env
->mach
= (res
>> 32) & 0xffffffff;
346 env
->macl
= res
& 0xffffffff;
347 if (env
->sr
& SR_S
) {
349 env
->mach
|= 0xffff0000;
351 env
->mach
&= 0x00007fff;
355 void helper_macw(uint32_t arg0
, uint32_t arg1
)
359 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
360 res
+= (int64_t) (int16_t) arg0
*(int64_t) (int16_t) arg1
;
361 env
->mach
= (res
>> 32) & 0xffffffff;
362 env
->macl
= res
& 0xffffffff;
363 if (env
->sr
& SR_S
) {
364 if (res
< -0x80000000) {
366 env
->macl
= 0x80000000;
367 } else if (res
> 0x000000007fffffff) {
369 env
->macl
= 0x7fffffff;
374 uint32_t helper_negc(uint32_t arg
)
379 arg
= temp
- (env
->sr
& SR_T
);
389 uint32_t helper_subc(uint32_t arg0
, uint32_t arg1
)
395 arg1
= tmp1
- (env
->sr
& SR_T
);
405 uint32_t helper_subv(uint32_t arg0
, uint32_t arg1
)
407 int32_t dest
, src
, ans
;
409 if ((int32_t) arg1
>= 0)
413 if ((int32_t) arg0
>= 0)
419 if ((int32_t) arg1
>= 0)
434 static inline void set_t(void)
439 static inline void clr_t(void)
444 void helper_ld_fpscr(uint32_t val
)
446 env
->fpscr
= val
& 0x003fffff;
448 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
450 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
453 uint32_t helper_fabs_FT(uint32_t t0
)
457 f
.f
= float32_abs(f
.f
);
461 uint64_t helper_fabs_DT(uint64_t t0
)
465 d
.d
= float64_abs(d
.d
);
469 uint32_t helper_fadd_FT(uint32_t t0
, uint32_t t1
)
474 f0
.f
= float32_add(f0
.f
, f1
.f
, &env
->fp_status
);
478 uint64_t helper_fadd_DT(uint64_t t0
, uint64_t t1
)
483 d0
.d
= float64_add(d0
.d
, d1
.d
, &env
->fp_status
);
487 void helper_fcmp_eq_FT(uint32_t t0
, uint32_t t1
)
493 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 0)
499 void helper_fcmp_eq_DT(uint64_t t0
, uint64_t t1
)
505 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 0)
511 void helper_fcmp_gt_FT(uint32_t t0
, uint32_t t1
)
517 if (float32_compare(f0
.f
, f1
.f
, &env
->fp_status
) == 1)
523 void helper_fcmp_gt_DT(uint64_t t0
, uint64_t t1
)
529 if (float64_compare(d0
.d
, d1
.d
, &env
->fp_status
) == 1)
535 uint64_t helper_fcnvsd_FT_DT(uint32_t t0
)
540 d
.d
= float32_to_float64(f
.f
, &env
->fp_status
);
544 uint32_t helper_fcnvds_DT_FT(uint64_t t0
)
549 f
.f
= float64_to_float32(d
.d
, &env
->fp_status
);
553 uint32_t helper_fdiv_FT(uint32_t t0
, uint32_t t1
)
558 f0
.f
= float32_div(f0
.f
, f1
.f
, &env
->fp_status
);
562 uint64_t helper_fdiv_DT(uint64_t t0
, uint64_t t1
)
567 d0
.d
= float64_div(d0
.d
, d1
.d
, &env
->fp_status
);
571 uint32_t helper_float_FT(uint32_t t0
)
574 f
.f
= int32_to_float32(t0
, &env
->fp_status
);
578 uint64_t helper_float_DT(uint32_t t0
)
581 d
.d
= int32_to_float64(t0
, &env
->fp_status
);
585 uint32_t helper_fmac_FT(uint32_t t0
, uint32_t t1
, uint32_t t2
)
587 CPU_FloatU f0
, f1
, f2
;
591 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
592 f0
.f
= float32_add(f0
.f
, f2
.f
, &env
->fp_status
);
596 uint32_t helper_fmul_FT(uint32_t t0
, uint32_t t1
)
601 f0
.f
= float32_mul(f0
.f
, f1
.f
, &env
->fp_status
);
605 uint64_t helper_fmul_DT(uint64_t t0
, uint64_t t1
)
610 d0
.d
= float64_mul(d0
.d
, d1
.d
, &env
->fp_status
);
614 uint32_t helper_fneg_T(uint32_t t0
)
618 f
.f
= float32_chs(f
.f
);
622 uint32_t helper_fsqrt_FT(uint32_t t0
)
626 f
.f
= float32_sqrt(f
.f
, &env
->fp_status
);
630 uint64_t helper_fsqrt_DT(uint64_t t0
)
634 d
.d
= float64_sqrt(d
.d
, &env
->fp_status
);
638 uint32_t helper_fsub_FT(uint32_t t0
, uint32_t t1
)
643 f0
.f
= float32_sub(f0
.f
, f1
.f
, &env
->fp_status
);
647 uint64_t helper_fsub_DT(uint64_t t0
, uint64_t t1
)
652 d0
.d
= float64_sub(d0
.d
, d1
.d
, &env
->fp_status
);
656 uint32_t helper_ftrc_FT(uint32_t t0
)
660 return float32_to_int32_round_to_zero(f
.f
, &env
->fp_status
);
663 uint32_t helper_ftrc_DT(uint64_t t0
)
667 return float64_to_int32_round_to_zero(d
.d
, &env
->fp_status
);