]>
git.proxmox.com Git - mirror_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 #ifndef CONFIG_USER_ONLY
25 #include "exec/softmmu_exec.h"
27 #define MMUSUFFIX _mmu
30 #include "exec/softmmu_template.h"
33 #include "exec/softmmu_template.h"
36 #include "exec/softmmu_template.h"
39 #include "exec/softmmu_template.h"
41 void tlb_fill(CPUSH4State
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
44 SuperHCPU
*cpu
= sh_env_get_cpu(env
);
47 ret
= superh_cpu_handle_mmu_fault(CPU(cpu
), addr
, is_write
, mmu_idx
);
49 /* now we have a real cpu fault */
51 cpu_restore_state(env
, retaddr
);
59 void helper_ldtlb(CPUSH4State
*env
)
61 #ifdef CONFIG_USER_ONLY
63 cpu_abort(env
, "Unhandled ldtlb");
69 static inline void QEMU_NORETURN
raise_exception(CPUSH4State
*env
, int index
,
72 env
->exception_index
= index
;
74 cpu_restore_state(env
, retaddr
);
79 void helper_raise_illegal_instruction(CPUSH4State
*env
)
81 raise_exception(env
, 0x180, 0);
84 void helper_raise_slot_illegal_instruction(CPUSH4State
*env
)
86 raise_exception(env
, 0x1a0, 0);
89 void helper_raise_fpu_disable(CPUSH4State
*env
)
91 raise_exception(env
, 0x800, 0);
94 void helper_raise_slot_fpu_disable(CPUSH4State
*env
)
96 raise_exception(env
, 0x820, 0);
99 void helper_debug(CPUSH4State
*env
)
101 raise_exception(env
, EXCP_DEBUG
, 0);
104 void helper_sleep(CPUSH4State
*env
)
106 CPUState
*cs
= CPU(sh_env_get_cpu(env
));
110 raise_exception(env
, EXCP_HLT
, 0);
113 void helper_trapa(CPUSH4State
*env
, uint32_t tra
)
116 raise_exception(env
, 0x160, 0);
119 void helper_movcal(CPUSH4State
*env
, uint32_t address
, uint32_t value
)
121 if (cpu_sh4_is_cached (env
, address
))
123 memory_content
*r
= malloc (sizeof(memory_content
));
124 r
->address
= address
;
128 *(env
->movcal_backup_tail
) = r
;
129 env
->movcal_backup_tail
= &(r
->next
);
133 void helper_discard_movcal_backup(CPUSH4State
*env
)
135 memory_content
*current
= env
->movcal_backup
;
139 memory_content
*next
= current
->next
;
141 env
->movcal_backup
= current
= next
;
143 env
->movcal_backup_tail
= &(env
->movcal_backup
);
147 void helper_ocbi(CPUSH4State
*env
, uint32_t address
)
149 memory_content
**current
= &(env
->movcal_backup
);
152 uint32_t a
= (*current
)->address
;
153 if ((a
& ~0x1F) == (address
& ~0x1F))
155 memory_content
*next
= (*current
)->next
;
156 cpu_stl_data(env
, a
, (*current
)->value
);
160 env
->movcal_backup_tail
= current
;
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(CPUSH4State
*env
, 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(CPUSH4State
*env
, 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(CPUSH4State
*env
, 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 static inline void set_t(CPUSH4State
*env
)
328 static inline void clr_t(CPUSH4State
*env
)
333 void helper_ld_fpscr(CPUSH4State
*env
, uint32_t val
)
335 env
->fpscr
= val
& FPSCR_MASK
;
336 if ((val
& FPSCR_RM_MASK
) == FPSCR_RM_ZERO
) {
337 set_float_rounding_mode(float_round_to_zero
, &env
->fp_status
);
339 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
341 set_flush_to_zero((val
& FPSCR_DN
) != 0, &env
->fp_status
);
344 static void update_fpscr(CPUSH4State
*env
, uintptr_t retaddr
)
346 int xcpt
, cause
, enable
;
348 xcpt
= get_float_exception_flags(&env
->fp_status
);
350 /* Clear the flag entries */
351 env
->fpscr
&= ~FPSCR_FLAG_MASK
;
353 if (unlikely(xcpt
)) {
354 if (xcpt
& float_flag_invalid
) {
355 env
->fpscr
|= FPSCR_FLAG_V
;
357 if (xcpt
& float_flag_divbyzero
) {
358 env
->fpscr
|= FPSCR_FLAG_Z
;
360 if (xcpt
& float_flag_overflow
) {
361 env
->fpscr
|= FPSCR_FLAG_O
;
363 if (xcpt
& float_flag_underflow
) {
364 env
->fpscr
|= FPSCR_FLAG_U
;
366 if (xcpt
& float_flag_inexact
) {
367 env
->fpscr
|= FPSCR_FLAG_I
;
370 /* Accumulate in cause entries */
371 env
->fpscr
|= (env
->fpscr
& FPSCR_FLAG_MASK
)
372 << (FPSCR_CAUSE_SHIFT
- FPSCR_FLAG_SHIFT
);
374 /* Generate an exception if enabled */
375 cause
= (env
->fpscr
& FPSCR_CAUSE_MASK
) >> FPSCR_CAUSE_SHIFT
;
376 enable
= (env
->fpscr
& FPSCR_ENABLE_MASK
) >> FPSCR_ENABLE_SHIFT
;
377 if (cause
& enable
) {
378 raise_exception(env
, 0x120, retaddr
);
383 float32
helper_fabs_FT(float32 t0
)
385 return float32_abs(t0
);
388 float64
helper_fabs_DT(float64 t0
)
390 return float64_abs(t0
);
393 float32
helper_fadd_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
395 set_float_exception_flags(0, &env
->fp_status
);
396 t0
= float32_add(t0
, t1
, &env
->fp_status
);
397 update_fpscr(env
, GETPC());
401 float64
helper_fadd_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
403 set_float_exception_flags(0, &env
->fp_status
);
404 t0
= float64_add(t0
, t1
, &env
->fp_status
);
405 update_fpscr(env
, GETPC());
409 void helper_fcmp_eq_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
413 set_float_exception_flags(0, &env
->fp_status
);
414 relation
= float32_compare(t0
, t1
, &env
->fp_status
);
415 if (unlikely(relation
== float_relation_unordered
)) {
416 update_fpscr(env
, GETPC());
417 } else if (relation
== float_relation_equal
) {
424 void helper_fcmp_eq_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
428 set_float_exception_flags(0, &env
->fp_status
);
429 relation
= float64_compare(t0
, t1
, &env
->fp_status
);
430 if (unlikely(relation
== float_relation_unordered
)) {
431 update_fpscr(env
, GETPC());
432 } else if (relation
== float_relation_equal
) {
439 void helper_fcmp_gt_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
443 set_float_exception_flags(0, &env
->fp_status
);
444 relation
= float32_compare(t0
, t1
, &env
->fp_status
);
445 if (unlikely(relation
== float_relation_unordered
)) {
446 update_fpscr(env
, GETPC());
447 } else if (relation
== float_relation_greater
) {
454 void helper_fcmp_gt_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
458 set_float_exception_flags(0, &env
->fp_status
);
459 relation
= float64_compare(t0
, t1
, &env
->fp_status
);
460 if (unlikely(relation
== float_relation_unordered
)) {
461 update_fpscr(env
, GETPC());
462 } else if (relation
== float_relation_greater
) {
469 float64
helper_fcnvsd_FT_DT(CPUSH4State
*env
, float32 t0
)
472 set_float_exception_flags(0, &env
->fp_status
);
473 ret
= float32_to_float64(t0
, &env
->fp_status
);
474 update_fpscr(env
, GETPC());
478 float32
helper_fcnvds_DT_FT(CPUSH4State
*env
, float64 t0
)
481 set_float_exception_flags(0, &env
->fp_status
);
482 ret
= float64_to_float32(t0
, &env
->fp_status
);
483 update_fpscr(env
, GETPC());
487 float32
helper_fdiv_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
489 set_float_exception_flags(0, &env
->fp_status
);
490 t0
= float32_div(t0
, t1
, &env
->fp_status
);
491 update_fpscr(env
, GETPC());
495 float64
helper_fdiv_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
497 set_float_exception_flags(0, &env
->fp_status
);
498 t0
= float64_div(t0
, t1
, &env
->fp_status
);
499 update_fpscr(env
, GETPC());
503 float32
helper_float_FT(CPUSH4State
*env
, uint32_t t0
)
506 set_float_exception_flags(0, &env
->fp_status
);
507 ret
= int32_to_float32(t0
, &env
->fp_status
);
508 update_fpscr(env
, GETPC());
512 float64
helper_float_DT(CPUSH4State
*env
, uint32_t t0
)
515 set_float_exception_flags(0, &env
->fp_status
);
516 ret
= int32_to_float64(t0
, &env
->fp_status
);
517 update_fpscr(env
, GETPC());
521 float32
helper_fmac_FT(CPUSH4State
*env
, float32 t0
, float32 t1
, float32 t2
)
523 set_float_exception_flags(0, &env
->fp_status
);
524 t0
= float32_muladd(t0
, t1
, t2
, 0, &env
->fp_status
);
525 update_fpscr(env
, GETPC());
529 float32
helper_fmul_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
531 set_float_exception_flags(0, &env
->fp_status
);
532 t0
= float32_mul(t0
, t1
, &env
->fp_status
);
533 update_fpscr(env
, GETPC());
537 float64
helper_fmul_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
539 set_float_exception_flags(0, &env
->fp_status
);
540 t0
= float64_mul(t0
, t1
, &env
->fp_status
);
541 update_fpscr(env
, GETPC());
545 float32
helper_fneg_T(float32 t0
)
547 return float32_chs(t0
);
550 float32
helper_fsqrt_FT(CPUSH4State
*env
, float32 t0
)
552 set_float_exception_flags(0, &env
->fp_status
);
553 t0
= float32_sqrt(t0
, &env
->fp_status
);
554 update_fpscr(env
, GETPC());
558 float64
helper_fsqrt_DT(CPUSH4State
*env
, float64 t0
)
560 set_float_exception_flags(0, &env
->fp_status
);
561 t0
= float64_sqrt(t0
, &env
->fp_status
);
562 update_fpscr(env
, GETPC());
566 float32
helper_fsub_FT(CPUSH4State
*env
, float32 t0
, float32 t1
)
568 set_float_exception_flags(0, &env
->fp_status
);
569 t0
= float32_sub(t0
, t1
, &env
->fp_status
);
570 update_fpscr(env
, GETPC());
574 float64
helper_fsub_DT(CPUSH4State
*env
, float64 t0
, float64 t1
)
576 set_float_exception_flags(0, &env
->fp_status
);
577 t0
= float64_sub(t0
, t1
, &env
->fp_status
);
578 update_fpscr(env
, GETPC());
582 uint32_t helper_ftrc_FT(CPUSH4State
*env
, float32 t0
)
585 set_float_exception_flags(0, &env
->fp_status
);
586 ret
= float32_to_int32_round_to_zero(t0
, &env
->fp_status
);
587 update_fpscr(env
, GETPC());
591 uint32_t helper_ftrc_DT(CPUSH4State
*env
, float64 t0
)
594 set_float_exception_flags(0, &env
->fp_status
);
595 ret
= float64_to_int32_round_to_zero(t0
, &env
->fp_status
);
596 update_fpscr(env
, GETPC());
600 void helper_fipr(CPUSH4State
*env
, uint32_t m
, uint32_t n
)
605 bank
= (env
->sr
& FPSCR_FR
) ? 16 : 0;
607 set_float_exception_flags(0, &env
->fp_status
);
609 for (i
= 0 ; i
< 4 ; i
++) {
610 p
= float32_mul(env
->fregs
[bank
+ m
+ i
],
611 env
->fregs
[bank
+ n
+ i
],
613 r
= float32_add(r
, p
, &env
->fp_status
);
615 update_fpscr(env
, GETPC());
617 env
->fregs
[bank
+ n
+ 3] = r
;
620 void helper_ftrv(CPUSH4State
*env
, uint32_t n
)
622 int bank_matrix
, bank_vector
;
627 bank_matrix
= (env
->sr
& FPSCR_FR
) ? 0 : 16;
628 bank_vector
= (env
->sr
& FPSCR_FR
) ? 16 : 0;
629 set_float_exception_flags(0, &env
->fp_status
);
630 for (i
= 0 ; i
< 4 ; i
++) {
632 for (j
= 0 ; j
< 4 ; j
++) {
633 p
= float32_mul(env
->fregs
[bank_matrix
+ 4 * j
+ i
],
634 env
->fregs
[bank_vector
+ j
],
636 r
[i
] = float32_add(r
[i
], p
, &env
->fp_status
);
639 update_fpscr(env
, GETPC());
641 for (i
= 0 ; i
< 4 ; i
++) {
642 env
->fregs
[bank_vector
+ i
] = r
[i
];