2 * MIPS emulation helpers for qemu.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
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/>.
19 #include "qemu/osdep.h"
21 #include "qemu/host-utils.h"
22 #include "exec/helper-proto.h"
23 #include "exec/cpu_ldst.h"
24 #include "sysemu/kvm.h"
26 /*****************************************************************************/
27 /* Exceptions processing helpers */
29 void helper_raise_exception_err(CPUMIPSState
*env
, uint32_t exception
,
32 do_raise_exception_err(env
, exception
, error_code
, 0);
35 void helper_raise_exception(CPUMIPSState
*env
, uint32_t exception
)
37 do_raise_exception(env
, exception
, GETPC());
40 void helper_raise_exception_debug(CPUMIPSState
*env
)
42 do_raise_exception(env
, EXCP_DEBUG
, 0);
45 static void raise_exception(CPUMIPSState
*env
, uint32_t exception
)
47 do_raise_exception(env
, exception
, 0);
50 #if defined(CONFIG_USER_ONLY)
51 #define HELPER_LD(name, insn, type) \
52 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
53 int mem_idx, uintptr_t retaddr) \
55 return (type) cpu_##insn##_data_ra(env, addr, retaddr); \
58 #define HELPER_LD(name, insn, type) \
59 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
60 int mem_idx, uintptr_t retaddr) \
64 case 0: return (type) cpu_##insn##_kernel_ra(env, addr, retaddr); \
65 case 1: return (type) cpu_##insn##_super_ra(env, addr, retaddr); \
67 case 2: return (type) cpu_##insn##_user_ra(env, addr, retaddr); \
71 HELPER_LD(lw
, ldl
, int32_t)
72 #if defined(TARGET_MIPS64)
73 HELPER_LD(ld
, ldq
, int64_t)
77 #if defined(CONFIG_USER_ONLY)
78 #define HELPER_ST(name, insn, type) \
79 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
80 type val, int mem_idx, uintptr_t retaddr) \
82 cpu_##insn##_data_ra(env, addr, val, retaddr); \
85 #define HELPER_ST(name, insn, type) \
86 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
87 type val, int mem_idx, uintptr_t retaddr) \
91 case 0: cpu_##insn##_kernel_ra(env, addr, val, retaddr); break; \
92 case 1: cpu_##insn##_super_ra(env, addr, val, retaddr); break; \
94 case 2: cpu_##insn##_user_ra(env, addr, val, retaddr); break; \
98 HELPER_ST(sb
, stb
, uint8_t)
99 HELPER_ST(sw
, stl
, uint32_t)
100 #if defined(TARGET_MIPS64)
101 HELPER_ST(sd
, stq
, uint64_t)
105 target_ulong
helper_clo (target_ulong arg1
)
110 target_ulong
helper_clz (target_ulong arg1
)
115 #if defined(TARGET_MIPS64)
116 target_ulong
helper_dclo (target_ulong arg1
)
121 target_ulong
helper_dclz (target_ulong arg1
)
125 #endif /* TARGET_MIPS64 */
127 /* 64 bits arithmetic for 32 bits hosts */
128 static inline uint64_t get_HILO(CPUMIPSState
*env
)
130 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
133 static inline target_ulong
set_HIT0_LO(CPUMIPSState
*env
, uint64_t HILO
)
136 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
137 tmp
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
141 static inline target_ulong
set_HI_LOT0(CPUMIPSState
*env
, uint64_t HILO
)
143 target_ulong tmp
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
144 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
148 /* Multiplication variants of the vr54xx. */
149 target_ulong
helper_muls(CPUMIPSState
*env
, target_ulong arg1
,
152 return set_HI_LOT0(env
, 0 - ((int64_t)(int32_t)arg1
*
153 (int64_t)(int32_t)arg2
));
156 target_ulong
helper_mulsu(CPUMIPSState
*env
, target_ulong arg1
,
159 return set_HI_LOT0(env
, 0 - (uint64_t)(uint32_t)arg1
*
160 (uint64_t)(uint32_t)arg2
);
163 target_ulong
helper_macc(CPUMIPSState
*env
, target_ulong arg1
,
166 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
167 (int64_t)(int32_t)arg2
);
170 target_ulong
helper_macchi(CPUMIPSState
*env
, target_ulong arg1
,
173 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
174 (int64_t)(int32_t)arg2
);
177 target_ulong
helper_maccu(CPUMIPSState
*env
, target_ulong arg1
,
180 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) +
181 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
184 target_ulong
helper_macchiu(CPUMIPSState
*env
, target_ulong arg1
,
187 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) +
188 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
191 target_ulong
helper_msac(CPUMIPSState
*env
, target_ulong arg1
,
194 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
195 (int64_t)(int32_t)arg2
);
198 target_ulong
helper_msachi(CPUMIPSState
*env
, target_ulong arg1
,
201 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
202 (int64_t)(int32_t)arg2
);
205 target_ulong
helper_msacu(CPUMIPSState
*env
, target_ulong arg1
,
208 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) -
209 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
212 target_ulong
helper_msachiu(CPUMIPSState
*env
, target_ulong arg1
,
215 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) -
216 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
219 target_ulong
helper_mulhi(CPUMIPSState
*env
, target_ulong arg1
,
222 return set_HIT0_LO(env
, (int64_t)(int32_t)arg1
* (int64_t)(int32_t)arg2
);
225 target_ulong
helper_mulhiu(CPUMIPSState
*env
, target_ulong arg1
,
228 return set_HIT0_LO(env
, (uint64_t)(uint32_t)arg1
*
229 (uint64_t)(uint32_t)arg2
);
232 target_ulong
helper_mulshi(CPUMIPSState
*env
, target_ulong arg1
,
235 return set_HIT0_LO(env
, 0 - (int64_t)(int32_t)arg1
*
236 (int64_t)(int32_t)arg2
);
239 target_ulong
helper_mulshiu(CPUMIPSState
*env
, target_ulong arg1
,
242 return set_HIT0_LO(env
, 0 - (uint64_t)(uint32_t)arg1
*
243 (uint64_t)(uint32_t)arg2
);
246 static inline target_ulong
bitswap(target_ulong v
)
248 v
= ((v
>> 1) & (target_ulong
)0x5555555555555555ULL
) |
249 ((v
& (target_ulong
)0x5555555555555555ULL
) << 1);
250 v
= ((v
>> 2) & (target_ulong
)0x3333333333333333ULL
) |
251 ((v
& (target_ulong
)0x3333333333333333ULL
) << 2);
252 v
= ((v
>> 4) & (target_ulong
)0x0F0F0F0F0F0F0F0FULL
) |
253 ((v
& (target_ulong
)0x0F0F0F0F0F0F0F0FULL
) << 4);
258 target_ulong
helper_dbitswap(target_ulong rt
)
264 target_ulong
helper_bitswap(target_ulong rt
)
266 return (int32_t)bitswap(rt
);
269 #ifndef CONFIG_USER_ONLY
271 static inline hwaddr
do_translate_address(CPUMIPSState
*env
,
272 target_ulong address
,
273 int rw
, uintptr_t retaddr
)
276 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
278 lladdr
= cpu_mips_translate_address(env
, address
, rw
);
280 if (lladdr
== -1LL) {
281 cpu_loop_exit_restore(cs
, retaddr
);
287 #define HELPER_LD_ATOMIC(name, insn, almask) \
288 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
290 if (arg & almask) { \
291 env->CP0_BadVAddr = arg; \
292 do_raise_exception(env, EXCP_AdEL, GETPC()); \
294 env->lladdr = do_translate_address(env, arg, 0, GETPC()); \
295 env->llval = do_##insn(env, arg, mem_idx, GETPC()); \
298 HELPER_LD_ATOMIC(ll
, lw
, 0x3)
300 HELPER_LD_ATOMIC(lld
, ld
, 0x7)
302 #undef HELPER_LD_ATOMIC
304 #define HELPER_ST_ATOMIC(name, ld_insn, st_insn, almask) \
305 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \
306 target_ulong arg2, int mem_idx) \
310 if (arg2 & almask) { \
311 env->CP0_BadVAddr = arg2; \
312 do_raise_exception(env, EXCP_AdES, GETPC()); \
314 if (do_translate_address(env, arg2, 1, GETPC()) == env->lladdr) { \
315 tmp = do_##ld_insn(env, arg2, mem_idx, GETPC()); \
316 if (tmp == env->llval) { \
317 do_##st_insn(env, arg2, arg1, mem_idx, GETPC()); \
323 HELPER_ST_ATOMIC(sc
, lw
, sw
, 0x3)
325 HELPER_ST_ATOMIC(scd
, ld
, sd
, 0x7)
327 #undef HELPER_ST_ATOMIC
330 #ifdef TARGET_WORDS_BIGENDIAN
331 #define GET_LMASK(v) ((v) & 3)
332 #define GET_OFFSET(addr, offset) (addr + (offset))
334 #define GET_LMASK(v) (((v) & 3) ^ 3)
335 #define GET_OFFSET(addr, offset) (addr - (offset))
338 void helper_swl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
341 do_sb(env
, arg2
, (uint8_t)(arg1
>> 24), mem_idx
, GETPC());
343 if (GET_LMASK(arg2
) <= 2) {
344 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 16), mem_idx
,
348 if (GET_LMASK(arg2
) <= 1) {
349 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 8), mem_idx
,
353 if (GET_LMASK(arg2
) == 0) {
354 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)arg1
, mem_idx
,
359 void helper_swr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
362 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
, GETPC());
364 if (GET_LMASK(arg2
) >= 1) {
365 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
,
369 if (GET_LMASK(arg2
) >= 2) {
370 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
,
374 if (GET_LMASK(arg2
) == 3) {
375 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
,
380 #if defined(TARGET_MIPS64)
381 /* "half" load and stores. We must do the memory access inline,
382 or fault handling won't work. */
384 #ifdef TARGET_WORDS_BIGENDIAN
385 #define GET_LMASK64(v) ((v) & 7)
387 #define GET_LMASK64(v) (((v) & 7) ^ 7)
390 void helper_sdl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
393 do_sb(env
, arg2
, (uint8_t)(arg1
>> 56), mem_idx
, GETPC());
395 if (GET_LMASK64(arg2
) <= 6) {
396 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 48), mem_idx
,
400 if (GET_LMASK64(arg2
) <= 5) {
401 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 40), mem_idx
,
405 if (GET_LMASK64(arg2
) <= 4) {
406 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)(arg1
>> 32), mem_idx
,
410 if (GET_LMASK64(arg2
) <= 3) {
411 do_sb(env
, GET_OFFSET(arg2
, 4), (uint8_t)(arg1
>> 24), mem_idx
,
415 if (GET_LMASK64(arg2
) <= 2) {
416 do_sb(env
, GET_OFFSET(arg2
, 5), (uint8_t)(arg1
>> 16), mem_idx
,
420 if (GET_LMASK64(arg2
) <= 1) {
421 do_sb(env
, GET_OFFSET(arg2
, 6), (uint8_t)(arg1
>> 8), mem_idx
,
425 if (GET_LMASK64(arg2
) <= 0) {
426 do_sb(env
, GET_OFFSET(arg2
, 7), (uint8_t)arg1
, mem_idx
,
431 void helper_sdr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
434 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
, GETPC());
436 if (GET_LMASK64(arg2
) >= 1) {
437 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
,
441 if (GET_LMASK64(arg2
) >= 2) {
442 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
,
446 if (GET_LMASK64(arg2
) >= 3) {
447 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
,
451 if (GET_LMASK64(arg2
) >= 4) {
452 do_sb(env
, GET_OFFSET(arg2
, -4), (uint8_t)(arg1
>> 32), mem_idx
,
456 if (GET_LMASK64(arg2
) >= 5) {
457 do_sb(env
, GET_OFFSET(arg2
, -5), (uint8_t)(arg1
>> 40), mem_idx
,
461 if (GET_LMASK64(arg2
) >= 6) {
462 do_sb(env
, GET_OFFSET(arg2
, -6), (uint8_t)(arg1
>> 48), mem_idx
,
466 if (GET_LMASK64(arg2
) == 7) {
467 do_sb(env
, GET_OFFSET(arg2
, -7), (uint8_t)(arg1
>> 56), mem_idx
,
471 #endif /* TARGET_MIPS64 */
473 static const int multiple_regs
[] = { 16, 17, 18, 19, 20, 21, 22, 23, 30 };
475 void helper_lwm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
478 target_ulong base_reglist
= reglist
& 0xf;
479 target_ulong do_r31
= reglist
& 0x10;
481 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
484 for (i
= 0; i
< base_reglist
; i
++) {
485 env
->active_tc
.gpr
[multiple_regs
[i
]] =
486 (target_long
)do_lw(env
, addr
, mem_idx
, GETPC());
492 env
->active_tc
.gpr
[31] = (target_long
)do_lw(env
, addr
, mem_idx
,
497 void helper_swm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
500 target_ulong base_reglist
= reglist
& 0xf;
501 target_ulong do_r31
= reglist
& 0x10;
503 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
506 for (i
= 0; i
< base_reglist
; i
++) {
507 do_sw(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
,
514 do_sw(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
, GETPC());
518 #if defined(TARGET_MIPS64)
519 void helper_ldm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
522 target_ulong base_reglist
= reglist
& 0xf;
523 target_ulong do_r31
= reglist
& 0x10;
525 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
528 for (i
= 0; i
< base_reglist
; i
++) {
529 env
->active_tc
.gpr
[multiple_regs
[i
]] = do_ld(env
, addr
, mem_idx
,
536 env
->active_tc
.gpr
[31] = do_ld(env
, addr
, mem_idx
, GETPC());
540 void helper_sdm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
543 target_ulong base_reglist
= reglist
& 0xf;
544 target_ulong do_r31
= reglist
& 0x10;
546 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
549 for (i
= 0; i
< base_reglist
; i
++) {
550 do_sd(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
,
557 do_sd(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
, GETPC());
562 #ifndef CONFIG_USER_ONLY
564 static bool mips_vpe_is_wfi(MIPSCPU
*c
)
566 CPUState
*cpu
= CPU(c
);
567 CPUMIPSState
*env
= &c
->env
;
569 /* If the VPE is halted but otherwise active, it means it's waiting for
571 return cpu
->halted
&& mips_vpe_active(env
);
574 static inline void mips_vpe_wake(MIPSCPU
*c
)
576 /* Dont set ->halted = 0 directly, let it be done via cpu_has_work
577 because there might be other conditions that state that c should
579 cpu_interrupt(CPU(c
), CPU_INTERRUPT_WAKE
);
582 static inline void mips_vpe_sleep(MIPSCPU
*cpu
)
584 CPUState
*cs
= CPU(cpu
);
586 /* The VPE was shut off, really go to bed.
587 Reset any old _WAKE requests. */
589 cpu_reset_interrupt(cs
, CPU_INTERRUPT_WAKE
);
592 static inline void mips_tc_wake(MIPSCPU
*cpu
, int tc
)
594 CPUMIPSState
*c
= &cpu
->env
;
596 /* FIXME: TC reschedule. */
597 if (mips_vpe_active(c
) && !mips_vpe_is_wfi(cpu
)) {
602 static inline void mips_tc_sleep(MIPSCPU
*cpu
, int tc
)
604 CPUMIPSState
*c
= &cpu
->env
;
606 /* FIXME: TC reschedule. */
607 if (!mips_vpe_active(c
)) {
614 * @env: CPU from which mapping is performed.
615 * @tc: Should point to an int with the value of the global TC index.
617 * This function will transform @tc into a local index within the
618 * returned #CPUMIPSState.
620 /* FIXME: This code assumes that all VPEs have the same number of TCs,
621 which depends on runtime setup. Can probably be fixed by
622 walking the list of CPUMIPSStates. */
623 static CPUMIPSState
*mips_cpu_map_tc(CPUMIPSState
*env
, int *tc
)
631 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))) {
632 /* Not allowed to address other CPUs. */
633 *tc
= env
->current_tc
;
637 cs
= CPU(mips_env_get_cpu(env
));
638 vpe_idx
= tc_idx
/ cs
->nr_threads
;
639 *tc
= tc_idx
% cs
->nr_threads
;
640 other_cs
= qemu_get_cpu(vpe_idx
);
641 if (other_cs
== NULL
) {
644 cpu
= MIPS_CPU(other_cs
);
648 /* The per VPE CP0_Status register shares some fields with the per TC
649 CP0_TCStatus registers. These fields are wired to the same registers,
650 so changes to either of them should be reflected on both registers.
652 Also, EntryHi shares the bottom 8 bit ASID with TCStauts.
654 These helper call synchronizes the regs for a given cpu. */
656 /* Called for updates to CP0_Status. Defined in "cpu.h" for gdbstub.c. */
657 /* static inline void sync_c0_status(CPUMIPSState *env, CPUMIPSState *cpu,
660 /* Called for updates to CP0_TCStatus. */
661 static void sync_c0_tcstatus(CPUMIPSState
*cpu
, int tc
,
665 uint32_t tcu
, tmx
, tasid
, tksu
;
666 uint32_t mask
= ((1U << CP0St_CU3
)
673 tcu
= (v
>> CP0TCSt_TCU0
) & 0xf;
674 tmx
= (v
>> CP0TCSt_TMX
) & 0x1;
676 tksu
= (v
>> CP0TCSt_TKSU
) & 0x3;
678 status
= tcu
<< CP0St_CU0
;
679 status
|= tmx
<< CP0St_MX
;
680 status
|= tksu
<< CP0St_KSU
;
682 cpu
->CP0_Status
&= ~mask
;
683 cpu
->CP0_Status
|= status
;
685 /* Sync the TASID with EntryHi. */
686 cpu
->CP0_EntryHi
&= ~0xff;
687 cpu
->CP0_EntryHi
|= tasid
;
692 /* Called for updates to CP0_EntryHi. */
693 static void sync_c0_entryhi(CPUMIPSState
*cpu
, int tc
)
696 uint32_t asid
, v
= cpu
->CP0_EntryHi
;
700 if (tc
== cpu
->current_tc
) {
701 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
703 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
711 target_ulong
helper_mfc0_mvpcontrol(CPUMIPSState
*env
)
713 return env
->mvp
->CP0_MVPControl
;
716 target_ulong
helper_mfc0_mvpconf0(CPUMIPSState
*env
)
718 return env
->mvp
->CP0_MVPConf0
;
721 target_ulong
helper_mfc0_mvpconf1(CPUMIPSState
*env
)
723 return env
->mvp
->CP0_MVPConf1
;
726 target_ulong
helper_mfc0_random(CPUMIPSState
*env
)
728 return (int32_t)cpu_mips_get_random(env
);
731 target_ulong
helper_mfc0_tcstatus(CPUMIPSState
*env
)
733 return env
->active_tc
.CP0_TCStatus
;
736 target_ulong
helper_mftc0_tcstatus(CPUMIPSState
*env
)
738 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
739 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
741 if (other_tc
== other
->current_tc
)
742 return other
->active_tc
.CP0_TCStatus
;
744 return other
->tcs
[other_tc
].CP0_TCStatus
;
747 target_ulong
helper_mfc0_tcbind(CPUMIPSState
*env
)
749 return env
->active_tc
.CP0_TCBind
;
752 target_ulong
helper_mftc0_tcbind(CPUMIPSState
*env
)
754 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
755 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
757 if (other_tc
== other
->current_tc
)
758 return other
->active_tc
.CP0_TCBind
;
760 return other
->tcs
[other_tc
].CP0_TCBind
;
763 target_ulong
helper_mfc0_tcrestart(CPUMIPSState
*env
)
765 return env
->active_tc
.PC
;
768 target_ulong
helper_mftc0_tcrestart(CPUMIPSState
*env
)
770 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
771 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
773 if (other_tc
== other
->current_tc
)
774 return other
->active_tc
.PC
;
776 return other
->tcs
[other_tc
].PC
;
779 target_ulong
helper_mfc0_tchalt(CPUMIPSState
*env
)
781 return env
->active_tc
.CP0_TCHalt
;
784 target_ulong
helper_mftc0_tchalt(CPUMIPSState
*env
)
786 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
787 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
789 if (other_tc
== other
->current_tc
)
790 return other
->active_tc
.CP0_TCHalt
;
792 return other
->tcs
[other_tc
].CP0_TCHalt
;
795 target_ulong
helper_mfc0_tccontext(CPUMIPSState
*env
)
797 return env
->active_tc
.CP0_TCContext
;
800 target_ulong
helper_mftc0_tccontext(CPUMIPSState
*env
)
802 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
803 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
805 if (other_tc
== other
->current_tc
)
806 return other
->active_tc
.CP0_TCContext
;
808 return other
->tcs
[other_tc
].CP0_TCContext
;
811 target_ulong
helper_mfc0_tcschedule(CPUMIPSState
*env
)
813 return env
->active_tc
.CP0_TCSchedule
;
816 target_ulong
helper_mftc0_tcschedule(CPUMIPSState
*env
)
818 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
819 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
821 if (other_tc
== other
->current_tc
)
822 return other
->active_tc
.CP0_TCSchedule
;
824 return other
->tcs
[other_tc
].CP0_TCSchedule
;
827 target_ulong
helper_mfc0_tcschefback(CPUMIPSState
*env
)
829 return env
->active_tc
.CP0_TCScheFBack
;
832 target_ulong
helper_mftc0_tcschefback(CPUMIPSState
*env
)
834 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
835 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
837 if (other_tc
== other
->current_tc
)
838 return other
->active_tc
.CP0_TCScheFBack
;
840 return other
->tcs
[other_tc
].CP0_TCScheFBack
;
843 target_ulong
helper_mfc0_count(CPUMIPSState
*env
)
845 return (int32_t)cpu_mips_get_count(env
);
848 target_ulong
helper_mftc0_entryhi(CPUMIPSState
*env
)
850 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
851 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
853 return other
->CP0_EntryHi
;
856 target_ulong
helper_mftc0_cause(CPUMIPSState
*env
)
858 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
860 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
862 if (other_tc
== other
->current_tc
) {
863 tccause
= other
->CP0_Cause
;
865 tccause
= other
->CP0_Cause
;
871 target_ulong
helper_mftc0_status(CPUMIPSState
*env
)
873 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
874 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
876 return other
->CP0_Status
;
879 target_ulong
helper_mfc0_lladdr(CPUMIPSState
*env
)
881 return (int32_t)(env
->lladdr
>> env
->CP0_LLAddr_shift
);
884 target_ulong
helper_mfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
886 return (int32_t)env
->CP0_WatchLo
[sel
];
889 target_ulong
helper_mfc0_watchhi(CPUMIPSState
*env
, uint32_t sel
)
891 return env
->CP0_WatchHi
[sel
];
894 target_ulong
helper_mfc0_debug(CPUMIPSState
*env
)
896 target_ulong t0
= env
->CP0_Debug
;
897 if (env
->hflags
& MIPS_HFLAG_DM
)
903 target_ulong
helper_mftc0_debug(CPUMIPSState
*env
)
905 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
907 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
909 if (other_tc
== other
->current_tc
)
910 tcstatus
= other
->active_tc
.CP0_Debug_tcstatus
;
912 tcstatus
= other
->tcs
[other_tc
].CP0_Debug_tcstatus
;
914 /* XXX: Might be wrong, check with EJTAG spec. */
915 return (other
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
916 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
919 #if defined(TARGET_MIPS64)
920 target_ulong
helper_dmfc0_tcrestart(CPUMIPSState
*env
)
922 return env
->active_tc
.PC
;
925 target_ulong
helper_dmfc0_tchalt(CPUMIPSState
*env
)
927 return env
->active_tc
.CP0_TCHalt
;
930 target_ulong
helper_dmfc0_tccontext(CPUMIPSState
*env
)
932 return env
->active_tc
.CP0_TCContext
;
935 target_ulong
helper_dmfc0_tcschedule(CPUMIPSState
*env
)
937 return env
->active_tc
.CP0_TCSchedule
;
940 target_ulong
helper_dmfc0_tcschefback(CPUMIPSState
*env
)
942 return env
->active_tc
.CP0_TCScheFBack
;
945 target_ulong
helper_dmfc0_lladdr(CPUMIPSState
*env
)
947 return env
->lladdr
>> env
->CP0_LLAddr_shift
;
950 target_ulong
helper_dmfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
952 return env
->CP0_WatchLo
[sel
];
954 #endif /* TARGET_MIPS64 */
956 void helper_mtc0_index(CPUMIPSState
*env
, target_ulong arg1
)
958 uint32_t index_p
= env
->CP0_Index
& 0x80000000;
959 uint32_t tlb_index
= arg1
& 0x7fffffff;
960 if (tlb_index
< env
->tlb
->nb_tlb
) {
961 if (env
->insn_flags
& ISA_MIPS32R6
) {
962 index_p
|= arg1
& 0x80000000;
964 env
->CP0_Index
= index_p
| tlb_index
;
968 void helper_mtc0_mvpcontrol(CPUMIPSState
*env
, target_ulong arg1
)
973 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
974 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
976 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
977 mask
|= (1 << CP0MVPCo_STLB
);
978 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (arg1
& mask
);
980 // TODO: Enable/disable shared TLB, enable/disable VPEs.
982 env
->mvp
->CP0_MVPControl
= newval
;
985 void helper_mtc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
990 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
991 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
992 newval
= (env
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
994 /* Yield scheduler intercept not implemented. */
995 /* Gating storage scheduler intercept not implemented. */
997 // TODO: Enable/disable TCs.
999 env
->CP0_VPEControl
= newval
;
1002 void helper_mttc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
1004 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1005 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1009 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
1010 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
1011 newval
= (other
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
1013 /* TODO: Enable/disable TCs. */
1015 other
->CP0_VPEControl
= newval
;
1018 target_ulong
helper_mftc0_vpecontrol(CPUMIPSState
*env
)
1020 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1021 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1022 /* FIXME: Mask away return zero on read bits. */
1023 return other
->CP0_VPEControl
;
1026 target_ulong
helper_mftc0_vpeconf0(CPUMIPSState
*env
)
1028 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1029 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1031 return other
->CP0_VPEConf0
;
1034 void helper_mtc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1039 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
1040 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
1041 mask
|= (0xff << CP0VPEC0_XTC
);
1042 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1044 newval
= (env
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1046 // TODO: TC exclusive handling due to ERL/EXL.
1048 env
->CP0_VPEConf0
= newval
;
1051 void helper_mttc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1053 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1054 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1058 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1059 newval
= (other
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1061 /* TODO: TC exclusive handling due to ERL/EXL. */
1062 other
->CP0_VPEConf0
= newval
;
1065 void helper_mtc0_vpeconf1(CPUMIPSState
*env
, target_ulong arg1
)
1070 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1071 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
1072 (0xff << CP0VPEC1_NCP1
);
1073 newval
= (env
->CP0_VPEConf1
& ~mask
) | (arg1
& mask
);
1075 /* UDI not implemented. */
1076 /* CP2 not implemented. */
1078 // TODO: Handle FPU (CP1) binding.
1080 env
->CP0_VPEConf1
= newval
;
1083 void helper_mtc0_yqmask(CPUMIPSState
*env
, target_ulong arg1
)
1085 /* Yield qualifier inputs not implemented. */
1086 env
->CP0_YQMask
= 0x00000000;
1089 void helper_mtc0_vpeopt(CPUMIPSState
*env
, target_ulong arg1
)
1091 env
->CP0_VPEOpt
= arg1
& 0x0000ffff;
1094 #define MTC0_ENTRYLO_MASK(env) ((env->PAMask >> 6) & 0x3FFFFFFF)
1096 void helper_mtc0_entrylo0(CPUMIPSState
*env
, target_ulong arg1
)
1098 /* 1k pages not implemented */
1099 target_ulong rxi
= arg1
& (env
->CP0_PageGrain
& (3u << CP0PG_XIE
));
1100 env
->CP0_EntryLo0
= (arg1
& MTC0_ENTRYLO_MASK(env
))
1101 | (rxi
<< (CP0EnLo_XI
- 30));
1104 #if defined(TARGET_MIPS64)
1105 #define DMTC0_ENTRYLO_MASK(env) (env->PAMask >> 6)
1107 void helper_dmtc0_entrylo0(CPUMIPSState
*env
, uint64_t arg1
)
1109 uint64_t rxi
= arg1
& ((env
->CP0_PageGrain
& (3ull << CP0PG_XIE
)) << 32);
1110 env
->CP0_EntryLo0
= (arg1
& DMTC0_ENTRYLO_MASK(env
)) | rxi
;
1114 void helper_mtc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1116 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
1119 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (arg1
& mask
);
1121 env
->active_tc
.CP0_TCStatus
= newval
;
1122 sync_c0_tcstatus(env
, env
->current_tc
, newval
);
1125 void helper_mttc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1127 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1128 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1130 if (other_tc
== other
->current_tc
)
1131 other
->active_tc
.CP0_TCStatus
= arg1
;
1133 other
->tcs
[other_tc
].CP0_TCStatus
= arg1
;
1134 sync_c0_tcstatus(other
, other_tc
, arg1
);
1137 void helper_mtc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1139 uint32_t mask
= (1 << CP0TCBd_TBE
);
1142 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1143 mask
|= (1 << CP0TCBd_CurVPE
);
1144 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1145 env
->active_tc
.CP0_TCBind
= newval
;
1148 void helper_mttc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1150 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1151 uint32_t mask
= (1 << CP0TCBd_TBE
);
1153 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1155 if (other
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1156 mask
|= (1 << CP0TCBd_CurVPE
);
1157 if (other_tc
== other
->current_tc
) {
1158 newval
= (other
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1159 other
->active_tc
.CP0_TCBind
= newval
;
1161 newval
= (other
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (arg1
& mask
);
1162 other
->tcs
[other_tc
].CP0_TCBind
= newval
;
1166 void helper_mtc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1168 env
->active_tc
.PC
= arg1
;
1169 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1171 /* MIPS16 not implemented. */
1174 void helper_mttc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1176 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1177 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1179 if (other_tc
== other
->current_tc
) {
1180 other
->active_tc
.PC
= arg1
;
1181 other
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1182 other
->lladdr
= 0ULL;
1183 /* MIPS16 not implemented. */
1185 other
->tcs
[other_tc
].PC
= arg1
;
1186 other
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1187 other
->lladdr
= 0ULL;
1188 /* MIPS16 not implemented. */
1192 void helper_mtc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1194 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1196 env
->active_tc
.CP0_TCHalt
= arg1
& 0x1;
1198 // TODO: Halt TC / Restart (if allocated+active) TC.
1199 if (env
->active_tc
.CP0_TCHalt
& 1) {
1200 mips_tc_sleep(cpu
, env
->current_tc
);
1202 mips_tc_wake(cpu
, env
->current_tc
);
1206 void helper_mttc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1208 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1209 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1210 MIPSCPU
*other_cpu
= mips_env_get_cpu(other
);
1212 // TODO: Halt TC / Restart (if allocated+active) TC.
1214 if (other_tc
== other
->current_tc
)
1215 other
->active_tc
.CP0_TCHalt
= arg1
;
1217 other
->tcs
[other_tc
].CP0_TCHalt
= arg1
;
1220 mips_tc_sleep(other_cpu
, other_tc
);
1222 mips_tc_wake(other_cpu
, other_tc
);
1226 void helper_mtc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1228 env
->active_tc
.CP0_TCContext
= arg1
;
1231 void helper_mttc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1233 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1234 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1236 if (other_tc
== other
->current_tc
)
1237 other
->active_tc
.CP0_TCContext
= arg1
;
1239 other
->tcs
[other_tc
].CP0_TCContext
= arg1
;
1242 void helper_mtc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1244 env
->active_tc
.CP0_TCSchedule
= arg1
;
1247 void helper_mttc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1249 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1250 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1252 if (other_tc
== other
->current_tc
)
1253 other
->active_tc
.CP0_TCSchedule
= arg1
;
1255 other
->tcs
[other_tc
].CP0_TCSchedule
= arg1
;
1258 void helper_mtc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1260 env
->active_tc
.CP0_TCScheFBack
= arg1
;
1263 void helper_mttc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1265 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1266 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1268 if (other_tc
== other
->current_tc
)
1269 other
->active_tc
.CP0_TCScheFBack
= arg1
;
1271 other
->tcs
[other_tc
].CP0_TCScheFBack
= arg1
;
1274 void helper_mtc0_entrylo1(CPUMIPSState
*env
, target_ulong arg1
)
1276 /* 1k pages not implemented */
1277 target_ulong rxi
= arg1
& (env
->CP0_PageGrain
& (3u << CP0PG_XIE
));
1278 env
->CP0_EntryLo1
= (arg1
& MTC0_ENTRYLO_MASK(env
))
1279 | (rxi
<< (CP0EnLo_XI
- 30));
1282 #if defined(TARGET_MIPS64)
1283 void helper_dmtc0_entrylo1(CPUMIPSState
*env
, uint64_t arg1
)
1285 uint64_t rxi
= arg1
& ((env
->CP0_PageGrain
& (3ull << CP0PG_XIE
)) << 32);
1286 env
->CP0_EntryLo1
= (arg1
& DMTC0_ENTRYLO_MASK(env
)) | rxi
;
1290 void helper_mtc0_context(CPUMIPSState
*env
, target_ulong arg1
)
1292 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (arg1
& ~0x007FFFFF);
1295 void helper_mtc0_pagemask(CPUMIPSState
*env
, target_ulong arg1
)
1297 uint64_t mask
= arg1
>> (TARGET_PAGE_BITS
+ 1);
1298 if (!(env
->insn_flags
& ISA_MIPS32R6
) || (arg1
== ~0) ||
1299 (mask
== 0x0000 || mask
== 0x0003 || mask
== 0x000F ||
1300 mask
== 0x003F || mask
== 0x00FF || mask
== 0x03FF ||
1301 mask
== 0x0FFF || mask
== 0x3FFF || mask
== 0xFFFF)) {
1302 env
->CP0_PageMask
= arg1
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1306 void helper_mtc0_pagegrain(CPUMIPSState
*env
, target_ulong arg1
)
1308 /* SmartMIPS not implemented */
1309 /* 1k pages not implemented */
1310 env
->CP0_PageGrain
= (arg1
& env
->CP0_PageGrain_rw_bitmask
) |
1311 (env
->CP0_PageGrain
& ~env
->CP0_PageGrain_rw_bitmask
);
1312 compute_hflags(env
);
1313 restore_pamask(env
);
1316 void helper_mtc0_wired(CPUMIPSState
*env
, target_ulong arg1
)
1318 if (env
->insn_flags
& ISA_MIPS32R6
) {
1319 if (arg1
< env
->tlb
->nb_tlb
) {
1320 env
->CP0_Wired
= arg1
;
1323 env
->CP0_Wired
= arg1
% env
->tlb
->nb_tlb
;
1327 void helper_mtc0_srsconf0(CPUMIPSState
*env
, target_ulong arg1
)
1329 env
->CP0_SRSConf0
|= arg1
& env
->CP0_SRSConf0_rw_bitmask
;
1332 void helper_mtc0_srsconf1(CPUMIPSState
*env
, target_ulong arg1
)
1334 env
->CP0_SRSConf1
|= arg1
& env
->CP0_SRSConf1_rw_bitmask
;
1337 void helper_mtc0_srsconf2(CPUMIPSState
*env
, target_ulong arg1
)
1339 env
->CP0_SRSConf2
|= arg1
& env
->CP0_SRSConf2_rw_bitmask
;
1342 void helper_mtc0_srsconf3(CPUMIPSState
*env
, target_ulong arg1
)
1344 env
->CP0_SRSConf3
|= arg1
& env
->CP0_SRSConf3_rw_bitmask
;
1347 void helper_mtc0_srsconf4(CPUMIPSState
*env
, target_ulong arg1
)
1349 env
->CP0_SRSConf4
|= arg1
& env
->CP0_SRSConf4_rw_bitmask
;
1352 void helper_mtc0_hwrena(CPUMIPSState
*env
, target_ulong arg1
)
1354 uint32_t mask
= 0x0000000F;
1356 if ((env
->CP0_Config1
& (1 << CP0C1_PC
)) &&
1357 (env
->insn_flags
& ISA_MIPS32R6
)) {
1360 if (env
->insn_flags
& ISA_MIPS32R6
) {
1363 if (env
->CP0_Config3
& (1 << CP0C3_ULRI
)) {
1366 if (arg1
& (1 << 29)) {
1367 env
->hflags
|= MIPS_HFLAG_HWRENA_ULR
;
1369 env
->hflags
&= ~MIPS_HFLAG_HWRENA_ULR
;
1373 env
->CP0_HWREna
= arg1
& mask
;
1376 void helper_mtc0_count(CPUMIPSState
*env
, target_ulong arg1
)
1378 cpu_mips_store_count(env
, arg1
);
1381 void helper_mtc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1383 target_ulong old
, val
, mask
;
1384 mask
= (TARGET_PAGE_MASK
<< 1) | 0xFF;
1385 if (((env
->CP0_Config4
>> CP0C4_IE
) & 0x3) >= 2) {
1386 mask
|= 1 << CP0EnHi_EHINV
;
1389 /* 1k pages not implemented */
1390 #if defined(TARGET_MIPS64)
1391 if (env
->insn_flags
& ISA_MIPS32R6
) {
1392 int entryhi_r
= extract64(arg1
, 62, 2);
1393 int config0_at
= extract32(env
->CP0_Config0
, 13, 2);
1394 bool no_supervisor
= (env
->CP0_Status_rw_bitmask
& 0x8) == 0;
1395 if ((entryhi_r
== 2) ||
1396 (entryhi_r
== 1 && (no_supervisor
|| config0_at
== 1))) {
1397 /* skip EntryHi.R field if new value is reserved */
1398 mask
&= ~(0x3ull
<< 62);
1401 mask
&= env
->SEGMask
;
1403 old
= env
->CP0_EntryHi
;
1404 val
= (arg1
& mask
) | (old
& ~mask
);
1405 env
->CP0_EntryHi
= val
;
1406 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1407 sync_c0_entryhi(env
, env
->current_tc
);
1409 /* If the ASID changes, flush qemu's TLB. */
1410 if ((old
& 0xFF) != (val
& 0xFF))
1411 cpu_mips_tlb_flush(env
, 1);
1414 void helper_mttc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1416 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1417 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1419 other
->CP0_EntryHi
= arg1
;
1420 sync_c0_entryhi(other
, other_tc
);
1423 void helper_mtc0_compare(CPUMIPSState
*env
, target_ulong arg1
)
1425 cpu_mips_store_compare(env
, arg1
);
1428 void helper_mtc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1430 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1433 old
= env
->CP0_Status
;
1434 cpu_mips_store_status(env
, arg1
);
1435 val
= env
->CP0_Status
;
1437 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1438 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1439 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1440 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1442 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1443 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1444 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1445 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1447 cpu_abort(CPU(cpu
), "Invalid MMU mode!\n");
1453 void helper_mttc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1455 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1456 uint32_t mask
= env
->CP0_Status_rw_bitmask
& ~0xf1000018;
1457 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1459 other
->CP0_Status
= (other
->CP0_Status
& ~mask
) | (arg1
& mask
);
1460 sync_c0_status(env
, other
, other_tc
);
1463 void helper_mtc0_intctl(CPUMIPSState
*env
, target_ulong arg1
)
1465 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000003e0) | (arg1
& 0x000003e0);
1468 void helper_mtc0_srsctl(CPUMIPSState
*env
, target_ulong arg1
)
1470 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1471 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (arg1
& mask
);
1474 void helper_mtc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1476 cpu_mips_store_cause(env
, arg1
);
1479 void helper_mttc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1481 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1482 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1484 cpu_mips_store_cause(other
, arg1
);
1487 target_ulong
helper_mftc0_epc(CPUMIPSState
*env
)
1489 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1490 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1492 return other
->CP0_EPC
;
1495 target_ulong
helper_mftc0_ebase(CPUMIPSState
*env
)
1497 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1498 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1500 return other
->CP0_EBase
;
1503 void helper_mtc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1505 env
->CP0_EBase
= (env
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1508 void helper_mttc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1510 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1511 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1512 other
->CP0_EBase
= (other
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1515 target_ulong
helper_mftc0_configx(CPUMIPSState
*env
, target_ulong idx
)
1517 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1518 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1521 case 0: return other
->CP0_Config0
;
1522 case 1: return other
->CP0_Config1
;
1523 case 2: return other
->CP0_Config2
;
1524 case 3: return other
->CP0_Config3
;
1525 /* 4 and 5 are reserved. */
1526 case 6: return other
->CP0_Config6
;
1527 case 7: return other
->CP0_Config7
;
1534 void helper_mtc0_config0(CPUMIPSState
*env
, target_ulong arg1
)
1536 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (arg1
& 0x00000007);
1539 void helper_mtc0_config2(CPUMIPSState
*env
, target_ulong arg1
)
1541 /* tertiary/secondary caches not implemented */
1542 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1545 void helper_mtc0_config3(CPUMIPSState
*env
, target_ulong arg1
)
1547 if (env
->insn_flags
& ASE_MICROMIPS
) {
1548 env
->CP0_Config3
= (env
->CP0_Config3
& ~(1 << CP0C3_ISA_ON_EXC
)) |
1549 (arg1
& (1 << CP0C3_ISA_ON_EXC
));
1553 void helper_mtc0_config4(CPUMIPSState
*env
, target_ulong arg1
)
1555 env
->CP0_Config4
= (env
->CP0_Config4
& (~env
->CP0_Config4_rw_bitmask
)) |
1556 (arg1
& env
->CP0_Config4_rw_bitmask
);
1559 void helper_mtc0_config5(CPUMIPSState
*env
, target_ulong arg1
)
1561 env
->CP0_Config5
= (env
->CP0_Config5
& (~env
->CP0_Config5_rw_bitmask
)) |
1562 (arg1
& env
->CP0_Config5_rw_bitmask
);
1563 compute_hflags(env
);
1566 void helper_mtc0_lladdr(CPUMIPSState
*env
, target_ulong arg1
)
1568 target_long mask
= env
->CP0_LLAddr_rw_bitmask
;
1569 arg1
= arg1
<< env
->CP0_LLAddr_shift
;
1570 env
->lladdr
= (env
->lladdr
& ~mask
) | (arg1
& mask
);
1573 void helper_mtc0_watchlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1575 /* Watch exceptions for instructions, data loads, data stores
1577 env
->CP0_WatchLo
[sel
] = (arg1
& ~0x7);
1580 void helper_mtc0_watchhi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1582 env
->CP0_WatchHi
[sel
] = (arg1
& 0x40FF0FF8);
1583 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & arg1
& 0x7);
1586 void helper_mtc0_xcontext(CPUMIPSState
*env
, target_ulong arg1
)
1588 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1589 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (arg1
& ~mask
);
1592 void helper_mtc0_framemask(CPUMIPSState
*env
, target_ulong arg1
)
1594 env
->CP0_Framemask
= arg1
; /* XXX */
1597 void helper_mtc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1599 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (arg1
& 0x13300120);
1600 if (arg1
& (1 << CP0DB_DM
))
1601 env
->hflags
|= MIPS_HFLAG_DM
;
1603 env
->hflags
&= ~MIPS_HFLAG_DM
;
1606 void helper_mttc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1608 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1609 uint32_t val
= arg1
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1610 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1612 /* XXX: Might be wrong, check with EJTAG spec. */
1613 if (other_tc
== other
->current_tc
)
1614 other
->active_tc
.CP0_Debug_tcstatus
= val
;
1616 other
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1617 other
->CP0_Debug
= (other
->CP0_Debug
&
1618 ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1619 (arg1
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1622 void helper_mtc0_performance0(CPUMIPSState
*env
, target_ulong arg1
)
1624 env
->CP0_Performance0
= arg1
& 0x000007ff;
1627 void helper_mtc0_taglo(CPUMIPSState
*env
, target_ulong arg1
)
1629 env
->CP0_TagLo
= arg1
& 0xFFFFFCF6;
1632 void helper_mtc0_datalo(CPUMIPSState
*env
, target_ulong arg1
)
1634 env
->CP0_DataLo
= arg1
; /* XXX */
1637 void helper_mtc0_taghi(CPUMIPSState
*env
, target_ulong arg1
)
1639 env
->CP0_TagHi
= arg1
; /* XXX */
1642 void helper_mtc0_datahi(CPUMIPSState
*env
, target_ulong arg1
)
1644 env
->CP0_DataHi
= arg1
; /* XXX */
1647 /* MIPS MT functions */
1648 target_ulong
helper_mftgpr(CPUMIPSState
*env
, uint32_t sel
)
1650 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1651 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1653 if (other_tc
== other
->current_tc
)
1654 return other
->active_tc
.gpr
[sel
];
1656 return other
->tcs
[other_tc
].gpr
[sel
];
1659 target_ulong
helper_mftlo(CPUMIPSState
*env
, uint32_t sel
)
1661 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1662 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1664 if (other_tc
== other
->current_tc
)
1665 return other
->active_tc
.LO
[sel
];
1667 return other
->tcs
[other_tc
].LO
[sel
];
1670 target_ulong
helper_mfthi(CPUMIPSState
*env
, uint32_t sel
)
1672 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1673 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1675 if (other_tc
== other
->current_tc
)
1676 return other
->active_tc
.HI
[sel
];
1678 return other
->tcs
[other_tc
].HI
[sel
];
1681 target_ulong
helper_mftacx(CPUMIPSState
*env
, uint32_t sel
)
1683 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1684 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1686 if (other_tc
== other
->current_tc
)
1687 return other
->active_tc
.ACX
[sel
];
1689 return other
->tcs
[other_tc
].ACX
[sel
];
1692 target_ulong
helper_mftdsp(CPUMIPSState
*env
)
1694 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1695 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1697 if (other_tc
== other
->current_tc
)
1698 return other
->active_tc
.DSPControl
;
1700 return other
->tcs
[other_tc
].DSPControl
;
1703 void helper_mttgpr(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1705 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1706 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1708 if (other_tc
== other
->current_tc
)
1709 other
->active_tc
.gpr
[sel
] = arg1
;
1711 other
->tcs
[other_tc
].gpr
[sel
] = arg1
;
1714 void helper_mttlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1716 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1717 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1719 if (other_tc
== other
->current_tc
)
1720 other
->active_tc
.LO
[sel
] = arg1
;
1722 other
->tcs
[other_tc
].LO
[sel
] = arg1
;
1725 void helper_mtthi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1727 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1728 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1730 if (other_tc
== other
->current_tc
)
1731 other
->active_tc
.HI
[sel
] = arg1
;
1733 other
->tcs
[other_tc
].HI
[sel
] = arg1
;
1736 void helper_mttacx(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1738 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1739 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1741 if (other_tc
== other
->current_tc
)
1742 other
->active_tc
.ACX
[sel
] = arg1
;
1744 other
->tcs
[other_tc
].ACX
[sel
] = arg1
;
1747 void helper_mttdsp(CPUMIPSState
*env
, target_ulong arg1
)
1749 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1750 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1752 if (other_tc
== other
->current_tc
)
1753 other
->active_tc
.DSPControl
= arg1
;
1755 other
->tcs
[other_tc
].DSPControl
= arg1
;
1758 /* MIPS MT functions */
1759 target_ulong
helper_dmt(void)
1765 target_ulong
helper_emt(void)
1771 target_ulong
helper_dvpe(CPUMIPSState
*env
)
1773 CPUState
*other_cs
= first_cpu
;
1774 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1776 CPU_FOREACH(other_cs
) {
1777 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
1778 /* Turn off all VPEs except the one executing the dvpe. */
1779 if (&other_cpu
->env
!= env
) {
1780 other_cpu
->env
.mvp
->CP0_MVPControl
&= ~(1 << CP0MVPCo_EVP
);
1781 mips_vpe_sleep(other_cpu
);
1787 target_ulong
helper_evpe(CPUMIPSState
*env
)
1789 CPUState
*other_cs
= first_cpu
;
1790 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1792 CPU_FOREACH(other_cs
) {
1793 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
1795 if (&other_cpu
->env
!= env
1796 /* If the VPE is WFI, don't disturb its sleep. */
1797 && !mips_vpe_is_wfi(other_cpu
)) {
1798 /* Enable the VPE. */
1799 other_cpu
->env
.mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
1800 mips_vpe_wake(other_cpu
); /* And wake it up. */
1805 #endif /* !CONFIG_USER_ONLY */
1807 void helper_fork(target_ulong arg1
, target_ulong arg2
)
1809 // arg1 = rt, arg2 = rs
1810 // TODO: store to TC register
1813 target_ulong
helper_yield(CPUMIPSState
*env
, target_ulong arg
)
1815 target_long arg1
= arg
;
1818 /* No scheduling policy implemented. */
1820 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1821 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1822 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1823 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1824 do_raise_exception(env
, EXCP_THREAD
, GETPC());
1827 } else if (arg1
== 0) {
1828 if (0 /* TODO: TC underflow */) {
1829 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1830 do_raise_exception(env
, EXCP_THREAD
, GETPC());
1832 // TODO: Deallocate TC
1834 } else if (arg1
> 0) {
1835 /* Yield qualifier inputs not implemented. */
1836 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1837 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1838 do_raise_exception(env
, EXCP_THREAD
, GETPC());
1840 return env
->CP0_YQMask
;
1843 #ifndef CONFIG_USER_ONLY
1844 /* TLB management */
1845 static void r4k_mips_tlb_flush_extra (CPUMIPSState
*env
, int first
)
1847 /* Discard entries from env->tlb[first] onwards. */
1848 while (env
->tlb
->tlb_in_use
> first
) {
1849 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1853 static inline uint64_t get_tlb_pfn_from_entrylo(uint64_t entrylo
)
1855 #if defined(TARGET_MIPS64)
1856 return extract64(entrylo
, 6, 54);
1858 return extract64(entrylo
, 6, 24) | /* PFN */
1859 (extract64(entrylo
, 32, 32) << 24); /* PFNX */
1863 static void r4k_fill_tlb(CPUMIPSState
*env
, int idx
)
1867 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1868 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1869 if (env
->CP0_EntryHi
& (1 << CP0EnHi_EHINV
)) {
1874 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1875 #if defined(TARGET_MIPS64)
1876 tlb
->VPN
&= env
->SEGMask
;
1878 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1879 tlb
->PageMask
= env
->CP0_PageMask
;
1880 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1881 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1882 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1883 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1884 tlb
->XI0
= (env
->CP0_EntryLo0
>> CP0EnLo_XI
) & 1;
1885 tlb
->RI0
= (env
->CP0_EntryLo0
>> CP0EnLo_RI
) & 1;
1886 tlb
->PFN
[0] = get_tlb_pfn_from_entrylo(env
->CP0_EntryLo0
) << 12;
1887 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1888 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1889 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1890 tlb
->XI1
= (env
->CP0_EntryLo1
>> CP0EnLo_XI
) & 1;
1891 tlb
->RI1
= (env
->CP0_EntryLo1
>> CP0EnLo_RI
) & 1;
1892 tlb
->PFN
[1] = get_tlb_pfn_from_entrylo(env
->CP0_EntryLo1
) << 12;
1895 void r4k_helper_tlbinv(CPUMIPSState
*env
)
1899 uint8_t ASID
= env
->CP0_EntryHi
& 0xFF;
1901 for (idx
= 0; idx
< env
->tlb
->nb_tlb
; idx
++) {
1902 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1903 if (!tlb
->G
&& tlb
->ASID
== ASID
) {
1907 cpu_mips_tlb_flush(env
, 1);
1910 void r4k_helper_tlbinvf(CPUMIPSState
*env
)
1914 for (idx
= 0; idx
< env
->tlb
->nb_tlb
; idx
++) {
1915 env
->tlb
->mmu
.r4k
.tlb
[idx
].EHINV
= 1;
1917 cpu_mips_tlb_flush(env
, 1);
1920 void r4k_helper_tlbwi(CPUMIPSState
*env
)
1926 bool G
, V0
, D0
, V1
, D1
;
1928 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1929 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1930 VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1931 #if defined(TARGET_MIPS64)
1932 VPN
&= env
->SEGMask
;
1934 ASID
= env
->CP0_EntryHi
& 0xff;
1935 G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1936 V0
= (env
->CP0_EntryLo0
& 2) != 0;
1937 D0
= (env
->CP0_EntryLo0
& 4) != 0;
1938 V1
= (env
->CP0_EntryLo1
& 2) != 0;
1939 D1
= (env
->CP0_EntryLo1
& 4) != 0;
1941 /* Discard cached TLB entries, unless tlbwi is just upgrading access
1942 permissions on the current entry. */
1943 if (tlb
->VPN
!= VPN
|| tlb
->ASID
!= ASID
|| tlb
->G
!= G
||
1944 (tlb
->V0
&& !V0
) || (tlb
->D0
&& !D0
) ||
1945 (tlb
->V1
&& !V1
) || (tlb
->D1
&& !D1
)) {
1946 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
1949 r4k_invalidate_tlb(env
, idx
, 0);
1950 r4k_fill_tlb(env
, idx
);
1953 void r4k_helper_tlbwr(CPUMIPSState
*env
)
1955 int r
= cpu_mips_get_random(env
);
1957 r4k_invalidate_tlb(env
, r
, 1);
1958 r4k_fill_tlb(env
, r
);
1961 void r4k_helper_tlbp(CPUMIPSState
*env
)
1970 ASID
= env
->CP0_EntryHi
& 0xFF;
1971 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
1972 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1973 /* 1k pages are not supported. */
1974 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1975 tag
= env
->CP0_EntryHi
& ~mask
;
1976 VPN
= tlb
->VPN
& ~mask
;
1977 #if defined(TARGET_MIPS64)
1978 tag
&= env
->SEGMask
;
1980 /* Check ASID, virtual page number & size */
1981 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
&& !tlb
->EHINV
) {
1987 if (i
== env
->tlb
->nb_tlb
) {
1988 /* No match. Discard any shadow entries, if any of them match. */
1989 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
1990 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1991 /* 1k pages are not supported. */
1992 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1993 tag
= env
->CP0_EntryHi
& ~mask
;
1994 VPN
= tlb
->VPN
& ~mask
;
1995 #if defined(TARGET_MIPS64)
1996 tag
&= env
->SEGMask
;
1998 /* Check ASID, virtual page number & size */
1999 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
2000 r4k_mips_tlb_flush_extra (env
, i
);
2005 env
->CP0_Index
|= 0x80000000;
2009 static inline uint64_t get_entrylo_pfn_from_tlb(uint64_t tlb_pfn
)
2011 #if defined(TARGET_MIPS64)
2012 return tlb_pfn
<< 6;
2014 return (extract64(tlb_pfn
, 0, 24) << 6) | /* PFN */
2015 (extract64(tlb_pfn
, 24, 32) << 32); /* PFNX */
2019 void r4k_helper_tlbr(CPUMIPSState
*env
)
2025 ASID
= env
->CP0_EntryHi
& 0xFF;
2026 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
2027 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
2029 /* If this will change the current ASID, flush qemu's TLB. */
2030 if (ASID
!= tlb
->ASID
)
2031 cpu_mips_tlb_flush (env
, 1);
2033 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
2036 env
->CP0_EntryHi
= 1 << CP0EnHi_EHINV
;
2037 env
->CP0_PageMask
= 0;
2038 env
->CP0_EntryLo0
= 0;
2039 env
->CP0_EntryLo1
= 0;
2041 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
2042 env
->CP0_PageMask
= tlb
->PageMask
;
2043 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
2044 ((uint64_t)tlb
->RI0
<< CP0EnLo_RI
) |
2045 ((uint64_t)tlb
->XI0
<< CP0EnLo_XI
) | (tlb
->C0
<< 3) |
2046 get_entrylo_pfn_from_tlb(tlb
->PFN
[0] >> 12);
2047 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
2048 ((uint64_t)tlb
->RI1
<< CP0EnLo_RI
) |
2049 ((uint64_t)tlb
->XI1
<< CP0EnLo_XI
) | (tlb
->C1
<< 3) |
2050 get_entrylo_pfn_from_tlb(tlb
->PFN
[1] >> 12);
2054 void helper_tlbwi(CPUMIPSState
*env
)
2056 env
->tlb
->helper_tlbwi(env
);
2059 void helper_tlbwr(CPUMIPSState
*env
)
2061 env
->tlb
->helper_tlbwr(env
);
2064 void helper_tlbp(CPUMIPSState
*env
)
2066 env
->tlb
->helper_tlbp(env
);
2069 void helper_tlbr(CPUMIPSState
*env
)
2071 env
->tlb
->helper_tlbr(env
);
2074 void helper_tlbinv(CPUMIPSState
*env
)
2076 env
->tlb
->helper_tlbinv(env
);
2079 void helper_tlbinvf(CPUMIPSState
*env
)
2081 env
->tlb
->helper_tlbinvf(env
);
2085 target_ulong
helper_di(CPUMIPSState
*env
)
2087 target_ulong t0
= env
->CP0_Status
;
2089 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
2093 target_ulong
helper_ei(CPUMIPSState
*env
)
2095 target_ulong t0
= env
->CP0_Status
;
2097 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
2101 static void debug_pre_eret(CPUMIPSState
*env
)
2103 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2104 qemu_log("ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2105 env
->active_tc
.PC
, env
->CP0_EPC
);
2106 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2107 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2108 if (env
->hflags
& MIPS_HFLAG_DM
)
2109 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2114 static void debug_post_eret(CPUMIPSState
*env
)
2116 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
2118 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2119 qemu_log(" => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2120 env
->active_tc
.PC
, env
->CP0_EPC
);
2121 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2122 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2123 if (env
->hflags
& MIPS_HFLAG_DM
)
2124 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2125 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
2126 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
2127 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
2128 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
2130 cpu_abort(CPU(cpu
), "Invalid MMU mode!\n");
2136 static void set_pc(CPUMIPSState
*env
, target_ulong error_pc
)
2138 env
->active_tc
.PC
= error_pc
& ~(target_ulong
)1;
2140 env
->hflags
|= MIPS_HFLAG_M16
;
2142 env
->hflags
&= ~(MIPS_HFLAG_M16
);
2146 static inline void exception_return(CPUMIPSState
*env
)
2148 debug_pre_eret(env
);
2149 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
2150 set_pc(env
, env
->CP0_ErrorEPC
);
2151 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
2153 set_pc(env
, env
->CP0_EPC
);
2154 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
2156 compute_hflags(env
);
2157 debug_post_eret(env
);
2160 void helper_eret(CPUMIPSState
*env
)
2162 exception_return(env
);
2166 void helper_eretnc(CPUMIPSState
*env
)
2168 exception_return(env
);
2171 void helper_deret(CPUMIPSState
*env
)
2173 debug_pre_eret(env
);
2174 set_pc(env
, env
->CP0_DEPC
);
2176 env
->hflags
&= ~MIPS_HFLAG_DM
;
2177 compute_hflags(env
);
2178 debug_post_eret(env
);
2180 #endif /* !CONFIG_USER_ONLY */
2182 static inline void check_hwrena(CPUMIPSState
*env
, int reg
)
2184 if ((env
->hflags
& MIPS_HFLAG_CP0
) || (env
->CP0_HWREna
& (1 << reg
))) {
2187 do_raise_exception(env
, EXCP_RI
, GETPC());
2190 target_ulong
helper_rdhwr_cpunum(CPUMIPSState
*env
)
2192 check_hwrena(env
, 0);
2193 return env
->CP0_EBase
& 0x3ff;
2196 target_ulong
helper_rdhwr_synci_step(CPUMIPSState
*env
)
2198 check_hwrena(env
, 1);
2199 return env
->SYNCI_Step
;
2202 target_ulong
helper_rdhwr_cc(CPUMIPSState
*env
)
2204 check_hwrena(env
, 2);
2205 #ifdef CONFIG_USER_ONLY
2206 return env
->CP0_Count
;
2208 return (int32_t)cpu_mips_get_count(env
);
2212 target_ulong
helper_rdhwr_ccres(CPUMIPSState
*env
)
2214 check_hwrena(env
, 3);
2218 target_ulong
helper_rdhwr_performance(CPUMIPSState
*env
)
2220 check_hwrena(env
, 4);
2221 return env
->CP0_Performance0
;
2224 target_ulong
helper_rdhwr_xnp(CPUMIPSState
*env
)
2226 check_hwrena(env
, 5);
2227 return (env
->CP0_Config5
>> CP0C5_XNP
) & 1;
2230 void helper_pmon(CPUMIPSState
*env
, int function
)
2234 case 2: /* TODO: char inbyte(int waitflag); */
2235 if (env
->active_tc
.gpr
[4] == 0)
2236 env
->active_tc
.gpr
[2] = -1;
2238 case 11: /* TODO: char inbyte (void); */
2239 env
->active_tc
.gpr
[2] = -1;
2243 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
2249 unsigned char *fmt
= (void *)(uintptr_t)env
->active_tc
.gpr
[4];
2256 void helper_wait(CPUMIPSState
*env
)
2258 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
2261 cpu_reset_interrupt(cs
, CPU_INTERRUPT_WAKE
);
2262 /* Last instruction in the block, PC was updated before
2263 - no need to recover PC and icount */
2264 raise_exception(env
, EXCP_HLT
);
2267 #if !defined(CONFIG_USER_ONLY)
2269 void mips_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
2270 int access_type
, int is_user
,
2273 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2274 CPUMIPSState
*env
= &cpu
->env
;
2278 env
->CP0_BadVAddr
= addr
;
2280 if (access_type
== MMU_DATA_STORE
) {
2284 if (access_type
== MMU_INST_FETCH
) {
2285 error_code
|= EXCP_INST_NOTAVAIL
;
2289 do_raise_exception_err(env
, excp
, error_code
, retaddr
);
2292 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2297 ret
= mips_cpu_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2299 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2300 CPUMIPSState
*env
= &cpu
->env
;
2302 do_raise_exception_err(env
, cs
->exception_index
,
2303 env
->error_code
, retaddr
);
2307 void mips_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2308 bool is_write
, bool is_exec
, int unused
,
2311 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2312 CPUMIPSState
*env
= &cpu
->env
;
2315 * Raising an exception with KVM enabled will crash because it won't be from
2316 * the main execution loop so the longjmp won't have a matching setjmp.
2317 * Until we can trigger a bus error exception through KVM lets just ignore
2320 if (kvm_enabled()) {
2325 raise_exception(env
, EXCP_IBE
);
2327 raise_exception(env
, EXCP_DBE
);
2330 #endif /* !CONFIG_USER_ONLY */
2332 /* Complex FPU operations which may need stack space. */
2334 #define FLOAT_TWO32 make_float32(1 << 30)
2335 #define FLOAT_TWO64 make_float64(1ULL << 62)
2336 #define FP_TO_INT32_OVERFLOW 0x7fffffff
2337 #define FP_TO_INT64_OVERFLOW 0x7fffffffffffffffULL
2339 /* convert MIPS rounding mode in FCR31 to IEEE library */
2340 unsigned int ieee_rm
[] = {
2341 float_round_nearest_even
,
2342 float_round_to_zero
,
2347 target_ulong
helper_cfc1(CPUMIPSState
*env
, uint32_t reg
)
2349 target_ulong arg1
= 0;
2353 arg1
= (int32_t)env
->active_fpu
.fcr0
;
2356 /* UFR Support - Read Status FR */
2357 if (env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) {
2358 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2360 ((env
->CP0_Status
& (1 << CP0St_FR
)) >> CP0St_FR
);
2362 do_raise_exception(env
, EXCP_RI
, GETPC());
2367 /* FRE Support - read Config5.FRE bit */
2368 if (env
->active_fpu
.fcr0
& (1 << FCR0_FREP
)) {
2369 if (env
->CP0_Config5
& (1 << CP0C5_UFE
)) {
2370 arg1
= (env
->CP0_Config5
>> CP0C5_FRE
) & 1;
2372 helper_raise_exception(env
, EXCP_RI
);
2377 arg1
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
2380 arg1
= env
->active_fpu
.fcr31
& 0x0003f07c;
2383 arg1
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
2386 arg1
= (int32_t)env
->active_fpu
.fcr31
;
2393 void helper_ctc1(CPUMIPSState
*env
, target_ulong arg1
, uint32_t fs
, uint32_t rt
)
2397 /* UFR Alias - Reset Status FR */
2398 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) && (rt
== 0))) {
2401 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2402 env
->CP0_Status
&= ~(1 << CP0St_FR
);
2403 compute_hflags(env
);
2405 do_raise_exception(env
, EXCP_RI
, GETPC());
2409 /* UNFR Alias - Set Status FR */
2410 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) && (rt
== 0))) {
2413 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2414 env
->CP0_Status
|= (1 << CP0St_FR
);
2415 compute_hflags(env
);
2417 do_raise_exception(env
, EXCP_RI
, GETPC());
2421 /* FRE Support - clear Config5.FRE bit */
2422 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_FREP
)) && (rt
== 0))) {
2425 if (env
->CP0_Config5
& (1 << CP0C5_UFE
)) {
2426 env
->CP0_Config5
&= ~(1 << CP0C5_FRE
);
2427 compute_hflags(env
);
2429 helper_raise_exception(env
, EXCP_RI
);
2433 /* FRE Support - set Config5.FRE bit */
2434 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_FREP
)) && (rt
== 0))) {
2437 if (env
->CP0_Config5
& (1 << CP0C5_UFE
)) {
2438 env
->CP0_Config5
|= (1 << CP0C5_FRE
);
2439 compute_hflags(env
);
2441 helper_raise_exception(env
, EXCP_RI
);
2445 if ((env
->insn_flags
& ISA_MIPS32R6
) || (arg1
& 0xffffff00)) {
2448 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((arg1
& 0xfe) << 24) |
2449 ((arg1
& 0x1) << 23);
2452 if (arg1
& 0x007c0000)
2454 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (arg1
& 0x0003f07c);
2457 if (arg1
& 0x007c0000)
2459 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (arg1
& 0x00000f83) |
2460 ((arg1
& 0x4) << 22);
2463 if (env
->insn_flags
& ISA_MIPS32R6
) {
2464 uint32_t mask
= 0xfefc0000;
2465 env
->active_fpu
.fcr31
= (arg1
& ~mask
) |
2466 (env
->active_fpu
.fcr31
& mask
);
2467 } else if (!(arg1
& 0x007c0000)) {
2468 env
->active_fpu
.fcr31
= arg1
;
2474 /* set rounding mode */
2475 restore_rounding_mode(env
);
2476 /* set flush-to-zero mode */
2477 restore_flush_mode(env
);
2478 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2479 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
))
2480 do_raise_exception(env
, EXCP_FPE
, GETPC());
2483 int ieee_ex_to_mips(int xcpt
)
2487 if (xcpt
& float_flag_invalid
) {
2490 if (xcpt
& float_flag_overflow
) {
2493 if (xcpt
& float_flag_underflow
) {
2494 ret
|= FP_UNDERFLOW
;
2496 if (xcpt
& float_flag_divbyzero
) {
2499 if (xcpt
& float_flag_inexact
) {
2506 static inline void update_fcr31(CPUMIPSState
*env
, uintptr_t pc
)
2508 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2510 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2513 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2515 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
) {
2516 do_raise_exception(env
, EXCP_FPE
, pc
);
2518 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2524 Single precition routines have a "s" suffix, double precision a
2525 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2526 paired single lower "pl", paired single upper "pu". */
2528 /* unary operations, modifying fp status */
2529 uint64_t helper_float_sqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2531 fdt0
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2532 update_fcr31(env
, GETPC());
2536 uint32_t helper_float_sqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2538 fst0
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2539 update_fcr31(env
, GETPC());
2543 uint64_t helper_float_cvtd_s(CPUMIPSState
*env
, uint32_t fst0
)
2547 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2548 fdt2
= float64_maybe_silence_nan(fdt2
);
2549 update_fcr31(env
, GETPC());
2553 uint64_t helper_float_cvtd_w(CPUMIPSState
*env
, uint32_t wt0
)
2557 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2558 update_fcr31(env
, GETPC());
2562 uint64_t helper_float_cvtd_l(CPUMIPSState
*env
, uint64_t dt0
)
2566 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2567 update_fcr31(env
, GETPC());
2571 uint64_t helper_float_cvtl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2575 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2576 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2577 & (float_flag_invalid
| float_flag_overflow
)) {
2578 dt2
= FP_TO_INT64_OVERFLOW
;
2580 update_fcr31(env
, GETPC());
2584 uint64_t helper_float_cvtl_s(CPUMIPSState
*env
, uint32_t fst0
)
2588 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2589 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2590 & (float_flag_invalid
| float_flag_overflow
)) {
2591 dt2
= FP_TO_INT64_OVERFLOW
;
2593 update_fcr31(env
, GETPC());
2597 uint64_t helper_float_cvtps_pw(CPUMIPSState
*env
, uint64_t dt0
)
2602 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2603 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2604 update_fcr31(env
, GETPC());
2605 return ((uint64_t)fsth2
<< 32) | fst2
;
2608 uint64_t helper_float_cvtpw_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2614 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2615 excp
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2616 if (excp
& (float_flag_overflow
| float_flag_invalid
)) {
2617 wt2
= FP_TO_INT32_OVERFLOW
;
2620 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2621 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2622 excph
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2623 if (excph
& (float_flag_overflow
| float_flag_invalid
)) {
2624 wth2
= FP_TO_INT32_OVERFLOW
;
2627 set_float_exception_flags(excp
| excph
, &env
->active_fpu
.fp_status
);
2628 update_fcr31(env
, GETPC());
2630 return ((uint64_t)wth2
<< 32) | wt2
;
2633 uint32_t helper_float_cvts_d(CPUMIPSState
*env
, uint64_t fdt0
)
2637 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2638 fst2
= float32_maybe_silence_nan(fst2
);
2639 update_fcr31(env
, GETPC());
2643 uint32_t helper_float_cvts_w(CPUMIPSState
*env
, uint32_t wt0
)
2647 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2648 update_fcr31(env
, GETPC());
2652 uint32_t helper_float_cvts_l(CPUMIPSState
*env
, uint64_t dt0
)
2656 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2657 update_fcr31(env
, GETPC());
2661 uint32_t helper_float_cvts_pl(CPUMIPSState
*env
, uint32_t wt0
)
2666 update_fcr31(env
, GETPC());
2670 uint32_t helper_float_cvts_pu(CPUMIPSState
*env
, uint32_t wth0
)
2675 update_fcr31(env
, GETPC());
2679 uint32_t helper_float_cvtw_s(CPUMIPSState
*env
, uint32_t fst0
)
2683 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2684 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2685 & (float_flag_invalid
| float_flag_overflow
)) {
2686 wt2
= FP_TO_INT32_OVERFLOW
;
2688 update_fcr31(env
, GETPC());
2692 uint32_t helper_float_cvtw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2696 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2697 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2698 & (float_flag_invalid
| float_flag_overflow
)) {
2699 wt2
= FP_TO_INT32_OVERFLOW
;
2701 update_fcr31(env
, GETPC());
2705 uint64_t helper_float_roundl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2709 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2710 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2711 restore_rounding_mode(env
);
2712 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2713 & (float_flag_invalid
| float_flag_overflow
)) {
2714 dt2
= FP_TO_INT64_OVERFLOW
;
2716 update_fcr31(env
, GETPC());
2720 uint64_t helper_float_roundl_s(CPUMIPSState
*env
, uint32_t fst0
)
2724 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2725 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2726 restore_rounding_mode(env
);
2727 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2728 & (float_flag_invalid
| float_flag_overflow
)) {
2729 dt2
= FP_TO_INT64_OVERFLOW
;
2731 update_fcr31(env
, GETPC());
2735 uint32_t helper_float_roundw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2739 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2740 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2741 restore_rounding_mode(env
);
2742 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2743 & (float_flag_invalid
| float_flag_overflow
)) {
2744 wt2
= FP_TO_INT32_OVERFLOW
;
2746 update_fcr31(env
, GETPC());
2750 uint32_t helper_float_roundw_s(CPUMIPSState
*env
, uint32_t fst0
)
2754 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2755 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2756 restore_rounding_mode(env
);
2757 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2758 & (float_flag_invalid
| float_flag_overflow
)) {
2759 wt2
= FP_TO_INT32_OVERFLOW
;
2761 update_fcr31(env
, GETPC());
2765 uint64_t helper_float_truncl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2769 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2770 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2771 & (float_flag_invalid
| float_flag_overflow
)) {
2772 dt2
= FP_TO_INT64_OVERFLOW
;
2774 update_fcr31(env
, GETPC());
2778 uint64_t helper_float_truncl_s(CPUMIPSState
*env
, uint32_t fst0
)
2782 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2783 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2784 & (float_flag_invalid
| float_flag_overflow
)) {
2785 dt2
= FP_TO_INT64_OVERFLOW
;
2787 update_fcr31(env
, GETPC());
2791 uint32_t helper_float_truncw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2795 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2796 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2797 & (float_flag_invalid
| float_flag_overflow
)) {
2798 wt2
= FP_TO_INT32_OVERFLOW
;
2800 update_fcr31(env
, GETPC());
2804 uint32_t helper_float_truncw_s(CPUMIPSState
*env
, uint32_t fst0
)
2808 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2809 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2810 & (float_flag_invalid
| float_flag_overflow
)) {
2811 wt2
= FP_TO_INT32_OVERFLOW
;
2813 update_fcr31(env
, GETPC());
2817 uint64_t helper_float_ceill_d(CPUMIPSState
*env
, uint64_t fdt0
)
2821 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2822 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2823 restore_rounding_mode(env
);
2824 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2825 & (float_flag_invalid
| float_flag_overflow
)) {
2826 dt2
= FP_TO_INT64_OVERFLOW
;
2828 update_fcr31(env
, GETPC());
2832 uint64_t helper_float_ceill_s(CPUMIPSState
*env
, uint32_t fst0
)
2836 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2837 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2838 restore_rounding_mode(env
);
2839 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2840 & (float_flag_invalid
| float_flag_overflow
)) {
2841 dt2
= FP_TO_INT64_OVERFLOW
;
2843 update_fcr31(env
, GETPC());
2847 uint32_t helper_float_ceilw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2851 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2852 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2853 restore_rounding_mode(env
);
2854 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2855 & (float_flag_invalid
| float_flag_overflow
)) {
2856 wt2
= FP_TO_INT32_OVERFLOW
;
2858 update_fcr31(env
, GETPC());
2862 uint32_t helper_float_ceilw_s(CPUMIPSState
*env
, uint32_t fst0
)
2866 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2867 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2868 restore_rounding_mode(env
);
2869 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2870 & (float_flag_invalid
| float_flag_overflow
)) {
2871 wt2
= FP_TO_INT32_OVERFLOW
;
2873 update_fcr31(env
, GETPC());
2877 uint64_t helper_float_floorl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2881 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2882 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2883 restore_rounding_mode(env
);
2884 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2885 & (float_flag_invalid
| float_flag_overflow
)) {
2886 dt2
= FP_TO_INT64_OVERFLOW
;
2888 update_fcr31(env
, GETPC());
2892 uint64_t helper_float_floorl_s(CPUMIPSState
*env
, uint32_t fst0
)
2896 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2897 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2898 restore_rounding_mode(env
);
2899 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2900 & (float_flag_invalid
| float_flag_overflow
)) {
2901 dt2
= FP_TO_INT64_OVERFLOW
;
2903 update_fcr31(env
, GETPC());
2907 uint32_t helper_float_floorw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2911 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2912 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2913 restore_rounding_mode(env
);
2914 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2915 & (float_flag_invalid
| float_flag_overflow
)) {
2916 wt2
= FP_TO_INT32_OVERFLOW
;
2918 update_fcr31(env
, GETPC());
2922 uint32_t helper_float_floorw_s(CPUMIPSState
*env
, uint32_t fst0
)
2926 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2927 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2928 restore_rounding_mode(env
);
2929 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2930 & (float_flag_invalid
| float_flag_overflow
)) {
2931 wt2
= FP_TO_INT32_OVERFLOW
;
2933 update_fcr31(env
, GETPC());
2937 /* unary operations, not modifying fp status */
2938 #define FLOAT_UNOP(name) \
2939 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
2941 return float64_ ## name(fdt0); \
2943 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
2945 return float32_ ## name(fst0); \
2947 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
2952 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2953 wth0 = float32_ ## name(fdt0 >> 32); \
2954 return ((uint64_t)wth0 << 32) | wt0; \
2960 /* MIPS specific unary operations */
2961 uint64_t helper_float_recip_d(CPUMIPSState
*env
, uint64_t fdt0
)
2965 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
2966 update_fcr31(env
, GETPC());
2970 uint32_t helper_float_recip_s(CPUMIPSState
*env
, uint32_t fst0
)
2974 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
2975 update_fcr31(env
, GETPC());
2979 uint64_t helper_float_rsqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2983 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2984 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
2985 update_fcr31(env
, GETPC());
2989 uint32_t helper_float_rsqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2993 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2994 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2995 update_fcr31(env
, GETPC());
2999 uint64_t helper_float_recip1_d(CPUMIPSState
*env
, uint64_t fdt0
)
3003 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
3004 update_fcr31(env
, GETPC());
3008 uint32_t helper_float_recip1_s(CPUMIPSState
*env
, uint32_t fst0
)
3012 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
3013 update_fcr31(env
, GETPC());
3017 uint64_t helper_float_recip1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
3022 fst2
= float32_div(float32_one
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
3023 fsth2
= float32_div(float32_one
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
3024 update_fcr31(env
, GETPC());
3025 return ((uint64_t)fsth2
<< 32) | fst2
;
3028 uint64_t helper_float_rsqrt1_d(CPUMIPSState
*env
, uint64_t fdt0
)
3032 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
3033 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
3034 update_fcr31(env
, GETPC());
3038 uint32_t helper_float_rsqrt1_s(CPUMIPSState
*env
, uint32_t fst0
)
3042 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
3043 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
3044 update_fcr31(env
, GETPC());
3048 uint64_t helper_float_rsqrt1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
3053 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
3054 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
3055 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
3056 fsth2
= float32_div(float32_one
, fsth2
, &env
->active_fpu
.fp_status
);
3057 update_fcr31(env
, GETPC());
3058 return ((uint64_t)fsth2
<< 32) | fst2
;
3061 #define FLOAT_RINT(name, bits) \
3062 uint ## bits ## _t helper_float_ ## name (CPUMIPSState *env, \
3063 uint ## bits ## _t fs) \
3065 uint ## bits ## _t fdret; \
3067 fdret = float ## bits ## _round_to_int(fs, &env->active_fpu.fp_status); \
3068 update_fcr31(env, GETPC()); \
3072 FLOAT_RINT(rint_s
, 32)
3073 FLOAT_RINT(rint_d
, 64)
3076 #define FLOAT_CLASS_SIGNALING_NAN 0x001
3077 #define FLOAT_CLASS_QUIET_NAN 0x002
3078 #define FLOAT_CLASS_NEGATIVE_INFINITY 0x004
3079 #define FLOAT_CLASS_NEGATIVE_NORMAL 0x008
3080 #define FLOAT_CLASS_NEGATIVE_SUBNORMAL 0x010
3081 #define FLOAT_CLASS_NEGATIVE_ZERO 0x020
3082 #define FLOAT_CLASS_POSITIVE_INFINITY 0x040
3083 #define FLOAT_CLASS_POSITIVE_NORMAL 0x080
3084 #define FLOAT_CLASS_POSITIVE_SUBNORMAL 0x100
3085 #define FLOAT_CLASS_POSITIVE_ZERO 0x200
3087 #define FLOAT_CLASS(name, bits) \
3088 uint ## bits ## _t helper_float_ ## name (uint ## bits ## _t arg) \
3090 if (float ## bits ## _is_signaling_nan(arg)) { \
3091 return FLOAT_CLASS_SIGNALING_NAN; \
3092 } else if (float ## bits ## _is_quiet_nan(arg)) { \
3093 return FLOAT_CLASS_QUIET_NAN; \
3094 } else if (float ## bits ## _is_neg(arg)) { \
3095 if (float ## bits ## _is_infinity(arg)) { \
3096 return FLOAT_CLASS_NEGATIVE_INFINITY; \
3097 } else if (float ## bits ## _is_zero(arg)) { \
3098 return FLOAT_CLASS_NEGATIVE_ZERO; \
3099 } else if (float ## bits ## _is_zero_or_denormal(arg)) { \
3100 return FLOAT_CLASS_NEGATIVE_SUBNORMAL; \
3102 return FLOAT_CLASS_NEGATIVE_NORMAL; \
3105 if (float ## bits ## _is_infinity(arg)) { \
3106 return FLOAT_CLASS_POSITIVE_INFINITY; \
3107 } else if (float ## bits ## _is_zero(arg)) { \
3108 return FLOAT_CLASS_POSITIVE_ZERO; \
3109 } else if (float ## bits ## _is_zero_or_denormal(arg)) { \
3110 return FLOAT_CLASS_POSITIVE_SUBNORMAL; \
3112 return FLOAT_CLASS_POSITIVE_NORMAL; \
3117 FLOAT_CLASS(class_s
, 32)
3118 FLOAT_CLASS(class_d
, 64)
3121 /* binary operations */
3122 #define FLOAT_BINOP(name) \
3123 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
3124 uint64_t fdt0, uint64_t fdt1) \
3128 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
3129 update_fcr31(env, GETPC()); \
3133 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
3134 uint32_t fst0, uint32_t fst1) \
3138 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
3139 update_fcr31(env, GETPC()); \
3143 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
3147 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3148 uint32_t fsth0 = fdt0 >> 32; \
3149 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3150 uint32_t fsth1 = fdt1 >> 32; \
3154 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
3155 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
3156 update_fcr31(env, GETPC()); \
3157 return ((uint64_t)wth2 << 32) | wt2; \
3166 /* MIPS specific binary operations */
3167 uint64_t helper_float_recip2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3169 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3170 fdt2
= float64_chs(float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
));
3171 update_fcr31(env
, GETPC());
3175 uint32_t helper_float_recip2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3177 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3178 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3179 update_fcr31(env
, GETPC());
3183 uint64_t helper_float_recip2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3185 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3186 uint32_t fsth0
= fdt0
>> 32;
3187 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3188 uint32_t fsth2
= fdt2
>> 32;
3190 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3191 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3192 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3193 fsth2
= float32_chs(float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
));
3194 update_fcr31(env
, GETPC());
3195 return ((uint64_t)fsth2
<< 32) | fst2
;
3198 uint64_t helper_float_rsqrt2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3200 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3201 fdt2
= float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
);
3202 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
3203 update_fcr31(env
, GETPC());
3207 uint32_t helper_float_rsqrt2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3209 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3210 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3211 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3212 update_fcr31(env
, GETPC());
3216 uint64_t helper_float_rsqrt2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3218 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3219 uint32_t fsth0
= fdt0
>> 32;
3220 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3221 uint32_t fsth2
= fdt2
>> 32;
3223 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3224 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3225 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3226 fsth2
= float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
);
3227 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3228 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3229 update_fcr31(env
, GETPC());
3230 return ((uint64_t)fsth2
<< 32) | fst2
;
3233 uint64_t helper_float_addr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3235 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3236 uint32_t fsth0
= fdt0
>> 32;
3237 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3238 uint32_t fsth1
= fdt1
>> 32;
3242 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3243 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3244 update_fcr31(env
, GETPC());
3245 return ((uint64_t)fsth2
<< 32) | fst2
;
3248 uint64_t helper_float_mulr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3250 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3251 uint32_t fsth0
= fdt0
>> 32;
3252 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3253 uint32_t fsth1
= fdt1
>> 32;
3257 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3258 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3259 update_fcr31(env
, GETPC());
3260 return ((uint64_t)fsth2
<< 32) | fst2
;
3263 #define FLOAT_MINMAX(name, bits, minmaxfunc) \
3264 uint ## bits ## _t helper_float_ ## name (CPUMIPSState *env, \
3265 uint ## bits ## _t fs, \
3266 uint ## bits ## _t ft) \
3268 uint ## bits ## _t fdret; \
3270 fdret = float ## bits ## _ ## minmaxfunc(fs, ft, \
3271 &env->active_fpu.fp_status); \
3272 update_fcr31(env, GETPC()); \
3276 FLOAT_MINMAX(max_s
, 32, maxnum
)
3277 FLOAT_MINMAX(max_d
, 64, maxnum
)
3278 FLOAT_MINMAX(maxa_s
, 32, maxnummag
)
3279 FLOAT_MINMAX(maxa_d
, 64, maxnummag
)
3281 FLOAT_MINMAX(min_s
, 32, minnum
)
3282 FLOAT_MINMAX(min_d
, 64, minnum
)
3283 FLOAT_MINMAX(mina_s
, 32, minnummag
)
3284 FLOAT_MINMAX(mina_d
, 64, minnummag
)
3287 /* ternary operations */
3288 #define UNFUSED_FMA(prefix, a, b, c, flags) \
3290 a = prefix##_mul(a, b, &env->active_fpu.fp_status); \
3291 if ((flags) & float_muladd_negate_c) { \
3292 a = prefix##_sub(a, c, &env->active_fpu.fp_status); \
3294 a = prefix##_add(a, c, &env->active_fpu.fp_status); \
3296 if ((flags) & float_muladd_negate_result) { \
3297 a = prefix##_chs(a); \
3301 /* FMA based operations */
3302 #define FLOAT_FMA(name, type) \
3303 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
3304 uint64_t fdt0, uint64_t fdt1, \
3307 UNFUSED_FMA(float64, fdt0, fdt1, fdt2, type); \
3308 update_fcr31(env, GETPC()); \
3312 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
3313 uint32_t fst0, uint32_t fst1, \
3316 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
3317 update_fcr31(env, GETPC()); \
3321 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
3322 uint64_t fdt0, uint64_t fdt1, \
3325 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3326 uint32_t fsth0 = fdt0 >> 32; \
3327 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3328 uint32_t fsth1 = fdt1 >> 32; \
3329 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3330 uint32_t fsth2 = fdt2 >> 32; \
3332 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
3333 UNFUSED_FMA(float32, fsth0, fsth1, fsth2, type); \
3334 update_fcr31(env, GETPC()); \
3335 return ((uint64_t)fsth0 << 32) | fst0; \
3338 FLOAT_FMA(msub
, float_muladd_negate_c
)
3339 FLOAT_FMA(nmadd
, float_muladd_negate_result
)
3340 FLOAT_FMA(nmsub
, float_muladd_negate_result
| float_muladd_negate_c
)
3343 #define FLOAT_FMADDSUB(name, bits, muladd_arg) \
3344 uint ## bits ## _t helper_float_ ## name (CPUMIPSState *env, \
3345 uint ## bits ## _t fs, \
3346 uint ## bits ## _t ft, \
3347 uint ## bits ## _t fd) \
3349 uint ## bits ## _t fdret; \
3351 fdret = float ## bits ## _muladd(fs, ft, fd, muladd_arg, \
3352 &env->active_fpu.fp_status); \
3353 update_fcr31(env, GETPC()); \
3357 FLOAT_FMADDSUB(maddf_s
, 32, 0)
3358 FLOAT_FMADDSUB(maddf_d
, 64, 0)
3359 FLOAT_FMADDSUB(msubf_s
, 32, float_muladd_negate_product
)
3360 FLOAT_FMADDSUB(msubf_d
, 64, float_muladd_negate_product
)
3361 #undef FLOAT_FMADDSUB
3363 /* compare operations */
3364 #define FOP_COND_D(op, cond) \
3365 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3366 uint64_t fdt1, int cc) \
3370 update_fcr31(env, GETPC()); \
3372 SET_FP_COND(cc, env->active_fpu); \
3374 CLEAR_FP_COND(cc, env->active_fpu); \
3376 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3377 uint64_t fdt1, int cc) \
3380 fdt0 = float64_abs(fdt0); \
3381 fdt1 = float64_abs(fdt1); \
3383 update_fcr31(env, GETPC()); \
3385 SET_FP_COND(cc, env->active_fpu); \
3387 CLEAR_FP_COND(cc, env->active_fpu); \
3390 /* NOTE: the comma operator will make "cond" to eval to false,
3391 * but float64_unordered_quiet() is still called. */
3392 FOP_COND_D(f
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3393 FOP_COND_D(un
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3394 FOP_COND_D(eq
, float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3395 FOP_COND_D(ueq
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3396 FOP_COND_D(olt
, float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3397 FOP_COND_D(ult
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3398 FOP_COND_D(ole
, float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3399 FOP_COND_D(ule
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3400 /* NOTE: the comma operator will make "cond" to eval to false,
3401 * but float64_unordered() is still called. */
3402 FOP_COND_D(sf
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3403 FOP_COND_D(ngle
,float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3404 FOP_COND_D(seq
, float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3405 FOP_COND_D(ngl
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3406 FOP_COND_D(lt
, float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3407 FOP_COND_D(nge
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3408 FOP_COND_D(le
, float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3409 FOP_COND_D(ngt
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3411 #define FOP_COND_S(op, cond) \
3412 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3413 uint32_t fst1, int cc) \
3417 update_fcr31(env, GETPC()); \
3419 SET_FP_COND(cc, env->active_fpu); \
3421 CLEAR_FP_COND(cc, env->active_fpu); \
3423 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3424 uint32_t fst1, int cc) \
3427 fst0 = float32_abs(fst0); \
3428 fst1 = float32_abs(fst1); \
3430 update_fcr31(env, GETPC()); \
3432 SET_FP_COND(cc, env->active_fpu); \
3434 CLEAR_FP_COND(cc, env->active_fpu); \
3437 /* NOTE: the comma operator will make "cond" to eval to false,
3438 * but float32_unordered_quiet() is still called. */
3439 FOP_COND_S(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3440 FOP_COND_S(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3441 FOP_COND_S(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3442 FOP_COND_S(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3443 FOP_COND_S(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3444 FOP_COND_S(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3445 FOP_COND_S(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3446 FOP_COND_S(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3447 /* NOTE: the comma operator will make "cond" to eval to false,
3448 * but float32_unordered() is still called. */
3449 FOP_COND_S(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3450 FOP_COND_S(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3451 FOP_COND_S(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3452 FOP_COND_S(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3453 FOP_COND_S(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3454 FOP_COND_S(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3455 FOP_COND_S(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3456 FOP_COND_S(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3458 #define FOP_COND_PS(op, condl, condh) \
3459 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3460 uint64_t fdt1, int cc) \
3462 uint32_t fst0, fsth0, fst1, fsth1; \
3464 fst0 = fdt0 & 0XFFFFFFFF; \
3465 fsth0 = fdt0 >> 32; \
3466 fst1 = fdt1 & 0XFFFFFFFF; \
3467 fsth1 = fdt1 >> 32; \
3470 update_fcr31(env, GETPC()); \
3472 SET_FP_COND(cc, env->active_fpu); \
3474 CLEAR_FP_COND(cc, env->active_fpu); \
3476 SET_FP_COND(cc + 1, env->active_fpu); \
3478 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3480 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3481 uint64_t fdt1, int cc) \
3483 uint32_t fst0, fsth0, fst1, fsth1; \
3485 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
3486 fsth0 = float32_abs(fdt0 >> 32); \
3487 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
3488 fsth1 = float32_abs(fdt1 >> 32); \
3491 update_fcr31(env, GETPC()); \
3493 SET_FP_COND(cc, env->active_fpu); \
3495 CLEAR_FP_COND(cc, env->active_fpu); \
3497 SET_FP_COND(cc + 1, env->active_fpu); \
3499 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3502 /* NOTE: the comma operator will make "cond" to eval to false,
3503 * but float32_unordered_quiet() is still called. */
3504 FOP_COND_PS(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3505 (float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3506 FOP_COND_PS(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3507 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3508 FOP_COND_PS(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3509 float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3510 FOP_COND_PS(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3511 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3512 FOP_COND_PS(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3513 float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3514 FOP_COND_PS(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3515 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3516 FOP_COND_PS(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3517 float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3518 FOP_COND_PS(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3519 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3520 /* NOTE: the comma operator will make "cond" to eval to false,
3521 * but float32_unordered() is still called. */
3522 FOP_COND_PS(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3523 (float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3524 FOP_COND_PS(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3525 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3526 FOP_COND_PS(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3527 float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3528 FOP_COND_PS(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3529 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3530 FOP_COND_PS(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3531 float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3532 FOP_COND_PS(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3533 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3534 FOP_COND_PS(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3535 float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3536 FOP_COND_PS(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3537 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3539 /* R6 compare operations */
3540 #define FOP_CONDN_D(op, cond) \
3541 uint64_t helper_r6_cmp_d_ ## op(CPUMIPSState * env, uint64_t fdt0, \
3546 update_fcr31(env, GETPC()); \
3554 /* NOTE: the comma operator will make "cond" to eval to false,
3555 * but float64_unordered_quiet() is still called. */
3556 FOP_CONDN_D(af
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3557 FOP_CONDN_D(un
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)))
3558 FOP_CONDN_D(eq
, (float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3559 FOP_CONDN_D(ueq
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3560 || float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3561 FOP_CONDN_D(lt
, (float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3562 FOP_CONDN_D(ult
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3563 || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3564 FOP_CONDN_D(le
, (float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3565 FOP_CONDN_D(ule
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3566 || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3567 /* NOTE: the comma operator will make "cond" to eval to false,
3568 * but float64_unordered() is still called. */
3569 FOP_CONDN_D(saf
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3570 FOP_CONDN_D(sun
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)))
3571 FOP_CONDN_D(seq
, (float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3572 FOP_CONDN_D(sueq
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3573 || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3574 FOP_CONDN_D(slt
, (float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3575 FOP_CONDN_D(sult
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3576 || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3577 FOP_CONDN_D(sle
, (float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3578 FOP_CONDN_D(sule
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3579 || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3580 FOP_CONDN_D(or, (float64_le_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3581 || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3582 FOP_CONDN_D(une
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3583 || float64_lt_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3584 || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3585 FOP_CONDN_D(ne
, (float64_lt_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3586 || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3587 FOP_CONDN_D(sor
, (float64_le(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3588 || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3589 FOP_CONDN_D(sune
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3590 || float64_lt(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3591 || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3592 FOP_CONDN_D(sne
, (float64_lt(fdt1
, fdt0
, &env
->active_fpu
.fp_status
)
3593 || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
)))
3595 #define FOP_CONDN_S(op, cond) \
3596 uint32_t helper_r6_cmp_s_ ## op(CPUMIPSState * env, uint32_t fst0, \
3601 update_fcr31(env, GETPC()); \
3609 /* NOTE: the comma operator will make "cond" to eval to false,
3610 * but float32_unordered_quiet() is still called. */
3611 FOP_CONDN_S(af
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3612 FOP_CONDN_S(un
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)))
3613 FOP_CONDN_S(eq
, (float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3614 FOP_CONDN_S(ueq
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3615 || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3616 FOP_CONDN_S(lt
, (float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3617 FOP_CONDN_S(ult
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3618 || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3619 FOP_CONDN_S(le
, (float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3620 FOP_CONDN_S(ule
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3621 || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3622 /* NOTE: the comma operator will make "cond" to eval to false,
3623 * but float32_unordered() is still called. */
3624 FOP_CONDN_S(saf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3625 FOP_CONDN_S(sun
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
)))
3626 FOP_CONDN_S(seq
, (float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3627 FOP_CONDN_S(sueq
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3628 || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3629 FOP_CONDN_S(slt
, (float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3630 FOP_CONDN_S(sult
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3631 || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3632 FOP_CONDN_S(sle
, (float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3633 FOP_CONDN_S(sule
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3634 || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3635 FOP_CONDN_S(or, (float32_le_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3636 || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3637 FOP_CONDN_S(une
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3638 || float32_lt_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3639 || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3640 FOP_CONDN_S(ne
, (float32_lt_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3641 || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3642 FOP_CONDN_S(sor
, (float32_le(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3643 || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3644 FOP_CONDN_S(sune
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3645 || float32_lt(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3646 || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3647 FOP_CONDN_S(sne
, (float32_lt(fst1
, fst0
, &env
->active_fpu
.fp_status
)
3648 || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
)))
3651 /* Data format min and max values */
3652 #define DF_BITS(df) (1 << ((df) + 3))
3654 /* Element-by-element access macros */
3655 #define DF_ELEMENTS(df) (MSA_WRLEN / DF_BITS(df))
3657 #if !defined(CONFIG_USER_ONLY)
3658 #define MEMOP_IDX(DF) \
3659 TCGMemOpIdx oi = make_memop_idx(MO_TE | DF | MO_UNALN, \
3660 cpu_mmu_index(env, false));
3662 #define MEMOP_IDX(DF)
3665 #define MSA_LD_DF(DF, TYPE, LD_INSN, ...) \
3666 void helper_msa_ld_ ## TYPE(CPUMIPSState *env, uint32_t wd, \
3667 target_ulong addr) \
3669 wr_t *pwd = &(env->active_fpu.fpr[wd].wr); \
3673 for (i = 0; i < DF_ELEMENTS(DF); i++) { \
3674 wx.TYPE[i] = LD_INSN(env, addr + (i << DF), ##__VA_ARGS__); \
3676 memcpy(pwd, &wx, sizeof(wr_t)); \
3679 #if !defined(CONFIG_USER_ONLY)
3680 MSA_LD_DF(DF_BYTE
, b
, helper_ret_ldub_mmu
, oi
, GETRA())
3681 MSA_LD_DF(DF_HALF
, h
, helper_ret_lduw_mmu
, oi
, GETRA())
3682 MSA_LD_DF(DF_WORD
, w
, helper_ret_ldul_mmu
, oi
, GETRA())
3683 MSA_LD_DF(DF_DOUBLE
, d
, helper_ret_ldq_mmu
, oi
, GETRA())
3685 MSA_LD_DF(DF_BYTE
, b
, cpu_ldub_data
)
3686 MSA_LD_DF(DF_HALF
, h
, cpu_lduw_data
)
3687 MSA_LD_DF(DF_WORD
, w
, cpu_ldl_data
)
3688 MSA_LD_DF(DF_DOUBLE
, d
, cpu_ldq_data
)
3691 #define MSA_PAGESPAN(x) \
3692 ((((x) & ~TARGET_PAGE_MASK) + MSA_WRLEN/8 - 1) >= TARGET_PAGE_SIZE)
3694 static inline void ensure_writable_pages(CPUMIPSState
*env
,
3699 #if !defined(CONFIG_USER_ONLY)
3700 target_ulong page_addr
;
3701 if (unlikely(MSA_PAGESPAN(addr
))) {
3703 probe_write(env
, addr
, mmu_idx
, retaddr
);
3705 page_addr
= (addr
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3706 probe_write(env
, page_addr
, mmu_idx
, retaddr
);
3711 #define MSA_ST_DF(DF, TYPE, ST_INSN, ...) \
3712 void helper_msa_st_ ## TYPE(CPUMIPSState *env, uint32_t wd, \
3713 target_ulong addr) \
3715 wr_t *pwd = &(env->active_fpu.fpr[wd].wr); \
3716 int mmu_idx = cpu_mmu_index(env, false); \
3719 ensure_writable_pages(env, addr, mmu_idx, GETRA()); \
3720 for (i = 0; i < DF_ELEMENTS(DF); i++) { \
3721 ST_INSN(env, addr + (i << DF), pwd->TYPE[i], ##__VA_ARGS__); \
3725 #if !defined(CONFIG_USER_ONLY)
3726 MSA_ST_DF(DF_BYTE
, b
, helper_ret_stb_mmu
, oi
, GETRA())
3727 MSA_ST_DF(DF_HALF
, h
, helper_ret_stw_mmu
, oi
, GETRA())
3728 MSA_ST_DF(DF_WORD
, w
, helper_ret_stl_mmu
, oi
, GETRA())
3729 MSA_ST_DF(DF_DOUBLE
, d
, helper_ret_stq_mmu
, oi
, GETRA())
3731 MSA_ST_DF(DF_BYTE
, b
, cpu_stb_data
)
3732 MSA_ST_DF(DF_HALF
, h
, cpu_stw_data
)
3733 MSA_ST_DF(DF_WORD
, w
, cpu_stl_data
)
3734 MSA_ST_DF(DF_DOUBLE
, d
, cpu_stq_data
)