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/>.
21 #include "qemu/host-utils.h"
22 #include "exec/helper-proto.h"
23 #include "exec/cpu_ldst.h"
25 #ifndef CONFIG_USER_ONLY
26 static inline void cpu_mips_tlb_flush (CPUMIPSState
*env
, int flush_global
);
29 /*****************************************************************************/
30 /* Exceptions processing helpers */
32 static inline void QEMU_NORETURN
do_raise_exception_err(CPUMIPSState
*env
,
37 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
39 if (exception
< EXCP_SC
) {
40 qemu_log("%s: %d %d\n", __func__
, exception
, error_code
);
42 cs
->exception_index
= exception
;
43 env
->error_code
= error_code
;
46 /* now we have a real cpu fault */
47 cpu_restore_state(cs
, pc
);
53 static inline void QEMU_NORETURN
do_raise_exception(CPUMIPSState
*env
,
57 do_raise_exception_err(env
, exception
, 0, pc
);
60 void helper_raise_exception_err(CPUMIPSState
*env
, uint32_t exception
,
63 do_raise_exception_err(env
, exception
, error_code
, 0);
66 void helper_raise_exception(CPUMIPSState
*env
, uint32_t exception
)
68 do_raise_exception(env
, exception
, 0);
71 #if defined(CONFIG_USER_ONLY)
72 #define HELPER_LD(name, insn, type) \
73 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
76 return (type) insn##_raw(addr); \
79 #define HELPER_LD(name, insn, type) \
80 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
85 case 0: return (type) cpu_##insn##_kernel(env, addr); break; \
86 case 1: return (type) cpu_##insn##_super(env, addr); break; \
88 case 2: return (type) cpu_##insn##_user(env, addr); break; \
92 HELPER_LD(lbu
, ldub
, uint8_t)
93 HELPER_LD(lw
, ldl
, int32_t)
95 HELPER_LD(ld
, ldq
, int64_t)
99 #if defined(CONFIG_USER_ONLY)
100 #define HELPER_ST(name, insn, type) \
101 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
102 type val, int mem_idx) \
104 insn##_raw(addr, val); \
107 #define HELPER_ST(name, insn, type) \
108 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
109 type val, int mem_idx) \
113 case 0: cpu_##insn##_kernel(env, addr, val); break; \
114 case 1: cpu_##insn##_super(env, addr, val); break; \
116 case 2: cpu_##insn##_user(env, addr, val); break; \
120 HELPER_ST(sb
, stb
, uint8_t)
121 HELPER_ST(sw
, stl
, uint32_t)
123 HELPER_ST(sd
, stq
, uint64_t)
127 target_ulong
helper_clo (target_ulong arg1
)
132 target_ulong
helper_clz (target_ulong arg1
)
137 #if defined(TARGET_MIPS64)
138 target_ulong
helper_dclo (target_ulong arg1
)
143 target_ulong
helper_dclz (target_ulong arg1
)
147 #endif /* TARGET_MIPS64 */
149 /* 64 bits arithmetic for 32 bits hosts */
150 static inline uint64_t get_HILO(CPUMIPSState
*env
)
152 return ((uint64_t)(env
->active_tc
.HI
[0]) << 32) | (uint32_t)env
->active_tc
.LO
[0];
155 static inline target_ulong
set_HIT0_LO(CPUMIPSState
*env
, uint64_t HILO
)
158 env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
159 tmp
= env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
163 static inline target_ulong
set_HI_LOT0(CPUMIPSState
*env
, uint64_t HILO
)
165 target_ulong tmp
= env
->active_tc
.LO
[0] = (int32_t)(HILO
& 0xFFFFFFFF);
166 env
->active_tc
.HI
[0] = (int32_t)(HILO
>> 32);
170 /* Multiplication variants of the vr54xx. */
171 target_ulong
helper_muls(CPUMIPSState
*env
, target_ulong arg1
,
174 return set_HI_LOT0(env
, 0 - ((int64_t)(int32_t)arg1
*
175 (int64_t)(int32_t)arg2
));
178 target_ulong
helper_mulsu(CPUMIPSState
*env
, target_ulong arg1
,
181 return set_HI_LOT0(env
, 0 - (uint64_t)(uint32_t)arg1
*
182 (uint64_t)(uint32_t)arg2
);
185 target_ulong
helper_macc(CPUMIPSState
*env
, target_ulong arg1
,
188 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
189 (int64_t)(int32_t)arg2
);
192 target_ulong
helper_macchi(CPUMIPSState
*env
, target_ulong arg1
,
195 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) + (int64_t)(int32_t)arg1
*
196 (int64_t)(int32_t)arg2
);
199 target_ulong
helper_maccu(CPUMIPSState
*env
, target_ulong arg1
,
202 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) +
203 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
206 target_ulong
helper_macchiu(CPUMIPSState
*env
, target_ulong arg1
,
209 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) +
210 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
213 target_ulong
helper_msac(CPUMIPSState
*env
, target_ulong arg1
,
216 return set_HI_LOT0(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
217 (int64_t)(int32_t)arg2
);
220 target_ulong
helper_msachi(CPUMIPSState
*env
, target_ulong arg1
,
223 return set_HIT0_LO(env
, (int64_t)get_HILO(env
) - (int64_t)(int32_t)arg1
*
224 (int64_t)(int32_t)arg2
);
227 target_ulong
helper_msacu(CPUMIPSState
*env
, target_ulong arg1
,
230 return set_HI_LOT0(env
, (uint64_t)get_HILO(env
) -
231 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
234 target_ulong
helper_msachiu(CPUMIPSState
*env
, target_ulong arg1
,
237 return set_HIT0_LO(env
, (uint64_t)get_HILO(env
) -
238 (uint64_t)(uint32_t)arg1
* (uint64_t)(uint32_t)arg2
);
241 target_ulong
helper_mulhi(CPUMIPSState
*env
, target_ulong arg1
,
244 return set_HIT0_LO(env
, (int64_t)(int32_t)arg1
* (int64_t)(int32_t)arg2
);
247 target_ulong
helper_mulhiu(CPUMIPSState
*env
, target_ulong arg1
,
250 return set_HIT0_LO(env
, (uint64_t)(uint32_t)arg1
*
251 (uint64_t)(uint32_t)arg2
);
254 target_ulong
helper_mulshi(CPUMIPSState
*env
, target_ulong arg1
,
257 return set_HIT0_LO(env
, 0 - (int64_t)(int32_t)arg1
*
258 (int64_t)(int32_t)arg2
);
261 target_ulong
helper_mulshiu(CPUMIPSState
*env
, target_ulong arg1
,
264 return set_HIT0_LO(env
, 0 - (uint64_t)(uint32_t)arg1
*
265 (uint64_t)(uint32_t)arg2
);
268 #ifndef CONFIG_USER_ONLY
270 static inline hwaddr
do_translate_address(CPUMIPSState
*env
,
271 target_ulong address
,
276 lladdr
= cpu_mips_translate_address(env
, address
, rw
);
278 if (lladdr
== -1LL) {
279 cpu_loop_exit(CPU(mips_env_get_cpu(env
)));
285 #define HELPER_LD_ATOMIC(name, insn) \
286 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
288 env->lladdr = do_translate_address(env, arg, 0); \
289 env->llval = do_##insn(env, arg, mem_idx); \
292 HELPER_LD_ATOMIC(ll
, lw
)
294 HELPER_LD_ATOMIC(lld
, ld
)
296 #undef HELPER_LD_ATOMIC
298 #define HELPER_ST_ATOMIC(name, ld_insn, st_insn, almask) \
299 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \
300 target_ulong arg2, int mem_idx) \
304 if (arg2 & almask) { \
305 env->CP0_BadVAddr = arg2; \
306 helper_raise_exception(env, EXCP_AdES); \
308 if (do_translate_address(env, arg2, 1) == env->lladdr) { \
309 tmp = do_##ld_insn(env, arg2, mem_idx); \
310 if (tmp == env->llval) { \
311 do_##st_insn(env, arg2, arg1, mem_idx); \
317 HELPER_ST_ATOMIC(sc
, lw
, sw
, 0x3)
319 HELPER_ST_ATOMIC(scd
, ld
, sd
, 0x7)
321 #undef HELPER_ST_ATOMIC
324 #ifdef TARGET_WORDS_BIGENDIAN
325 #define GET_LMASK(v) ((v) & 3)
326 #define GET_OFFSET(addr, offset) (addr + (offset))
328 #define GET_LMASK(v) (((v) & 3) ^ 3)
329 #define GET_OFFSET(addr, offset) (addr - (offset))
332 void helper_swl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
335 do_sb(env
, arg2
, (uint8_t)(arg1
>> 24), mem_idx
);
337 if (GET_LMASK(arg2
) <= 2)
338 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 16), mem_idx
);
340 if (GET_LMASK(arg2
) <= 1)
341 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 8), mem_idx
);
343 if (GET_LMASK(arg2
) == 0)
344 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)arg1
, mem_idx
);
347 void helper_swr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
350 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
352 if (GET_LMASK(arg2
) >= 1)
353 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
355 if (GET_LMASK(arg2
) >= 2)
356 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
358 if (GET_LMASK(arg2
) == 3)
359 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
362 #if defined(TARGET_MIPS64)
363 /* "half" load and stores. We must do the memory access inline,
364 or fault handling won't work. */
366 #ifdef TARGET_WORDS_BIGENDIAN
367 #define GET_LMASK64(v) ((v) & 7)
369 #define GET_LMASK64(v) (((v) & 7) ^ 7)
372 void helper_sdl(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
375 do_sb(env
, arg2
, (uint8_t)(arg1
>> 56), mem_idx
);
377 if (GET_LMASK64(arg2
) <= 6)
378 do_sb(env
, GET_OFFSET(arg2
, 1), (uint8_t)(arg1
>> 48), mem_idx
);
380 if (GET_LMASK64(arg2
) <= 5)
381 do_sb(env
, GET_OFFSET(arg2
, 2), (uint8_t)(arg1
>> 40), mem_idx
);
383 if (GET_LMASK64(arg2
) <= 4)
384 do_sb(env
, GET_OFFSET(arg2
, 3), (uint8_t)(arg1
>> 32), mem_idx
);
386 if (GET_LMASK64(arg2
) <= 3)
387 do_sb(env
, GET_OFFSET(arg2
, 4), (uint8_t)(arg1
>> 24), mem_idx
);
389 if (GET_LMASK64(arg2
) <= 2)
390 do_sb(env
, GET_OFFSET(arg2
, 5), (uint8_t)(arg1
>> 16), mem_idx
);
392 if (GET_LMASK64(arg2
) <= 1)
393 do_sb(env
, GET_OFFSET(arg2
, 6), (uint8_t)(arg1
>> 8), mem_idx
);
395 if (GET_LMASK64(arg2
) <= 0)
396 do_sb(env
, GET_OFFSET(arg2
, 7), (uint8_t)arg1
, mem_idx
);
399 void helper_sdr(CPUMIPSState
*env
, target_ulong arg1
, target_ulong arg2
,
402 do_sb(env
, arg2
, (uint8_t)arg1
, mem_idx
);
404 if (GET_LMASK64(arg2
) >= 1)
405 do_sb(env
, GET_OFFSET(arg2
, -1), (uint8_t)(arg1
>> 8), mem_idx
);
407 if (GET_LMASK64(arg2
) >= 2)
408 do_sb(env
, GET_OFFSET(arg2
, -2), (uint8_t)(arg1
>> 16), mem_idx
);
410 if (GET_LMASK64(arg2
) >= 3)
411 do_sb(env
, GET_OFFSET(arg2
, -3), (uint8_t)(arg1
>> 24), mem_idx
);
413 if (GET_LMASK64(arg2
) >= 4)
414 do_sb(env
, GET_OFFSET(arg2
, -4), (uint8_t)(arg1
>> 32), mem_idx
);
416 if (GET_LMASK64(arg2
) >= 5)
417 do_sb(env
, GET_OFFSET(arg2
, -5), (uint8_t)(arg1
>> 40), mem_idx
);
419 if (GET_LMASK64(arg2
) >= 6)
420 do_sb(env
, GET_OFFSET(arg2
, -6), (uint8_t)(arg1
>> 48), mem_idx
);
422 if (GET_LMASK64(arg2
) == 7)
423 do_sb(env
, GET_OFFSET(arg2
, -7), (uint8_t)(arg1
>> 56), mem_idx
);
425 #endif /* TARGET_MIPS64 */
427 static const int multiple_regs
[] = { 16, 17, 18, 19, 20, 21, 22, 23, 30 };
429 void helper_lwm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
432 target_ulong base_reglist
= reglist
& 0xf;
433 target_ulong do_r31
= reglist
& 0x10;
435 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
438 for (i
= 0; i
< base_reglist
; i
++) {
439 env
->active_tc
.gpr
[multiple_regs
[i
]] =
440 (target_long
)do_lw(env
, addr
, mem_idx
);
446 env
->active_tc
.gpr
[31] = (target_long
)do_lw(env
, addr
, mem_idx
);
450 void helper_swm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
453 target_ulong base_reglist
= reglist
& 0xf;
454 target_ulong do_r31
= reglist
& 0x10;
456 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
459 for (i
= 0; i
< base_reglist
; i
++) {
460 do_sw(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
);
466 do_sw(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
);
470 #if defined(TARGET_MIPS64)
471 void helper_ldm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
474 target_ulong base_reglist
= reglist
& 0xf;
475 target_ulong do_r31
= reglist
& 0x10;
477 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
480 for (i
= 0; i
< base_reglist
; i
++) {
481 env
->active_tc
.gpr
[multiple_regs
[i
]] = do_ld(env
, addr
, mem_idx
);
487 env
->active_tc
.gpr
[31] = do_ld(env
, addr
, mem_idx
);
491 void helper_sdm(CPUMIPSState
*env
, target_ulong addr
, target_ulong reglist
,
494 target_ulong base_reglist
= reglist
& 0xf;
495 target_ulong do_r31
= reglist
& 0x10;
497 if (base_reglist
> 0 && base_reglist
<= ARRAY_SIZE (multiple_regs
)) {
500 for (i
= 0; i
< base_reglist
; i
++) {
501 do_sd(env
, addr
, env
->active_tc
.gpr
[multiple_regs
[i
]], mem_idx
);
507 do_sd(env
, addr
, env
->active_tc
.gpr
[31], mem_idx
);
512 #ifndef CONFIG_USER_ONLY
514 static bool mips_vpe_is_wfi(MIPSCPU
*c
)
516 CPUState
*cpu
= CPU(c
);
517 CPUMIPSState
*env
= &c
->env
;
519 /* If the VPE is halted but otherwise active, it means it's waiting for
521 return cpu
->halted
&& mips_vpe_active(env
);
524 static inline void mips_vpe_wake(MIPSCPU
*c
)
526 /* Dont set ->halted = 0 directly, let it be done via cpu_has_work
527 because there might be other conditions that state that c should
529 cpu_interrupt(CPU(c
), CPU_INTERRUPT_WAKE
);
532 static inline void mips_vpe_sleep(MIPSCPU
*cpu
)
534 CPUState
*cs
= CPU(cpu
);
536 /* The VPE was shut off, really go to bed.
537 Reset any old _WAKE requests. */
539 cpu_reset_interrupt(cs
, CPU_INTERRUPT_WAKE
);
542 static inline void mips_tc_wake(MIPSCPU
*cpu
, int tc
)
544 CPUMIPSState
*c
= &cpu
->env
;
546 /* FIXME: TC reschedule. */
547 if (mips_vpe_active(c
) && !mips_vpe_is_wfi(cpu
)) {
552 static inline void mips_tc_sleep(MIPSCPU
*cpu
, int tc
)
554 CPUMIPSState
*c
= &cpu
->env
;
556 /* FIXME: TC reschedule. */
557 if (!mips_vpe_active(c
)) {
564 * @env: CPU from which mapping is performed.
565 * @tc: Should point to an int with the value of the global TC index.
567 * This function will transform @tc into a local index within the
568 * returned #CPUMIPSState.
570 /* FIXME: This code assumes that all VPEs have the same number of TCs,
571 which depends on runtime setup. Can probably be fixed by
572 walking the list of CPUMIPSStates. */
573 static CPUMIPSState
*mips_cpu_map_tc(CPUMIPSState
*env
, int *tc
)
581 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))) {
582 /* Not allowed to address other CPUs. */
583 *tc
= env
->current_tc
;
587 cs
= CPU(mips_env_get_cpu(env
));
588 vpe_idx
= tc_idx
/ cs
->nr_threads
;
589 *tc
= tc_idx
% cs
->nr_threads
;
590 other_cs
= qemu_get_cpu(vpe_idx
);
591 if (other_cs
== NULL
) {
594 cpu
= MIPS_CPU(other_cs
);
598 /* The per VPE CP0_Status register shares some fields with the per TC
599 CP0_TCStatus registers. These fields are wired to the same registers,
600 so changes to either of them should be reflected on both registers.
602 Also, EntryHi shares the bottom 8 bit ASID with TCStauts.
604 These helper call synchronizes the regs for a given cpu. */
606 /* Called for updates to CP0_Status. */
607 static void sync_c0_status(CPUMIPSState
*env
, CPUMIPSState
*cpu
, int tc
)
609 int32_t tcstatus
, *tcst
;
610 uint32_t v
= cpu
->CP0_Status
;
611 uint32_t cu
, mx
, asid
, ksu
;
612 uint32_t mask
= ((1 << CP0TCSt_TCU3
)
613 | (1 << CP0TCSt_TCU2
)
614 | (1 << CP0TCSt_TCU1
)
615 | (1 << CP0TCSt_TCU0
)
617 | (3 << CP0TCSt_TKSU
)
618 | (0xff << CP0TCSt_TASID
));
620 cu
= (v
>> CP0St_CU0
) & 0xf;
621 mx
= (v
>> CP0St_MX
) & 0x1;
622 ksu
= (v
>> CP0St_KSU
) & 0x3;
623 asid
= env
->CP0_EntryHi
& 0xff;
625 tcstatus
= cu
<< CP0TCSt_TCU0
;
626 tcstatus
|= mx
<< CP0TCSt_TMX
;
627 tcstatus
|= ksu
<< CP0TCSt_TKSU
;
630 if (tc
== cpu
->current_tc
) {
631 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
633 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
641 /* Called for updates to CP0_TCStatus. */
642 static void sync_c0_tcstatus(CPUMIPSState
*cpu
, int tc
,
646 uint32_t tcu
, tmx
, tasid
, tksu
;
647 uint32_t mask
= ((1U << CP0St_CU3
)
654 tcu
= (v
>> CP0TCSt_TCU0
) & 0xf;
655 tmx
= (v
>> CP0TCSt_TMX
) & 0x1;
657 tksu
= (v
>> CP0TCSt_TKSU
) & 0x3;
659 status
= tcu
<< CP0St_CU0
;
660 status
|= tmx
<< CP0St_MX
;
661 status
|= tksu
<< CP0St_KSU
;
663 cpu
->CP0_Status
&= ~mask
;
664 cpu
->CP0_Status
|= status
;
666 /* Sync the TASID with EntryHi. */
667 cpu
->CP0_EntryHi
&= ~0xff;
668 cpu
->CP0_EntryHi
= tasid
;
673 /* Called for updates to CP0_EntryHi. */
674 static void sync_c0_entryhi(CPUMIPSState
*cpu
, int tc
)
677 uint32_t asid
, v
= cpu
->CP0_EntryHi
;
681 if (tc
== cpu
->current_tc
) {
682 tcst
= &cpu
->active_tc
.CP0_TCStatus
;
684 tcst
= &cpu
->tcs
[tc
].CP0_TCStatus
;
692 target_ulong
helper_mfc0_mvpcontrol(CPUMIPSState
*env
)
694 return env
->mvp
->CP0_MVPControl
;
697 target_ulong
helper_mfc0_mvpconf0(CPUMIPSState
*env
)
699 return env
->mvp
->CP0_MVPConf0
;
702 target_ulong
helper_mfc0_mvpconf1(CPUMIPSState
*env
)
704 return env
->mvp
->CP0_MVPConf1
;
707 target_ulong
helper_mfc0_random(CPUMIPSState
*env
)
709 return (int32_t)cpu_mips_get_random(env
);
712 target_ulong
helper_mfc0_tcstatus(CPUMIPSState
*env
)
714 return env
->active_tc
.CP0_TCStatus
;
717 target_ulong
helper_mftc0_tcstatus(CPUMIPSState
*env
)
719 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
720 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
722 if (other_tc
== other
->current_tc
)
723 return other
->active_tc
.CP0_TCStatus
;
725 return other
->tcs
[other_tc
].CP0_TCStatus
;
728 target_ulong
helper_mfc0_tcbind(CPUMIPSState
*env
)
730 return env
->active_tc
.CP0_TCBind
;
733 target_ulong
helper_mftc0_tcbind(CPUMIPSState
*env
)
735 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
736 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
738 if (other_tc
== other
->current_tc
)
739 return other
->active_tc
.CP0_TCBind
;
741 return other
->tcs
[other_tc
].CP0_TCBind
;
744 target_ulong
helper_mfc0_tcrestart(CPUMIPSState
*env
)
746 return env
->active_tc
.PC
;
749 target_ulong
helper_mftc0_tcrestart(CPUMIPSState
*env
)
751 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
752 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
754 if (other_tc
== other
->current_tc
)
755 return other
->active_tc
.PC
;
757 return other
->tcs
[other_tc
].PC
;
760 target_ulong
helper_mfc0_tchalt(CPUMIPSState
*env
)
762 return env
->active_tc
.CP0_TCHalt
;
765 target_ulong
helper_mftc0_tchalt(CPUMIPSState
*env
)
767 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
768 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
770 if (other_tc
== other
->current_tc
)
771 return other
->active_tc
.CP0_TCHalt
;
773 return other
->tcs
[other_tc
].CP0_TCHalt
;
776 target_ulong
helper_mfc0_tccontext(CPUMIPSState
*env
)
778 return env
->active_tc
.CP0_TCContext
;
781 target_ulong
helper_mftc0_tccontext(CPUMIPSState
*env
)
783 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
784 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
786 if (other_tc
== other
->current_tc
)
787 return other
->active_tc
.CP0_TCContext
;
789 return other
->tcs
[other_tc
].CP0_TCContext
;
792 target_ulong
helper_mfc0_tcschedule(CPUMIPSState
*env
)
794 return env
->active_tc
.CP0_TCSchedule
;
797 target_ulong
helper_mftc0_tcschedule(CPUMIPSState
*env
)
799 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
800 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
802 if (other_tc
== other
->current_tc
)
803 return other
->active_tc
.CP0_TCSchedule
;
805 return other
->tcs
[other_tc
].CP0_TCSchedule
;
808 target_ulong
helper_mfc0_tcschefback(CPUMIPSState
*env
)
810 return env
->active_tc
.CP0_TCScheFBack
;
813 target_ulong
helper_mftc0_tcschefback(CPUMIPSState
*env
)
815 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
816 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
818 if (other_tc
== other
->current_tc
)
819 return other
->active_tc
.CP0_TCScheFBack
;
821 return other
->tcs
[other_tc
].CP0_TCScheFBack
;
824 target_ulong
helper_mfc0_count(CPUMIPSState
*env
)
826 return (int32_t)cpu_mips_get_count(env
);
829 target_ulong
helper_mftc0_entryhi(CPUMIPSState
*env
)
831 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
832 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
834 return other
->CP0_EntryHi
;
837 target_ulong
helper_mftc0_cause(CPUMIPSState
*env
)
839 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
841 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
843 if (other_tc
== other
->current_tc
) {
844 tccause
= other
->CP0_Cause
;
846 tccause
= other
->CP0_Cause
;
852 target_ulong
helper_mftc0_status(CPUMIPSState
*env
)
854 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
855 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
857 return other
->CP0_Status
;
860 target_ulong
helper_mfc0_lladdr(CPUMIPSState
*env
)
862 return (int32_t)(env
->lladdr
>> env
->CP0_LLAddr_shift
);
865 target_ulong
helper_mfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
867 return (int32_t)env
->CP0_WatchLo
[sel
];
870 target_ulong
helper_mfc0_watchhi(CPUMIPSState
*env
, uint32_t sel
)
872 return env
->CP0_WatchHi
[sel
];
875 target_ulong
helper_mfc0_debug(CPUMIPSState
*env
)
877 target_ulong t0
= env
->CP0_Debug
;
878 if (env
->hflags
& MIPS_HFLAG_DM
)
884 target_ulong
helper_mftc0_debug(CPUMIPSState
*env
)
886 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
888 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
890 if (other_tc
== other
->current_tc
)
891 tcstatus
= other
->active_tc
.CP0_Debug_tcstatus
;
893 tcstatus
= other
->tcs
[other_tc
].CP0_Debug_tcstatus
;
895 /* XXX: Might be wrong, check with EJTAG spec. */
896 return (other
->CP0_Debug
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
897 (tcstatus
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
900 #if defined(TARGET_MIPS64)
901 target_ulong
helper_dmfc0_tcrestart(CPUMIPSState
*env
)
903 return env
->active_tc
.PC
;
906 target_ulong
helper_dmfc0_tchalt(CPUMIPSState
*env
)
908 return env
->active_tc
.CP0_TCHalt
;
911 target_ulong
helper_dmfc0_tccontext(CPUMIPSState
*env
)
913 return env
->active_tc
.CP0_TCContext
;
916 target_ulong
helper_dmfc0_tcschedule(CPUMIPSState
*env
)
918 return env
->active_tc
.CP0_TCSchedule
;
921 target_ulong
helper_dmfc0_tcschefback(CPUMIPSState
*env
)
923 return env
->active_tc
.CP0_TCScheFBack
;
926 target_ulong
helper_dmfc0_lladdr(CPUMIPSState
*env
)
928 return env
->lladdr
>> env
->CP0_LLAddr_shift
;
931 target_ulong
helper_dmfc0_watchlo(CPUMIPSState
*env
, uint32_t sel
)
933 return env
->CP0_WatchLo
[sel
];
935 #endif /* TARGET_MIPS64 */
937 void helper_mtc0_index(CPUMIPSState
*env
, target_ulong arg1
)
940 unsigned int tmp
= env
->tlb
->nb_tlb
;
946 env
->CP0_Index
= (env
->CP0_Index
& 0x80000000) | (arg1
& (num
- 1));
949 void helper_mtc0_mvpcontrol(CPUMIPSState
*env
, target_ulong arg1
)
954 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
))
955 mask
|= (1 << CP0MVPCo_CPA
) | (1 << CP0MVPCo_VPC
) |
957 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
958 mask
|= (1 << CP0MVPCo_STLB
);
959 newval
= (env
->mvp
->CP0_MVPControl
& ~mask
) | (arg1
& mask
);
961 // TODO: Enable/disable shared TLB, enable/disable VPEs.
963 env
->mvp
->CP0_MVPControl
= newval
;
966 void helper_mtc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
971 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
972 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
973 newval
= (env
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
975 /* Yield scheduler intercept not implemented. */
976 /* Gating storage scheduler intercept not implemented. */
978 // TODO: Enable/disable TCs.
980 env
->CP0_VPEControl
= newval
;
983 void helper_mttc0_vpecontrol(CPUMIPSState
*env
, target_ulong arg1
)
985 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
986 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
990 mask
= (1 << CP0VPECo_YSI
) | (1 << CP0VPECo_GSI
) |
991 (1 << CP0VPECo_TE
) | (0xff << CP0VPECo_TargTC
);
992 newval
= (other
->CP0_VPEControl
& ~mask
) | (arg1
& mask
);
994 /* TODO: Enable/disable TCs. */
996 other
->CP0_VPEControl
= newval
;
999 target_ulong
helper_mftc0_vpecontrol(CPUMIPSState
*env
)
1001 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1002 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1003 /* FIXME: Mask away return zero on read bits. */
1004 return other
->CP0_VPEControl
;
1007 target_ulong
helper_mftc0_vpeconf0(CPUMIPSState
*env
)
1009 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1010 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1012 return other
->CP0_VPEConf0
;
1015 void helper_mtc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1020 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) {
1021 if (env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))
1022 mask
|= (0xff << CP0VPEC0_XTC
);
1023 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1025 newval
= (env
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1027 // TODO: TC exclusive handling due to ERL/EXL.
1029 env
->CP0_VPEConf0
= newval
;
1032 void helper_mttc0_vpeconf0(CPUMIPSState
*env
, target_ulong arg1
)
1034 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1035 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1039 mask
|= (1 << CP0VPEC0_MVP
) | (1 << CP0VPEC0_VPA
);
1040 newval
= (other
->CP0_VPEConf0
& ~mask
) | (arg1
& mask
);
1042 /* TODO: TC exclusive handling due to ERL/EXL. */
1043 other
->CP0_VPEConf0
= newval
;
1046 void helper_mtc0_vpeconf1(CPUMIPSState
*env
, target_ulong arg1
)
1051 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1052 mask
|= (0xff << CP0VPEC1_NCX
) | (0xff << CP0VPEC1_NCP2
) |
1053 (0xff << CP0VPEC1_NCP1
);
1054 newval
= (env
->CP0_VPEConf1
& ~mask
) | (arg1
& mask
);
1056 /* UDI not implemented. */
1057 /* CP2 not implemented. */
1059 // TODO: Handle FPU (CP1) binding.
1061 env
->CP0_VPEConf1
= newval
;
1064 void helper_mtc0_yqmask(CPUMIPSState
*env
, target_ulong arg1
)
1066 /* Yield qualifier inputs not implemented. */
1067 env
->CP0_YQMask
= 0x00000000;
1070 void helper_mtc0_vpeopt(CPUMIPSState
*env
, target_ulong arg1
)
1072 env
->CP0_VPEOpt
= arg1
& 0x0000ffff;
1075 void helper_mtc0_entrylo0(CPUMIPSState
*env
, target_ulong arg1
)
1077 /* Large physaddr (PABITS) not implemented */
1078 /* 1k pages not implemented */
1079 env
->CP0_EntryLo0
= arg1
& 0x3FFFFFFF;
1082 void helper_mtc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1084 uint32_t mask
= env
->CP0_TCStatus_rw_bitmask
;
1087 newval
= (env
->active_tc
.CP0_TCStatus
& ~mask
) | (arg1
& mask
);
1089 env
->active_tc
.CP0_TCStatus
= newval
;
1090 sync_c0_tcstatus(env
, env
->current_tc
, newval
);
1093 void helper_mttc0_tcstatus(CPUMIPSState
*env
, target_ulong arg1
)
1095 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1096 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1098 if (other_tc
== other
->current_tc
)
1099 other
->active_tc
.CP0_TCStatus
= arg1
;
1101 other
->tcs
[other_tc
].CP0_TCStatus
= arg1
;
1102 sync_c0_tcstatus(other
, other_tc
, arg1
);
1105 void helper_mtc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1107 uint32_t mask
= (1 << CP0TCBd_TBE
);
1110 if (env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1111 mask
|= (1 << CP0TCBd_CurVPE
);
1112 newval
= (env
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1113 env
->active_tc
.CP0_TCBind
= newval
;
1116 void helper_mttc0_tcbind(CPUMIPSState
*env
, target_ulong arg1
)
1118 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1119 uint32_t mask
= (1 << CP0TCBd_TBE
);
1121 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1123 if (other
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_VPC
))
1124 mask
|= (1 << CP0TCBd_CurVPE
);
1125 if (other_tc
== other
->current_tc
) {
1126 newval
= (other
->active_tc
.CP0_TCBind
& ~mask
) | (arg1
& mask
);
1127 other
->active_tc
.CP0_TCBind
= newval
;
1129 newval
= (other
->tcs
[other_tc
].CP0_TCBind
& ~mask
) | (arg1
& mask
);
1130 other
->tcs
[other_tc
].CP0_TCBind
= newval
;
1134 void helper_mtc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1136 env
->active_tc
.PC
= arg1
;
1137 env
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1139 /* MIPS16 not implemented. */
1142 void helper_mttc0_tcrestart(CPUMIPSState
*env
, target_ulong arg1
)
1144 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1145 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1147 if (other_tc
== other
->current_tc
) {
1148 other
->active_tc
.PC
= arg1
;
1149 other
->active_tc
.CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1150 other
->lladdr
= 0ULL;
1151 /* MIPS16 not implemented. */
1153 other
->tcs
[other_tc
].PC
= arg1
;
1154 other
->tcs
[other_tc
].CP0_TCStatus
&= ~(1 << CP0TCSt_TDS
);
1155 other
->lladdr
= 0ULL;
1156 /* MIPS16 not implemented. */
1160 void helper_mtc0_tchalt(CPUMIPSState
*env
, target_ulong arg1
)
1162 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1164 env
->active_tc
.CP0_TCHalt
= arg1
& 0x1;
1166 // TODO: Halt TC / Restart (if allocated+active) TC.
1167 if (env
->active_tc
.CP0_TCHalt
& 1) {
1168 mips_tc_sleep(cpu
, env
->current_tc
);
1170 mips_tc_wake(cpu
, env
->current_tc
);
1174 void helper_mttc0_tchalt(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
);
1178 MIPSCPU
*other_cpu
= mips_env_get_cpu(other
);
1180 // TODO: Halt TC / Restart (if allocated+active) TC.
1182 if (other_tc
== other
->current_tc
)
1183 other
->active_tc
.CP0_TCHalt
= arg1
;
1185 other
->tcs
[other_tc
].CP0_TCHalt
= arg1
;
1188 mips_tc_sleep(other_cpu
, other_tc
);
1190 mips_tc_wake(other_cpu
, other_tc
);
1194 void helper_mtc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1196 env
->active_tc
.CP0_TCContext
= arg1
;
1199 void helper_mttc0_tccontext(CPUMIPSState
*env
, target_ulong arg1
)
1201 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1202 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1204 if (other_tc
== other
->current_tc
)
1205 other
->active_tc
.CP0_TCContext
= arg1
;
1207 other
->tcs
[other_tc
].CP0_TCContext
= arg1
;
1210 void helper_mtc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1212 env
->active_tc
.CP0_TCSchedule
= arg1
;
1215 void helper_mttc0_tcschedule(CPUMIPSState
*env
, target_ulong arg1
)
1217 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1218 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1220 if (other_tc
== other
->current_tc
)
1221 other
->active_tc
.CP0_TCSchedule
= arg1
;
1223 other
->tcs
[other_tc
].CP0_TCSchedule
= arg1
;
1226 void helper_mtc0_tcschefback(CPUMIPSState
*env
, target_ulong arg1
)
1228 env
->active_tc
.CP0_TCScheFBack
= arg1
;
1231 void helper_mttc0_tcschefback(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_TCScheFBack
= arg1
;
1239 other
->tcs
[other_tc
].CP0_TCScheFBack
= arg1
;
1242 void helper_mtc0_entrylo1(CPUMIPSState
*env
, target_ulong arg1
)
1244 /* Large physaddr (PABITS) not implemented */
1245 /* 1k pages not implemented */
1246 env
->CP0_EntryLo1
= arg1
& 0x3FFFFFFF;
1249 void helper_mtc0_context(CPUMIPSState
*env
, target_ulong arg1
)
1251 env
->CP0_Context
= (env
->CP0_Context
& 0x007FFFFF) | (arg1
& ~0x007FFFFF);
1254 void helper_mtc0_pagemask(CPUMIPSState
*env
, target_ulong arg1
)
1256 /* 1k pages not implemented */
1257 env
->CP0_PageMask
= arg1
& (0x1FFFFFFF & (TARGET_PAGE_MASK
<< 1));
1260 void helper_mtc0_pagegrain(CPUMIPSState
*env
, target_ulong arg1
)
1262 /* SmartMIPS not implemented */
1263 /* Large physaddr (PABITS) not implemented */
1264 /* 1k pages not implemented */
1265 env
->CP0_PageGrain
= 0;
1268 void helper_mtc0_wired(CPUMIPSState
*env
, target_ulong arg1
)
1270 env
->CP0_Wired
= arg1
% env
->tlb
->nb_tlb
;
1273 void helper_mtc0_srsconf0(CPUMIPSState
*env
, target_ulong arg1
)
1275 env
->CP0_SRSConf0
|= arg1
& env
->CP0_SRSConf0_rw_bitmask
;
1278 void helper_mtc0_srsconf1(CPUMIPSState
*env
, target_ulong arg1
)
1280 env
->CP0_SRSConf1
|= arg1
& env
->CP0_SRSConf1_rw_bitmask
;
1283 void helper_mtc0_srsconf2(CPUMIPSState
*env
, target_ulong arg1
)
1285 env
->CP0_SRSConf2
|= arg1
& env
->CP0_SRSConf2_rw_bitmask
;
1288 void helper_mtc0_srsconf3(CPUMIPSState
*env
, target_ulong arg1
)
1290 env
->CP0_SRSConf3
|= arg1
& env
->CP0_SRSConf3_rw_bitmask
;
1293 void helper_mtc0_srsconf4(CPUMIPSState
*env
, target_ulong arg1
)
1295 env
->CP0_SRSConf4
|= arg1
& env
->CP0_SRSConf4_rw_bitmask
;
1298 void helper_mtc0_hwrena(CPUMIPSState
*env
, target_ulong arg1
)
1300 uint32_t mask
= 0x0000000F;
1302 if (env
->CP0_Config3
& (1 << CP0C3_ULRI
)) {
1305 if (arg1
& (1 << 29)) {
1306 env
->hflags
|= MIPS_HFLAG_HWRENA_ULR
;
1308 env
->hflags
&= ~MIPS_HFLAG_HWRENA_ULR
;
1312 env
->CP0_HWREna
= arg1
& mask
;
1315 void helper_mtc0_count(CPUMIPSState
*env
, target_ulong arg1
)
1317 cpu_mips_store_count(env
, arg1
);
1320 void helper_mtc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1322 target_ulong old
, val
;
1324 /* 1k pages not implemented */
1325 val
= arg1
& ((TARGET_PAGE_MASK
<< 1) | 0xFF);
1326 #if defined(TARGET_MIPS64)
1327 val
&= env
->SEGMask
;
1329 old
= env
->CP0_EntryHi
;
1330 env
->CP0_EntryHi
= val
;
1331 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1332 sync_c0_entryhi(env
, env
->current_tc
);
1334 /* If the ASID changes, flush qemu's TLB. */
1335 if ((old
& 0xFF) != (val
& 0xFF))
1336 cpu_mips_tlb_flush(env
, 1);
1339 void helper_mttc0_entryhi(CPUMIPSState
*env
, target_ulong arg1
)
1341 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1342 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1344 other
->CP0_EntryHi
= arg1
;
1345 sync_c0_entryhi(other
, other_tc
);
1348 void helper_mtc0_compare(CPUMIPSState
*env
, target_ulong arg1
)
1350 cpu_mips_store_compare(env
, arg1
);
1353 void helper_mtc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1355 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1357 uint32_t mask
= env
->CP0_Status_rw_bitmask
;
1360 old
= env
->CP0_Status
;
1361 env
->CP0_Status
= (env
->CP0_Status
& ~mask
) | val
;
1362 if (env
->CP0_Config3
& (1 << CP0C3_MT
)) {
1363 sync_c0_status(env
, env
, env
->current_tc
);
1365 compute_hflags(env
);
1368 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1369 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1370 old
, old
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1371 val
, val
& env
->CP0_Cause
& CP0Ca_IP_mask
,
1373 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
1374 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
1375 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
1376 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
1378 cpu_abort(CPU(cpu
), "Invalid MMU mode!\n");
1384 void helper_mttc0_status(CPUMIPSState
*env
, target_ulong arg1
)
1386 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1387 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1389 other
->CP0_Status
= arg1
& ~0xf1000018;
1390 sync_c0_status(env
, other
, other_tc
);
1393 void helper_mtc0_intctl(CPUMIPSState
*env
, target_ulong arg1
)
1395 /* vectored interrupts not implemented, no performance counters. */
1396 env
->CP0_IntCtl
= (env
->CP0_IntCtl
& ~0x000003e0) | (arg1
& 0x000003e0);
1399 void helper_mtc0_srsctl(CPUMIPSState
*env
, target_ulong arg1
)
1401 uint32_t mask
= (0xf << CP0SRSCtl_ESS
) | (0xf << CP0SRSCtl_PSS
);
1402 env
->CP0_SRSCtl
= (env
->CP0_SRSCtl
& ~mask
) | (arg1
& mask
);
1405 static void mtc0_cause(CPUMIPSState
*cpu
, target_ulong arg1
)
1407 uint32_t mask
= 0x00C00300;
1408 uint32_t old
= cpu
->CP0_Cause
;
1411 if (cpu
->insn_flags
& ISA_MIPS32R2
) {
1412 mask
|= 1 << CP0Ca_DC
;
1413 mask
|= 1 << CP0Ca_PCI
;
1416 cpu
->CP0_Cause
= (cpu
->CP0_Cause
& ~mask
) | (arg1
& mask
);
1418 if ((old
^ cpu
->CP0_Cause
) & (1 << CP0Ca_DC
)) {
1419 if (cpu
->CP0_Cause
& (1 << CP0Ca_DC
)) {
1420 cpu_mips_stop_count(cpu
);
1422 cpu_mips_start_count(cpu
);
1426 /* Set/reset software interrupts */
1427 for (i
= 0 ; i
< 2 ; i
++) {
1428 if ((old
^ cpu
->CP0_Cause
) & (1 << (CP0Ca_IP
+ i
))) {
1429 cpu_mips_soft_irq(cpu
, i
, cpu
->CP0_Cause
& (1 << (CP0Ca_IP
+ i
)));
1434 void helper_mtc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1436 mtc0_cause(env
, arg1
);
1439 void helper_mttc0_cause(CPUMIPSState
*env
, target_ulong arg1
)
1441 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1442 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1444 mtc0_cause(other
, arg1
);
1447 target_ulong
helper_mftc0_epc(CPUMIPSState
*env
)
1449 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1450 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1452 return other
->CP0_EPC
;
1455 target_ulong
helper_mftc0_ebase(CPUMIPSState
*env
)
1457 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1458 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1460 return other
->CP0_EBase
;
1463 void helper_mtc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1465 /* vectored interrupts not implemented */
1466 env
->CP0_EBase
= (env
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1469 void helper_mttc0_ebase(CPUMIPSState
*env
, target_ulong arg1
)
1471 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1472 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1473 other
->CP0_EBase
= (other
->CP0_EBase
& ~0x3FFFF000) | (arg1
& 0x3FFFF000);
1476 target_ulong
helper_mftc0_configx(CPUMIPSState
*env
, target_ulong idx
)
1478 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1479 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1482 case 0: return other
->CP0_Config0
;
1483 case 1: return other
->CP0_Config1
;
1484 case 2: return other
->CP0_Config2
;
1485 case 3: return other
->CP0_Config3
;
1486 /* 4 and 5 are reserved. */
1487 case 6: return other
->CP0_Config6
;
1488 case 7: return other
->CP0_Config7
;
1495 void helper_mtc0_config0(CPUMIPSState
*env
, target_ulong arg1
)
1497 env
->CP0_Config0
= (env
->CP0_Config0
& 0x81FFFFF8) | (arg1
& 0x00000007);
1500 void helper_mtc0_config2(CPUMIPSState
*env
, target_ulong arg1
)
1502 /* tertiary/secondary caches not implemented */
1503 env
->CP0_Config2
= (env
->CP0_Config2
& 0x8FFF0FFF);
1506 void helper_mtc0_config4(CPUMIPSState
*env
, target_ulong arg1
)
1508 env
->CP0_Config4
= (env
->CP0_Config4
& (~env
->CP0_Config4_rw_bitmask
)) |
1509 (arg1
& env
->CP0_Config4_rw_bitmask
);
1512 void helper_mtc0_config5(CPUMIPSState
*env
, target_ulong arg1
)
1514 env
->CP0_Config5
= (env
->CP0_Config5
& (~env
->CP0_Config5_rw_bitmask
)) |
1515 (arg1
& env
->CP0_Config5_rw_bitmask
);
1518 void helper_mtc0_lladdr(CPUMIPSState
*env
, target_ulong arg1
)
1520 target_long mask
= env
->CP0_LLAddr_rw_bitmask
;
1521 arg1
= arg1
<< env
->CP0_LLAddr_shift
;
1522 env
->lladdr
= (env
->lladdr
& ~mask
) | (arg1
& mask
);
1525 void helper_mtc0_watchlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1527 /* Watch exceptions for instructions, data loads, data stores
1529 env
->CP0_WatchLo
[sel
] = (arg1
& ~0x7);
1532 void helper_mtc0_watchhi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1534 env
->CP0_WatchHi
[sel
] = (arg1
& 0x40FF0FF8);
1535 env
->CP0_WatchHi
[sel
] &= ~(env
->CP0_WatchHi
[sel
] & arg1
& 0x7);
1538 void helper_mtc0_xcontext(CPUMIPSState
*env
, target_ulong arg1
)
1540 target_ulong mask
= (1ULL << (env
->SEGBITS
- 7)) - 1;
1541 env
->CP0_XContext
= (env
->CP0_XContext
& mask
) | (arg1
& ~mask
);
1544 void helper_mtc0_framemask(CPUMIPSState
*env
, target_ulong arg1
)
1546 env
->CP0_Framemask
= arg1
; /* XXX */
1549 void helper_mtc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1551 env
->CP0_Debug
= (env
->CP0_Debug
& 0x8C03FC1F) | (arg1
& 0x13300120);
1552 if (arg1
& (1 << CP0DB_DM
))
1553 env
->hflags
|= MIPS_HFLAG_DM
;
1555 env
->hflags
&= ~MIPS_HFLAG_DM
;
1558 void helper_mttc0_debug(CPUMIPSState
*env
, target_ulong arg1
)
1560 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1561 uint32_t val
= arg1
& ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
));
1562 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1564 /* XXX: Might be wrong, check with EJTAG spec. */
1565 if (other_tc
== other
->current_tc
)
1566 other
->active_tc
.CP0_Debug_tcstatus
= val
;
1568 other
->tcs
[other_tc
].CP0_Debug_tcstatus
= val
;
1569 other
->CP0_Debug
= (other
->CP0_Debug
&
1570 ((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
))) |
1571 (arg1
& ~((1 << CP0DB_SSt
) | (1 << CP0DB_Halt
)));
1574 void helper_mtc0_performance0(CPUMIPSState
*env
, target_ulong arg1
)
1576 env
->CP0_Performance0
= arg1
& 0x000007ff;
1579 void helper_mtc0_taglo(CPUMIPSState
*env
, target_ulong arg1
)
1581 env
->CP0_TagLo
= arg1
& 0xFFFFFCF6;
1584 void helper_mtc0_datalo(CPUMIPSState
*env
, target_ulong arg1
)
1586 env
->CP0_DataLo
= arg1
; /* XXX */
1589 void helper_mtc0_taghi(CPUMIPSState
*env
, target_ulong arg1
)
1591 env
->CP0_TagHi
= arg1
; /* XXX */
1594 void helper_mtc0_datahi(CPUMIPSState
*env
, target_ulong arg1
)
1596 env
->CP0_DataHi
= arg1
; /* XXX */
1599 /* MIPS MT functions */
1600 target_ulong
helper_mftgpr(CPUMIPSState
*env
, uint32_t sel
)
1602 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1603 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1605 if (other_tc
== other
->current_tc
)
1606 return other
->active_tc
.gpr
[sel
];
1608 return other
->tcs
[other_tc
].gpr
[sel
];
1611 target_ulong
helper_mftlo(CPUMIPSState
*env
, uint32_t sel
)
1613 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1614 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1616 if (other_tc
== other
->current_tc
)
1617 return other
->active_tc
.LO
[sel
];
1619 return other
->tcs
[other_tc
].LO
[sel
];
1622 target_ulong
helper_mfthi(CPUMIPSState
*env
, uint32_t sel
)
1624 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1625 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1627 if (other_tc
== other
->current_tc
)
1628 return other
->active_tc
.HI
[sel
];
1630 return other
->tcs
[other_tc
].HI
[sel
];
1633 target_ulong
helper_mftacx(CPUMIPSState
*env
, uint32_t sel
)
1635 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1636 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1638 if (other_tc
== other
->current_tc
)
1639 return other
->active_tc
.ACX
[sel
];
1641 return other
->tcs
[other_tc
].ACX
[sel
];
1644 target_ulong
helper_mftdsp(CPUMIPSState
*env
)
1646 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1647 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1649 if (other_tc
== other
->current_tc
)
1650 return other
->active_tc
.DSPControl
;
1652 return other
->tcs
[other_tc
].DSPControl
;
1655 void helper_mttgpr(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1657 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1658 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1660 if (other_tc
== other
->current_tc
)
1661 other
->active_tc
.gpr
[sel
] = arg1
;
1663 other
->tcs
[other_tc
].gpr
[sel
] = arg1
;
1666 void helper_mttlo(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1668 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1669 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1671 if (other_tc
== other
->current_tc
)
1672 other
->active_tc
.LO
[sel
] = arg1
;
1674 other
->tcs
[other_tc
].LO
[sel
] = arg1
;
1677 void helper_mtthi(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1679 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1680 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1682 if (other_tc
== other
->current_tc
)
1683 other
->active_tc
.HI
[sel
] = arg1
;
1685 other
->tcs
[other_tc
].HI
[sel
] = arg1
;
1688 void helper_mttacx(CPUMIPSState
*env
, target_ulong arg1
, uint32_t sel
)
1690 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1691 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1693 if (other_tc
== other
->current_tc
)
1694 other
->active_tc
.ACX
[sel
] = arg1
;
1696 other
->tcs
[other_tc
].ACX
[sel
] = arg1
;
1699 void helper_mttdsp(CPUMIPSState
*env
, target_ulong arg1
)
1701 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
1702 CPUMIPSState
*other
= mips_cpu_map_tc(env
, &other_tc
);
1704 if (other_tc
== other
->current_tc
)
1705 other
->active_tc
.DSPControl
= arg1
;
1707 other
->tcs
[other_tc
].DSPControl
= arg1
;
1710 /* MIPS MT functions */
1711 target_ulong
helper_dmt(void)
1717 target_ulong
helper_emt(void)
1723 target_ulong
helper_dvpe(CPUMIPSState
*env
)
1725 CPUState
*other_cs
= first_cpu
;
1726 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1728 CPU_FOREACH(other_cs
) {
1729 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
1730 /* Turn off all VPEs except the one executing the dvpe. */
1731 if (&other_cpu
->env
!= env
) {
1732 other_cpu
->env
.mvp
->CP0_MVPControl
&= ~(1 << CP0MVPCo_EVP
);
1733 mips_vpe_sleep(other_cpu
);
1739 target_ulong
helper_evpe(CPUMIPSState
*env
)
1741 CPUState
*other_cs
= first_cpu
;
1742 target_ulong prev
= env
->mvp
->CP0_MVPControl
;
1744 CPU_FOREACH(other_cs
) {
1745 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
1747 if (&other_cpu
->env
!= env
1748 /* If the VPE is WFI, don't disturb its sleep. */
1749 && !mips_vpe_is_wfi(other_cpu
)) {
1750 /* Enable the VPE. */
1751 other_cpu
->env
.mvp
->CP0_MVPControl
|= (1 << CP0MVPCo_EVP
);
1752 mips_vpe_wake(other_cpu
); /* And wake it up. */
1757 #endif /* !CONFIG_USER_ONLY */
1759 void helper_fork(target_ulong arg1
, target_ulong arg2
)
1761 fprintf(stderr
, "%s:%u - %s\n", __FILE__
, __LINE__
, __func__
);
1762 // arg1 = rt, arg2 = rs
1763 // TODO: store to TC register, assert to detect test cases.
1764 g_assert_not_reached();
1767 target_ulong
helper_yield(CPUMIPSState
*env
, target_ulong arg
)
1769 target_long arg1
= arg
;
1772 /* No scheduling policy implemented. */
1774 if (env
->CP0_VPEControl
& (1 << CP0VPECo_YSI
) &&
1775 env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_DT
)) {
1776 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1777 env
->CP0_VPEControl
|= 4 << CP0VPECo_EXCPT
;
1778 helper_raise_exception(env
, EXCP_THREAD
);
1781 } else if (arg1
== 0) {
1782 if (0 /* TODO: TC underflow */) {
1783 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1784 helper_raise_exception(env
, EXCP_THREAD
);
1786 // TODO: Deallocate TC
1788 } else if (arg1
> 0) {
1789 /* Yield qualifier inputs not implemented. */
1790 env
->CP0_VPEControl
&= ~(0x7 << CP0VPECo_EXCPT
);
1791 env
->CP0_VPEControl
|= 2 << CP0VPECo_EXCPT
;
1792 helper_raise_exception(env
, EXCP_THREAD
);
1794 return env
->CP0_YQMask
;
1797 #ifndef CONFIG_USER_ONLY
1798 /* TLB management */
1799 static void cpu_mips_tlb_flush (CPUMIPSState
*env
, int flush_global
)
1801 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
1803 /* Flush qemu's TLB and discard all shadowed entries. */
1804 tlb_flush(CPU(cpu
), flush_global
);
1805 env
->tlb
->tlb_in_use
= env
->tlb
->nb_tlb
;
1808 static void r4k_mips_tlb_flush_extra (CPUMIPSState
*env
, int first
)
1810 /* Discard entries from env->tlb[first] onwards. */
1811 while (env
->tlb
->tlb_in_use
> first
) {
1812 r4k_invalidate_tlb(env
, --env
->tlb
->tlb_in_use
, 0);
1816 static void r4k_fill_tlb(CPUMIPSState
*env
, int idx
)
1820 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1821 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1822 tlb
->VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1823 #if defined(TARGET_MIPS64)
1824 tlb
->VPN
&= env
->SEGMask
;
1826 tlb
->ASID
= env
->CP0_EntryHi
& 0xFF;
1827 tlb
->PageMask
= env
->CP0_PageMask
;
1828 tlb
->G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1829 tlb
->V0
= (env
->CP0_EntryLo0
& 2) != 0;
1830 tlb
->D0
= (env
->CP0_EntryLo0
& 4) != 0;
1831 tlb
->C0
= (env
->CP0_EntryLo0
>> 3) & 0x7;
1832 tlb
->PFN
[0] = (env
->CP0_EntryLo0
>> 6) << 12;
1833 tlb
->V1
= (env
->CP0_EntryLo1
& 2) != 0;
1834 tlb
->D1
= (env
->CP0_EntryLo1
& 4) != 0;
1835 tlb
->C1
= (env
->CP0_EntryLo1
>> 3) & 0x7;
1836 tlb
->PFN
[1] = (env
->CP0_EntryLo1
>> 6) << 12;
1839 void r4k_helper_tlbwi(CPUMIPSState
*env
)
1845 bool G
, V0
, D0
, V1
, D1
;
1847 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1848 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1849 VPN
= env
->CP0_EntryHi
& (TARGET_PAGE_MASK
<< 1);
1850 #if defined(TARGET_MIPS64)
1851 VPN
&= env
->SEGMask
;
1853 ASID
= env
->CP0_EntryHi
& 0xff;
1854 G
= env
->CP0_EntryLo0
& env
->CP0_EntryLo1
& 1;
1855 V0
= (env
->CP0_EntryLo0
& 2) != 0;
1856 D0
= (env
->CP0_EntryLo0
& 4) != 0;
1857 V1
= (env
->CP0_EntryLo1
& 2) != 0;
1858 D1
= (env
->CP0_EntryLo1
& 4) != 0;
1860 /* Discard cached TLB entries, unless tlbwi is just upgrading access
1861 permissions on the current entry. */
1862 if (tlb
->VPN
!= VPN
|| tlb
->ASID
!= ASID
|| tlb
->G
!= G
||
1863 (tlb
->V0
&& !V0
) || (tlb
->D0
&& !D0
) ||
1864 (tlb
->V1
&& !V1
) || (tlb
->D1
&& !D1
)) {
1865 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
1868 r4k_invalidate_tlb(env
, idx
, 0);
1869 r4k_fill_tlb(env
, idx
);
1872 void r4k_helper_tlbwr(CPUMIPSState
*env
)
1874 int r
= cpu_mips_get_random(env
);
1876 r4k_invalidate_tlb(env
, r
, 1);
1877 r4k_fill_tlb(env
, r
);
1880 void r4k_helper_tlbp(CPUMIPSState
*env
)
1889 ASID
= env
->CP0_EntryHi
& 0xFF;
1890 for (i
= 0; i
< env
->tlb
->nb_tlb
; i
++) {
1891 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1892 /* 1k pages are not supported. */
1893 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1894 tag
= env
->CP0_EntryHi
& ~mask
;
1895 VPN
= tlb
->VPN
& ~mask
;
1896 #if defined(TARGET_MIPS64)
1897 tag
&= env
->SEGMask
;
1899 /* Check ASID, virtual page number & size */
1900 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1906 if (i
== env
->tlb
->nb_tlb
) {
1907 /* No match. Discard any shadow entries, if any of them match. */
1908 for (i
= env
->tlb
->nb_tlb
; i
< env
->tlb
->tlb_in_use
; i
++) {
1909 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[i
];
1910 /* 1k pages are not supported. */
1911 mask
= tlb
->PageMask
| ~(TARGET_PAGE_MASK
<< 1);
1912 tag
= env
->CP0_EntryHi
& ~mask
;
1913 VPN
= tlb
->VPN
& ~mask
;
1914 #if defined(TARGET_MIPS64)
1915 tag
&= env
->SEGMask
;
1917 /* Check ASID, virtual page number & size */
1918 if ((tlb
->G
== 1 || tlb
->ASID
== ASID
) && VPN
== tag
) {
1919 r4k_mips_tlb_flush_extra (env
, i
);
1924 env
->CP0_Index
|= 0x80000000;
1928 void r4k_helper_tlbr(CPUMIPSState
*env
)
1934 ASID
= env
->CP0_EntryHi
& 0xFF;
1935 idx
= (env
->CP0_Index
& ~0x80000000) % env
->tlb
->nb_tlb
;
1936 tlb
= &env
->tlb
->mmu
.r4k
.tlb
[idx
];
1938 /* If this will change the current ASID, flush qemu's TLB. */
1939 if (ASID
!= tlb
->ASID
)
1940 cpu_mips_tlb_flush (env
, 1);
1942 r4k_mips_tlb_flush_extra(env
, env
->tlb
->nb_tlb
);
1944 env
->CP0_EntryHi
= tlb
->VPN
| tlb
->ASID
;
1945 env
->CP0_PageMask
= tlb
->PageMask
;
1946 env
->CP0_EntryLo0
= tlb
->G
| (tlb
->V0
<< 1) | (tlb
->D0
<< 2) |
1947 (tlb
->C0
<< 3) | (tlb
->PFN
[0] >> 6);
1948 env
->CP0_EntryLo1
= tlb
->G
| (tlb
->V1
<< 1) | (tlb
->D1
<< 2) |
1949 (tlb
->C1
<< 3) | (tlb
->PFN
[1] >> 6);
1952 void helper_tlbwi(CPUMIPSState
*env
)
1954 env
->tlb
->helper_tlbwi(env
);
1957 void helper_tlbwr(CPUMIPSState
*env
)
1959 env
->tlb
->helper_tlbwr(env
);
1962 void helper_tlbp(CPUMIPSState
*env
)
1964 env
->tlb
->helper_tlbp(env
);
1967 void helper_tlbr(CPUMIPSState
*env
)
1969 env
->tlb
->helper_tlbr(env
);
1973 target_ulong
helper_di(CPUMIPSState
*env
)
1975 target_ulong t0
= env
->CP0_Status
;
1977 env
->CP0_Status
= t0
& ~(1 << CP0St_IE
);
1981 target_ulong
helper_ei(CPUMIPSState
*env
)
1983 target_ulong t0
= env
->CP0_Status
;
1985 env
->CP0_Status
= t0
| (1 << CP0St_IE
);
1989 static void debug_pre_eret(CPUMIPSState
*env
)
1991 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
1992 qemu_log("ERET: PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
1993 env
->active_tc
.PC
, env
->CP0_EPC
);
1994 if (env
->CP0_Status
& (1 << CP0St_ERL
))
1995 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
1996 if (env
->hflags
& MIPS_HFLAG_DM
)
1997 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2002 static void debug_post_eret(CPUMIPSState
*env
)
2004 MIPSCPU
*cpu
= mips_env_get_cpu(env
);
2006 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
2007 qemu_log(" => PC " TARGET_FMT_lx
" EPC " TARGET_FMT_lx
,
2008 env
->active_tc
.PC
, env
->CP0_EPC
);
2009 if (env
->CP0_Status
& (1 << CP0St_ERL
))
2010 qemu_log(" ErrorEPC " TARGET_FMT_lx
, env
->CP0_ErrorEPC
);
2011 if (env
->hflags
& MIPS_HFLAG_DM
)
2012 qemu_log(" DEPC " TARGET_FMT_lx
, env
->CP0_DEPC
);
2013 switch (env
->hflags
& MIPS_HFLAG_KSU
) {
2014 case MIPS_HFLAG_UM
: qemu_log(", UM\n"); break;
2015 case MIPS_HFLAG_SM
: qemu_log(", SM\n"); break;
2016 case MIPS_HFLAG_KM
: qemu_log("\n"); break;
2018 cpu_abort(CPU(cpu
), "Invalid MMU mode!\n");
2024 static void set_pc(CPUMIPSState
*env
, target_ulong error_pc
)
2026 env
->active_tc
.PC
= error_pc
& ~(target_ulong
)1;
2028 env
->hflags
|= MIPS_HFLAG_M16
;
2030 env
->hflags
&= ~(MIPS_HFLAG_M16
);
2034 void helper_eret(CPUMIPSState
*env
)
2036 debug_pre_eret(env
);
2037 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
2038 set_pc(env
, env
->CP0_ErrorEPC
);
2039 env
->CP0_Status
&= ~(1 << CP0St_ERL
);
2041 set_pc(env
, env
->CP0_EPC
);
2042 env
->CP0_Status
&= ~(1 << CP0St_EXL
);
2044 compute_hflags(env
);
2045 debug_post_eret(env
);
2049 void helper_deret(CPUMIPSState
*env
)
2051 debug_pre_eret(env
);
2052 set_pc(env
, env
->CP0_DEPC
);
2054 env
->hflags
&= MIPS_HFLAG_DM
;
2055 compute_hflags(env
);
2056 debug_post_eret(env
);
2059 #endif /* !CONFIG_USER_ONLY */
2061 target_ulong
helper_rdhwr_cpunum(CPUMIPSState
*env
)
2063 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2064 (env
->CP0_HWREna
& (1 << 0)))
2065 return env
->CP0_EBase
& 0x3ff;
2067 helper_raise_exception(env
, EXCP_RI
);
2072 target_ulong
helper_rdhwr_synci_step(CPUMIPSState
*env
)
2074 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2075 (env
->CP0_HWREna
& (1 << 1)))
2076 return env
->SYNCI_Step
;
2078 helper_raise_exception(env
, EXCP_RI
);
2083 target_ulong
helper_rdhwr_cc(CPUMIPSState
*env
)
2085 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2086 (env
->CP0_HWREna
& (1 << 2)))
2087 return env
->CP0_Count
;
2089 helper_raise_exception(env
, EXCP_RI
);
2094 target_ulong
helper_rdhwr_ccres(CPUMIPSState
*env
)
2096 if ((env
->hflags
& MIPS_HFLAG_CP0
) ||
2097 (env
->CP0_HWREna
& (1 << 3)))
2100 helper_raise_exception(env
, EXCP_RI
);
2105 void helper_pmon(CPUMIPSState
*env
, int function
)
2109 case 2: /* TODO: char inbyte(int waitflag); */
2110 if (env
->active_tc
.gpr
[4] == 0)
2111 env
->active_tc
.gpr
[2] = -1;
2113 case 11: /* TODO: char inbyte (void); */
2114 env
->active_tc
.gpr
[2] = -1;
2118 printf("%c", (char)(env
->active_tc
.gpr
[4] & 0xFF));
2122 #ifndef CONFIG_USER_ONLY
2125 unsigned char *fmt
= (void *)(uintptr_t)env
->active_tc
.gpr
[4];
2133 void QEMU_NORETURN
helper_wait(CPUMIPSState
*env
)
2135 CPUState
*cs
= CPU(mips_env_get_cpu(env
));
2138 cpu_reset_interrupt(cs
, CPU_INTERRUPT_WAKE
);
2139 helper_raise_exception(env
, EXCP_HLT
);
2142 #if !defined(CONFIG_USER_ONLY)
2144 void QEMU_NORETURN
mips_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
2145 int is_write
, int is_user
, uintptr_t retaddr
)
2147 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2148 CPUMIPSState
*env
= &cpu
->env
;
2150 env
->CP0_BadVAddr
= addr
;
2151 do_raise_exception(env
, (is_write
== 1) ? EXCP_AdES
: EXCP_AdEL
, retaddr
);
2154 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2159 ret
= mips_cpu_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2161 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2162 CPUMIPSState
*env
= &cpu
->env
;
2164 do_raise_exception_err(env
, cs
->exception_index
,
2165 env
->error_code
, retaddr
);
2169 void mips_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2170 bool is_write
, bool is_exec
, int unused
,
2173 MIPSCPU
*cpu
= MIPS_CPU(cs
);
2174 CPUMIPSState
*env
= &cpu
->env
;
2177 helper_raise_exception(env
, EXCP_IBE
);
2179 helper_raise_exception(env
, EXCP_DBE
);
2182 #endif /* !CONFIG_USER_ONLY */
2184 /* Complex FPU operations which may need stack space. */
2186 #define FLOAT_TWO32 make_float32(1 << 30)
2187 #define FLOAT_TWO64 make_float64(1ULL << 62)
2188 #define FP_TO_INT32_OVERFLOW 0x7fffffff
2189 #define FP_TO_INT64_OVERFLOW 0x7fffffffffffffffULL
2191 /* convert MIPS rounding mode in FCR31 to IEEE library */
2192 static unsigned int ieee_rm
[] = {
2193 float_round_nearest_even
,
2194 float_round_to_zero
,
2199 static inline void restore_rounding_mode(CPUMIPSState
*env
)
2201 set_float_rounding_mode(ieee_rm
[env
->active_fpu
.fcr31
& 3],
2202 &env
->active_fpu
.fp_status
);
2205 static inline void restore_flush_mode(CPUMIPSState
*env
)
2207 set_flush_to_zero((env
->active_fpu
.fcr31
& (1 << 24)) != 0,
2208 &env
->active_fpu
.fp_status
);
2211 target_ulong
helper_cfc1(CPUMIPSState
*env
, uint32_t reg
)
2213 target_ulong arg1
= 0;
2217 arg1
= (int32_t)env
->active_fpu
.fcr0
;
2220 /* UFR Support - Read Status FR */
2221 if (env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) {
2222 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2224 ((env
->CP0_Status
& (1 << CP0St_FR
)) >> CP0St_FR
);
2226 helper_raise_exception(env
, EXCP_RI
);
2231 arg1
= ((env
->active_fpu
.fcr31
>> 24) & 0xfe) | ((env
->active_fpu
.fcr31
>> 23) & 0x1);
2234 arg1
= env
->active_fpu
.fcr31
& 0x0003f07c;
2237 arg1
= (env
->active_fpu
.fcr31
& 0x00000f83) | ((env
->active_fpu
.fcr31
>> 22) & 0x4);
2240 arg1
= (int32_t)env
->active_fpu
.fcr31
;
2247 void helper_ctc1(CPUMIPSState
*env
, target_ulong arg1
, uint32_t fs
, uint32_t rt
)
2251 /* UFR Alias - Reset Status FR */
2252 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) && (rt
== 0))) {
2255 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2256 env
->CP0_Status
&= ~(1 << CP0St_FR
);
2257 compute_hflags(env
);
2259 helper_raise_exception(env
, EXCP_RI
);
2263 /* UNFR Alias - Set Status FR */
2264 if (!((env
->active_fpu
.fcr0
& (1 << FCR0_UFRP
)) && (rt
== 0))) {
2267 if (env
->CP0_Config5
& (1 << CP0C5_UFR
)) {
2268 env
->CP0_Status
|= (1 << CP0St_FR
);
2269 compute_hflags(env
);
2271 helper_raise_exception(env
, EXCP_RI
);
2275 if (arg1
& 0xffffff00)
2277 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0x017fffff) | ((arg1
& 0xfe) << 24) |
2278 ((arg1
& 0x1) << 23);
2281 if (arg1
& 0x007c0000)
2283 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfffc0f83) | (arg1
& 0x0003f07c);
2286 if (arg1
& 0x007c0000)
2288 env
->active_fpu
.fcr31
= (env
->active_fpu
.fcr31
& 0xfefff07c) | (arg1
& 0x00000f83) |
2289 ((arg1
& 0x4) << 22);
2292 if (arg1
& 0x007c0000)
2294 env
->active_fpu
.fcr31
= arg1
;
2299 /* set rounding mode */
2300 restore_rounding_mode(env
);
2301 /* set flush-to-zero mode */
2302 restore_flush_mode(env
);
2303 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2304 if ((GET_FP_ENABLE(env
->active_fpu
.fcr31
) | 0x20) & GET_FP_CAUSE(env
->active_fpu
.fcr31
)) {
2305 do_raise_exception(env
, EXCP_FPE
, GETPC());
2309 static int ieee_ex_to_mips(int xcpt
)
2313 if (xcpt
& float_flag_invalid
) {
2316 if (xcpt
& float_flag_overflow
) {
2319 if (xcpt
& float_flag_underflow
) {
2320 ret
|= FP_UNDERFLOW
;
2322 if (xcpt
& float_flag_divbyzero
) {
2325 if (xcpt
& float_flag_inexact
) {
2332 static inline void update_fcr31(CPUMIPSState
*env
, uintptr_t pc
)
2334 int tmp
= ieee_ex_to_mips(get_float_exception_flags(&env
->active_fpu
.fp_status
));
2336 SET_FP_CAUSE(env
->active_fpu
.fcr31
, tmp
);
2339 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2341 if (GET_FP_ENABLE(env
->active_fpu
.fcr31
) & tmp
) {
2342 do_raise_exception(env
, EXCP_FPE
, pc
);
2344 UPDATE_FP_FLAGS(env
->active_fpu
.fcr31
, tmp
);
2350 Single precition routines have a "s" suffix, double precision a
2351 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2352 paired single lower "pl", paired single upper "pu". */
2354 /* unary operations, modifying fp status */
2355 uint64_t helper_float_sqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2357 fdt0
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2358 update_fcr31(env
, GETPC());
2362 uint32_t helper_float_sqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2364 fst0
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2365 update_fcr31(env
, GETPC());
2369 uint64_t helper_float_cvtd_s(CPUMIPSState
*env
, uint32_t fst0
)
2373 fdt2
= float32_to_float64(fst0
, &env
->active_fpu
.fp_status
);
2374 update_fcr31(env
, GETPC());
2378 uint64_t helper_float_cvtd_w(CPUMIPSState
*env
, uint32_t wt0
)
2382 fdt2
= int32_to_float64(wt0
, &env
->active_fpu
.fp_status
);
2383 update_fcr31(env
, GETPC());
2387 uint64_t helper_float_cvtd_l(CPUMIPSState
*env
, uint64_t dt0
)
2391 fdt2
= int64_to_float64(dt0
, &env
->active_fpu
.fp_status
);
2392 update_fcr31(env
, GETPC());
2396 uint64_t helper_float_cvtl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2400 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2401 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2402 & (float_flag_invalid
| float_flag_overflow
)) {
2403 dt2
= FP_TO_INT64_OVERFLOW
;
2405 update_fcr31(env
, GETPC());
2409 uint64_t helper_float_cvtl_s(CPUMIPSState
*env
, uint32_t fst0
)
2413 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2414 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2415 & (float_flag_invalid
| float_flag_overflow
)) {
2416 dt2
= FP_TO_INT64_OVERFLOW
;
2418 update_fcr31(env
, GETPC());
2422 uint64_t helper_float_cvtps_pw(CPUMIPSState
*env
, uint64_t dt0
)
2427 fst2
= int32_to_float32(dt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2428 fsth2
= int32_to_float32(dt0
>> 32, &env
->active_fpu
.fp_status
);
2429 update_fcr31(env
, GETPC());
2430 return ((uint64_t)fsth2
<< 32) | fst2
;
2433 uint64_t helper_float_cvtpw_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2439 wt2
= float32_to_int32(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2440 excp
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2441 if (excp
& (float_flag_overflow
| float_flag_invalid
)) {
2442 wt2
= FP_TO_INT32_OVERFLOW
;
2445 set_float_exception_flags(0, &env
->active_fpu
.fp_status
);
2446 wth2
= float32_to_int32(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2447 excph
= get_float_exception_flags(&env
->active_fpu
.fp_status
);
2448 if (excph
& (float_flag_overflow
| float_flag_invalid
)) {
2449 wth2
= FP_TO_INT32_OVERFLOW
;
2452 set_float_exception_flags(excp
| excph
, &env
->active_fpu
.fp_status
);
2453 update_fcr31(env
, GETPC());
2455 return ((uint64_t)wth2
<< 32) | wt2
;
2458 uint32_t helper_float_cvts_d(CPUMIPSState
*env
, uint64_t fdt0
)
2462 fst2
= float64_to_float32(fdt0
, &env
->active_fpu
.fp_status
);
2463 update_fcr31(env
, GETPC());
2467 uint32_t helper_float_cvts_w(CPUMIPSState
*env
, uint32_t wt0
)
2471 fst2
= int32_to_float32(wt0
, &env
->active_fpu
.fp_status
);
2472 update_fcr31(env
, GETPC());
2476 uint32_t helper_float_cvts_l(CPUMIPSState
*env
, uint64_t dt0
)
2480 fst2
= int64_to_float32(dt0
, &env
->active_fpu
.fp_status
);
2481 update_fcr31(env
, GETPC());
2485 uint32_t helper_float_cvts_pl(CPUMIPSState
*env
, uint32_t wt0
)
2490 update_fcr31(env
, GETPC());
2494 uint32_t helper_float_cvts_pu(CPUMIPSState
*env
, uint32_t wth0
)
2499 update_fcr31(env
, GETPC());
2503 uint32_t helper_float_cvtw_s(CPUMIPSState
*env
, uint32_t fst0
)
2507 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2508 update_fcr31(env
, GETPC());
2509 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2510 & (float_flag_invalid
| float_flag_overflow
)) {
2511 wt2
= FP_TO_INT32_OVERFLOW
;
2516 uint32_t helper_float_cvtw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2520 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2521 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2522 & (float_flag_invalid
| float_flag_overflow
)) {
2523 wt2
= FP_TO_INT32_OVERFLOW
;
2525 update_fcr31(env
, GETPC());
2529 uint64_t helper_float_roundl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2533 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2534 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2535 restore_rounding_mode(env
);
2536 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2537 & (float_flag_invalid
| float_flag_overflow
)) {
2538 dt2
= FP_TO_INT64_OVERFLOW
;
2540 update_fcr31(env
, GETPC());
2544 uint64_t helper_float_roundl_s(CPUMIPSState
*env
, uint32_t fst0
)
2548 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2549 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2550 restore_rounding_mode(env
);
2551 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2552 & (float_flag_invalid
| float_flag_overflow
)) {
2553 dt2
= FP_TO_INT64_OVERFLOW
;
2555 update_fcr31(env
, GETPC());
2559 uint32_t helper_float_roundw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2563 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2564 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2565 restore_rounding_mode(env
);
2566 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2567 & (float_flag_invalid
| float_flag_overflow
)) {
2568 wt2
= FP_TO_INT32_OVERFLOW
;
2570 update_fcr31(env
, GETPC());
2574 uint32_t helper_float_roundw_s(CPUMIPSState
*env
, uint32_t fst0
)
2578 set_float_rounding_mode(float_round_nearest_even
, &env
->active_fpu
.fp_status
);
2579 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2580 restore_rounding_mode(env
);
2581 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2582 & (float_flag_invalid
| float_flag_overflow
)) {
2583 wt2
= FP_TO_INT32_OVERFLOW
;
2585 update_fcr31(env
, GETPC());
2589 uint64_t helper_float_truncl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2593 dt2
= float64_to_int64_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2594 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2595 & (float_flag_invalid
| float_flag_overflow
)) {
2596 dt2
= FP_TO_INT64_OVERFLOW
;
2598 update_fcr31(env
, GETPC());
2602 uint64_t helper_float_truncl_s(CPUMIPSState
*env
, uint32_t fst0
)
2606 dt2
= float32_to_int64_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2607 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2608 & (float_flag_invalid
| float_flag_overflow
)) {
2609 dt2
= FP_TO_INT64_OVERFLOW
;
2611 update_fcr31(env
, GETPC());
2615 uint32_t helper_float_truncw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2619 wt2
= float64_to_int32_round_to_zero(fdt0
, &env
->active_fpu
.fp_status
);
2620 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2621 & (float_flag_invalid
| float_flag_overflow
)) {
2622 wt2
= FP_TO_INT32_OVERFLOW
;
2624 update_fcr31(env
, GETPC());
2628 uint32_t helper_float_truncw_s(CPUMIPSState
*env
, uint32_t fst0
)
2632 wt2
= float32_to_int32_round_to_zero(fst0
, &env
->active_fpu
.fp_status
);
2633 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2634 & (float_flag_invalid
| float_flag_overflow
)) {
2635 wt2
= FP_TO_INT32_OVERFLOW
;
2637 update_fcr31(env
, GETPC());
2641 uint64_t helper_float_ceill_d(CPUMIPSState
*env
, uint64_t fdt0
)
2645 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2646 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2647 restore_rounding_mode(env
);
2648 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2649 & (float_flag_invalid
| float_flag_overflow
)) {
2650 dt2
= FP_TO_INT64_OVERFLOW
;
2652 update_fcr31(env
, GETPC());
2656 uint64_t helper_float_ceill_s(CPUMIPSState
*env
, uint32_t fst0
)
2660 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2661 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2662 restore_rounding_mode(env
);
2663 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2664 & (float_flag_invalid
| float_flag_overflow
)) {
2665 dt2
= FP_TO_INT64_OVERFLOW
;
2667 update_fcr31(env
, GETPC());
2671 uint32_t helper_float_ceilw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2675 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2676 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2677 restore_rounding_mode(env
);
2678 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2679 & (float_flag_invalid
| float_flag_overflow
)) {
2680 wt2
= FP_TO_INT32_OVERFLOW
;
2682 update_fcr31(env
, GETPC());
2686 uint32_t helper_float_ceilw_s(CPUMIPSState
*env
, uint32_t fst0
)
2690 set_float_rounding_mode(float_round_up
, &env
->active_fpu
.fp_status
);
2691 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2692 restore_rounding_mode(env
);
2693 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2694 & (float_flag_invalid
| float_flag_overflow
)) {
2695 wt2
= FP_TO_INT32_OVERFLOW
;
2697 update_fcr31(env
, GETPC());
2701 uint64_t helper_float_floorl_d(CPUMIPSState
*env
, uint64_t fdt0
)
2705 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2706 dt2
= float64_to_int64(fdt0
, &env
->active_fpu
.fp_status
);
2707 restore_rounding_mode(env
);
2708 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2709 & (float_flag_invalid
| float_flag_overflow
)) {
2710 dt2
= FP_TO_INT64_OVERFLOW
;
2712 update_fcr31(env
, GETPC());
2716 uint64_t helper_float_floorl_s(CPUMIPSState
*env
, uint32_t fst0
)
2720 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2721 dt2
= float32_to_int64(fst0
, &env
->active_fpu
.fp_status
);
2722 restore_rounding_mode(env
);
2723 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2724 & (float_flag_invalid
| float_flag_overflow
)) {
2725 dt2
= FP_TO_INT64_OVERFLOW
;
2727 update_fcr31(env
, GETPC());
2731 uint32_t helper_float_floorw_d(CPUMIPSState
*env
, uint64_t fdt0
)
2735 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2736 wt2
= float64_to_int32(fdt0
, &env
->active_fpu
.fp_status
);
2737 restore_rounding_mode(env
);
2738 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2739 & (float_flag_invalid
| float_flag_overflow
)) {
2740 wt2
= FP_TO_INT32_OVERFLOW
;
2742 update_fcr31(env
, GETPC());
2746 uint32_t helper_float_floorw_s(CPUMIPSState
*env
, uint32_t fst0
)
2750 set_float_rounding_mode(float_round_down
, &env
->active_fpu
.fp_status
);
2751 wt2
= float32_to_int32(fst0
, &env
->active_fpu
.fp_status
);
2752 restore_rounding_mode(env
);
2753 if (get_float_exception_flags(&env
->active_fpu
.fp_status
)
2754 & (float_flag_invalid
| float_flag_overflow
)) {
2755 wt2
= FP_TO_INT32_OVERFLOW
;
2757 update_fcr31(env
, GETPC());
2761 /* unary operations, not modifying fp status */
2762 #define FLOAT_UNOP(name) \
2763 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
2765 return float64_ ## name(fdt0); \
2767 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
2769 return float32_ ## name(fst0); \
2771 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
2776 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2777 wth0 = float32_ ## name(fdt0 >> 32); \
2778 return ((uint64_t)wth0 << 32) | wt0; \
2784 /* MIPS specific unary operations */
2785 uint64_t helper_float_recip_d(CPUMIPSState
*env
, uint64_t fdt0
)
2789 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
2790 update_fcr31(env
, GETPC());
2794 uint32_t helper_float_recip_s(CPUMIPSState
*env
, uint32_t fst0
)
2798 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
2799 update_fcr31(env
, GETPC());
2803 uint64_t helper_float_rsqrt_d(CPUMIPSState
*env
, uint64_t fdt0
)
2807 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2808 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
2809 update_fcr31(env
, GETPC());
2813 uint32_t helper_float_rsqrt_s(CPUMIPSState
*env
, uint32_t fst0
)
2817 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2818 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2819 update_fcr31(env
, GETPC());
2823 uint64_t helper_float_recip1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2827 fdt2
= float64_div(float64_one
, fdt0
, &env
->active_fpu
.fp_status
);
2828 update_fcr31(env
, GETPC());
2832 uint32_t helper_float_recip1_s(CPUMIPSState
*env
, uint32_t fst0
)
2836 fst2
= float32_div(float32_one
, fst0
, &env
->active_fpu
.fp_status
);
2837 update_fcr31(env
, GETPC());
2841 uint64_t helper_float_recip1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2846 fst2
= float32_div(float32_one
, fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2847 fsth2
= float32_div(float32_one
, fdt0
>> 32, &env
->active_fpu
.fp_status
);
2848 update_fcr31(env
, GETPC());
2849 return ((uint64_t)fsth2
<< 32) | fst2
;
2852 uint64_t helper_float_rsqrt1_d(CPUMIPSState
*env
, uint64_t fdt0
)
2856 fdt2
= float64_sqrt(fdt0
, &env
->active_fpu
.fp_status
);
2857 fdt2
= float64_div(float64_one
, fdt2
, &env
->active_fpu
.fp_status
);
2858 update_fcr31(env
, GETPC());
2862 uint32_t helper_float_rsqrt1_s(CPUMIPSState
*env
, uint32_t fst0
)
2866 fst2
= float32_sqrt(fst0
, &env
->active_fpu
.fp_status
);
2867 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2868 update_fcr31(env
, GETPC());
2872 uint64_t helper_float_rsqrt1_ps(CPUMIPSState
*env
, uint64_t fdt0
)
2877 fst2
= float32_sqrt(fdt0
& 0XFFFFFFFF, &env
->active_fpu
.fp_status
);
2878 fsth2
= float32_sqrt(fdt0
>> 32, &env
->active_fpu
.fp_status
);
2879 fst2
= float32_div(float32_one
, fst2
, &env
->active_fpu
.fp_status
);
2880 fsth2
= float32_div(float32_one
, fsth2
, &env
->active_fpu
.fp_status
);
2881 update_fcr31(env
, GETPC());
2882 return ((uint64_t)fsth2
<< 32) | fst2
;
2885 #define FLOAT_OP(name, p) void helper_float_##name##_##p(CPUMIPSState *env)
2887 /* binary operations */
2888 #define FLOAT_BINOP(name) \
2889 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2890 uint64_t fdt0, uint64_t fdt1) \
2894 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2895 update_fcr31(env, GETPC()); \
2899 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
2900 uint32_t fst0, uint32_t fst1) \
2904 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2905 update_fcr31(env, GETPC()); \
2909 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
2913 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2914 uint32_t fsth0 = fdt0 >> 32; \
2915 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2916 uint32_t fsth1 = fdt1 >> 32; \
2920 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2921 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
2922 update_fcr31(env, GETPC()); \
2923 return ((uint64_t)wth2 << 32) | wt2; \
2932 #define UNFUSED_FMA(prefix, a, b, c, flags) \
2934 a = prefix##_mul(a, b, &env->active_fpu.fp_status); \
2935 if ((flags) & float_muladd_negate_c) { \
2936 a = prefix##_sub(a, c, &env->active_fpu.fp_status); \
2938 a = prefix##_add(a, c, &env->active_fpu.fp_status); \
2940 if ((flags) & float_muladd_negate_result) { \
2941 a = prefix##_chs(a); \
2945 /* FMA based operations */
2946 #define FLOAT_FMA(name, type) \
2947 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2948 uint64_t fdt0, uint64_t fdt1, \
2951 UNFUSED_FMA(float64, fdt0, fdt1, fdt2, type); \
2952 update_fcr31(env, GETPC()); \
2956 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
2957 uint32_t fst0, uint32_t fst1, \
2960 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
2961 update_fcr31(env, GETPC()); \
2965 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
2966 uint64_t fdt0, uint64_t fdt1, \
2969 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2970 uint32_t fsth0 = fdt0 >> 32; \
2971 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2972 uint32_t fsth1 = fdt1 >> 32; \
2973 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2974 uint32_t fsth2 = fdt2 >> 32; \
2976 UNFUSED_FMA(float32, fst0, fst1, fst2, type); \
2977 UNFUSED_FMA(float32, fsth0, fsth1, fsth2, type); \
2978 update_fcr31(env, GETPC()); \
2979 return ((uint64_t)fsth0 << 32) | fst0; \
2982 FLOAT_FMA(msub
, float_muladd_negate_c
)
2983 FLOAT_FMA(nmadd
, float_muladd_negate_result
)
2984 FLOAT_FMA(nmsub
, float_muladd_negate_result
| float_muladd_negate_c
)
2987 /* MIPS specific binary operations */
2988 uint64_t helper_float_recip2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
2990 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
2991 fdt2
= float64_chs(float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
));
2992 update_fcr31(env
, GETPC());
2996 uint32_t helper_float_recip2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
2998 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
2999 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3000 update_fcr31(env
, GETPC());
3004 uint64_t helper_float_recip2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3006 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3007 uint32_t fsth0
= fdt0
>> 32;
3008 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3009 uint32_t fsth2
= fdt2
>> 32;
3011 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3012 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3013 fst2
= float32_chs(float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
));
3014 fsth2
= float32_chs(float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
));
3015 update_fcr31(env
, GETPC());
3016 return ((uint64_t)fsth2
<< 32) | fst2
;
3019 uint64_t helper_float_rsqrt2_d(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3021 fdt2
= float64_mul(fdt0
, fdt2
, &env
->active_fpu
.fp_status
);
3022 fdt2
= float64_sub(fdt2
, float64_one
, &env
->active_fpu
.fp_status
);
3023 fdt2
= float64_chs(float64_div(fdt2
, FLOAT_TWO64
, &env
->active_fpu
.fp_status
));
3024 update_fcr31(env
, GETPC());
3028 uint32_t helper_float_rsqrt2_s(CPUMIPSState
*env
, uint32_t fst0
, uint32_t fst2
)
3030 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3031 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3032 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3033 update_fcr31(env
, GETPC());
3037 uint64_t helper_float_rsqrt2_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt2
)
3039 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3040 uint32_t fsth0
= fdt0
>> 32;
3041 uint32_t fst2
= fdt2
& 0XFFFFFFFF;
3042 uint32_t fsth2
= fdt2
>> 32;
3044 fst2
= float32_mul(fst0
, fst2
, &env
->active_fpu
.fp_status
);
3045 fsth2
= float32_mul(fsth0
, fsth2
, &env
->active_fpu
.fp_status
);
3046 fst2
= float32_sub(fst2
, float32_one
, &env
->active_fpu
.fp_status
);
3047 fsth2
= float32_sub(fsth2
, float32_one
, &env
->active_fpu
.fp_status
);
3048 fst2
= float32_chs(float32_div(fst2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3049 fsth2
= float32_chs(float32_div(fsth2
, FLOAT_TWO32
, &env
->active_fpu
.fp_status
));
3050 update_fcr31(env
, GETPC());
3051 return ((uint64_t)fsth2
<< 32) | fst2
;
3054 uint64_t helper_float_addr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3056 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3057 uint32_t fsth0
= fdt0
>> 32;
3058 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3059 uint32_t fsth1
= fdt1
>> 32;
3063 fst2
= float32_add (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3064 fsth2
= float32_add (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3065 update_fcr31(env
, GETPC());
3066 return ((uint64_t)fsth2
<< 32) | fst2
;
3069 uint64_t helper_float_mulr_ps(CPUMIPSState
*env
, uint64_t fdt0
, uint64_t fdt1
)
3071 uint32_t fst0
= fdt0
& 0XFFFFFFFF;
3072 uint32_t fsth0
= fdt0
>> 32;
3073 uint32_t fst1
= fdt1
& 0XFFFFFFFF;
3074 uint32_t fsth1
= fdt1
>> 32;
3078 fst2
= float32_mul (fst0
, fsth0
, &env
->active_fpu
.fp_status
);
3079 fsth2
= float32_mul (fst1
, fsth1
, &env
->active_fpu
.fp_status
);
3080 update_fcr31(env
, GETPC());
3081 return ((uint64_t)fsth2
<< 32) | fst2
;
3084 /* compare operations */
3085 #define FOP_COND_D(op, cond) \
3086 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3087 uint64_t fdt1, int cc) \
3091 update_fcr31(env, GETPC()); \
3093 SET_FP_COND(cc, env->active_fpu); \
3095 CLEAR_FP_COND(cc, env->active_fpu); \
3097 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3098 uint64_t fdt1, int cc) \
3101 fdt0 = float64_abs(fdt0); \
3102 fdt1 = float64_abs(fdt1); \
3104 update_fcr31(env, GETPC()); \
3106 SET_FP_COND(cc, env->active_fpu); \
3108 CLEAR_FP_COND(cc, env->active_fpu); \
3111 /* NOTE: the comma operator will make "cond" to eval to false,
3112 * but float64_unordered_quiet() is still called. */
3113 FOP_COND_D(f
, (float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3114 FOP_COND_D(un
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3115 FOP_COND_D(eq
, float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3116 FOP_COND_D(ueq
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3117 FOP_COND_D(olt
, float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3118 FOP_COND_D(ult
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3119 FOP_COND_D(ole
, float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3120 FOP_COND_D(ule
, float64_unordered_quiet(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le_quiet(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3121 /* NOTE: the comma operator will make "cond" to eval to false,
3122 * but float64_unordered() is still called. */
3123 FOP_COND_D(sf
, (float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
), 0))
3124 FOP_COND_D(ngle
,float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
))
3125 FOP_COND_D(seq
, float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3126 FOP_COND_D(ngl
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_eq(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3127 FOP_COND_D(lt
, float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3128 FOP_COND_D(nge
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_lt(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3129 FOP_COND_D(le
, float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3130 FOP_COND_D(ngt
, float64_unordered(fdt1
, fdt0
, &env
->active_fpu
.fp_status
) || float64_le(fdt0
, fdt1
, &env
->active_fpu
.fp_status
))
3132 #define FOP_COND_S(op, cond) \
3133 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3134 uint32_t fst1, int cc) \
3138 update_fcr31(env, GETPC()); \
3140 SET_FP_COND(cc, env->active_fpu); \
3142 CLEAR_FP_COND(cc, env->active_fpu); \
3144 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3145 uint32_t fst1, int cc) \
3148 fst0 = float32_abs(fst0); \
3149 fst1 = float32_abs(fst1); \
3151 update_fcr31(env, GETPC()); \
3153 SET_FP_COND(cc, env->active_fpu); \
3155 CLEAR_FP_COND(cc, env->active_fpu); \
3158 /* NOTE: the comma operator will make "cond" to eval to false,
3159 * but float32_unordered_quiet() is still called. */
3160 FOP_COND_S(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3161 FOP_COND_S(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3162 FOP_COND_S(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3163 FOP_COND_S(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3164 FOP_COND_S(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3165 FOP_COND_S(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3166 FOP_COND_S(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3167 FOP_COND_S(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3168 /* NOTE: the comma operator will make "cond" to eval to false,
3169 * but float32_unordered() is still called. */
3170 FOP_COND_S(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0))
3171 FOP_COND_S(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
))
3172 FOP_COND_S(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3173 FOP_COND_S(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3174 FOP_COND_S(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3175 FOP_COND_S(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3176 FOP_COND_S(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3177 FOP_COND_S(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
))
3179 #define FOP_COND_PS(op, condl, condh) \
3180 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3181 uint64_t fdt1, int cc) \
3183 uint32_t fst0, fsth0, fst1, fsth1; \
3185 fst0 = fdt0 & 0XFFFFFFFF; \
3186 fsth0 = fdt0 >> 32; \
3187 fst1 = fdt1 & 0XFFFFFFFF; \
3188 fsth1 = fdt1 >> 32; \
3191 update_fcr31(env, GETPC()); \
3193 SET_FP_COND(cc, env->active_fpu); \
3195 CLEAR_FP_COND(cc, env->active_fpu); \
3197 SET_FP_COND(cc + 1, env->active_fpu); \
3199 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3201 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3202 uint64_t fdt1, int cc) \
3204 uint32_t fst0, fsth0, fst1, fsth1; \
3206 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
3207 fsth0 = float32_abs(fdt0 >> 32); \
3208 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
3209 fsth1 = float32_abs(fdt1 >> 32); \
3212 update_fcr31(env, GETPC()); \
3214 SET_FP_COND(cc, env->active_fpu); \
3216 CLEAR_FP_COND(cc, env->active_fpu); \
3218 SET_FP_COND(cc + 1, env->active_fpu); \
3220 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3223 /* NOTE: the comma operator will make "cond" to eval to false,
3224 * but float32_unordered_quiet() is still called. */
3225 FOP_COND_PS(f
, (float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3226 (float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3227 FOP_COND_PS(un
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3228 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3229 FOP_COND_PS(eq
, float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3230 float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3231 FOP_COND_PS(ueq
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3232 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3233 FOP_COND_PS(olt
, float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3234 float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3235 FOP_COND_PS(ult
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3236 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3237 FOP_COND_PS(ole
, float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3238 float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3239 FOP_COND_PS(ule
, float32_unordered_quiet(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3240 float32_unordered_quiet(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le_quiet(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3241 /* NOTE: the comma operator will make "cond" to eval to false,
3242 * but float32_unordered() is still called. */
3243 FOP_COND_PS(sf
, (float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
), 0),
3244 (float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
), 0))
3245 FOP_COND_PS(ngle
,float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
),
3246 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
))
3247 FOP_COND_PS(seq
, float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3248 float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3249 FOP_COND_PS(ngl
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_eq(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3250 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_eq(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3251 FOP_COND_PS(lt
, float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3252 float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3253 FOP_COND_PS(nge
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_lt(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3254 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_lt(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3255 FOP_COND_PS(le
, float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3256 float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))
3257 FOP_COND_PS(ngt
, float32_unordered(fst1
, fst0
, &env
->active_fpu
.fp_status
) || float32_le(fst0
, fst1
, &env
->active_fpu
.fp_status
),
3258 float32_unordered(fsth1
, fsth0
, &env
->active_fpu
.fp_status
) || float32_le(fsth0
, fsth1
, &env
->active_fpu
.fp_status
))