]>
git.proxmox.com Git - qemu.git/blob - target-sh4/op_helper.c
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 static void cpu_restore_state_from_retaddr(CPUSH4State
*env
, uintptr_t retaddr
)
29 tb
= tb_find_pc(retaddr
);
31 /* the PC is inside the translated code. It means that we have
32 a virtual CPU fault */
33 cpu_restore_state(tb
, env
, retaddr
);
38 #ifndef CONFIG_USER_ONLY
39 #include "softmmu_exec.h"
41 #define MMUSUFFIX _mmu
44 #include "softmmu_template.h"
47 #include "softmmu_template.h"
50 #include "softmmu_template.h"
53 #include "softmmu_template.h"
55 void tlb_fill(CPUSH4State
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
60 ret
= cpu_sh4_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
62 /* now we have a real cpu fault */
63 cpu_restore_state_from_retaddr(env
, retaddr
);
70 void helper_ldtlb(CPUSH4State
*env
)
72 #ifdef CONFIG_USER_ONLY
74 cpu_abort(env
, "Unhandled ldtlb");
80 static inline void raise_exception(CPUSH4State
*env
, int index
,
83 env
->exception_index
= index
;
84 cpu_restore_state_from_retaddr(env
, retaddr
);
88 void helper_raise_illegal_instruction(CPUSH4State
*env
)
90 raise_exception(env
, 0x180, GETPC());
93 void helper_raise_slot_illegal_instruction(CPUSH4State
*env
)
95 raise_exception(env
, 0x1a0, GETPC());
98 void helper_raise_fpu_disable(CPUSH4State
*env
)
100 raise_exception(env
, 0x800, GETPC());
103 void helper_raise_slot_fpu_disable(CPUSH4State
*env
)
105 raise_exception(env
, 0x820, GETPC());
108 void helper_debug(CPUSH4State
*env
)
110 env
->exception_index
= EXCP_DEBUG
;
114 void helper_sleep(CPUSH4State
*env
, uint32_t next_pc
)
118 env
->exception_index
= EXCP_HLT
;
123 void helper_trapa(CPUSH4State
*env
, uint32_t tra
)
126 raise_exception(env
, 0x160, GETPC());
129 void helper_movcal(CPUSH4State
*env
, uint32_t address
, uint32_t value
)
131 if (cpu_sh4_is_cached (env
, address
))
133 memory_content
*r
= malloc (sizeof(memory_content
));
134 r
->address
= address
;
138 *(env
->movcal_backup_tail
) = r
;
139 env
->movcal_backup_tail
= &(r
->next
);
143 void helper_discard_movcal_backup(CPUSH4State
*env
)
145 memory_content
*current
= env
->movcal_backup
;
149 memory_content
*next
= current
->next
;
151 env
->movcal_backup
= current
= next
;
153 env
->movcal_backup_tail
= &(env
->movcal_backup
);
157 void helper_ocbi(CPUSH4State
*env
, uint32_t address
)
159 memory_content
**current
= &(env
->movcal_backup
);
162 uint32_t a
= (*current
)->address
;
163 if ((a
& ~0x1F) == (address
& ~0x1F))
165 memory_content
*next
= (*current
)->next
;
166 cpu_stl_data(env
, a
, (*current
)->value
);
170 env
->movcal_backup_tail
= current
;
180 uint32_t helper_addv(CPUSH4State
*env
, uint32_t arg0
, uint32_t arg1
)
182 uint32_t dest
, src
, ans
;
184 if ((int32_t) arg1
>= 0)
188 if ((int32_t) arg0
>= 0)
194 if ((int32_t) arg1
>= 0)
199 if (src
== 0 || src
== 2) {
209 #define T (env->sr & SR_T)
210 #define Q (env->sr & SR_Q ? 1 : 0)
211 #define M (env->sr & SR_M ? 1 : 0)
212 #define SETT env->sr |= SR_T
213 #define CLRT env->sr &= ~SR_T
214 #define SETQ env->sr |= SR_Q
215 #define CLRQ env->sr &= ~SR_Q
216 #define SETM env->sr |= SR_M
217 #define CLRM env->sr &= ~SR_M
219 uint32_t helper_div1(CPUSH4State
*env
, uint32_t arg0
, uint32_t arg1
)
222 uint8_t old_q
, tmp1
= 0xff;
224 //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T);
226 if ((0x80000000 & arg1
) != 0)
323 //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T);
327 void helper_macl(CPUSH4State
*env
, uint32_t arg0
, uint32_t arg1
)
331 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
332 res
+= (int64_t) (int32_t) arg0
*(int64_t) (int32_t) arg1
;
333 env
->mach
= (res
>> 32) & 0xffffffff;
334 env
->macl
= res
& 0xffffffff;
335 if (env
->sr
& SR_S
) {
337 env
->mach
|= 0xffff0000;
339 env
->mach
&= 0x00007fff;
343 void helper_macw(CPUSH4State
*env
, uint32_t arg0
, uint32_t arg1
)
347 res
= ((uint64_t) env
->mach
<< 32) | env
->macl
;
348 res
+= (int64_t) (int16_t) arg0
*(int64_t) (int16_t) arg1
;
349 env
->mach
= (res
>> 32) & 0xffffffff;
350 env
->macl
= res
& 0xffffffff;
351 if (env
->sr
& SR_S
) {
352 if (res
< -0x80000000) {
354 env
->macl
= 0x80000000;
355 } else if (res
> 0x000000007fffffff) {
357 env
->macl
= 0x7fffffff;
362 uint32_t helper_subv(CPUSH4State
*env
, uint32_t arg0
, uint32_t arg1
)
364 int32_t dest
, src
, ans
;
366 if ((int32_t) arg1
>= 0)
370 if ((int32_t) arg0
>= 0)
376 if ((int32_t) arg1
>= 0)
391 static inline void set_t(CPUSH4State
*env
)
396 static inline void clr_t(CPUSH4State
*env
)
401 void helper_ld_fpscr(CPUSH4State
*env
, uint32_t val
)
403 env
->fpscr
= val
& FPSCR_MASK
;
404 if ((val
& FPSCR_RM_MASK
) == FPSCR_RM_ZERO
) {
405 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
407 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
409 set_flush_to_zero((val
& FPSCR_DN
) != 0, &env
->fp_status
);
412 static void update_fpscr(CPUSH4State
*env
, uintptr_t retaddr
)
414 int xcpt
, cause
, enable
;
416 xcpt
= get_float_exception_flags(&env
->fp_status
);
418 /* Clear the flag entries */
419 env
->fpscr
&= ~FPSCR_FLAG_MASK
;
421 if (unlikely(xcpt
)) {
422 if (xcpt
& float_flag_invalid
) {
423 env
->fpscr
|= FPSCR_FLAG_V
;
425 if (xcpt
& float_flag_divbyzero
) {
426 env
->fpscr
|= FPSCR_FLAG_Z
;
428 if (xcpt
& float_flag_overflow
) {
429 env
->fpscr
|= FPSCR_FLAG_O
;
431 if (xcpt
& float_flag_underflow
) {
432 env
->fpscr
|= FPSCR_FLAG_U
;
434 if (xcpt
& float_flag_inexact
) {
435 env
->fpscr
|= FPSCR_FLAG_I
;
438 /* Accumulate in cause entries */
439 env
->fpscr
|= (env
->fpscr
& FPSCR_FLAG_MASK
)
440 << (FPSCR_CAUSE_SHIFT
- FPSCR_FLAG_SHIFT
);
442 /* Generate an exception if enabled */
443 cause
= (env
->fpscr
& FPSCR_CAUSE_MASK
) >> FPSCR_CAUSE_SHIFT
;
444 enable
= (env
->fpscr
& FPSCR_ENABLE_MASK
) >> FPSCR_ENABLE_SHIFT
;
445 if (cause
& enable
) {
446 cpu_restore_state_from_retaddr(env
, retaddr
);
447 env
->exception_index
= 0x120;
453 float32
helper_fabs_FT(float32 t0
)
455 return float32_abs(t0
);
458 float64
helper_fabs_DT(float64 t0
)
460 return float64_abs(t0
);
463 float32
helper_fadd_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
465 set_float_exception_flags(0, &env
->fp_status
);
466 t0
= float32_add(t0
, t1
, &env
->fp_status
);
467 update_fpscr(env
, GETPC());
471 float64
helper_fadd_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
473 set_float_exception_flags(0, &env
->fp_status
);
474 t0
= float64_add(t0
, t1
, &env
->fp_status
);
475 update_fpscr(env
, GETPC());
479 void helper_fcmp_eq_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
483 set_float_exception_flags(0, &env
->fp_status
);
484 relation
= float32_compare(t0
, t1
, &env
->fp_status
);
485 if (unlikely(relation
== float_relation_unordered
)) {
486 update_fpscr(env
, GETPC());
487 } else if (relation
== float_relation_equal
) {
494 void helper_fcmp_eq_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
498 set_float_exception_flags(0, &env
->fp_status
);
499 relation
= float64_compare(t0
, t1
, &env
->fp_status
);
500 if (unlikely(relation
== float_relation_unordered
)) {
501 update_fpscr(env
, GETPC());
502 } else if (relation
== float_relation_equal
) {
509 void helper_fcmp_gt_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
513 set_float_exception_flags(0, &env
->fp_status
);
514 relation
= float32_compare(t0
, t1
, &env
->fp_status
);
515 if (unlikely(relation
== float_relation_unordered
)) {
516 update_fpscr(env
, GETPC());
517 } else if (relation
== float_relation_greater
) {
524 void helper_fcmp_gt_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
528 set_float_exception_flags(0, &env
->fp_status
);
529 relation
= float64_compare(t0
, t1
, &env
->fp_status
);
530 if (unlikely(relation
== float_relation_unordered
)) {
531 update_fpscr(env
, GETPC());
532 } else if (relation
== float_relation_greater
) {
539 float64
helper_fcnvsd_FT_DT(CPUSH4State
*env
, float32 t0
)
542 set_float_exception_flags(0, &env
->fp_status
);
543 ret
= float32_to_float64(t0
, &env
->fp_status
);
544 update_fpscr(env
, GETPC());
548 float32
helper_fcnvds_DT_FT(CPUSH4State
*env
, float64 t0
)
551 set_float_exception_flags(0, &env
->fp_status
);
552 ret
= float64_to_float32(t0
, &env
->fp_status
);
553 update_fpscr(env
, GETPC());
557 float32
helper_fdiv_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
559 set_float_exception_flags(0, &env
->fp_status
);
560 t0
= float32_div(t0
, t1
, &env
->fp_status
);
561 update_fpscr(env
, GETPC());
565 float64
helper_fdiv_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
567 set_float_exception_flags(0, &env
->fp_status
);
568 t0
= float64_div(t0
, t1
, &env
->fp_status
);
569 update_fpscr(env
, GETPC());
573 float32
helper_float_FT(CPUSH4State
*env
, uint32_t t0
)
576 set_float_exception_flags(0, &env
->fp_status
);
577 ret
= int32_to_float32(t0
, &env
->fp_status
);
578 update_fpscr(env
, GETPC());
582 float64
helper_float_DT(CPUSH4State
*env
, uint32_t t0
)
585 set_float_exception_flags(0, &env
->fp_status
);
586 ret
= int32_to_float64(t0
, &env
->fp_status
);
587 update_fpscr(env
, GETPC());
591 float32
helper_fmac_FT(CPUSH4State
*env
, float32 t0
, float32 t1
, float32 t2
)
593 set_float_exception_flags(0, &env
->fp_status
);
594 t0
= float32_muladd(t0
, t1
, t2
, 0, &env
->fp_status
);
595 update_fpscr(env
, GETPC());
599 float32
helper_fmul_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
601 set_float_exception_flags(0, &env
->fp_status
);
602 t0
= float32_mul(t0
, t1
, &env
->fp_status
);
603 update_fpscr(env
, GETPC());
607 float64
helper_fmul_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
609 set_float_exception_flags(0, &env
->fp_status
);
610 t0
= float64_mul(t0
, t1
, &env
->fp_status
);
611 update_fpscr(env
, GETPC());
615 float32
helper_fneg_T(float32 t0
)
617 return float32_chs(t0
);
620 float32
helper_fsqrt_FT(CPUSH4State
*env
, float32 t0
)
622 set_float_exception_flags(0, &env
->fp_status
);
623 t0
= float32_sqrt(t0
, &env
->fp_status
);
624 update_fpscr(env
, GETPC());
628 float64
helper_fsqrt_DT(CPUSH4State
*env
, float64 t0
)
630 set_float_exception_flags(0, &env
->fp_status
);
631 t0
= float64_sqrt(t0
, &env
->fp_status
);
632 update_fpscr(env
, GETPC());
636 float32
helper_fsub_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
638 set_float_exception_flags(0, &env
->fp_status
);
639 t0
= float32_sub(t0
, t1
, &env
->fp_status
);
640 update_fpscr(env
, GETPC());
644 float64
helper_fsub_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
646 set_float_exception_flags(0, &env
->fp_status
);
647 t0
= float64_sub(t0
, t1
, &env
->fp_status
);
648 update_fpscr(env
, GETPC());
652 uint32_t helper_ftrc_FT(CPUSH4State
*env
, float32 t0
)
655 set_float_exception_flags(0, &env
->fp_status
);
656 ret
= float32_to_int32_round_to_zero(t0
, &env
->fp_status
);
657 update_fpscr(env
, GETPC());
661 uint32_t helper_ftrc_DT(CPUSH4State
*env
, float64 t0
)
664 set_float_exception_flags(0, &env
->fp_status
);
665 ret
= float64_to_int32_round_to_zero(t0
, &env
->fp_status
);
666 update_fpscr(env
, GETPC());
670 void helper_fipr(CPUSH4State
*env
, uint32_t m
, uint32_t n
)
675 bank
= (env
->sr
& FPSCR_FR
) ? 16 : 0;
677 set_float_exception_flags(0, &env
->fp_status
);
679 for (i
= 0 ; i
< 4 ; i
++) {
680 p
= float32_mul(env
->fregs
[bank
+ m
+ i
],
681 env
->fregs
[bank
+ n
+ i
],
683 r
= float32_add(r
, p
, &env
->fp_status
);
685 update_fpscr(env
, GETPC());
687 env
->fregs
[bank
+ n
+ 3] = r
;
690 void helper_ftrv(CPUSH4State
*env
, uint32_t n
)
692 int bank_matrix
, bank_vector
;
697 bank_matrix
= (env
->sr
& FPSCR_FR
) ? 0 : 16;
698 bank_vector
= (env
->sr
& FPSCR_FR
) ? 16 : 0;
699 set_float_exception_flags(0, &env
->fp_status
);
700 for (i
= 0 ; i
< 4 ; i
++) {
702 for (j
= 0 ; j
< 4 ; j
++) {
703 p
= float32_mul(env
->fregs
[bank_matrix
+ 4 * j
+ i
],
704 env
->fregs
[bank_vector
+ j
],
706 r
[i
] = float32_add(r
[i
], p
, &env
->fp_status
);
709 update_fpscr(env
, GETPC());
711 for (i
= 0 ; i
< 4 ; i
++) {
712 env
->fregs
[bank_vector
+ i
] = r
[i
];