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)
392 float32 ret = float32_abs(*(float32*)&t0);
393 return *(uint32_t*)(&ret);
396 uint64_t helper_fabs_DT(uint64_t t0)
398 float64 ret = float64_abs(*(float64*)&t0);
399 return *(uint64_t*)(&ret);
402 uint32_t helper_fadd_FT(uint32_t t0, uint32_t t1)
404 float32 ret = float32_add(*(float32*)&t0, *(float32*)&t1, &env->fp_status);
405 return *(uint32_t*)(&ret);
408 uint64_t helper_fadd_DT(uint64_t t0, uint64_t t1)
410 float64 ret = float64_add(*(float64*)&t0, *(float64*)&t1, &env->fp_status);
411 return *(uint64_t*)(&ret);
414 void helper_fcmp_eq_FT(uint32_t t0, uint32_t t1)
416 if (float32_compare(*(float32*)&t0, *(float32*)&t1, &env->fp_status) == 0)
422 void helper_fcmp_eq_DT(uint64_t t0, uint64_t t1)
424 if (float64_compare(*(float64*)&t0, *(float64*)&t1, &env->fp_status) == 0)
430 void helper_fcmp_gt_FT(uint32_t t0, uint32_t t1)
432 if (float32_compare(*(float32*)&t0, *(float32*)&t1, &env->fp_status) == 1)
438 void helper_fcmp_gt_DT(uint64_t t0, uint64_t t1)
440 if (float64_compare(*(float64*)&t0, *(float64*)&t1, &env->fp_status) == 1)
446 uint64_t helper_fcnvsd_FT_DT(uint32_t t0)
448 float64 ret = float32_to_float64(*(float32*)&t0, &env->fp_status);
449 return *(uint64_t*)(&ret);
452 uint32_t helper_fcnvds_DT_FT(uint64_t t0)
454 float32 ret = float64_to_float32(*(float64*)&t0, &env->fp_status);
455 return *(uint32_t*)(&ret);
458 uint32_t helper_fdiv_FT(uint32_t t0, uint32_t t1)
460 float32 ret = float32_div(*(float32*)&t0, *(float32*)&t1, &env->fp_status);
461 return *(uint32_t*)(&ret);
464 uint64_t helper_fdiv_DT(uint64_t t0, uint64_t t1)
466 float64 ret = float64_div(*(float64*)&t0, *(float64*)&t1, &env->fp_status);
467 return *(uint64_t*)(&ret);
470 uint32_t helper_float_FT(uint32_t t0)
472 float32 ret = int32_to_float32(t0, &env->fp_status);
473 return *(uint32_t*)(&ret);
476 uint64_t helper_float_DT(uint32_t t0)
478 float64 ret = int32_to_float64(t0, &env->fp_status);
479 return *(uint64_t*)(&ret);
482 uint32_t helper_fmul_FT(uint32_t t0, uint32_t t1)
484 float32 ret = float32_mul(*(float32*)&t0, *(float32*)&t1, &env->fp_status);
485 return *(uint32_t*)(&ret);
488 uint64_t helper_fmul_DT(uint64_t t0, uint64_t t1)
490 float64 ret = float64_mul(*(float64*)&t0, *(float64*)&t1, &env->fp_status);
491 return *(uint64_t*)(&ret);
494 uint32_t helper_fneg_T(uint32_t t0)
496 float32 ret = float32_chs(*(float32*)&t0);
497 return *(uint32_t*)(&ret);
500 uint32_t helper_fsqrt_FT(uint32_t t0)
502 float32 ret = float32_sqrt(*(float32*)&t0, &env->fp_status);
503 return *(uint32_t*)(&ret);
506 uint64_t helper_fsqrt_DT(uint64_t t0)
508 float64 ret = float64_sqrt(*(float64*)&t0, &env->fp_status);
509 return *(uint64_t*)(&ret);
512 uint32_t helper_fsub_FT(uint32_t t0, uint32_t t1)
514 float32 ret = float32_sub(*(float32*)&t0, *(float32*)&t1, &env->fp_status);
515 return *(uint32_t*)(&ret);
518 uint64_t helper_fsub_DT(uint64_t t0, uint64_t t1)
520 float64 ret = float64_sub(*(float64*)&t0, *(float64*)&t1, &env->fp_status);
521 return *(uint64_t*)(&ret);
524 uint32_t helper_ftrc_FT(uint32_t t0)
526 return float32_to_int32_round_to_zero(*(float32*)&t0, &env->fp_status);
529 uint32_t helper_ftrc_DT(uint64_t t0)
531 return float64_to_int32_round_to_zero(*(float64*)&t0, &env->fp_status);