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 "host-utils.h"
25 #if !defined(CONFIG_USER_ONLY)
26 #include "softmmu_exec.h"
27 #endif /* !defined(CONFIG_USER_ONLY) */
29 #ifndef CONFIG_USER_ONLY
30 static inline void cpu_mips_tlb_flush (CPUMIPSState *env, int flush_global);
33 /*****************************************************************************/
34 /* Exceptions processing helpers */
36 void helper_raise_exception_err(CPUMIPSState *env, uint32_t exception,
40 if (exception < 0x100)
41 qemu_log("%s: %d %d\n", __func__, exception, error_code);
43 env->exception_index = exception;
44 env->error_code = error_code;
48 void helper_raise_exception(CPUMIPSState *env, uint32_t exception)
50 helper_raise_exception_err(env, exception, 0);
53 #if !defined(CONFIG_USER_ONLY)
54 static void do_restore_state(CPUMIPSState *env, uintptr_t pc)
60 cpu_restore_state(tb, env, pc);
65 #if defined(CONFIG_USER_ONLY)
66 #define HELPER_LD(name, insn, type) \
67 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
70 return (type) insn##_raw(addr); \
73 #define HELPER_LD(name, insn, type) \
74 static inline type do_##name(CPUMIPSState *env, target_ulong addr, \
79 case 0: return (type) cpu_##insn##_kernel(env, addr); break; \
80 case 1: return (type) cpu_##insn##_super(env, addr); break; \
82 case 2: return (type) cpu_##insn##_user(env, addr); break; \
86 HELPER_LD(lbu, ldub, uint8_t)
87 HELPER_LD(lw, ldl, int32_t)
89 HELPER_LD(ld, ldq, int64_t)
93 #if defined(CONFIG_USER_ONLY)
94 #define HELPER_ST(name, insn, type) \
95 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
96 type val, int mem_idx) \
98 insn##_raw(addr, val); \
101 #define HELPER_ST(name, insn, type) \
102 static inline void do_##name(CPUMIPSState *env, target_ulong addr, \
103 type val, int mem_idx) \
107 case 0: cpu_##insn##_kernel(env, addr, val); break; \
108 case 1: cpu_##insn##_super(env, addr, val); break; \
110 case 2: cpu_##insn##_user(env, addr, val); break; \
114 HELPER_ST(sb, stb, uint8_t)
115 HELPER_ST(sw, stl, uint32_t)
117 HELPER_ST(sd, stq, uint64_t)
121 target_ulong helper_clo (target_ulong arg1)
126 target_ulong helper_clz (target_ulong arg1)
131 #if defined(TARGET_MIPS64)
132 target_ulong helper_dclo (target_ulong arg1)
137 target_ulong helper_dclz (target_ulong arg1)
141 #endif /* TARGET_MIPS64 */
143 /* 64 bits arithmetic for 32 bits hosts */
144 static inline uint64_t get_HILO(CPUMIPSState *env)
146 return ((uint64_t)(env->active_tc.HI[0]) << 32) | (uint32_t)env->active_tc.LO[0];
149 static inline target_ulong set_HIT0_LO(CPUMIPSState *env, uint64_t HILO)
152 env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
153 tmp = env->active_tc.HI[0] = (int32_t)(HILO >> 32);
157 static inline target_ulong set_HI_LOT0(CPUMIPSState *env, uint64_t HILO)
159 target_ulong tmp = env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
160 env->active_tc.HI[0] = (int32_t)(HILO >> 32);
164 /* Multiplication variants of the vr54xx. */
165 target_ulong helper_muls(CPUMIPSState *env, target_ulong arg1,
168 return set_HI_LOT0(env, 0 - ((int64_t)(int32_t)arg1 *
169 (int64_t)(int32_t)arg2));
172 target_ulong helper_mulsu(CPUMIPSState *env, target_ulong arg1,
175 return set_HI_LOT0(env, 0 - (uint64_t)(uint32_t)arg1 *
176 (uint64_t)(uint32_t)arg2);
179 target_ulong helper_macc(CPUMIPSState *env, target_ulong arg1,
182 return set_HI_LOT0(env, (int64_t)get_HILO(env) + (int64_t)(int32_t)arg1 *
183 (int64_t)(int32_t)arg2);
186 target_ulong helper_macchi(CPUMIPSState *env, target_ulong arg1,
189 return set_HIT0_LO(env, (int64_t)get_HILO(env) + (int64_t)(int32_t)arg1 *
190 (int64_t)(int32_t)arg2);
193 target_ulong helper_maccu(CPUMIPSState *env, target_ulong arg1,
196 return set_HI_LOT0(env, (uint64_t)get_HILO(env) +
197 (uint64_t)(uint32_t)arg1 * (uint64_t)(uint32_t)arg2);
200 target_ulong helper_macchiu(CPUMIPSState *env, target_ulong arg1,
203 return set_HIT0_LO(env, (uint64_t)get_HILO(env) +
204 (uint64_t)(uint32_t)arg1 * (uint64_t)(uint32_t)arg2);
207 target_ulong helper_msac(CPUMIPSState *env, target_ulong arg1,
210 return set_HI_LOT0(env, (int64_t)get_HILO(env) - (int64_t)(int32_t)arg1 *
211 (int64_t)(int32_t)arg2);
214 target_ulong helper_msachi(CPUMIPSState *env, target_ulong arg1,
217 return set_HIT0_LO(env, (int64_t)get_HILO(env) - (int64_t)(int32_t)arg1 *
218 (int64_t)(int32_t)arg2);
221 target_ulong helper_msacu(CPUMIPSState *env, target_ulong arg1,
224 return set_HI_LOT0(env, (uint64_t)get_HILO(env) -
225 (uint64_t)(uint32_t)arg1 * (uint64_t)(uint32_t)arg2);
228 target_ulong helper_msachiu(CPUMIPSState *env, target_ulong arg1,
231 return set_HIT0_LO(env, (uint64_t)get_HILO(env) -
232 (uint64_t)(uint32_t)arg1 * (uint64_t)(uint32_t)arg2);
235 target_ulong helper_mulhi(CPUMIPSState *env, target_ulong arg1,
238 return set_HIT0_LO(env, (int64_t)(int32_t)arg1 * (int64_t)(int32_t)arg2);
241 target_ulong helper_mulhiu(CPUMIPSState *env, target_ulong arg1,
244 return set_HIT0_LO(env, (uint64_t)(uint32_t)arg1 *
245 (uint64_t)(uint32_t)arg2);
248 target_ulong helper_mulshi(CPUMIPSState *env, target_ulong arg1,
251 return set_HIT0_LO(env, 0 - (int64_t)(int32_t)arg1 *
252 (int64_t)(int32_t)arg2);
255 target_ulong helper_mulshiu(CPUMIPSState *env, target_ulong arg1,
258 return set_HIT0_LO(env, 0 - (uint64_t)(uint32_t)arg1 *
259 (uint64_t)(uint32_t)arg2);
263 void helper_dmult(CPUMIPSState *env, target_ulong arg1, target_ulong arg2)
265 muls64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), arg1, arg2);
268 void helper_dmultu(CPUMIPSState *env, target_ulong arg1, target_ulong arg2)
270 mulu64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), arg1, arg2);
274 #ifndef CONFIG_USER_ONLY
276 static inline target_phys_addr_t do_translate_address(CPUMIPSState *env,
277 target_ulong address,
280 target_phys_addr_t lladdr;
282 lladdr = cpu_mips_translate_address(env, address, rw);
284 if (lladdr == -1LL) {
291 #define HELPER_LD_ATOMIC(name, insn) \
292 target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
294 env->lladdr = do_translate_address(env, arg, 0); \
295 env->llval = do_##insn(env, arg, mem_idx); \
298 HELPER_LD_ATOMIC(ll, lw)
300 HELPER_LD_ATOMIC(lld, ld)
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 helper_raise_exception(env, EXCP_AdES); \
314 if (do_translate_address(env, arg2, 1) == env->lladdr) { \
315 tmp = do_##ld_insn(env, arg2, mem_idx); \
316 if (tmp == env->llval) { \
317 do_##st_insn(env, arg2, arg1, mem_idx); \
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 target_ulong helper_lwl(CPUMIPSState *env, target_ulong arg1,
339 target_ulong arg2, int mem_idx)
343 tmp = do_lbu(env, arg2, mem_idx);
344 arg1 = (arg1 & 0x00FFFFFF) | (tmp << 24);
346 if (GET_LMASK(arg2) <= 2) {
347 tmp = do_lbu(env, GET_OFFSET(arg2, 1), mem_idx);
348 arg1 = (arg1 & 0xFF00FFFF) | (tmp << 16);
351 if (GET_LMASK(arg2) <= 1) {
352 tmp = do_lbu(env, GET_OFFSET(arg2, 2), mem_idx);
353 arg1 = (arg1 & 0xFFFF00FF) | (tmp << 8);
356 if (GET_LMASK(arg2) == 0) {
357 tmp = do_lbu(env, GET_OFFSET(arg2, 3), mem_idx);
358 arg1 = (arg1 & 0xFFFFFF00) | tmp;
360 return (int32_t)arg1;
363 target_ulong helper_lwr(CPUMIPSState *env, target_ulong arg1,
364 target_ulong arg2, int mem_idx)
368 tmp = do_lbu(env, arg2, mem_idx);
369 arg1 = (arg1 & 0xFFFFFF00) | tmp;
371 if (GET_LMASK(arg2) >= 1) {
372 tmp = do_lbu(env, GET_OFFSET(arg2, -1), mem_idx);
373 arg1 = (arg1 & 0xFFFF00FF) | (tmp << 8);
376 if (GET_LMASK(arg2) >= 2) {
377 tmp = do_lbu(env, GET_OFFSET(arg2, -2), mem_idx);
378 arg1 = (arg1 & 0xFF00FFFF) | (tmp << 16);
381 if (GET_LMASK(arg2) == 3) {
382 tmp = do_lbu(env, GET_OFFSET(arg2, -3), mem_idx);
383 arg1 = (arg1 & 0x00FFFFFF) | (tmp << 24);
385 return (int32_t)arg1;
388 void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
391 do_sb(env, arg2, (uint8_t)(arg1 >> 24), mem_idx);
393 if (GET_LMASK(arg2) <= 2)
394 do_sb(env, GET_OFFSET(arg2, 1), (uint8_t)(arg1 >> 16), mem_idx);
396 if (GET_LMASK(arg2) <= 1)
397 do_sb(env, GET_OFFSET(arg2, 2), (uint8_t)(arg1 >> 8), mem_idx);
399 if (GET_LMASK(arg2) == 0)
400 do_sb(env, GET_OFFSET(arg2, 3), (uint8_t)arg1, mem_idx);
403 void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
406 do_sb(env, arg2, (uint8_t)arg1, mem_idx);
408 if (GET_LMASK(arg2) >= 1)
409 do_sb(env, GET_OFFSET(arg2, -1), (uint8_t)(arg1 >> 8), mem_idx);
411 if (GET_LMASK(arg2) >= 2)
412 do_sb(env, GET_OFFSET(arg2, -2), (uint8_t)(arg1 >> 16), mem_idx);
414 if (GET_LMASK(arg2) == 3)
415 do_sb(env, GET_OFFSET(arg2, -3), (uint8_t)(arg1 >> 24), mem_idx);
418 #if defined(TARGET_MIPS64)
419 /* "half" load and stores. We must do the memory access inline,
420 or fault handling won't work. */
422 #ifdef TARGET_WORDS_BIGENDIAN
423 #define GET_LMASK64(v) ((v) & 7)
425 #define GET_LMASK64(v) (((v) & 7) ^ 7)
428 target_ulong helper_ldl(CPUMIPSState *env, target_ulong arg1,
429 target_ulong arg2, int mem_idx)
433 tmp = do_lbu(env, arg2, mem_idx);
434 arg1 = (arg1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
436 if (GET_LMASK64(arg2) <= 6) {
437 tmp = do_lbu(env, GET_OFFSET(arg2, 1), mem_idx);
438 arg1 = (arg1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
441 if (GET_LMASK64(arg2) <= 5) {
442 tmp = do_lbu(env, GET_OFFSET(arg2, 2), mem_idx);
443 arg1 = (arg1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
446 if (GET_LMASK64(arg2) <= 4) {
447 tmp = do_lbu(env, GET_OFFSET(arg2, 3), mem_idx);
448 arg1 = (arg1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
451 if (GET_LMASK64(arg2) <= 3) {
452 tmp = do_lbu(env, GET_OFFSET(arg2, 4), mem_idx);
453 arg1 = (arg1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
456 if (GET_LMASK64(arg2) <= 2) {
457 tmp = do_lbu(env, GET_OFFSET(arg2, 5), mem_idx);
458 arg1 = (arg1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
461 if (GET_LMASK64(arg2) <= 1) {
462 tmp = do_lbu(env, GET_OFFSET(arg2, 6), mem_idx);
463 arg1 = (arg1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
466 if (GET_LMASK64(arg2) == 0) {
467 tmp = do_lbu(env, GET_OFFSET(arg2, 7), mem_idx);
468 arg1 = (arg1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
474 target_ulong helper_ldr(CPUMIPSState *env, target_ulong arg1,
475 target_ulong arg2, int mem_idx)
479 tmp = do_lbu(env, arg2, mem_idx);
480 arg1 = (arg1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
482 if (GET_LMASK64(arg2) >= 1) {
483 tmp = do_lbu(env, GET_OFFSET(arg2, -1), mem_idx);
484 arg1 = (arg1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
487 if (GET_LMASK64(arg2) >= 2) {
488 tmp = do_lbu(env, GET_OFFSET(arg2, -2), mem_idx);
489 arg1 = (arg1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
492 if (GET_LMASK64(arg2) >= 3) {
493 tmp = do_lbu(env, GET_OFFSET(arg2, -3), mem_idx);
494 arg1 = (arg1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
497 if (GET_LMASK64(arg2) >= 4) {
498 tmp = do_lbu(env, GET_OFFSET(arg2, -4), mem_idx);
499 arg1 = (arg1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
502 if (GET_LMASK64(arg2) >= 5) {
503 tmp = do_lbu(env, GET_OFFSET(arg2, -5), mem_idx);
504 arg1 = (arg1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
507 if (GET_LMASK64(arg2) >= 6) {
508 tmp = do_lbu(env, GET_OFFSET(arg2, -6), mem_idx);
509 arg1 = (arg1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
512 if (GET_LMASK64(arg2) == 7) {
513 tmp = do_lbu(env, GET_OFFSET(arg2, -7), mem_idx);
514 arg1 = (arg1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
520 void helper_sdl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
523 do_sb(env, arg2, (uint8_t)(arg1 >> 56), mem_idx);
525 if (GET_LMASK64(arg2) <= 6)
526 do_sb(env, GET_OFFSET(arg2, 1), (uint8_t)(arg1 >> 48), mem_idx);
528 if (GET_LMASK64(arg2) <= 5)
529 do_sb(env, GET_OFFSET(arg2, 2), (uint8_t)(arg1 >> 40), mem_idx);
531 if (GET_LMASK64(arg2) <= 4)
532 do_sb(env, GET_OFFSET(arg2, 3), (uint8_t)(arg1 >> 32), mem_idx);
534 if (GET_LMASK64(arg2) <= 3)
535 do_sb(env, GET_OFFSET(arg2, 4), (uint8_t)(arg1 >> 24), mem_idx);
537 if (GET_LMASK64(arg2) <= 2)
538 do_sb(env, GET_OFFSET(arg2, 5), (uint8_t)(arg1 >> 16), mem_idx);
540 if (GET_LMASK64(arg2) <= 1)
541 do_sb(env, GET_OFFSET(arg2, 6), (uint8_t)(arg1 >> 8), mem_idx);
543 if (GET_LMASK64(arg2) <= 0)
544 do_sb(env, GET_OFFSET(arg2, 7), (uint8_t)arg1, mem_idx);
547 void helper_sdr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
550 do_sb(env, arg2, (uint8_t)arg1, mem_idx);
552 if (GET_LMASK64(arg2) >= 1)
553 do_sb(env, GET_OFFSET(arg2, -1), (uint8_t)(arg1 >> 8), mem_idx);
555 if (GET_LMASK64(arg2) >= 2)
556 do_sb(env, GET_OFFSET(arg2, -2), (uint8_t)(arg1 >> 16), mem_idx);
558 if (GET_LMASK64(arg2) >= 3)
559 do_sb(env, GET_OFFSET(arg2, -3), (uint8_t)(arg1 >> 24), mem_idx);
561 if (GET_LMASK64(arg2) >= 4)
562 do_sb(env, GET_OFFSET(arg2, -4), (uint8_t)(arg1 >> 32), mem_idx);
564 if (GET_LMASK64(arg2) >= 5)
565 do_sb(env, GET_OFFSET(arg2, -5), (uint8_t)(arg1 >> 40), mem_idx);
567 if (GET_LMASK64(arg2) >= 6)
568 do_sb(env, GET_OFFSET(arg2, -6), (uint8_t)(arg1 >> 48), mem_idx);
570 if (GET_LMASK64(arg2) == 7)
571 do_sb(env, GET_OFFSET(arg2, -7), (uint8_t)(arg1 >> 56), mem_idx);
573 #endif /* TARGET_MIPS64 */
575 static const int multiple_regs[] = { 16, 17, 18, 19, 20, 21, 22, 23, 30 };
577 void helper_lwm(CPUMIPSState *env, target_ulong addr, target_ulong reglist,
580 target_ulong base_reglist = reglist & 0xf;
581 target_ulong do_r31 = reglist & 0x10;
582 #ifdef CONFIG_USER_ONLY
584 #define ldfun(env, addr) ldl_raw(addr)
586 uint32_t (*ldfun)(CPUMIPSState *env, target_ulong);
590 case 0: ldfun = cpu_ldl_kernel; break;
591 case 1: ldfun = cpu_ldl_super; break;
593 case 2: ldfun = cpu_ldl_user; break;
597 if (base_reglist > 0 && base_reglist <= ARRAY_SIZE (multiple_regs)) {
600 for (i = 0; i < base_reglist; i++) {
601 env->active_tc.gpr[multiple_regs[i]] = (target_long)ldfun(env, addr);
607 env->active_tc.gpr[31] = (target_long)ldfun(env, addr);
611 void helper_swm(CPUMIPSState *env, target_ulong addr, target_ulong reglist,
614 target_ulong base_reglist = reglist & 0xf;
615 target_ulong do_r31 = reglist & 0x10;
616 #ifdef CONFIG_USER_ONLY
618 #define stfun(env, addr, val) stl_raw(addr, val)
620 void (*stfun)(CPUMIPSState *env, target_ulong, uint32_t);
624 case 0: stfun = cpu_stl_kernel; break;
625 case 1: stfun = cpu_stl_super; break;
627 case 2: stfun = cpu_stl_user; break;
631 if (base_reglist > 0 && base_reglist <= ARRAY_SIZE (multiple_regs)) {
634 for (i = 0; i < base_reglist; i++) {
635 stfun(env, addr, env->active_tc.gpr[multiple_regs[i]]);
641 stfun(env, addr, env->active_tc.gpr[31]);
645 #if defined(TARGET_MIPS64)
646 void helper_ldm(CPUMIPSState *env, target_ulong addr, target_ulong reglist,
649 target_ulong base_reglist = reglist & 0xf;
650 target_ulong do_r31 = reglist & 0x10;
651 #ifdef CONFIG_USER_ONLY
653 #define ldfun(env, addr) ldq_raw(addr)
655 uint64_t (*ldfun)(CPUMIPSState *env, target_ulong);
659 case 0: ldfun = cpu_ldq_kernel; break;
660 case 1: ldfun = cpu_ldq_super; break;
662 case 2: ldfun = cpu_ldq_user; break;
666 if (base_reglist > 0 && base_reglist <= ARRAY_SIZE (multiple_regs)) {
669 for (i = 0; i < base_reglist; i++) {
670 env->active_tc.gpr[multiple_regs[i]] = ldfun(env, addr);
676 env->active_tc.gpr[31] = ldfun(env, addr);
680 void helper_sdm(CPUMIPSState *env, target_ulong addr, target_ulong reglist,
683 target_ulong base_reglist = reglist & 0xf;
684 target_ulong do_r31 = reglist & 0x10;
685 #ifdef CONFIG_USER_ONLY
687 #define stfun(env, addr, val) stq_raw(addr, val)
689 void (*stfun)(CPUMIPSState *env, target_ulong, uint64_t);
693 case 0: stfun = cpu_stq_kernel; break;
694 case 1: stfun = cpu_stq_super; break;
696 case 2: stfun = cpu_stq_user; break;
700 if (base_reglist > 0 && base_reglist <= ARRAY_SIZE (multiple_regs)) {
703 for (i = 0; i < base_reglist; i++) {
704 stfun(env, addr, env->active_tc.gpr[multiple_regs[i]]);
710 stfun(env, addr, env->active_tc.gpr[31]);
715 #ifndef CONFIG_USER_ONLY
717 static bool mips_vpe_is_wfi(MIPSCPU *c)
719 CPUMIPSState *env = &c->env;
721 /* If the VPE is halted but otherwise active, it means it's waiting for
723 return env->halted && mips_vpe_active(env);
726 static inline void mips_vpe_wake(CPUMIPSState *c)
728 /* Dont set ->halted = 0 directly, let it be done via cpu_has_work
729 because there might be other conditions that state that c should
731 cpu_interrupt(c, CPU_INTERRUPT_WAKE);
734 static inline void mips_vpe_sleep(CPUMIPSState *c)
736 /* The VPE was shut off, really go to bed.
737 Reset any old _WAKE requests. */
739 cpu_reset_interrupt(c, CPU_INTERRUPT_WAKE);
742 static inline void mips_tc_wake(MIPSCPU *cpu, int tc)
744 CPUMIPSState *c = &cpu->env;
746 /* FIXME: TC reschedule. */
747 if (mips_vpe_active(c) && !mips_vpe_is_wfi(cpu)) {
752 static inline void mips_tc_sleep(MIPSCPU *cpu, int tc)
754 CPUMIPSState *c = &cpu->env;
756 /* FIXME: TC reschedule. */
757 if (!mips_vpe_active(c)) {
762 /* tc should point to an int with the value of the global TC index.
763 This function will transform it into a local index within the
764 returned CPUMIPSState.
766 FIXME: This code assumes that all VPEs have the same number of TCs,
767 which depends on runtime setup. Can probably be fixed by
768 walking the list of CPUMIPSStates. */
769 static CPUMIPSState *mips_cpu_map_tc(CPUMIPSState *env, int *tc)
772 int vpe_idx, nr_threads = env->nr_threads;
775 if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))) {
776 /* Not allowed to address other CPUs. */
777 *tc = env->current_tc;
781 vpe_idx = tc_idx / nr_threads;
782 *tc = tc_idx % nr_threads;
783 other = qemu_get_cpu(vpe_idx);
784 return other ? other : env;
787 /* The per VPE CP0_Status register shares some fields with the per TC
788 CP0_TCStatus registers. These fields are wired to the same registers,
789 so changes to either of them should be reflected on both registers.
791 Also, EntryHi shares the bottom 8 bit ASID with TCStauts.
793 These helper call synchronizes the regs for a given cpu. */
795 /* Called for updates to CP0_Status. */
796 static void sync_c0_status(CPUMIPSState *env, CPUMIPSState *cpu, int tc)
798 int32_t tcstatus, *tcst;
799 uint32_t v = cpu->CP0_Status;
800 uint32_t cu, mx, asid, ksu;
801 uint32_t mask = ((1 << CP0TCSt_TCU3)
802 | (1 << CP0TCSt_TCU2)
803 | (1 << CP0TCSt_TCU1)
804 | (1 << CP0TCSt_TCU0)
806 | (3 << CP0TCSt_TKSU)
807 | (0xff << CP0TCSt_TASID));
809 cu = (v >> CP0St_CU0) & 0xf;
810 mx = (v >> CP0St_MX) & 0x1;
811 ksu = (v >> CP0St_KSU) & 0x3;
812 asid = env->CP0_EntryHi & 0xff;
814 tcstatus = cu << CP0TCSt_TCU0;
815 tcstatus |= mx << CP0TCSt_TMX;
816 tcstatus |= ksu << CP0TCSt_TKSU;
819 if (tc == cpu->current_tc) {
820 tcst = &cpu->active_tc.CP0_TCStatus;
822 tcst = &cpu->tcs[tc].CP0_TCStatus;
830 /* Called for updates to CP0_TCStatus. */
831 static void sync_c0_tcstatus(CPUMIPSState *cpu, int tc,
835 uint32_t tcu, tmx, tasid, tksu;
836 uint32_t mask = ((1 << CP0St_CU3)
843 tcu = (v >> CP0TCSt_TCU0) & 0xf;
844 tmx = (v >> CP0TCSt_TMX) & 0x1;
846 tksu = (v >> CP0TCSt_TKSU) & 0x3;
848 status = tcu << CP0St_CU0;
849 status |= tmx << CP0St_MX;
850 status |= tksu << CP0St_KSU;
852 cpu->CP0_Status &= ~mask;
853 cpu->CP0_Status |= status;
855 /* Sync the TASID with EntryHi. */
856 cpu->CP0_EntryHi &= ~0xff;
857 cpu->CP0_EntryHi = tasid;
862 /* Called for updates to CP0_EntryHi. */
863 static void sync_c0_entryhi(CPUMIPSState *cpu, int tc)
866 uint32_t asid, v = cpu->CP0_EntryHi;
870 if (tc == cpu->current_tc) {
871 tcst = &cpu->active_tc.CP0_TCStatus;
873 tcst = &cpu->tcs[tc].CP0_TCStatus;
881 target_ulong helper_mfc0_mvpcontrol(CPUMIPSState *env)
883 return env->mvp->CP0_MVPControl;
886 target_ulong helper_mfc0_mvpconf0(CPUMIPSState *env)
888 return env->mvp->CP0_MVPConf0;
891 target_ulong helper_mfc0_mvpconf1(CPUMIPSState *env)
893 return env->mvp->CP0_MVPConf1;
896 target_ulong helper_mfc0_random(CPUMIPSState *env)
898 return (int32_t)cpu_mips_get_random(env);
901 target_ulong helper_mfc0_tcstatus(CPUMIPSState *env)
903 return env->active_tc.CP0_TCStatus;
906 target_ulong helper_mftc0_tcstatus(CPUMIPSState *env)
908 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
909 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
911 if (other_tc == other->current_tc)
912 return other->active_tc.CP0_TCStatus;
914 return other->tcs[other_tc].CP0_TCStatus;
917 target_ulong helper_mfc0_tcbind(CPUMIPSState *env)
919 return env->active_tc.CP0_TCBind;
922 target_ulong helper_mftc0_tcbind(CPUMIPSState *env)
924 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
925 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
927 if (other_tc == other->current_tc)
928 return other->active_tc.CP0_TCBind;
930 return other->tcs[other_tc].CP0_TCBind;
933 target_ulong helper_mfc0_tcrestart(CPUMIPSState *env)
935 return env->active_tc.PC;
938 target_ulong helper_mftc0_tcrestart(CPUMIPSState *env)
940 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
941 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
943 if (other_tc == other->current_tc)
944 return other->active_tc.PC;
946 return other->tcs[other_tc].PC;
949 target_ulong helper_mfc0_tchalt(CPUMIPSState *env)
951 return env->active_tc.CP0_TCHalt;
954 target_ulong helper_mftc0_tchalt(CPUMIPSState *env)
956 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
957 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
959 if (other_tc == other->current_tc)
960 return other->active_tc.CP0_TCHalt;
962 return other->tcs[other_tc].CP0_TCHalt;
965 target_ulong helper_mfc0_tccontext(CPUMIPSState *env)
967 return env->active_tc.CP0_TCContext;
970 target_ulong helper_mftc0_tccontext(CPUMIPSState *env)
972 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
973 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
975 if (other_tc == other->current_tc)
976 return other->active_tc.CP0_TCContext;
978 return other->tcs[other_tc].CP0_TCContext;
981 target_ulong helper_mfc0_tcschedule(CPUMIPSState *env)
983 return env->active_tc.CP0_TCSchedule;
986 target_ulong helper_mftc0_tcschedule(CPUMIPSState *env)
988 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
989 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
991 if (other_tc == other->current_tc)
992 return other->active_tc.CP0_TCSchedule;
994 return other->tcs[other_tc].CP0_TCSchedule;
997 target_ulong helper_mfc0_tcschefback(CPUMIPSState *env)
999 return env->active_tc.CP0_TCScheFBack;
1002 target_ulong helper_mftc0_tcschefback(CPUMIPSState *env)
1004 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1005 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1007 if (other_tc == other->current_tc)
1008 return other->active_tc.CP0_TCScheFBack;
1010 return other->tcs[other_tc].CP0_TCScheFBack;
1013 target_ulong helper_mfc0_count(CPUMIPSState *env)
1015 return (int32_t)cpu_mips_get_count(env);
1018 target_ulong helper_mftc0_entryhi(CPUMIPSState *env)
1020 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1021 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1023 return other->CP0_EntryHi;
1026 target_ulong helper_mftc0_cause(CPUMIPSState *env)
1028 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1030 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1032 if (other_tc == other->current_tc) {
1033 tccause = other->CP0_Cause;
1035 tccause = other->CP0_Cause;
1041 target_ulong helper_mftc0_status(CPUMIPSState *env)
1043 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1044 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1046 return other->CP0_Status;
1049 target_ulong helper_mfc0_lladdr(CPUMIPSState *env)
1051 return (int32_t)(env->lladdr >> env->CP0_LLAddr_shift);
1054 target_ulong helper_mfc0_watchlo(CPUMIPSState *env, uint32_t sel)
1056 return (int32_t)env->CP0_WatchLo[sel];
1059 target_ulong helper_mfc0_watchhi(CPUMIPSState *env, uint32_t sel)
1061 return env->CP0_WatchHi[sel];
1064 target_ulong helper_mfc0_debug(CPUMIPSState *env)
1066 target_ulong t0 = env->CP0_Debug;
1067 if (env->hflags & MIPS_HFLAG_DM)
1068 t0 |= 1 << CP0DB_DM;
1073 target_ulong helper_mftc0_debug(CPUMIPSState *env)
1075 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1077 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1079 if (other_tc == other->current_tc)
1080 tcstatus = other->active_tc.CP0_Debug_tcstatus;
1082 tcstatus = other->tcs[other_tc].CP0_Debug_tcstatus;
1084 /* XXX: Might be wrong, check with EJTAG spec. */
1085 return (other->CP0_Debug & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
1086 (tcstatus & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
1089 #if defined(TARGET_MIPS64)
1090 target_ulong helper_dmfc0_tcrestart(CPUMIPSState *env)
1092 return env->active_tc.PC;
1095 target_ulong helper_dmfc0_tchalt(CPUMIPSState *env)
1097 return env->active_tc.CP0_TCHalt;
1100 target_ulong helper_dmfc0_tccontext(CPUMIPSState *env)
1102 return env->active_tc.CP0_TCContext;
1105 target_ulong helper_dmfc0_tcschedule(CPUMIPSState *env)
1107 return env->active_tc.CP0_TCSchedule;
1110 target_ulong helper_dmfc0_tcschefback(CPUMIPSState *env)
1112 return env->active_tc.CP0_TCScheFBack;
1115 target_ulong helper_dmfc0_lladdr(CPUMIPSState *env)
1117 return env->lladdr >> env->CP0_LLAddr_shift;
1120 target_ulong helper_dmfc0_watchlo(CPUMIPSState *env, uint32_t sel)
1122 return env->CP0_WatchLo[sel];
1124 #endif /* TARGET_MIPS64 */
1126 void helper_mtc0_index(CPUMIPSState *env, target_ulong arg1)
1129 unsigned int tmp = env->tlb->nb_tlb;
1135 env->CP0_Index = (env->CP0_Index & 0x80000000) | (arg1 & (num - 1));
1138 void helper_mtc0_mvpcontrol(CPUMIPSState *env, target_ulong arg1)
1143 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))
1144 mask |= (1 << CP0MVPCo_CPA) | (1 << CP0MVPCo_VPC) |
1145 (1 << CP0MVPCo_EVP);
1146 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1147 mask |= (1 << CP0MVPCo_STLB);
1148 newval = (env->mvp->CP0_MVPControl & ~mask) | (arg1 & mask);
1150 // TODO: Enable/disable shared TLB, enable/disable VPEs.
1152 env->mvp->CP0_MVPControl = newval;
1155 void helper_mtc0_vpecontrol(CPUMIPSState *env, target_ulong arg1)
1160 mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
1161 (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
1162 newval = (env->CP0_VPEControl & ~mask) | (arg1 & mask);
1164 /* Yield scheduler intercept not implemented. */
1165 /* Gating storage scheduler intercept not implemented. */
1167 // TODO: Enable/disable TCs.
1169 env->CP0_VPEControl = newval;
1172 void helper_mttc0_vpecontrol(CPUMIPSState *env, target_ulong arg1)
1174 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1175 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1179 mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
1180 (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
1181 newval = (other->CP0_VPEControl & ~mask) | (arg1 & mask);
1183 /* TODO: Enable/disable TCs. */
1185 other->CP0_VPEControl = newval;
1188 target_ulong helper_mftc0_vpecontrol(CPUMIPSState *env)
1190 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1191 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1192 /* FIXME: Mask away return zero on read bits. */
1193 return other->CP0_VPEControl;
1196 target_ulong helper_mftc0_vpeconf0(CPUMIPSState *env)
1198 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1199 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1201 return other->CP0_VPEConf0;
1204 void helper_mtc0_vpeconf0(CPUMIPSState *env, target_ulong arg1)
1209 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
1210 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))
1211 mask |= (0xff << CP0VPEC0_XTC);
1212 mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
1214 newval = (env->CP0_VPEConf0 & ~mask) | (arg1 & mask);
1216 // TODO: TC exclusive handling due to ERL/EXL.
1218 env->CP0_VPEConf0 = newval;
1221 void helper_mttc0_vpeconf0(CPUMIPSState *env, target_ulong arg1)
1223 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1224 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1228 mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
1229 newval = (other->CP0_VPEConf0 & ~mask) | (arg1 & mask);
1231 /* TODO: TC exclusive handling due to ERL/EXL. */
1232 other->CP0_VPEConf0 = newval;
1235 void helper_mtc0_vpeconf1(CPUMIPSState *env, target_ulong arg1)
1240 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1241 mask |= (0xff << CP0VPEC1_NCX) | (0xff << CP0VPEC1_NCP2) |
1242 (0xff << CP0VPEC1_NCP1);
1243 newval = (env->CP0_VPEConf1 & ~mask) | (arg1 & mask);
1245 /* UDI not implemented. */
1246 /* CP2 not implemented. */
1248 // TODO: Handle FPU (CP1) binding.
1250 env->CP0_VPEConf1 = newval;
1253 void helper_mtc0_yqmask(CPUMIPSState *env, target_ulong arg1)
1255 /* Yield qualifier inputs not implemented. */
1256 env->CP0_YQMask = 0x00000000;
1259 void helper_mtc0_vpeopt(CPUMIPSState *env, target_ulong arg1)
1261 env->CP0_VPEOpt = arg1 & 0x0000ffff;
1264 void helper_mtc0_entrylo0(CPUMIPSState *env, target_ulong arg1)
1266 /* Large physaddr (PABITS) not implemented */
1267 /* 1k pages not implemented */
1268 env->CP0_EntryLo0 = arg1 & 0x3FFFFFFF;
1271 void helper_mtc0_tcstatus(CPUMIPSState *env, target_ulong arg1)
1273 uint32_t mask = env->CP0_TCStatus_rw_bitmask;
1276 newval = (env->active_tc.CP0_TCStatus & ~mask) | (arg1 & mask);
1278 env->active_tc.CP0_TCStatus = newval;
1279 sync_c0_tcstatus(env, env->current_tc, newval);
1282 void helper_mttc0_tcstatus(CPUMIPSState *env, target_ulong arg1)
1284 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1285 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1287 if (other_tc == other->current_tc)
1288 other->active_tc.CP0_TCStatus = arg1;
1290 other->tcs[other_tc].CP0_TCStatus = arg1;
1291 sync_c0_tcstatus(other, other_tc, arg1);
1294 void helper_mtc0_tcbind(CPUMIPSState *env, target_ulong arg1)
1296 uint32_t mask = (1 << CP0TCBd_TBE);
1299 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1300 mask |= (1 << CP0TCBd_CurVPE);
1301 newval = (env->active_tc.CP0_TCBind & ~mask) | (arg1 & mask);
1302 env->active_tc.CP0_TCBind = newval;
1305 void helper_mttc0_tcbind(CPUMIPSState *env, target_ulong arg1)
1307 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1308 uint32_t mask = (1 << CP0TCBd_TBE);
1310 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1312 if (other->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1313 mask |= (1 << CP0TCBd_CurVPE);
1314 if (other_tc == other->current_tc) {
1315 newval = (other->active_tc.CP0_TCBind & ~mask) | (arg1 & mask);
1316 other->active_tc.CP0_TCBind = newval;
1318 newval = (other->tcs[other_tc].CP0_TCBind & ~mask) | (arg1 & mask);
1319 other->tcs[other_tc].CP0_TCBind = newval;
1323 void helper_mtc0_tcrestart(CPUMIPSState *env, target_ulong arg1)
1325 env->active_tc.PC = arg1;
1326 env->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1328 /* MIPS16 not implemented. */
1331 void helper_mttc0_tcrestart(CPUMIPSState *env, target_ulong arg1)
1333 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1334 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1336 if (other_tc == other->current_tc) {
1337 other->active_tc.PC = arg1;
1338 other->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1339 other->lladdr = 0ULL;
1340 /* MIPS16 not implemented. */
1342 other->tcs[other_tc].PC = arg1;
1343 other->tcs[other_tc].CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1344 other->lladdr = 0ULL;
1345 /* MIPS16 not implemented. */
1349 void helper_mtc0_tchalt(CPUMIPSState *env, target_ulong arg1)
1351 MIPSCPU *cpu = mips_env_get_cpu(env);
1353 env->active_tc.CP0_TCHalt = arg1 & 0x1;
1355 // TODO: Halt TC / Restart (if allocated+active) TC.
1356 if (env->active_tc.CP0_TCHalt & 1) {
1357 mips_tc_sleep(cpu, env->current_tc);
1359 mips_tc_wake(cpu, env->current_tc);
1363 void helper_mttc0_tchalt(CPUMIPSState *env, target_ulong arg1)
1365 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1366 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1367 MIPSCPU *other_cpu = mips_env_get_cpu(other);
1369 // TODO: Halt TC / Restart (if allocated+active) TC.
1371 if (other_tc == other->current_tc)
1372 other->active_tc.CP0_TCHalt = arg1;
1374 other->tcs[other_tc].CP0_TCHalt = arg1;
1377 mips_tc_sleep(other_cpu, other_tc);
1379 mips_tc_wake(other_cpu, other_tc);
1383 void helper_mtc0_tccontext(CPUMIPSState *env, target_ulong arg1)
1385 env->active_tc.CP0_TCContext = arg1;
1388 void helper_mttc0_tccontext(CPUMIPSState *env, target_ulong arg1)
1390 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1391 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1393 if (other_tc == other->current_tc)
1394 other->active_tc.CP0_TCContext = arg1;
1396 other->tcs[other_tc].CP0_TCContext = arg1;
1399 void helper_mtc0_tcschedule(CPUMIPSState *env, target_ulong arg1)
1401 env->active_tc.CP0_TCSchedule = arg1;
1404 void helper_mttc0_tcschedule(CPUMIPSState *env, target_ulong arg1)
1406 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1407 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1409 if (other_tc == other->current_tc)
1410 other->active_tc.CP0_TCSchedule = arg1;
1412 other->tcs[other_tc].CP0_TCSchedule = arg1;
1415 void helper_mtc0_tcschefback(CPUMIPSState *env, target_ulong arg1)
1417 env->active_tc.CP0_TCScheFBack = arg1;
1420 void helper_mttc0_tcschefback(CPUMIPSState *env, target_ulong arg1)
1422 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1423 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1425 if (other_tc == other->current_tc)
1426 other->active_tc.CP0_TCScheFBack = arg1;
1428 other->tcs[other_tc].CP0_TCScheFBack = arg1;
1431 void helper_mtc0_entrylo1(CPUMIPSState *env, target_ulong arg1)
1433 /* Large physaddr (PABITS) not implemented */
1434 /* 1k pages not implemented */
1435 env->CP0_EntryLo1 = arg1 & 0x3FFFFFFF;
1438 void helper_mtc0_context(CPUMIPSState *env, target_ulong arg1)
1440 env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (arg1 & ~0x007FFFFF);
1443 void helper_mtc0_pagemask(CPUMIPSState *env, target_ulong arg1)
1445 /* 1k pages not implemented */
1446 env->CP0_PageMask = arg1 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
1449 void helper_mtc0_pagegrain(CPUMIPSState *env, target_ulong arg1)
1451 /* SmartMIPS not implemented */
1452 /* Large physaddr (PABITS) not implemented */
1453 /* 1k pages not implemented */
1454 env->CP0_PageGrain = 0;
1457 void helper_mtc0_wired(CPUMIPSState *env, target_ulong arg1)
1459 env->CP0_Wired = arg1 % env->tlb->nb_tlb;
1462 void helper_mtc0_srsconf0(CPUMIPSState *env, target_ulong arg1)
1464 env->CP0_SRSConf0 |= arg1 & env->CP0_SRSConf0_rw_bitmask;
1467 void helper_mtc0_srsconf1(CPUMIPSState *env, target_ulong arg1)
1469 env->CP0_SRSConf1 |= arg1 & env->CP0_SRSConf1_rw_bitmask;
1472 void helper_mtc0_srsconf2(CPUMIPSState *env, target_ulong arg1)
1474 env->CP0_SRSConf2 |= arg1 & env->CP0_SRSConf2_rw_bitmask;
1477 void helper_mtc0_srsconf3(CPUMIPSState *env, target_ulong arg1)
1479 env->CP0_SRSConf3 |= arg1 & env->CP0_SRSConf3_rw_bitmask;
1482 void helper_mtc0_srsconf4(CPUMIPSState *env, target_ulong arg1)
1484 env->CP0_SRSConf4 |= arg1 & env->CP0_SRSConf4_rw_bitmask;
1487 void helper_mtc0_hwrena(CPUMIPSState *env, target_ulong arg1)
1489 env->CP0_HWREna = arg1 & 0x0000000F;
1492 void helper_mtc0_count(CPUMIPSState *env, target_ulong arg1)
1494 cpu_mips_store_count(env, arg1);
1497 void helper_mtc0_entryhi(CPUMIPSState *env, target_ulong arg1)
1499 target_ulong old, val;
1501 /* 1k pages not implemented */
1502 val = arg1 & ((TARGET_PAGE_MASK << 1) | 0xFF);
1503 #if defined(TARGET_MIPS64)
1504 val &= env->SEGMask;
1506 old = env->CP0_EntryHi;
1507 env->CP0_EntryHi = val;
1508 if (env->CP0_Config3 & (1 << CP0C3_MT)) {
1509 sync_c0_entryhi(env, env->current_tc);
1511 /* If the ASID changes, flush qemu's TLB. */
1512 if ((old & 0xFF) != (val & 0xFF))
1513 cpu_mips_tlb_flush(env, 1);
1516 void helper_mttc0_entryhi(CPUMIPSState *env, target_ulong arg1)
1518 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1519 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1521 other->CP0_EntryHi = arg1;
1522 sync_c0_entryhi(other, other_tc);
1525 void helper_mtc0_compare(CPUMIPSState *env, target_ulong arg1)
1527 cpu_mips_store_compare(env, arg1);
1530 void helper_mtc0_status(CPUMIPSState *env, target_ulong arg1)
1533 uint32_t mask = env->CP0_Status_rw_bitmask;
1536 old = env->CP0_Status;
1537 env->CP0_Status = (env->CP0_Status & ~mask) | val;
1538 if (env->CP0_Config3 & (1 << CP0C3_MT)) {
1539 sync_c0_status(env, env, env->current_tc);
1541 compute_hflags(env);
1544 if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
1545 qemu_log("Status %08x (%08x) => %08x (%08x) Cause %08x",
1546 old, old & env->CP0_Cause & CP0Ca_IP_mask,
1547 val, val & env->CP0_Cause & CP0Ca_IP_mask,
1549 switch (env->hflags & MIPS_HFLAG_KSU) {
1550 case MIPS_HFLAG_UM: qemu_log(", UM\n"); break;
1551 case MIPS_HFLAG_SM: qemu_log(", SM\n"); break;
1552 case MIPS_HFLAG_KM: qemu_log("\n"); break;
1553 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
1558 void helper_mttc0_status(CPUMIPSState *env, target_ulong arg1)
1560 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1561 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1563 other->CP0_Status = arg1 & ~0xf1000018;
1564 sync_c0_status(env, other, other_tc);
1567 void helper_mtc0_intctl(CPUMIPSState *env, target_ulong arg1)
1569 /* vectored interrupts not implemented, no performance counters. */
1570 env->CP0_IntCtl = (env->CP0_IntCtl & ~0x000003e0) | (arg1 & 0x000003e0);
1573 void helper_mtc0_srsctl(CPUMIPSState *env, target_ulong arg1)
1575 uint32_t mask = (0xf << CP0SRSCtl_ESS) | (0xf << CP0SRSCtl_PSS);
1576 env->CP0_SRSCtl = (env->CP0_SRSCtl & ~mask) | (arg1 & mask);
1579 static void mtc0_cause(CPUMIPSState *cpu, target_ulong arg1)
1581 uint32_t mask = 0x00C00300;
1582 uint32_t old = cpu->CP0_Cause;
1585 if (cpu->insn_flags & ISA_MIPS32R2) {
1586 mask |= 1 << CP0Ca_DC;
1589 cpu->CP0_Cause = (cpu->CP0_Cause & ~mask) | (arg1 & mask);
1591 if ((old ^ cpu->CP0_Cause) & (1 << CP0Ca_DC)) {
1592 if (cpu->CP0_Cause & (1 << CP0Ca_DC)) {
1593 cpu_mips_stop_count(cpu);
1595 cpu_mips_start_count(cpu);
1599 /* Set/reset software interrupts */
1600 for (i = 0 ; i < 2 ; i++) {
1601 if ((old ^ cpu->CP0_Cause) & (1 << (CP0Ca_IP + i))) {
1602 cpu_mips_soft_irq(cpu, i, cpu->CP0_Cause & (1 << (CP0Ca_IP + i)));
1607 void helper_mtc0_cause(CPUMIPSState *env, target_ulong arg1)
1609 mtc0_cause(env, arg1);
1612 void helper_mttc0_cause(CPUMIPSState *env, target_ulong arg1)
1614 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1615 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1617 mtc0_cause(other, arg1);
1620 target_ulong helper_mftc0_epc(CPUMIPSState *env)
1622 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1623 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1625 return other->CP0_EPC;
1628 target_ulong helper_mftc0_ebase(CPUMIPSState *env)
1630 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1631 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1633 return other->CP0_EBase;
1636 void helper_mtc0_ebase(CPUMIPSState *env, target_ulong arg1)
1638 /* vectored interrupts not implemented */
1639 env->CP0_EBase = (env->CP0_EBase & ~0x3FFFF000) | (arg1 & 0x3FFFF000);
1642 void helper_mttc0_ebase(CPUMIPSState *env, target_ulong arg1)
1644 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1645 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1646 other->CP0_EBase = (other->CP0_EBase & ~0x3FFFF000) | (arg1 & 0x3FFFF000);
1649 target_ulong helper_mftc0_configx(CPUMIPSState *env, target_ulong idx)
1651 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1652 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1655 case 0: return other->CP0_Config0;
1656 case 1: return other->CP0_Config1;
1657 case 2: return other->CP0_Config2;
1658 case 3: return other->CP0_Config3;
1659 /* 4 and 5 are reserved. */
1660 case 6: return other->CP0_Config6;
1661 case 7: return other->CP0_Config7;
1668 void helper_mtc0_config0(CPUMIPSState *env, target_ulong arg1)
1670 env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (arg1 & 0x00000007);
1673 void helper_mtc0_config2(CPUMIPSState *env, target_ulong arg1)
1675 /* tertiary/secondary caches not implemented */
1676 env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
1679 void helper_mtc0_lladdr(CPUMIPSState *env, target_ulong arg1)
1681 target_long mask = env->CP0_LLAddr_rw_bitmask;
1682 arg1 = arg1 << env->CP0_LLAddr_shift;
1683 env->lladdr = (env->lladdr & ~mask) | (arg1 & mask);
1686 void helper_mtc0_watchlo(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1688 /* Watch exceptions for instructions, data loads, data stores
1690 env->CP0_WatchLo[sel] = (arg1 & ~0x7);
1693 void helper_mtc0_watchhi(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1695 env->CP0_WatchHi[sel] = (arg1 & 0x40FF0FF8);
1696 env->CP0_WatchHi[sel] &= ~(env->CP0_WatchHi[sel] & arg1 & 0x7);
1699 void helper_mtc0_xcontext(CPUMIPSState *env, target_ulong arg1)
1701 target_ulong mask = (1ULL << (env->SEGBITS - 7)) - 1;
1702 env->CP0_XContext = (env->CP0_XContext & mask) | (arg1 & ~mask);
1705 void helper_mtc0_framemask(CPUMIPSState *env, target_ulong arg1)
1707 env->CP0_Framemask = arg1; /* XXX */
1710 void helper_mtc0_debug(CPUMIPSState *env, target_ulong arg1)
1712 env->CP0_Debug = (env->CP0_Debug & 0x8C03FC1F) | (arg1 & 0x13300120);
1713 if (arg1 & (1 << CP0DB_DM))
1714 env->hflags |= MIPS_HFLAG_DM;
1716 env->hflags &= ~MIPS_HFLAG_DM;
1719 void helper_mttc0_debug(CPUMIPSState *env, target_ulong arg1)
1721 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1722 uint32_t val = arg1 & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt));
1723 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1725 /* XXX: Might be wrong, check with EJTAG spec. */
1726 if (other_tc == other->current_tc)
1727 other->active_tc.CP0_Debug_tcstatus = val;
1729 other->tcs[other_tc].CP0_Debug_tcstatus = val;
1730 other->CP0_Debug = (other->CP0_Debug &
1731 ((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
1732 (arg1 & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
1735 void helper_mtc0_performance0(CPUMIPSState *env, target_ulong arg1)
1737 env->CP0_Performance0 = arg1 & 0x000007ff;
1740 void helper_mtc0_taglo(CPUMIPSState *env, target_ulong arg1)
1742 env->CP0_TagLo = arg1 & 0xFFFFFCF6;
1745 void helper_mtc0_datalo(CPUMIPSState *env, target_ulong arg1)
1747 env->CP0_DataLo = arg1; /* XXX */
1750 void helper_mtc0_taghi(CPUMIPSState *env, target_ulong arg1)
1752 env->CP0_TagHi = arg1; /* XXX */
1755 void helper_mtc0_datahi(CPUMIPSState *env, target_ulong arg1)
1757 env->CP0_DataHi = arg1; /* XXX */
1760 /* MIPS MT functions */
1761 target_ulong helper_mftgpr(CPUMIPSState *env, uint32_t sel)
1763 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1764 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1766 if (other_tc == other->current_tc)
1767 return other->active_tc.gpr[sel];
1769 return other->tcs[other_tc].gpr[sel];
1772 target_ulong helper_mftlo(CPUMIPSState *env, uint32_t sel)
1774 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1775 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1777 if (other_tc == other->current_tc)
1778 return other->active_tc.LO[sel];
1780 return other->tcs[other_tc].LO[sel];
1783 target_ulong helper_mfthi(CPUMIPSState *env, uint32_t sel)
1785 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1786 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1788 if (other_tc == other->current_tc)
1789 return other->active_tc.HI[sel];
1791 return other->tcs[other_tc].HI[sel];
1794 target_ulong helper_mftacx(CPUMIPSState *env, uint32_t sel)
1796 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1797 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1799 if (other_tc == other->current_tc)
1800 return other->active_tc.ACX[sel];
1802 return other->tcs[other_tc].ACX[sel];
1805 target_ulong helper_mftdsp(CPUMIPSState *env)
1807 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1808 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1810 if (other_tc == other->current_tc)
1811 return other->active_tc.DSPControl;
1813 return other->tcs[other_tc].DSPControl;
1816 void helper_mttgpr(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1818 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1819 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1821 if (other_tc == other->current_tc)
1822 other->active_tc.gpr[sel] = arg1;
1824 other->tcs[other_tc].gpr[sel] = arg1;
1827 void helper_mttlo(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1829 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1830 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1832 if (other_tc == other->current_tc)
1833 other->active_tc.LO[sel] = arg1;
1835 other->tcs[other_tc].LO[sel] = arg1;
1838 void helper_mtthi(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1840 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1841 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1843 if (other_tc == other->current_tc)
1844 other->active_tc.HI[sel] = arg1;
1846 other->tcs[other_tc].HI[sel] = arg1;
1849 void helper_mttacx(CPUMIPSState *env, target_ulong arg1, uint32_t sel)
1851 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1852 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1854 if (other_tc == other->current_tc)
1855 other->active_tc.ACX[sel] = arg1;
1857 other->tcs[other_tc].ACX[sel] = arg1;
1860 void helper_mttdsp(CPUMIPSState *env, target_ulong arg1)
1862 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1863 CPUMIPSState *other = mips_cpu_map_tc(env, &other_tc);
1865 if (other_tc == other->current_tc)
1866 other->active_tc.DSPControl = arg1;
1868 other->tcs[other_tc].DSPControl = arg1;
1871 /* MIPS MT functions */
1872 target_ulong helper_dmt(void)
1878 target_ulong helper_emt(void)
1884 target_ulong helper_dvpe(CPUMIPSState *env)
1886 CPUMIPSState *other_cpu_env = first_cpu;
1887 target_ulong prev = env->mvp->CP0_MVPControl;
1890 /* Turn off all VPEs except the one executing the dvpe. */
1891 if (other_cpu_env != env) {
1892 other_cpu_env->mvp->CP0_MVPControl &= ~(1 << CP0MVPCo_EVP);
1893 mips_vpe_sleep(other_cpu_env);
1895 other_cpu_env = other_cpu_env->next_cpu;
1896 } while (other_cpu_env);
1900 target_ulong helper_evpe(CPUMIPSState *env)
1902 CPUMIPSState *other_cpu_env = first_cpu;
1903 target_ulong prev = env->mvp->CP0_MVPControl;
1906 MIPSCPU *other_cpu = mips_env_get_cpu(other_cpu_env);
1908 if (other_cpu_env != env
1909 /* If the VPE is WFI, don't disturb its sleep. */
1910 && !mips_vpe_is_wfi(other_cpu)) {
1911 /* Enable the VPE. */
1912 other_cpu_env->mvp->CP0_MVPControl |= (1 << CP0MVPCo_EVP);
1913 mips_vpe_wake(other_cpu_env); /* And wake it up. */
1915 other_cpu_env = other_cpu_env->next_cpu;
1916 } while (other_cpu_env);
1919 #endif /* !CONFIG_USER_ONLY */
1921 void helper_fork(target_ulong arg1, target_ulong arg2)
1923 // arg1 = rt, arg2 = rs
1925 // TODO: store to TC register
1928 target_ulong helper_yield(CPUMIPSState *env, target_ulong arg)
1930 target_long arg1 = arg;
1933 /* No scheduling policy implemented. */
1935 if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
1936 env->active_tc.CP0_TCStatus & (1 << CP0TCSt_DT)) {
1937 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1938 env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
1939 helper_raise_exception(env, EXCP_THREAD);
1942 } else if (arg1 == 0) {
1943 if (0 /* TODO: TC underflow */) {
1944 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1945 helper_raise_exception(env, EXCP_THREAD);
1947 // TODO: Deallocate TC
1949 } else if (arg1 > 0) {
1950 /* Yield qualifier inputs not implemented. */
1951 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1952 env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
1953 helper_raise_exception(env, EXCP_THREAD);
1955 return env->CP0_YQMask;
1958 #ifndef CONFIG_USER_ONLY
1959 /* TLB management */
1960 static void cpu_mips_tlb_flush (CPUMIPSState *env, int flush_global)
1962 /* Flush qemu's TLB and discard all shadowed entries. */
1963 tlb_flush (env, flush_global);
1964 env->tlb->tlb_in_use = env->tlb->nb_tlb;
1967 static void r4k_mips_tlb_flush_extra (CPUMIPSState *env, int first)
1969 /* Discard entries from env->tlb[first] onwards. */
1970 while (env->tlb->tlb_in_use > first) {
1971 r4k_invalidate_tlb(env, --env->tlb->tlb_in_use, 0);
1975 static void r4k_fill_tlb(CPUMIPSState *env, int idx)
1979 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1980 tlb = &env->tlb->mmu.r4k.tlb[idx];
1981 tlb->VPN = env->CP0_EntryHi & (TARGET_PAGE_MASK << 1);
1982 #if defined(TARGET_MIPS64)
1983 tlb->VPN &= env->SEGMask;
1985 tlb->ASID = env->CP0_EntryHi & 0xFF;
1986 tlb->PageMask = env->CP0_PageMask;
1987 tlb->G = env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1;
1988 tlb->V0 = (env->CP0_EntryLo0 & 2) != 0;
1989 tlb->D0 = (env->CP0_EntryLo0 & 4) != 0;
1990 tlb->C0 = (env->CP0_EntryLo0 >> 3) & 0x7;
1991 tlb->PFN[0] = (env->CP0_EntryLo0 >> 6) << 12;
1992 tlb->V1 = (env->CP0_EntryLo1 & 2) != 0;
1993 tlb->D1 = (env->CP0_EntryLo1 & 4) != 0;
1994 tlb->C1 = (env->CP0_EntryLo1 >> 3) & 0x7;
1995 tlb->PFN[1] = (env->CP0_EntryLo1 >> 6) << 12;
1998 void r4k_helper_tlbwi(CPUMIPSState *env)
2002 idx = (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb;
2004 /* Discard cached TLB entries. We could avoid doing this if the
2005 tlbwi is just upgrading access permissions on the current entry;
2006 that might be a further win. */
2007 r4k_mips_tlb_flush_extra (env, env->tlb->nb_tlb);
2009 r4k_invalidate_tlb(env, idx, 0);
2010 r4k_fill_tlb(env, idx);
2013 void r4k_helper_tlbwr(CPUMIPSState *env)
2015 int r = cpu_mips_get_random(env);
2017 r4k_invalidate_tlb(env, r, 1);
2018 r4k_fill_tlb(env, r);
2021 void r4k_helper_tlbp(CPUMIPSState *env)
2030 ASID = env->CP0_EntryHi & 0xFF;
2031 for (i = 0; i < env->tlb->nb_tlb; i++) {
2032 tlb = &env->tlb->mmu.r4k.tlb[i];
2033 /* 1k pages are not supported. */
2034 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
2035 tag = env->CP0_EntryHi & ~mask;
2036 VPN = tlb->VPN & ~mask;
2037 /* Check ASID, virtual page number & size */
2038 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
2044 if (i == env->tlb->nb_tlb) {
2045 /* No match. Discard any shadow entries, if any of them match. */
2046 for (i = env->tlb->nb_tlb; i < env->tlb->tlb_in_use; i++) {
2047 tlb = &env->tlb->mmu.r4k.tlb[i];
2048 /* 1k pages are not supported. */
2049 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
2050 tag = env->CP0_EntryHi & ~mask;
2051 VPN = tlb->VPN & ~mask;
2052 /* Check ASID, virtual page number & size */
2053 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
2054 r4k_mips_tlb_flush_extra (env, i);
2059 env->CP0_Index |= 0x80000000;
2063 void r4k_helper_tlbr(CPUMIPSState *env)
2069 ASID = env->CP0_EntryHi & 0xFF;
2070 idx = (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb;
2071 tlb = &env->tlb->mmu.r4k.tlb[idx];
2073 /* If this will change the current ASID, flush qemu's TLB. */
2074 if (ASID != tlb->ASID)
2075 cpu_mips_tlb_flush (env, 1);
2077 r4k_mips_tlb_flush_extra(env, env->tlb->nb_tlb);
2079 env->CP0_EntryHi = tlb->VPN | tlb->ASID;
2080 env->CP0_PageMask = tlb->PageMask;
2081 env->CP0_EntryLo0 = tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) |
2082 (tlb->C0 << 3) | (tlb->PFN[0] >> 6);
2083 env->CP0_EntryLo1 = tlb->G | (tlb->V1 << 1) | (tlb->D1 << 2) |
2084 (tlb->C1 << 3) | (tlb->PFN[1] >> 6);
2087 void helper_tlbwi(CPUMIPSState *env)
2089 env->tlb->helper_tlbwi(env);
2092 void helper_tlbwr(CPUMIPSState *env)
2094 env->tlb->helper_tlbwr(env);
2097 void helper_tlbp(CPUMIPSState *env)
2099 env->tlb->helper_tlbp(env);
2102 void helper_tlbr(CPUMIPSState *env)
2104 env->tlb->helper_tlbr(env);
2108 target_ulong helper_di(CPUMIPSState *env)
2110 target_ulong t0 = env->CP0_Status;
2112 env->CP0_Status = t0 & ~(1 << CP0St_IE);
2116 target_ulong helper_ei(CPUMIPSState *env)
2118 target_ulong t0 = env->CP0_Status;
2120 env->CP0_Status = t0 | (1 << CP0St_IE);
2124 static void debug_pre_eret(CPUMIPSState *env)
2126 if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
2127 qemu_log("ERET: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
2128 env->active_tc.PC, env->CP0_EPC);
2129 if (env->CP0_Status & (1 << CP0St_ERL))
2130 qemu_log(" ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
2131 if (env->hflags & MIPS_HFLAG_DM)
2132 qemu_log(" DEPC " TARGET_FMT_lx, env->CP0_DEPC);
2137 static void debug_post_eret(CPUMIPSState *env)
2139 if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
2140 qemu_log(" => PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
2141 env->active_tc.PC, env->CP0_EPC);
2142 if (env->CP0_Status & (1 << CP0St_ERL))
2143 qemu_log(" ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
2144 if (env->hflags & MIPS_HFLAG_DM)
2145 qemu_log(" DEPC " TARGET_FMT_lx, env->CP0_DEPC);
2146 switch (env->hflags & MIPS_HFLAG_KSU) {
2147 case MIPS_HFLAG_UM: qemu_log(", UM\n"); break;
2148 case MIPS_HFLAG_SM: qemu_log(", SM\n"); break;
2149 case MIPS_HFLAG_KM: qemu_log("\n"); break;
2150 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
2155 static void set_pc(CPUMIPSState *env, target_ulong error_pc)
2157 env->active_tc.PC = error_pc & ~(target_ulong)1;
2159 env->hflags |= MIPS_HFLAG_M16;
2161 env->hflags &= ~(MIPS_HFLAG_M16);
2165 void helper_eret(CPUMIPSState *env)
2167 debug_pre_eret(env);
2168 if (env->CP0_Status & (1 << CP0St_ERL)) {
2169 set_pc(env, env->CP0_ErrorEPC);
2170 env->CP0_Status &= ~(1 << CP0St_ERL);
2172 set_pc(env, env->CP0_EPC);
2173 env->CP0_Status &= ~(1 << CP0St_EXL);
2175 compute_hflags(env);
2176 debug_post_eret(env);
2180 void helper_deret(CPUMIPSState *env)
2182 debug_pre_eret(env);
2183 set_pc(env, env->CP0_DEPC);
2185 env->hflags &= MIPS_HFLAG_DM;
2186 compute_hflags(env);
2187 debug_post_eret(env);
2190 #endif /* !CONFIG_USER_ONLY */
2192 target_ulong helper_rdhwr_cpunum(CPUMIPSState *env)
2194 if ((env->hflags & MIPS_HFLAG_CP0) ||
2195 (env->CP0_HWREna & (1 << 0)))
2196 return env->CP0_EBase & 0x3ff;
2198 helper_raise_exception(env, EXCP_RI);
2203 target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
2205 if ((env->hflags & MIPS_HFLAG_CP0) ||
2206 (env->CP0_HWREna & (1 << 1)))
2207 return env->SYNCI_Step;
2209 helper_raise_exception(env, EXCP_RI);
2214 target_ulong helper_rdhwr_cc(CPUMIPSState *env)
2216 if ((env->hflags & MIPS_HFLAG_CP0) ||
2217 (env->CP0_HWREna & (1 << 2)))
2218 return env->CP0_Count;
2220 helper_raise_exception(env, EXCP_RI);
2225 target_ulong helper_rdhwr_ccres(CPUMIPSState *env)
2227 if ((env->hflags & MIPS_HFLAG_CP0) ||
2228 (env->CP0_HWREna & (1 << 3)))
2231 helper_raise_exception(env, EXCP_RI);
2236 void helper_pmon(CPUMIPSState *env, int function)
2240 case 2: /* TODO: char inbyte(int waitflag); */
2241 if (env->active_tc.gpr[4] == 0)
2242 env->active_tc.gpr[2] = -1;
2244 case 11: /* TODO: char inbyte (void); */
2245 env->active_tc.gpr[2] = -1;
2249 printf("%c", (char)(env->active_tc.gpr[4] & 0xFF));
2255 unsigned char *fmt = (void *)(uintptr_t)env->active_tc.gpr[4];
2262 void helper_wait(CPUMIPSState *env)
2265 cpu_reset_interrupt(env, CPU_INTERRUPT_WAKE);
2266 helper_raise_exception(env, EXCP_HLT);
2269 #if !defined(CONFIG_USER_ONLY)
2271 static void QEMU_NORETURN do_unaligned_access(CPUMIPSState *env,
2272 target_ulong addr, int is_write,
2273 int is_user, uintptr_t retaddr);
2275 #define MMUSUFFIX _mmu
2276 #define ALIGNED_ONLY
2279 #include "softmmu_template.h"
2282 #include "softmmu_template.h"
2285 #include "softmmu_template.h"
2288 #include "softmmu_template.h"
2290 static void do_unaligned_access(CPUMIPSState *env, target_ulong addr,
2291 int is_write, int is_user, uintptr_t retaddr)
2293 env->CP0_BadVAddr = addr;
2294 do_restore_state(env, retaddr);
2295 helper_raise_exception(env, (is_write == 1) ? EXCP_AdES : EXCP_AdEL);
2298 void tlb_fill(CPUMIPSState *env, target_ulong addr, int is_write, int mmu_idx,
2301 TranslationBlock *tb;
2304 ret = cpu_mips_handle_mmu_fault(env, addr, is_write, mmu_idx);
2307 /* now we have a real cpu fault */
2308 tb = tb_find_pc(retaddr);
2310 /* the PC is inside the translated code. It means that we have
2311 a virtual CPU fault */
2312 cpu_restore_state(tb, env, retaddr);
2315 helper_raise_exception_err(env, env->exception_index, env->error_code);
2319 void cpu_unassigned_access(CPUMIPSState *env, target_phys_addr_t addr,
2320 int is_write, int is_exec, int unused, int size)
2323 helper_raise_exception(env, EXCP_IBE);
2325 helper_raise_exception(env, EXCP_DBE);
2327 #endif /* !CONFIG_USER_ONLY */
2329 /* Complex FPU operations which may need stack space. */
2331 #define FLOAT_ONE32 make_float32(0x3f8 << 20)
2332 #define FLOAT_ONE64 make_float64(0x3ffULL << 52)
2333 #define FLOAT_TWO32 make_float32(1 << 30)
2334 #define FLOAT_TWO64 make_float64(1ULL << 62)
2335 #define FLOAT_QNAN32 0x7fbfffff
2336 #define FLOAT_QNAN64 0x7ff7ffffffffffffULL
2337 #define FLOAT_SNAN32 0x7fffffff
2338 #define FLOAT_SNAN64 0x7fffffffffffffffULL
2340 /* convert MIPS rounding mode in FCR31 to IEEE library */
2341 static unsigned int ieee_rm[] = {
2342 float_round_nearest_even,
2343 float_round_to_zero,
2348 #define RESTORE_ROUNDING_MODE \
2349 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
2351 #define RESTORE_FLUSH_MODE \
2352 set_flush_to_zero((env->active_fpu.fcr31 & (1 << 24)) != 0, &env->active_fpu.fp_status);
2354 target_ulong helper_cfc1(CPUMIPSState *env, uint32_t reg)
2360 arg1 = (int32_t)env->active_fpu.fcr0;
2363 arg1 = ((env->active_fpu.fcr31 >> 24) & 0xfe) | ((env->active_fpu.fcr31 >> 23) & 0x1);
2366 arg1 = env->active_fpu.fcr31 & 0x0003f07c;
2369 arg1 = (env->active_fpu.fcr31 & 0x00000f83) | ((env->active_fpu.fcr31 >> 22) & 0x4);
2372 arg1 = (int32_t)env->active_fpu.fcr31;
2379 void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t reg)
2383 if (arg1 & 0xffffff00)
2385 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0x017fffff) | ((arg1 & 0xfe) << 24) |
2386 ((arg1 & 0x1) << 23);
2389 if (arg1 & 0x007c0000)
2391 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfffc0f83) | (arg1 & 0x0003f07c);
2394 if (arg1 & 0x007c0000)
2396 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfefff07c) | (arg1 & 0x00000f83) |
2397 ((arg1 & 0x4) << 22);
2400 if (arg1 & 0x007c0000)
2402 env->active_fpu.fcr31 = arg1;
2407 /* set rounding mode */
2408 RESTORE_ROUNDING_MODE;
2409 /* set flush-to-zero mode */
2411 set_float_exception_flags(0, &env->active_fpu.fp_status);
2412 if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) & GET_FP_CAUSE(env->active_fpu.fcr31))
2413 helper_raise_exception(env, EXCP_FPE);
2416 static inline int ieee_ex_to_mips(int xcpt)
2420 if (xcpt & float_flag_invalid) {
2423 if (xcpt & float_flag_overflow) {
2426 if (xcpt & float_flag_underflow) {
2427 ret |= FP_UNDERFLOW;
2429 if (xcpt & float_flag_divbyzero) {
2432 if (xcpt & float_flag_inexact) {
2439 static inline void update_fcr31(CPUMIPSState *env)
2441 int tmp = ieee_ex_to_mips(get_float_exception_flags(&env->active_fpu.fp_status));
2443 SET_FP_CAUSE(env->active_fpu.fcr31, tmp);
2444 if (GET_FP_ENABLE(env->active_fpu.fcr31) & tmp)
2445 helper_raise_exception(env, EXCP_FPE);
2447 UPDATE_FP_FLAGS(env->active_fpu.fcr31, tmp);
2451 Single precition routines have a "s" suffix, double precision a
2452 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2453 paired single lower "pl", paired single upper "pu". */
2455 /* unary operations, modifying fp status */
2456 uint64_t helper_float_sqrt_d(CPUMIPSState *env, uint64_t fdt0)
2458 return float64_sqrt(fdt0, &env->active_fpu.fp_status);
2461 uint32_t helper_float_sqrt_s(CPUMIPSState *env, uint32_t fst0)
2463 return float32_sqrt(fst0, &env->active_fpu.fp_status);
2466 uint64_t helper_float_cvtd_s(CPUMIPSState *env, uint32_t fst0)
2470 set_float_exception_flags(0, &env->active_fpu.fp_status);
2471 fdt2 = float32_to_float64(fst0, &env->active_fpu.fp_status);
2476 uint64_t helper_float_cvtd_w(CPUMIPSState *env, uint32_t wt0)
2480 set_float_exception_flags(0, &env->active_fpu.fp_status);
2481 fdt2 = int32_to_float64(wt0, &env->active_fpu.fp_status);
2486 uint64_t helper_float_cvtd_l(CPUMIPSState *env, uint64_t dt0)
2490 set_float_exception_flags(0, &env->active_fpu.fp_status);
2491 fdt2 = int64_to_float64(dt0, &env->active_fpu.fp_status);
2496 uint64_t helper_float_cvtl_d(CPUMIPSState *env, uint64_t fdt0)
2500 set_float_exception_flags(0, &env->active_fpu.fp_status);
2501 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
2503 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2508 uint64_t helper_float_cvtl_s(CPUMIPSState *env, uint32_t fst0)
2512 set_float_exception_flags(0, &env->active_fpu.fp_status);
2513 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
2515 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2520 uint64_t helper_float_cvtps_pw(CPUMIPSState *env, uint64_t dt0)
2525 set_float_exception_flags(0, &env->active_fpu.fp_status);
2526 fst2 = int32_to_float32(dt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2527 fsth2 = int32_to_float32(dt0 >> 32, &env->active_fpu.fp_status);
2529 return ((uint64_t)fsth2 << 32) | fst2;
2532 uint64_t helper_float_cvtpw_ps(CPUMIPSState *env, uint64_t fdt0)
2537 set_float_exception_flags(0, &env->active_fpu.fp_status);
2538 wt2 = float32_to_int32(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2539 wth2 = float32_to_int32(fdt0 >> 32, &env->active_fpu.fp_status);
2541 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID)) {
2543 wth2 = FLOAT_SNAN32;
2545 return ((uint64_t)wth2 << 32) | wt2;
2548 uint32_t helper_float_cvts_d(CPUMIPSState *env, uint64_t fdt0)
2552 set_float_exception_flags(0, &env->active_fpu.fp_status);
2553 fst2 = float64_to_float32(fdt0, &env->active_fpu.fp_status);
2558 uint32_t helper_float_cvts_w(CPUMIPSState *env, uint32_t wt0)
2562 set_float_exception_flags(0, &env->active_fpu.fp_status);
2563 fst2 = int32_to_float32(wt0, &env->active_fpu.fp_status);
2568 uint32_t helper_float_cvts_l(CPUMIPSState *env, uint64_t dt0)
2572 set_float_exception_flags(0, &env->active_fpu.fp_status);
2573 fst2 = int64_to_float32(dt0, &env->active_fpu.fp_status);
2578 uint32_t helper_float_cvts_pl(CPUMIPSState *env, uint32_t wt0)
2582 set_float_exception_flags(0, &env->active_fpu.fp_status);
2588 uint32_t helper_float_cvts_pu(CPUMIPSState *env, uint32_t wth0)
2592 set_float_exception_flags(0, &env->active_fpu.fp_status);
2598 uint32_t helper_float_cvtw_s(CPUMIPSState *env, uint32_t fst0)
2602 set_float_exception_flags(0, &env->active_fpu.fp_status);
2603 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
2605 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2610 uint32_t helper_float_cvtw_d(CPUMIPSState *env, uint64_t fdt0)
2614 set_float_exception_flags(0, &env->active_fpu.fp_status);
2615 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
2617 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2622 uint64_t helper_float_roundl_d(CPUMIPSState *env, uint64_t fdt0)
2626 set_float_exception_flags(0, &env->active_fpu.fp_status);
2627 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2628 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
2629 RESTORE_ROUNDING_MODE;
2631 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2636 uint64_t helper_float_roundl_s(CPUMIPSState *env, uint32_t fst0)
2640 set_float_exception_flags(0, &env->active_fpu.fp_status);
2641 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2642 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
2643 RESTORE_ROUNDING_MODE;
2645 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2650 uint32_t helper_float_roundw_d(CPUMIPSState *env, uint64_t fdt0)
2654 set_float_exception_flags(0, &env->active_fpu.fp_status);
2655 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2656 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
2657 RESTORE_ROUNDING_MODE;
2659 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2664 uint32_t helper_float_roundw_s(CPUMIPSState *env, uint32_t fst0)
2668 set_float_exception_flags(0, &env->active_fpu.fp_status);
2669 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2670 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
2671 RESTORE_ROUNDING_MODE;
2673 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2678 uint64_t helper_float_truncl_d(CPUMIPSState *env, uint64_t fdt0)
2682 set_float_exception_flags(0, &env->active_fpu.fp_status);
2683 dt2 = float64_to_int64_round_to_zero(fdt0, &env->active_fpu.fp_status);
2685 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2690 uint64_t helper_float_truncl_s(CPUMIPSState *env, uint32_t fst0)
2694 set_float_exception_flags(0, &env->active_fpu.fp_status);
2695 dt2 = float32_to_int64_round_to_zero(fst0, &env->active_fpu.fp_status);
2697 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2702 uint32_t helper_float_truncw_d(CPUMIPSState *env, uint64_t fdt0)
2706 set_float_exception_flags(0, &env->active_fpu.fp_status);
2707 wt2 = float64_to_int32_round_to_zero(fdt0, &env->active_fpu.fp_status);
2709 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2714 uint32_t helper_float_truncw_s(CPUMIPSState *env, uint32_t fst0)
2718 set_float_exception_flags(0, &env->active_fpu.fp_status);
2719 wt2 = float32_to_int32_round_to_zero(fst0, &env->active_fpu.fp_status);
2721 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2726 uint64_t helper_float_ceill_d(CPUMIPSState *env, uint64_t fdt0)
2730 set_float_exception_flags(0, &env->active_fpu.fp_status);
2731 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2732 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
2733 RESTORE_ROUNDING_MODE;
2735 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2740 uint64_t helper_float_ceill_s(CPUMIPSState *env, uint32_t fst0)
2744 set_float_exception_flags(0, &env->active_fpu.fp_status);
2745 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2746 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
2747 RESTORE_ROUNDING_MODE;
2749 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2754 uint32_t helper_float_ceilw_d(CPUMIPSState *env, uint64_t fdt0)
2758 set_float_exception_flags(0, &env->active_fpu.fp_status);
2759 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2760 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
2761 RESTORE_ROUNDING_MODE;
2763 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2768 uint32_t helper_float_ceilw_s(CPUMIPSState *env, uint32_t fst0)
2772 set_float_exception_flags(0, &env->active_fpu.fp_status);
2773 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2774 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
2775 RESTORE_ROUNDING_MODE;
2777 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2782 uint64_t helper_float_floorl_d(CPUMIPSState *env, uint64_t fdt0)
2786 set_float_exception_flags(0, &env->active_fpu.fp_status);
2787 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2788 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
2789 RESTORE_ROUNDING_MODE;
2791 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2796 uint64_t helper_float_floorl_s(CPUMIPSState *env, uint32_t fst0)
2800 set_float_exception_flags(0, &env->active_fpu.fp_status);
2801 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2802 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
2803 RESTORE_ROUNDING_MODE;
2805 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2810 uint32_t helper_float_floorw_d(CPUMIPSState *env, uint64_t fdt0)
2814 set_float_exception_flags(0, &env->active_fpu.fp_status);
2815 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2816 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
2817 RESTORE_ROUNDING_MODE;
2819 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2824 uint32_t helper_float_floorw_s(CPUMIPSState *env, uint32_t fst0)
2828 set_float_exception_flags(0, &env->active_fpu.fp_status);
2829 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2830 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
2831 RESTORE_ROUNDING_MODE;
2833 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
2838 /* unary operations, not modifying fp status */
2839 #define FLOAT_UNOP(name) \
2840 uint64_t helper_float_ ## name ## _d(uint64_t fdt0) \
2842 return float64_ ## name(fdt0); \
2844 uint32_t helper_float_ ## name ## _s(uint32_t fst0) \
2846 return float32_ ## name(fst0); \
2848 uint64_t helper_float_ ## name ## _ps(uint64_t fdt0) \
2853 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2854 wth0 = float32_ ## name(fdt0 >> 32); \
2855 return ((uint64_t)wth0 << 32) | wt0; \
2861 /* MIPS specific unary operations */
2862 uint64_t helper_float_recip_d(CPUMIPSState *env, uint64_t fdt0)
2866 set_float_exception_flags(0, &env->active_fpu.fp_status);
2867 fdt2 = float64_div(FLOAT_ONE64, fdt0, &env->active_fpu.fp_status);
2872 uint32_t helper_float_recip_s(CPUMIPSState *env, uint32_t fst0)
2876 set_float_exception_flags(0, &env->active_fpu.fp_status);
2877 fst2 = float32_div(FLOAT_ONE32, fst0, &env->active_fpu.fp_status);
2882 uint64_t helper_float_rsqrt_d(CPUMIPSState *env, uint64_t fdt0)
2886 set_float_exception_flags(0, &env->active_fpu.fp_status);
2887 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
2888 fdt2 = float64_div(FLOAT_ONE64, fdt2, &env->active_fpu.fp_status);
2893 uint32_t helper_float_rsqrt_s(CPUMIPSState *env, uint32_t fst0)
2897 set_float_exception_flags(0, &env->active_fpu.fp_status);
2898 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
2899 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
2904 uint64_t helper_float_recip1_d(CPUMIPSState *env, uint64_t fdt0)
2908 set_float_exception_flags(0, &env->active_fpu.fp_status);
2909 fdt2 = float64_div(FLOAT_ONE64, fdt0, &env->active_fpu.fp_status);
2914 uint32_t helper_float_recip1_s(CPUMIPSState *env, uint32_t fst0)
2918 set_float_exception_flags(0, &env->active_fpu.fp_status);
2919 fst2 = float32_div(FLOAT_ONE32, fst0, &env->active_fpu.fp_status);
2924 uint64_t helper_float_recip1_ps(CPUMIPSState *env, uint64_t fdt0)
2929 set_float_exception_flags(0, &env->active_fpu.fp_status);
2930 fst2 = float32_div(FLOAT_ONE32, fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2931 fsth2 = float32_div(FLOAT_ONE32, fdt0 >> 32, &env->active_fpu.fp_status);
2933 return ((uint64_t)fsth2 << 32) | fst2;
2936 uint64_t helper_float_rsqrt1_d(CPUMIPSState *env, uint64_t fdt0)
2940 set_float_exception_flags(0, &env->active_fpu.fp_status);
2941 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
2942 fdt2 = float64_div(FLOAT_ONE64, fdt2, &env->active_fpu.fp_status);
2947 uint32_t helper_float_rsqrt1_s(CPUMIPSState *env, uint32_t fst0)
2951 set_float_exception_flags(0, &env->active_fpu.fp_status);
2952 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
2953 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
2958 uint64_t helper_float_rsqrt1_ps(CPUMIPSState *env, uint64_t fdt0)
2963 set_float_exception_flags(0, &env->active_fpu.fp_status);
2964 fst2 = float32_sqrt(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2965 fsth2 = float32_sqrt(fdt0 >> 32, &env->active_fpu.fp_status);
2966 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
2967 fsth2 = float32_div(FLOAT_ONE32, fsth2, &env->active_fpu.fp_status);
2969 return ((uint64_t)fsth2 << 32) | fst2;
2972 #define FLOAT_OP(name, p) void helper_float_##name##_##p(CPUMIPSState *env)
2974 /* binary operations */
2975 #define FLOAT_BINOP(name) \
2976 uint64_t helper_float_ ## name ## _d(CPUMIPSState *env, \
2977 uint64_t fdt0, uint64_t fdt1) \
2981 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2982 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
2983 update_fcr31(env); \
2984 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2985 dt2 = FLOAT_QNAN64; \
2989 uint32_t helper_float_ ## name ## _s(CPUMIPSState *env, \
2990 uint32_t fst0, uint32_t fst1) \
2994 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2995 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2996 update_fcr31(env); \
2997 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
2998 wt2 = FLOAT_QNAN32; \
3002 uint64_t helper_float_ ## name ## _ps(CPUMIPSState *env, \
3006 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3007 uint32_t fsth0 = fdt0 >> 32; \
3008 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3009 uint32_t fsth1 = fdt1 >> 32; \
3013 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3014 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
3015 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
3016 update_fcr31(env); \
3017 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) { \
3018 wt2 = FLOAT_QNAN32; \
3019 wth2 = FLOAT_QNAN32; \
3021 return ((uint64_t)wth2 << 32) | wt2; \
3030 /* ternary operations */
3031 #define FLOAT_TERNOP(name1, name2) \
3032 uint64_t helper_float_ ## name1 ## name2 ## _d(CPUMIPSState *env, \
3037 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
3038 return float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
3041 uint32_t helper_float_ ## name1 ## name2 ## _s(CPUMIPSState *env, \
3046 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3047 return float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3050 uint64_t helper_float_ ## name1 ## name2 ## _ps(CPUMIPSState *env, \
3055 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3056 uint32_t fsth0 = fdt0 >> 32; \
3057 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3058 uint32_t fsth1 = fdt1 >> 32; \
3059 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3060 uint32_t fsth2 = fdt2 >> 32; \
3062 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3063 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
3064 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3065 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
3066 return ((uint64_t)fsth2 << 32) | fst2; \
3069 FLOAT_TERNOP(mul, add)
3070 FLOAT_TERNOP(mul, sub)
3073 /* negated ternary operations */
3074 #define FLOAT_NTERNOP(name1, name2) \
3075 uint64_t helper_float_n ## name1 ## name2 ## _d(CPUMIPSState *env, \
3080 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
3081 fdt2 = float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
3082 return float64_chs(fdt2); \
3085 uint32_t helper_float_n ## name1 ## name2 ## _s(CPUMIPSState *env, \
3090 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3091 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3092 return float32_chs(fst2); \
3095 uint64_t helper_float_n ## name1 ## name2 ## _ps(CPUMIPSState *env, \
3100 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
3101 uint32_t fsth0 = fdt0 >> 32; \
3102 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
3103 uint32_t fsth1 = fdt1 >> 32; \
3104 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
3105 uint32_t fsth2 = fdt2 >> 32; \
3107 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
3108 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
3109 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
3110 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
3111 fst2 = float32_chs(fst2); \
3112 fsth2 = float32_chs(fsth2); \
3113 return ((uint64_t)fsth2 << 32) | fst2; \
3116 FLOAT_NTERNOP(mul, add)
3117 FLOAT_NTERNOP(mul, sub)
3118 #undef FLOAT_NTERNOP
3120 /* MIPS specific binary operations */
3121 uint64_t helper_float_recip2_d(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
3123 set_float_exception_flags(0, &env->active_fpu.fp_status);
3124 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
3125 fdt2 = float64_chs(float64_sub(fdt2, FLOAT_ONE64, &env->active_fpu.fp_status));
3130 uint32_t helper_float_recip2_s(CPUMIPSState *env, uint32_t fst0, uint32_t fst2)
3132 set_float_exception_flags(0, &env->active_fpu.fp_status);
3133 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
3134 fst2 = float32_chs(float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status));
3139 uint64_t helper_float_recip2_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
3141 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
3142 uint32_t fsth0 = fdt0 >> 32;
3143 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
3144 uint32_t fsth2 = fdt2 >> 32;
3146 set_float_exception_flags(0, &env->active_fpu.fp_status);
3147 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
3148 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
3149 fst2 = float32_chs(float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status));
3150 fsth2 = float32_chs(float32_sub(fsth2, FLOAT_ONE32, &env->active_fpu.fp_status));
3152 return ((uint64_t)fsth2 << 32) | fst2;
3155 uint64_t helper_float_rsqrt2_d(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
3157 set_float_exception_flags(0, &env->active_fpu.fp_status);
3158 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
3159 fdt2 = float64_sub(fdt2, FLOAT_ONE64, &env->active_fpu.fp_status);
3160 fdt2 = float64_chs(float64_div(fdt2, FLOAT_TWO64, &env->active_fpu.fp_status));
3165 uint32_t helper_float_rsqrt2_s(CPUMIPSState *env, uint32_t fst0, uint32_t fst2)
3167 set_float_exception_flags(0, &env->active_fpu.fp_status);
3168 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
3169 fst2 = float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status);
3170 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32, &env->active_fpu.fp_status));
3175 uint64_t helper_float_rsqrt2_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt2)
3177 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
3178 uint32_t fsth0 = fdt0 >> 32;
3179 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
3180 uint32_t fsth2 = fdt2 >> 32;
3182 set_float_exception_flags(0, &env->active_fpu.fp_status);
3183 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
3184 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
3185 fst2 = float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status);
3186 fsth2 = float32_sub(fsth2, FLOAT_ONE32, &env->active_fpu.fp_status);
3187 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32, &env->active_fpu.fp_status));
3188 fsth2 = float32_chs(float32_div(fsth2, FLOAT_TWO32, &env->active_fpu.fp_status));
3190 return ((uint64_t)fsth2 << 32) | fst2;
3193 uint64_t helper_float_addr_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt1)
3195 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
3196 uint32_t fsth0 = fdt0 >> 32;
3197 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
3198 uint32_t fsth1 = fdt1 >> 32;
3202 set_float_exception_flags(0, &env->active_fpu.fp_status);
3203 fst2 = float32_add (fst0, fsth0, &env->active_fpu.fp_status);
3204 fsth2 = float32_add (fst1, fsth1, &env->active_fpu.fp_status);
3206 return ((uint64_t)fsth2 << 32) | fst2;
3209 uint64_t helper_float_mulr_ps(CPUMIPSState *env, uint64_t fdt0, uint64_t fdt1)
3211 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
3212 uint32_t fsth0 = fdt0 >> 32;
3213 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
3214 uint32_t fsth1 = fdt1 >> 32;
3218 set_float_exception_flags(0, &env->active_fpu.fp_status);
3219 fst2 = float32_mul (fst0, fsth0, &env->active_fpu.fp_status);
3220 fsth2 = float32_mul (fst1, fsth1, &env->active_fpu.fp_status);
3222 return ((uint64_t)fsth2 << 32) | fst2;
3225 /* compare operations */
3226 #define FOP_COND_D(op, cond) \
3227 void helper_cmp_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3228 uint64_t fdt1, int cc) \
3231 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3233 update_fcr31(env); \
3235 SET_FP_COND(cc, env->active_fpu); \
3237 CLEAR_FP_COND(cc, env->active_fpu); \
3239 void helper_cmpabs_d_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3240 uint64_t fdt1, int cc) \
3243 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3244 fdt0 = float64_abs(fdt0); \
3245 fdt1 = float64_abs(fdt1); \
3247 update_fcr31(env); \
3249 SET_FP_COND(cc, env->active_fpu); \
3251 CLEAR_FP_COND(cc, env->active_fpu); \
3254 /* NOTE: the comma operator will make "cond" to eval to false,
3255 * but float64_unordered_quiet() is still called. */
3256 FOP_COND_D(f, (float64_unordered_quiet(fdt1, fdt0, &env->active_fpu.fp_status), 0))
3257 FOP_COND_D(un, float64_unordered_quiet(fdt1, fdt0, &env->active_fpu.fp_status))
3258 FOP_COND_D(eq, float64_eq_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3259 FOP_COND_D(ueq, float64_unordered_quiet(fdt1, fdt0, &env->active_fpu.fp_status) || float64_eq_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3260 FOP_COND_D(olt, float64_lt_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3261 FOP_COND_D(ult, float64_unordered_quiet(fdt1, fdt0, &env->active_fpu.fp_status) || float64_lt_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3262 FOP_COND_D(ole, float64_le_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3263 FOP_COND_D(ule, float64_unordered_quiet(fdt1, fdt0, &env->active_fpu.fp_status) || float64_le_quiet(fdt0, fdt1, &env->active_fpu.fp_status))
3264 /* NOTE: the comma operator will make "cond" to eval to false,
3265 * but float64_unordered() is still called. */
3266 FOP_COND_D(sf, (float64_unordered(fdt1, fdt0, &env->active_fpu.fp_status), 0))
3267 FOP_COND_D(ngle,float64_unordered(fdt1, fdt0, &env->active_fpu.fp_status))
3268 FOP_COND_D(seq, float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
3269 FOP_COND_D(ngl, float64_unordered(fdt1, fdt0, &env->active_fpu.fp_status) || float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
3270 FOP_COND_D(lt, float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
3271 FOP_COND_D(nge, float64_unordered(fdt1, fdt0, &env->active_fpu.fp_status) || float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
3272 FOP_COND_D(le, float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
3273 FOP_COND_D(ngt, float64_unordered(fdt1, fdt0, &env->active_fpu.fp_status) || float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
3275 #define FOP_COND_S(op, cond) \
3276 void helper_cmp_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3277 uint32_t fst1, int cc) \
3280 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3282 update_fcr31(env); \
3284 SET_FP_COND(cc, env->active_fpu); \
3286 CLEAR_FP_COND(cc, env->active_fpu); \
3288 void helper_cmpabs_s_ ## op(CPUMIPSState *env, uint32_t fst0, \
3289 uint32_t fst1, int cc) \
3292 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3293 fst0 = float32_abs(fst0); \
3294 fst1 = float32_abs(fst1); \
3296 update_fcr31(env); \
3298 SET_FP_COND(cc, env->active_fpu); \
3300 CLEAR_FP_COND(cc, env->active_fpu); \
3303 /* NOTE: the comma operator will make "cond" to eval to false,
3304 * but float32_unordered_quiet() is still called. */
3305 FOP_COND_S(f, (float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status), 0))
3306 FOP_COND_S(un, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status))
3307 FOP_COND_S(eq, float32_eq_quiet(fst0, fst1, &env->active_fpu.fp_status))
3308 FOP_COND_S(ueq, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_eq_quiet(fst0, fst1, &env->active_fpu.fp_status))
3309 FOP_COND_S(olt, float32_lt_quiet(fst0, fst1, &env->active_fpu.fp_status))
3310 FOP_COND_S(ult, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_lt_quiet(fst0, fst1, &env->active_fpu.fp_status))
3311 FOP_COND_S(ole, float32_le_quiet(fst0, fst1, &env->active_fpu.fp_status))
3312 FOP_COND_S(ule, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_le_quiet(fst0, fst1, &env->active_fpu.fp_status))
3313 /* NOTE: the comma operator will make "cond" to eval to false,
3314 * but float32_unordered() is still called. */
3315 FOP_COND_S(sf, (float32_unordered(fst1, fst0, &env->active_fpu.fp_status), 0))
3316 FOP_COND_S(ngle,float32_unordered(fst1, fst0, &env->active_fpu.fp_status))
3317 FOP_COND_S(seq, float32_eq(fst0, fst1, &env->active_fpu.fp_status))
3318 FOP_COND_S(ngl, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status))
3319 FOP_COND_S(lt, float32_lt(fst0, fst1, &env->active_fpu.fp_status))
3320 FOP_COND_S(nge, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status))
3321 FOP_COND_S(le, float32_le(fst0, fst1, &env->active_fpu.fp_status))
3322 FOP_COND_S(ngt, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status))
3324 #define FOP_COND_PS(op, condl, condh) \
3325 void helper_cmp_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3326 uint64_t fdt1, int cc) \
3328 uint32_t fst0, fsth0, fst1, fsth1; \
3330 set_float_exception_flags(0, &env->active_fpu.fp_status); \
3331 fst0 = fdt0 & 0XFFFFFFFF; \
3332 fsth0 = fdt0 >> 32; \
3333 fst1 = fdt1 & 0XFFFFFFFF; \
3334 fsth1 = fdt1 >> 32; \
3337 update_fcr31(env); \
3339 SET_FP_COND(cc, env->active_fpu); \
3341 CLEAR_FP_COND(cc, env->active_fpu); \
3343 SET_FP_COND(cc + 1, env->active_fpu); \
3345 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3347 void helper_cmpabs_ps_ ## op(CPUMIPSState *env, uint64_t fdt0, \
3348 uint64_t fdt1, int cc) \
3350 uint32_t fst0, fsth0, fst1, fsth1; \
3352 fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
3353 fsth0 = float32_abs(fdt0 >> 32); \
3354 fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
3355 fsth1 = float32_abs(fdt1 >> 32); \
3358 update_fcr31(env); \
3360 SET_FP_COND(cc, env->active_fpu); \
3362 CLEAR_FP_COND(cc, env->active_fpu); \
3364 SET_FP_COND(cc + 1, env->active_fpu); \
3366 CLEAR_FP_COND(cc + 1, env->active_fpu); \
3369 /* NOTE: the comma operator will make "cond" to eval to false,
3370 * but float32_unordered_quiet() is still called. */
3371 FOP_COND_PS(f, (float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status), 0),
3372 (float32_unordered_quiet(fsth1, fsth0, &env->active_fpu.fp_status), 0))
3373 FOP_COND_PS(un, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status),
3374 float32_unordered_quiet(fsth1, fsth0, &env->active_fpu.fp_status))
3375 FOP_COND_PS(eq, float32_eq_quiet(fst0, fst1, &env->active_fpu.fp_status),
3376 float32_eq_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3377 FOP_COND_PS(ueq, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_eq_quiet(fst0, fst1, &env->active_fpu.fp_status),
3378 float32_unordered_quiet(fsth1, fsth0, &env->active_fpu.fp_status) || float32_eq_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3379 FOP_COND_PS(olt, float32_lt_quiet(fst0, fst1, &env->active_fpu.fp_status),
3380 float32_lt_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3381 FOP_COND_PS(ult, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_lt_quiet(fst0, fst1, &env->active_fpu.fp_status),
3382 float32_unordered_quiet(fsth1, fsth0, &env->active_fpu.fp_status) || float32_lt_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3383 FOP_COND_PS(ole, float32_le_quiet(fst0, fst1, &env->active_fpu.fp_status),
3384 float32_le_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3385 FOP_COND_PS(ule, float32_unordered_quiet(fst1, fst0, &env->active_fpu.fp_status) || float32_le_quiet(fst0, fst1, &env->active_fpu.fp_status),
3386 float32_unordered_quiet(fsth1, fsth0, &env->active_fpu.fp_status) || float32_le_quiet(fsth0, fsth1, &env->active_fpu.fp_status))
3387 /* NOTE: the comma operator will make "cond" to eval to false,
3388 * but float32_unordered() is still called. */
3389 FOP_COND_PS(sf, (float32_unordered(fst1, fst0, &env->active_fpu.fp_status), 0),
3390 (float32_unordered(fsth1, fsth0, &env->active_fpu.fp_status), 0))
3391 FOP_COND_PS(ngle,float32_unordered(fst1, fst0, &env->active_fpu.fp_status),
3392 float32_unordered(fsth1, fsth0, &env->active_fpu.fp_status))
3393 FOP_COND_PS(seq, float32_eq(fst0, fst1, &env->active_fpu.fp_status),
3394 float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
3395 FOP_COND_PS(ngl, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status),
3396 float32_unordered(fsth1, fsth0, &env->active_fpu.fp_status) || float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
3397 FOP_COND_PS(lt, float32_lt(fst0, fst1, &env->active_fpu.fp_status),
3398 float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
3399 FOP_COND_PS(nge, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status),
3400 float32_unordered(fsth1, fsth0, &env->active_fpu.fp_status) || float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
3401 FOP_COND_PS(le, float32_le(fst0, fst1, &env->active_fpu.fp_status),
3402 float32_le(fsth0, fsth1, &env->active_fpu.fp_status))
3403 FOP_COND_PS(ngt, float32_unordered(fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status),
3404 float32_unordered(fsth1, fsth0, &env->active_fpu.fp_status) || float32_le(fsth0, fsth1, &env->active_fpu.fp_status))