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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "host-utils.h"
25 /*****************************************************************************/
26 /* Exceptions processing helpers */
28 void do_raise_exception_err (uint32_t exception, int error_code)
31 if (logfile && exception < 0x100)
32 fprintf(logfile, "%s: %d %d\n", __func__, exception, error_code);
34 env->exception_index = exception;
35 env->error_code = error_code;
39 void do_raise_exception (uint32_t exception)
41 do_raise_exception_err(exception, 0);
44 void do_interrupt_restart (void)
46 if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
47 !(env->CP0_Status & (1 << CP0St_ERL)) &&
48 !(env->hflags & MIPS_HFLAG_DM) &&
49 (env->CP0_Status & (1 << CP0St_IE)) &&
50 (env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask)) {
51 env->CP0_Cause &= ~(0x1f << CP0Ca_EC);
52 do_raise_exception(EXCP_EXT_INTERRUPT);
56 void do_restore_state (void *pc_ptr)
59 unsigned long pc = (unsigned long) pc_ptr;
63 cpu_restore_state (tb, env, pc, NULL);
67 target_ulong do_clo (target_ulong t0)
72 target_ulong do_clz (target_ulong t0)
77 #if defined(TARGET_MIPS64)
78 target_ulong do_dclo (target_ulong t0)
83 target_ulong do_dclz (target_ulong t0)
87 #endif /* TARGET_MIPS64 */
89 /* 64 bits arithmetic for 32 bits hosts */
90 static always_inline uint64_t get_HILO (void)
92 return ((uint64_t)(env->active_tc.HI[0]) << 32) | (uint32_t)env->active_tc.LO[0];
95 static always_inline void set_HILO (uint64_t HILO)
97 env->active_tc.LO[0] = (int32_t)HILO;
98 env->active_tc.HI[0] = (int32_t)(HILO >> 32);
101 static always_inline void set_HIT0_LO (target_ulong t0, uint64_t HILO)
103 env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
104 t0 = env->active_tc.HI[0] = (int32_t)(HILO >> 32);
107 static always_inline void set_HI_LOT0 (target_ulong t0, uint64_t HILO)
109 t0 = env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
110 env->active_tc.HI[0] = (int32_t)(HILO >> 32);
113 #if TARGET_LONG_BITS > HOST_LONG_BITS
114 void do_madd (target_ulong t0, target_ulong t1)
118 tmp = ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
119 set_HILO((int64_t)get_HILO() + tmp);
122 void do_maddu (target_ulong t0, target_ulong t1)
126 tmp = ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
127 set_HILO(get_HILO() + tmp);
130 void do_msub (target_ulong t0, target_ulong t1)
134 tmp = ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
135 set_HILO((int64_t)get_HILO() - tmp);
138 void do_msubu (target_ulong t0, target_ulong t1)
142 tmp = ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
143 set_HILO(get_HILO() - tmp);
145 #endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
147 /* Multiplication variants of the vr54xx. */
148 target_ulong do_muls (target_ulong t0, target_ulong t1)
150 set_HI_LOT0(t0, 0 - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
155 target_ulong do_mulsu (target_ulong t0, target_ulong t1)
157 set_HI_LOT0(t0, 0 - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
162 target_ulong do_macc (target_ulong t0, target_ulong t1)
164 set_HI_LOT0(t0, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
169 target_ulong do_macchi (target_ulong t0, target_ulong t1)
171 set_HIT0_LO(t0, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
176 target_ulong do_maccu (target_ulong t0, target_ulong t1)
178 set_HI_LOT0(t0, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
183 target_ulong do_macchiu (target_ulong t0, target_ulong t1)
185 set_HIT0_LO(t0, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
190 target_ulong do_msac (target_ulong t0, target_ulong t1)
192 set_HI_LOT0(t0, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
197 target_ulong do_msachi (target_ulong t0, target_ulong t1)
199 set_HIT0_LO(t0, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
204 target_ulong do_msacu (target_ulong t0, target_ulong t1)
206 set_HI_LOT0(t0, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
211 target_ulong do_msachiu (target_ulong t0, target_ulong t1)
213 set_HIT0_LO(t0, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
218 target_ulong do_mulhi (target_ulong t0, target_ulong t1)
220 set_HIT0_LO(t0, (int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
225 target_ulong do_mulhiu (target_ulong t0, target_ulong t1)
227 set_HIT0_LO(t0, (uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
232 target_ulong do_mulshi (target_ulong t0, target_ulong t1)
234 set_HIT0_LO(t0, 0 - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
239 target_ulong do_mulshiu (target_ulong t0, target_ulong t1)
241 set_HIT0_LO(t0, 0 - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
247 void do_dmult (target_ulong t0, target_ulong t1)
249 muls64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), t0, t1);
252 void do_dmultu (target_ulong t0, target_ulong t1)
254 mulu64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), t0, t1);
258 #ifdef TARGET_WORDS_BIGENDIAN
259 #define GET_LMASK(v) ((v) & 3)
260 #define GET_OFFSET(addr, offset) (addr + (offset))
262 #define GET_LMASK(v) (((v) & 3) ^ 3)
263 #define GET_OFFSET(addr, offset) (addr - (offset))
266 target_ulong do_lwl(target_ulong t0, target_ulong t1, int mem_idx)
270 #ifdef CONFIG_USER_ONLY
271 #define ldfun ldub_raw
273 int (*ldfun)(target_ulong);
277 case 0: ldfun = ldub_kernel; break;
278 case 1: ldfun = ldub_super; break;
280 case 2: ldfun = ldub_user; break;
284 t1 = (t1 & 0x00FFFFFF) | (tmp << 24);
286 if (GET_LMASK(t0) <= 2) {
287 tmp = ldfun(GET_OFFSET(t0, 1));
288 t1 = (t1 & 0xFF00FFFF) | (tmp << 16);
291 if (GET_LMASK(t0) <= 1) {
292 tmp = ldfun(GET_OFFSET(t0, 2));
293 t1 = (t1 & 0xFFFF00FF) | (tmp << 8);
296 if (GET_LMASK(t0) == 0) {
297 tmp = ldfun(GET_OFFSET(t0, 3));
298 t1 = (t1 & 0xFFFFFF00) | tmp;
303 target_ulong do_lwr(target_ulong t0, target_ulong t1, int mem_idx)
307 #ifdef CONFIG_USER_ONLY
308 #define ldfun ldub_raw
310 int (*ldfun)(target_ulong);
314 case 0: ldfun = ldub_kernel; break;
315 case 1: ldfun = ldub_super; break;
317 case 2: ldfun = ldub_user; break;
321 t1 = (t1 & 0xFFFFFF00) | tmp;
323 if (GET_LMASK(t0) >= 1) {
324 tmp = ldfun(GET_OFFSET(t0, -1));
325 t1 = (t1 & 0xFFFF00FF) | (tmp << 8);
328 if (GET_LMASK(t0) >= 2) {
329 tmp = ldfun(GET_OFFSET(t0, -2));
330 t1 = (t1 & 0xFF00FFFF) | (tmp << 16);
333 if (GET_LMASK(t0) == 3) {
334 tmp = ldfun(GET_OFFSET(t0, -3));
335 t1 = (t1 & 0x00FFFFFF) | (tmp << 24);
340 void do_swl(target_ulong t0, target_ulong t1, int mem_idx)
342 #ifdef CONFIG_USER_ONLY
343 #define stfun stb_raw
345 void (*stfun)(target_ulong, int);
349 case 0: stfun = stb_kernel; break;
350 case 1: stfun = stb_super; break;
352 case 2: stfun = stb_user; break;
355 stfun(t0, (uint8_t)(t1 >> 24));
357 if (GET_LMASK(t0) <= 2)
358 stfun(GET_OFFSET(t0, 1), (uint8_t)(t1 >> 16));
360 if (GET_LMASK(t0) <= 1)
361 stfun(GET_OFFSET(t0, 2), (uint8_t)(t1 >> 8));
363 if (GET_LMASK(t0) == 0)
364 stfun(GET_OFFSET(t0, 3), (uint8_t)t1);
367 void do_swr(target_ulong t0, target_ulong t1, int mem_idx)
369 #ifdef CONFIG_USER_ONLY
370 #define stfun stb_raw
372 void (*stfun)(target_ulong, int);
376 case 0: stfun = stb_kernel; break;
377 case 1: stfun = stb_super; break;
379 case 2: stfun = stb_user; break;
382 stfun(t0, (uint8_t)t1);
384 if (GET_LMASK(t0) >= 1)
385 stfun(GET_OFFSET(t0, -1), (uint8_t)(t1 >> 8));
387 if (GET_LMASK(t0) >= 2)
388 stfun(GET_OFFSET(t0, -2), (uint8_t)(t1 >> 16));
390 if (GET_LMASK(t0) == 3)
391 stfun(GET_OFFSET(t0, -3), (uint8_t)(t1 >> 24));
394 #if defined(TARGET_MIPS64)
395 /* "half" load and stores. We must do the memory access inline,
396 or fault handling won't work. */
398 #ifdef TARGET_WORDS_BIGENDIAN
399 #define GET_LMASK64(v) ((v) & 7)
401 #define GET_LMASK64(v) (((v) & 7) ^ 7)
404 target_ulong do_ldl(target_ulong t0, target_ulong t1, int mem_idx)
408 #ifdef CONFIG_USER_ONLY
409 #define ldfun ldub_raw
411 int (*ldfun)(target_ulong);
415 case 0: ldfun = ldub_kernel; break;
416 case 1: ldfun = ldub_super; break;
418 case 2: ldfun = ldub_user; break;
422 t1 = (t1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
424 if (GET_LMASK64(t0) <= 6) {
425 tmp = ldfun(GET_OFFSET(t0, 1));
426 t1 = (t1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
429 if (GET_LMASK64(t0) <= 5) {
430 tmp = ldfun(GET_OFFSET(t0, 2));
431 t1 = (t1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
434 if (GET_LMASK64(t0) <= 4) {
435 tmp = ldfun(GET_OFFSET(t0, 3));
436 t1 = (t1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
439 if (GET_LMASK64(t0) <= 3) {
440 tmp = ldfun(GET_OFFSET(t0, 4));
441 t1 = (t1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
444 if (GET_LMASK64(t0) <= 2) {
445 tmp = ldfun(GET_OFFSET(t0, 5));
446 t1 = (t1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
449 if (GET_LMASK64(t0) <= 1) {
450 tmp = ldfun(GET_OFFSET(t0, 6));
451 t1 = (t1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
454 if (GET_LMASK64(t0) == 0) {
455 tmp = ldfun(GET_OFFSET(t0, 7));
456 t1 = (t1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
462 target_ulong do_ldr(target_ulong t0, target_ulong t1, int mem_idx)
466 #ifdef CONFIG_USER_ONLY
467 #define ldfun ldub_raw
469 int (*ldfun)(target_ulong);
473 case 0: ldfun = ldub_kernel; break;
474 case 1: ldfun = ldub_super; break;
476 case 2: ldfun = ldub_user; break;
480 t1 = (t1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
482 if (GET_LMASK64(t0) >= 1) {
483 tmp = ldfun(GET_OFFSET(t0, -1));
484 t1 = (t1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
487 if (GET_LMASK64(t0) >= 2) {
488 tmp = ldfun(GET_OFFSET(t0, -2));
489 t1 = (t1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
492 if (GET_LMASK64(t0) >= 3) {
493 tmp = ldfun(GET_OFFSET(t0, -3));
494 t1 = (t1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
497 if (GET_LMASK64(t0) >= 4) {
498 tmp = ldfun(GET_OFFSET(t0, -4));
499 t1 = (t1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
502 if (GET_LMASK64(t0) >= 5) {
503 tmp = ldfun(GET_OFFSET(t0, -5));
504 t1 = (t1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
507 if (GET_LMASK64(t0) >= 6) {
508 tmp = ldfun(GET_OFFSET(t0, -6));
509 t1 = (t1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
512 if (GET_LMASK64(t0) == 7) {
513 tmp = ldfun(GET_OFFSET(t0, -7));
514 t1 = (t1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
520 void do_sdl(target_ulong t0, target_ulong t1, int mem_idx)
522 #ifdef CONFIG_USER_ONLY
523 #define stfun stb_raw
525 void (*stfun)(target_ulong, int);
529 case 0: stfun = stb_kernel; break;
530 case 1: stfun = stb_super; break;
532 case 2: stfun = stb_user; break;
535 stfun(t0, (uint8_t)(t1 >> 56));
537 if (GET_LMASK64(t0) <= 6)
538 stfun(GET_OFFSET(t0, 1), (uint8_t)(t1 >> 48));
540 if (GET_LMASK64(t0) <= 5)
541 stfun(GET_OFFSET(t0, 2), (uint8_t)(t1 >> 40));
543 if (GET_LMASK64(t0) <= 4)
544 stfun(GET_OFFSET(t0, 3), (uint8_t)(t1 >> 32));
546 if (GET_LMASK64(t0) <= 3)
547 stfun(GET_OFFSET(t0, 4), (uint8_t)(t1 >> 24));
549 if (GET_LMASK64(t0) <= 2)
550 stfun(GET_OFFSET(t0, 5), (uint8_t)(t1 >> 16));
552 if (GET_LMASK64(t0) <= 1)
553 stfun(GET_OFFSET(t0, 6), (uint8_t)(t1 >> 8));
555 if (GET_LMASK64(t0) <= 0)
556 stfun(GET_OFFSET(t0, 7), (uint8_t)t1);
559 void do_sdr(target_ulong t0, target_ulong t1, int mem_idx)
561 #ifdef CONFIG_USER_ONLY
562 #define stfun stb_raw
564 void (*stfun)(target_ulong, int);
568 case 0: stfun = stb_kernel; break;
569 case 1: stfun = stb_super; break;
571 case 2: stfun = stb_user; break;
574 stfun(t0, (uint8_t)t1);
576 if (GET_LMASK64(t0) >= 1)
577 stfun(GET_OFFSET(t0, -1), (uint8_t)(t1 >> 8));
579 if (GET_LMASK64(t0) >= 2)
580 stfun(GET_OFFSET(t0, -2), (uint8_t)(t1 >> 16));
582 if (GET_LMASK64(t0) >= 3)
583 stfun(GET_OFFSET(t0, -3), (uint8_t)(t1 >> 24));
585 if (GET_LMASK64(t0) >= 4)
586 stfun(GET_OFFSET(t0, -4), (uint8_t)(t1 >> 32));
588 if (GET_LMASK64(t0) >= 5)
589 stfun(GET_OFFSET(t0, -5), (uint8_t)(t1 >> 40));
591 if (GET_LMASK64(t0) >= 6)
592 stfun(GET_OFFSET(t0, -6), (uint8_t)(t1 >> 48));
594 if (GET_LMASK64(t0) == 7)
595 stfun(GET_OFFSET(t0, -7), (uint8_t)(t1 >> 56));
597 #endif /* TARGET_MIPS64 */
599 #ifdef CONFIG_USER_ONLY
600 void do_mfc0_random (void)
602 cpu_abort(env, "mfc0 random\n");
605 void do_mfc0_count (void)
607 cpu_abort(env, "mfc0 count\n");
610 void cpu_mips_store_count(CPUState *env, uint32_t value)
612 cpu_abort(env, "mtc0 count\n");
615 void cpu_mips_store_compare(CPUState *env, uint32_t value)
617 cpu_abort(env, "mtc0 compare\n");
620 void cpu_mips_start_count(CPUState *env)
622 cpu_abort(env, "start count\n");
625 void cpu_mips_stop_count(CPUState *env)
627 cpu_abort(env, "stop count\n");
630 void cpu_mips_update_irq(CPUState *env)
632 cpu_abort(env, "mtc0 status / mtc0 cause\n");
635 void do_mtc0_status_debug(uint32_t old, uint32_t val)
637 cpu_abort(env, "mtc0 status debug\n");
640 void do_mtc0_status_irqraise_debug (void)
642 cpu_abort(env, "mtc0 status irqraise debug\n");
645 void cpu_mips_tlb_flush (CPUState *env, int flush_global)
647 cpu_abort(env, "mips_tlb_flush\n");
653 target_ulong do_mfc0_mvpcontrol (void)
655 return env->mvp->CP0_MVPControl;
658 target_ulong do_mfc0_mvpconf0 (void)
660 return env->mvp->CP0_MVPConf0;
663 target_ulong do_mfc0_mvpconf1 (void)
665 return env->mvp->CP0_MVPConf1;
668 target_ulong do_mfc0_random (void)
670 return (int32_t)cpu_mips_get_random(env);
673 target_ulong do_mfc0_tcstatus (void)
675 return env->active_tc.CP0_TCStatus;
678 target_ulong do_mftc0_tcstatus(void)
680 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
682 if (other_tc == env->current_tc)
683 return env->active_tc.CP0_TCStatus;
685 return env->tcs[other_tc].CP0_TCStatus;
688 target_ulong do_mfc0_tcbind (void)
690 return env->active_tc.CP0_TCBind;
693 target_ulong do_mftc0_tcbind(void)
695 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
697 if (other_tc == env->current_tc)
698 return env->active_tc.CP0_TCBind;
700 return env->tcs[other_tc].CP0_TCBind;
703 target_ulong do_mfc0_tcrestart (void)
705 return env->active_tc.PC;
708 target_ulong do_mftc0_tcrestart(void)
710 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
712 if (other_tc == env->current_tc)
713 return env->active_tc.PC;
715 return env->tcs[other_tc].PC;
718 target_ulong do_mfc0_tchalt (void)
720 return env->active_tc.CP0_TCHalt;
723 target_ulong do_mftc0_tchalt(void)
725 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
727 if (other_tc == env->current_tc)
728 return env->active_tc.CP0_TCHalt;
730 return env->tcs[other_tc].CP0_TCHalt;
733 target_ulong do_mfc0_tccontext (void)
735 return env->active_tc.CP0_TCContext;
738 target_ulong do_mftc0_tccontext(void)
740 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
742 if (other_tc == env->current_tc)
743 return env->active_tc.CP0_TCContext;
745 return env->tcs[other_tc].CP0_TCContext;
748 target_ulong do_mfc0_tcschedule (void)
750 return env->active_tc.CP0_TCSchedule;
753 target_ulong do_mftc0_tcschedule(void)
755 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
757 if (other_tc == env->current_tc)
758 return env->active_tc.CP0_TCSchedule;
760 return env->tcs[other_tc].CP0_TCSchedule;
763 target_ulong do_mfc0_tcschefback (void)
765 return env->active_tc.CP0_TCScheFBack;
768 target_ulong do_mftc0_tcschefback(void)
770 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
772 if (other_tc == env->current_tc)
773 return env->active_tc.CP0_TCScheFBack;
775 return env->tcs[other_tc].CP0_TCScheFBack;
778 target_ulong do_mfc0_count (void)
780 return (int32_t)cpu_mips_get_count(env);
783 target_ulong do_mftc0_entryhi(void)
785 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
788 if (other_tc == env->current_tc)
789 tcstatus = env->active_tc.CP0_TCStatus;
791 tcstatus = env->tcs[other_tc].CP0_TCStatus;
793 return (env->CP0_EntryHi & ~0xff) | (tcstatus & 0xff);
796 target_ulong do_mftc0_status(void)
798 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
802 if (other_tc == env->current_tc)
803 tcstatus = env->active_tc.CP0_TCStatus;
805 tcstatus = env->tcs[other_tc].CP0_TCStatus;
807 t0 = env->CP0_Status & ~0xf1000018;
808 t0 |= tcstatus & (0xf << CP0TCSt_TCU0);
809 t0 |= (tcstatus & (1 << CP0TCSt_TMX)) >> (CP0TCSt_TMX - CP0St_MX);
810 t0 |= (tcstatus & (0x3 << CP0TCSt_TKSU)) >> (CP0TCSt_TKSU - CP0St_KSU);
815 target_ulong do_mfc0_lladdr (void)
817 return (int32_t)env->CP0_LLAddr >> 4;
820 target_ulong do_mfc0_watchlo (uint32_t sel)
822 return (int32_t)env->CP0_WatchLo[sel];
825 target_ulong do_mfc0_watchhi (uint32_t sel)
827 return env->CP0_WatchHi[sel];
830 target_ulong do_mfc0_debug (void)
832 target_ulong t0 = env->CP0_Debug;
833 if (env->hflags & MIPS_HFLAG_DM)
839 target_ulong do_mftc0_debug(void)
841 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
844 if (other_tc == env->current_tc)
845 tcstatus = env->active_tc.CP0_Debug_tcstatus;
847 tcstatus = env->tcs[other_tc].CP0_Debug_tcstatus;
849 /* XXX: Might be wrong, check with EJTAG spec. */
850 return (env->CP0_Debug & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
851 (tcstatus & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
854 #if defined(TARGET_MIPS64)
855 target_ulong do_dmfc0_tcrestart (void)
857 return env->active_tc.PC;
860 target_ulong do_dmfc0_tchalt (void)
862 return env->active_tc.CP0_TCHalt;
865 target_ulong do_dmfc0_tccontext (void)
867 return env->active_tc.CP0_TCContext;
870 target_ulong do_dmfc0_tcschedule (void)
872 return env->active_tc.CP0_TCSchedule;
875 target_ulong do_dmfc0_tcschefback (void)
877 return env->active_tc.CP0_TCScheFBack;
880 target_ulong do_dmfc0_lladdr (void)
882 return env->CP0_LLAddr >> 4;
885 target_ulong do_dmfc0_watchlo (uint32_t sel)
887 return env->CP0_WatchLo[sel];
889 #endif /* TARGET_MIPS64 */
891 void do_mtc0_index (target_ulong t0)
894 unsigned int tmp = env->tlb->nb_tlb;
900 env->CP0_Index = (env->CP0_Index & 0x80000000) | (t0 & (num - 1));
903 void do_mtc0_mvpcontrol (target_ulong t0)
908 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))
909 mask |= (1 << CP0MVPCo_CPA) | (1 << CP0MVPCo_VPC) |
911 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
912 mask |= (1 << CP0MVPCo_STLB);
913 newval = (env->mvp->CP0_MVPControl & ~mask) | (t0 & mask);
915 // TODO: Enable/disable shared TLB, enable/disable VPEs.
917 env->mvp->CP0_MVPControl = newval;
920 void do_mtc0_vpecontrol (target_ulong t0)
925 mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
926 (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
927 newval = (env->CP0_VPEControl & ~mask) | (t0 & mask);
929 /* Yield scheduler intercept not implemented. */
930 /* Gating storage scheduler intercept not implemented. */
932 // TODO: Enable/disable TCs.
934 env->CP0_VPEControl = newval;
937 void do_mtc0_vpeconf0 (target_ulong t0)
942 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
943 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))
944 mask |= (0xff << CP0VPEC0_XTC);
945 mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
947 newval = (env->CP0_VPEConf0 & ~mask) | (t0 & mask);
949 // TODO: TC exclusive handling due to ERL/EXL.
951 env->CP0_VPEConf0 = newval;
954 void do_mtc0_vpeconf1 (target_ulong t0)
959 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
960 mask |= (0xff << CP0VPEC1_NCX) | (0xff << CP0VPEC1_NCP2) |
961 (0xff << CP0VPEC1_NCP1);
962 newval = (env->CP0_VPEConf1 & ~mask) | (t0 & mask);
964 /* UDI not implemented. */
965 /* CP2 not implemented. */
967 // TODO: Handle FPU (CP1) binding.
969 env->CP0_VPEConf1 = newval;
972 void do_mtc0_yqmask (target_ulong t0)
974 /* Yield qualifier inputs not implemented. */
975 env->CP0_YQMask = 0x00000000;
978 void do_mtc0_vpeopt (target_ulong t0)
980 env->CP0_VPEOpt = t0 & 0x0000ffff;
983 void do_mtc0_entrylo0 (target_ulong t0)
985 /* Large physaddr (PABITS) not implemented */
986 /* 1k pages not implemented */
987 env->CP0_EntryLo0 = t0 & 0x3FFFFFFF;
990 void do_mtc0_tcstatus (target_ulong t0)
992 uint32_t mask = env->CP0_TCStatus_rw_bitmask;
995 newval = (env->active_tc.CP0_TCStatus & ~mask) | (t0 & mask);
997 // TODO: Sync with CP0_Status.
999 env->active_tc.CP0_TCStatus = newval;
1002 void do_mttc0_tcstatus (target_ulong t0)
1004 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1006 // TODO: Sync with CP0_Status.
1008 if (other_tc == env->current_tc)
1009 env->active_tc.CP0_TCStatus = t0;
1011 env->tcs[other_tc].CP0_TCStatus = t0;
1014 void do_mtc0_tcbind (target_ulong t0)
1016 uint32_t mask = (1 << CP0TCBd_TBE);
1019 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1020 mask |= (1 << CP0TCBd_CurVPE);
1021 newval = (env->active_tc.CP0_TCBind & ~mask) | (t0 & mask);
1022 env->active_tc.CP0_TCBind = newval;
1025 void do_mttc0_tcbind (target_ulong t0)
1027 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1028 uint32_t mask = (1 << CP0TCBd_TBE);
1031 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1032 mask |= (1 << CP0TCBd_CurVPE);
1033 if (other_tc == env->current_tc) {
1034 newval = (env->active_tc.CP0_TCBind & ~mask) | (t0 & mask);
1035 env->active_tc.CP0_TCBind = newval;
1037 newval = (env->tcs[other_tc].CP0_TCBind & ~mask) | (t0 & mask);
1038 env->tcs[other_tc].CP0_TCBind = newval;
1042 void do_mtc0_tcrestart (target_ulong t0)
1044 env->active_tc.PC = t0;
1045 env->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1046 env->CP0_LLAddr = 0ULL;
1047 /* MIPS16 not implemented. */
1050 void do_mttc0_tcrestart (target_ulong t0)
1052 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1054 if (other_tc == env->current_tc) {
1055 env->active_tc.PC = t0;
1056 env->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1057 env->CP0_LLAddr = 0ULL;
1058 /* MIPS16 not implemented. */
1060 env->tcs[other_tc].PC = t0;
1061 env->tcs[other_tc].CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1062 env->CP0_LLAddr = 0ULL;
1063 /* MIPS16 not implemented. */
1067 void do_mtc0_tchalt (target_ulong t0)
1069 env->active_tc.CP0_TCHalt = t0 & 0x1;
1071 // TODO: Halt TC / Restart (if allocated+active) TC.
1074 void do_mttc0_tchalt (target_ulong t0)
1076 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1078 // TODO: Halt TC / Restart (if allocated+active) TC.
1080 if (other_tc == env->current_tc)
1081 env->active_tc.CP0_TCHalt = t0;
1083 env->tcs[other_tc].CP0_TCHalt = t0;
1086 void do_mtc0_tccontext (target_ulong t0)
1088 env->active_tc.CP0_TCContext = t0;
1091 void do_mttc0_tccontext (target_ulong t0)
1093 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1095 if (other_tc == env->current_tc)
1096 env->active_tc.CP0_TCContext = t0;
1098 env->tcs[other_tc].CP0_TCContext = t0;
1101 void do_mtc0_tcschedule (target_ulong t0)
1103 env->active_tc.CP0_TCSchedule = t0;
1106 void do_mttc0_tcschedule (target_ulong t0)
1108 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1110 if (other_tc == env->current_tc)
1111 env->active_tc.CP0_TCSchedule = t0;
1113 env->tcs[other_tc].CP0_TCSchedule = t0;
1116 void do_mtc0_tcschefback (target_ulong t0)
1118 env->active_tc.CP0_TCScheFBack = t0;
1121 void do_mttc0_tcschefback (target_ulong t0)
1123 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1125 if (other_tc == env->current_tc)
1126 env->active_tc.CP0_TCScheFBack = t0;
1128 env->tcs[other_tc].CP0_TCScheFBack = t0;
1131 void do_mtc0_entrylo1 (target_ulong t0)
1133 /* Large physaddr (PABITS) not implemented */
1134 /* 1k pages not implemented */
1135 env->CP0_EntryLo1 = t0 & 0x3FFFFFFF;
1138 void do_mtc0_context (target_ulong t0)
1140 env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (t0 & ~0x007FFFFF);
1143 void do_mtc0_pagemask (target_ulong t0)
1145 /* 1k pages not implemented */
1146 env->CP0_PageMask = t0 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
1149 void do_mtc0_pagegrain (target_ulong t0)
1151 /* SmartMIPS not implemented */
1152 /* Large physaddr (PABITS) not implemented */
1153 /* 1k pages not implemented */
1154 env->CP0_PageGrain = 0;
1157 void do_mtc0_wired (target_ulong t0)
1159 env->CP0_Wired = t0 % env->tlb->nb_tlb;
1162 void do_mtc0_srsconf0 (target_ulong t0)
1164 env->CP0_SRSConf0 |= t0 & env->CP0_SRSConf0_rw_bitmask;
1167 void do_mtc0_srsconf1 (target_ulong t0)
1169 env->CP0_SRSConf1 |= t0 & env->CP0_SRSConf1_rw_bitmask;
1172 void do_mtc0_srsconf2 (target_ulong t0)
1174 env->CP0_SRSConf2 |= t0 & env->CP0_SRSConf2_rw_bitmask;
1177 void do_mtc0_srsconf3 (target_ulong t0)
1179 env->CP0_SRSConf3 |= t0 & env->CP0_SRSConf3_rw_bitmask;
1182 void do_mtc0_srsconf4 (target_ulong t0)
1184 env->CP0_SRSConf4 |= t0 & env->CP0_SRSConf4_rw_bitmask;
1187 void do_mtc0_hwrena (target_ulong t0)
1189 env->CP0_HWREna = t0 & 0x0000000F;
1192 void do_mtc0_count (target_ulong t0)
1194 cpu_mips_store_count(env, t0);
1197 void do_mtc0_entryhi (target_ulong t0)
1199 target_ulong old, val;
1201 /* 1k pages not implemented */
1202 val = t0 & ((TARGET_PAGE_MASK << 1) | 0xFF);
1203 #if defined(TARGET_MIPS64)
1204 val &= env->SEGMask;
1206 old = env->CP0_EntryHi;
1207 env->CP0_EntryHi = val;
1208 if (env->CP0_Config3 & (1 << CP0C3_MT)) {
1209 uint32_t tcst = env->active_tc.CP0_TCStatus & ~0xff;
1210 env->active_tc.CP0_TCStatus = tcst | (val & 0xff);
1212 /* If the ASID changes, flush qemu's TLB. */
1213 if ((old & 0xFF) != (val & 0xFF))
1214 cpu_mips_tlb_flush(env, 1);
1217 void do_mttc0_entryhi(target_ulong t0)
1219 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1222 env->CP0_EntryHi = (env->CP0_EntryHi & 0xff) | (t0 & ~0xff);
1223 if (other_tc == env->current_tc) {
1224 tcstatus = (env->active_tc.CP0_TCStatus & ~0xff) | (t0 & 0xff);
1225 env->active_tc.CP0_TCStatus = tcstatus;
1227 tcstatus = (env->tcs[other_tc].CP0_TCStatus & ~0xff) | (t0 & 0xff);
1228 env->tcs[other_tc].CP0_TCStatus = tcstatus;
1232 void do_mtc0_compare (target_ulong t0)
1234 cpu_mips_store_compare(env, t0);
1237 void do_mtc0_status (target_ulong t0)
1240 uint32_t mask = env->CP0_Status_rw_bitmask;
1243 old = env->CP0_Status;
1244 env->CP0_Status = (env->CP0_Status & ~mask) | val;
1245 compute_hflags(env);
1246 if (loglevel & CPU_LOG_EXEC)
1247 do_mtc0_status_debug(old, val);
1248 cpu_mips_update_irq(env);
1251 void do_mttc0_status(target_ulong t0)
1253 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1254 int32_t tcstatus = env->tcs[other_tc].CP0_TCStatus;
1256 env->CP0_Status = t0 & ~0xf1000018;
1257 tcstatus = (tcstatus & ~(0xf << CP0TCSt_TCU0)) | (t0 & (0xf << CP0St_CU0));
1258 tcstatus = (tcstatus & ~(1 << CP0TCSt_TMX)) | ((t0 & (1 << CP0St_MX)) << (CP0TCSt_TMX - CP0St_MX));
1259 tcstatus = (tcstatus & ~(0x3 << CP0TCSt_TKSU)) | ((t0 & (0x3 << CP0St_KSU)) << (CP0TCSt_TKSU - CP0St_KSU));
1260 if (other_tc == env->current_tc)
1261 env->active_tc.CP0_TCStatus = tcstatus;
1263 env->tcs[other_tc].CP0_TCStatus = tcstatus;
1266 void do_mtc0_intctl (target_ulong t0)
1268 /* vectored interrupts not implemented, no performance counters. */
1269 env->CP0_IntCtl = (env->CP0_IntCtl & ~0x000002e0) | (t0 & 0x000002e0);
1272 void do_mtc0_srsctl (target_ulong t0)
1274 uint32_t mask = (0xf << CP0SRSCtl_ESS) | (0xf << CP0SRSCtl_PSS);
1275 env->CP0_SRSCtl = (env->CP0_SRSCtl & ~mask) | (t0 & mask);
1278 void do_mtc0_cause (target_ulong t0)
1280 uint32_t mask = 0x00C00300;
1281 uint32_t old = env->CP0_Cause;
1283 if (env->insn_flags & ISA_MIPS32R2)
1284 mask |= 1 << CP0Ca_DC;
1286 env->CP0_Cause = (env->CP0_Cause & ~mask) | (t0 & mask);
1288 if ((old ^ env->CP0_Cause) & (1 << CP0Ca_DC)) {
1289 if (env->CP0_Cause & (1 << CP0Ca_DC))
1290 cpu_mips_stop_count(env);
1292 cpu_mips_start_count(env);
1295 /* Handle the software interrupt as an hardware one, as they
1297 if (t0 & CP0Ca_IP_mask) {
1298 cpu_mips_update_irq(env);
1302 void do_mtc0_ebase (target_ulong t0)
1304 /* vectored interrupts not implemented */
1305 /* Multi-CPU not implemented */
1306 env->CP0_EBase = 0x80000000 | (t0 & 0x3FFFF000);
1309 void do_mtc0_config0 (target_ulong t0)
1311 env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (t0 & 0x00000007);
1314 void do_mtc0_config2 (target_ulong t0)
1316 /* tertiary/secondary caches not implemented */
1317 env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
1320 void do_mtc0_watchlo (target_ulong t0, uint32_t sel)
1322 /* Watch exceptions for instructions, data loads, data stores
1324 env->CP0_WatchLo[sel] = (t0 & ~0x7);
1327 void do_mtc0_watchhi (target_ulong t0, uint32_t sel)
1329 env->CP0_WatchHi[sel] = (t0 & 0x40FF0FF8);
1330 env->CP0_WatchHi[sel] &= ~(env->CP0_WatchHi[sel] & t0 & 0x7);
1333 void do_mtc0_xcontext (target_ulong t0)
1335 target_ulong mask = (1ULL << (env->SEGBITS - 7)) - 1;
1336 env->CP0_XContext = (env->CP0_XContext & mask) | (t0 & ~mask);
1339 void do_mtc0_framemask (target_ulong t0)
1341 env->CP0_Framemask = t0; /* XXX */
1344 void do_mtc0_debug (target_ulong t0)
1346 env->CP0_Debug = (env->CP0_Debug & 0x8C03FC1F) | (t0 & 0x13300120);
1347 if (t0 & (1 << CP0DB_DM))
1348 env->hflags |= MIPS_HFLAG_DM;
1350 env->hflags &= ~MIPS_HFLAG_DM;
1353 void do_mttc0_debug(target_ulong t0)
1355 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1356 uint32_t val = t0 & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt));
1358 /* XXX: Might be wrong, check with EJTAG spec. */
1359 if (other_tc == env->current_tc)
1360 env->active_tc.CP0_Debug_tcstatus = val;
1362 env->tcs[other_tc].CP0_Debug_tcstatus = val;
1363 env->CP0_Debug = (env->CP0_Debug & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
1364 (t0 & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
1367 void do_mtc0_performance0 (target_ulong t0)
1369 env->CP0_Performance0 = t0 & 0x000007ff;
1372 void do_mtc0_taglo (target_ulong t0)
1374 env->CP0_TagLo = t0 & 0xFFFFFCF6;
1377 void do_mtc0_datalo (target_ulong t0)
1379 env->CP0_DataLo = t0; /* XXX */
1382 void do_mtc0_taghi (target_ulong t0)
1384 env->CP0_TagHi = t0; /* XXX */
1387 void do_mtc0_datahi (target_ulong t0)
1389 env->CP0_DataHi = t0; /* XXX */
1392 void do_mtc0_status_debug(uint32_t old, uint32_t val)
1394 fprintf(logfile, "Status %08x (%08x) => %08x (%08x) Cause %08x",
1395 old, old & env->CP0_Cause & CP0Ca_IP_mask,
1396 val, val & env->CP0_Cause & CP0Ca_IP_mask,
1398 switch (env->hflags & MIPS_HFLAG_KSU) {
1399 case MIPS_HFLAG_UM: fputs(", UM\n", logfile); break;
1400 case MIPS_HFLAG_SM: fputs(", SM\n", logfile); break;
1401 case MIPS_HFLAG_KM: fputs("\n", logfile); break;
1402 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
1406 void do_mtc0_status_irqraise_debug(void)
1408 fprintf(logfile, "Raise pending IRQs\n");
1410 #endif /* !CONFIG_USER_ONLY */
1412 /* MIPS MT functions */
1413 target_ulong do_mftgpr(target_ulong t0, uint32_t sel)
1415 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1417 if (other_tc == env->current_tc)
1418 return env->active_tc.gpr[sel];
1420 return env->tcs[other_tc].gpr[sel];
1423 target_ulong do_mftlo(target_ulong t0, uint32_t sel)
1425 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1427 if (other_tc == env->current_tc)
1428 return env->active_tc.LO[sel];
1430 return env->tcs[other_tc].LO[sel];
1433 target_ulong do_mfthi(target_ulong t0, uint32_t sel)
1435 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1437 if (other_tc == env->current_tc)
1438 return env->active_tc.HI[sel];
1440 return env->tcs[other_tc].HI[sel];
1443 target_ulong do_mftacx(target_ulong t0, uint32_t sel)
1445 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1447 if (other_tc == env->current_tc)
1448 return env->active_tc.ACX[sel];
1450 return env->tcs[other_tc].ACX[sel];
1453 target_ulong do_mftdsp(target_ulong t0)
1455 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1457 if (other_tc == env->current_tc)
1458 return env->active_tc.DSPControl;
1460 return env->tcs[other_tc].DSPControl;
1463 void do_mttgpr(target_ulong t0, uint32_t sel)
1465 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1467 if (other_tc == env->current_tc)
1468 env->active_tc.gpr[sel] = t0;
1470 env->tcs[other_tc].gpr[sel] = t0;
1473 void do_mttlo(target_ulong t0, uint32_t sel)
1475 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1477 if (other_tc == env->current_tc)
1478 env->active_tc.LO[sel] = t0;
1480 env->tcs[other_tc].LO[sel] = t0;
1483 void do_mtthi(target_ulong t0, uint32_t sel)
1485 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1487 if (other_tc == env->current_tc)
1488 env->active_tc.HI[sel] = t0;
1490 env->tcs[other_tc].HI[sel] = t0;
1493 void do_mttacx(target_ulong t0, uint32_t sel)
1495 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1497 if (other_tc == env->current_tc)
1498 env->active_tc.ACX[sel] = t0;
1500 env->tcs[other_tc].ACX[sel] = t0;
1503 void do_mttdsp(target_ulong t0)
1505 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1507 if (other_tc == env->current_tc)
1508 env->active_tc.DSPControl = t0;
1510 env->tcs[other_tc].DSPControl = t0;
1513 /* MIPS MT functions */
1514 target_ulong do_dmt(target_ulong t0)
1523 target_ulong do_emt(target_ulong t0)
1532 target_ulong do_dvpe(target_ulong t0)
1541 target_ulong do_evpe(target_ulong t0)
1550 void do_fork(target_ulong t0, target_ulong t1)
1554 // TODO: store to TC register
1557 target_ulong do_yield(target_ulong t0)
1560 /* No scheduling policy implemented. */
1562 if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
1563 env->active_tc.CP0_TCStatus & (1 << CP0TCSt_DT)) {
1564 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1565 env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
1566 do_raise_exception(EXCP_THREAD);
1569 } else if (t0 == 0) {
1570 if (0 /* TODO: TC underflow */) {
1571 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1572 do_raise_exception(EXCP_THREAD);
1574 // TODO: Deallocate TC
1576 } else if (t0 > 0) {
1577 /* Yield qualifier inputs not implemented. */
1578 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1579 env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
1580 do_raise_exception(EXCP_THREAD);
1582 return env->CP0_YQMask;
1586 void fpu_handle_exception(void)
1588 #ifdef CONFIG_SOFTFLOAT
1589 int flags = get_float_exception_flags(&env->fpu->fp_status);
1590 unsigned int cpuflags = 0, enable, cause = 0;
1592 enable = GET_FP_ENABLE(env->fpu->fcr31);
1594 /* determine current flags */
1595 if (flags & float_flag_invalid) {
1596 cpuflags |= FP_INVALID;
1597 cause |= FP_INVALID & enable;
1599 if (flags & float_flag_divbyzero) {
1600 cpuflags |= FP_DIV0;
1601 cause |= FP_DIV0 & enable;
1603 if (flags & float_flag_overflow) {
1604 cpuflags |= FP_OVERFLOW;
1605 cause |= FP_OVERFLOW & enable;
1607 if (flags & float_flag_underflow) {
1608 cpuflags |= FP_UNDERFLOW;
1609 cause |= FP_UNDERFLOW & enable;
1611 if (flags & float_flag_inexact) {
1612 cpuflags |= FP_INEXACT;
1613 cause |= FP_INEXACT & enable;
1615 SET_FP_FLAGS(env->fpu->fcr31, cpuflags);
1616 SET_FP_CAUSE(env->fpu->fcr31, cause);
1618 SET_FP_FLAGS(env->fpu->fcr31, 0);
1619 SET_FP_CAUSE(env->fpu->fcr31, 0);
1623 #ifndef CONFIG_USER_ONLY
1624 /* TLB management */
1625 void cpu_mips_tlb_flush (CPUState *env, int flush_global)
1627 /* Flush qemu's TLB and discard all shadowed entries. */
1628 tlb_flush (env, flush_global);
1629 env->tlb->tlb_in_use = env->tlb->nb_tlb;
1632 static void r4k_mips_tlb_flush_extra (CPUState *env, int first)
1634 /* Discard entries from env->tlb[first] onwards. */
1635 while (env->tlb->tlb_in_use > first) {
1636 r4k_invalidate_tlb(env, --env->tlb->tlb_in_use, 0);
1640 static void r4k_fill_tlb (int idx)
1644 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
1645 tlb = &env->tlb->mmu.r4k.tlb[idx];
1646 tlb->VPN = env->CP0_EntryHi & (TARGET_PAGE_MASK << 1);
1647 #if defined(TARGET_MIPS64)
1648 tlb->VPN &= env->SEGMask;
1650 tlb->ASID = env->CP0_EntryHi & 0xFF;
1651 tlb->PageMask = env->CP0_PageMask;
1652 tlb->G = env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1;
1653 tlb->V0 = (env->CP0_EntryLo0 & 2) != 0;
1654 tlb->D0 = (env->CP0_EntryLo0 & 4) != 0;
1655 tlb->C0 = (env->CP0_EntryLo0 >> 3) & 0x7;
1656 tlb->PFN[0] = (env->CP0_EntryLo0 >> 6) << 12;
1657 tlb->V1 = (env->CP0_EntryLo1 & 2) != 0;
1658 tlb->D1 = (env->CP0_EntryLo1 & 4) != 0;
1659 tlb->C1 = (env->CP0_EntryLo1 >> 3) & 0x7;
1660 tlb->PFN[1] = (env->CP0_EntryLo1 >> 6) << 12;
1663 void r4k_do_tlbwi (void)
1665 /* Discard cached TLB entries. We could avoid doing this if the
1666 tlbwi is just upgrading access permissions on the current entry;
1667 that might be a further win. */
1668 r4k_mips_tlb_flush_extra (env, env->tlb->nb_tlb);
1670 r4k_invalidate_tlb(env, env->CP0_Index % env->tlb->nb_tlb, 0);
1671 r4k_fill_tlb(env->CP0_Index % env->tlb->nb_tlb);
1674 void r4k_do_tlbwr (void)
1676 int r = cpu_mips_get_random(env);
1678 r4k_invalidate_tlb(env, r, 1);
1682 void r4k_do_tlbp (void)
1691 ASID = env->CP0_EntryHi & 0xFF;
1692 for (i = 0; i < env->tlb->nb_tlb; i++) {
1693 tlb = &env->tlb->mmu.r4k.tlb[i];
1694 /* 1k pages are not supported. */
1695 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
1696 tag = env->CP0_EntryHi & ~mask;
1697 VPN = tlb->VPN & ~mask;
1698 /* Check ASID, virtual page number & size */
1699 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
1705 if (i == env->tlb->nb_tlb) {
1706 /* No match. Discard any shadow entries, if any of them match. */
1707 for (i = env->tlb->nb_tlb; i < env->tlb->tlb_in_use; i++) {
1708 tlb = &env->tlb->mmu.r4k.tlb[i];
1709 /* 1k pages are not supported. */
1710 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
1711 tag = env->CP0_EntryHi & ~mask;
1712 VPN = tlb->VPN & ~mask;
1713 /* Check ASID, virtual page number & size */
1714 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
1715 r4k_mips_tlb_flush_extra (env, i);
1720 env->CP0_Index |= 0x80000000;
1724 void r4k_do_tlbr (void)
1729 ASID = env->CP0_EntryHi & 0xFF;
1730 tlb = &env->tlb->mmu.r4k.tlb[env->CP0_Index % env->tlb->nb_tlb];
1732 /* If this will change the current ASID, flush qemu's TLB. */
1733 if (ASID != tlb->ASID)
1734 cpu_mips_tlb_flush (env, 1);
1736 r4k_mips_tlb_flush_extra(env, env->tlb->nb_tlb);
1738 env->CP0_EntryHi = tlb->VPN | tlb->ASID;
1739 env->CP0_PageMask = tlb->PageMask;
1740 env->CP0_EntryLo0 = tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) |
1741 (tlb->C0 << 3) | (tlb->PFN[0] >> 6);
1742 env->CP0_EntryLo1 = tlb->G | (tlb->V1 << 1) | (tlb->D1 << 2) |
1743 (tlb->C1 << 3) | (tlb->PFN[1] >> 6);
1746 #endif /* !CONFIG_USER_ONLY */
1749 target_ulong do_di (void)
1751 target_ulong t0 = env->CP0_Status;
1753 env->CP0_Status = t0 & ~(1 << CP0St_IE);
1754 cpu_mips_update_irq(env);
1759 target_ulong do_ei (void)
1761 target_ulong t0 = env->CP0_Status;
1763 env->CP0_Status = t0 | (1 << CP0St_IE);
1764 cpu_mips_update_irq(env);
1769 void debug_pre_eret (void)
1771 fprintf(logfile, "ERET: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
1772 env->active_tc.PC, env->CP0_EPC);
1773 if (env->CP0_Status & (1 << CP0St_ERL))
1774 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
1775 if (env->hflags & MIPS_HFLAG_DM)
1776 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
1777 fputs("\n", logfile);
1780 void debug_post_eret (void)
1782 fprintf(logfile, " => PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
1783 env->active_tc.PC, env->CP0_EPC);
1784 if (env->CP0_Status & (1 << CP0St_ERL))
1785 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
1786 if (env->hflags & MIPS_HFLAG_DM)
1787 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
1788 switch (env->hflags & MIPS_HFLAG_KSU) {
1789 case MIPS_HFLAG_UM: fputs(", UM\n", logfile); break;
1790 case MIPS_HFLAG_SM: fputs(", SM\n", logfile); break;
1791 case MIPS_HFLAG_KM: fputs("\n", logfile); break;
1792 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
1798 if (loglevel & CPU_LOG_EXEC)
1800 if (env->CP0_Status & (1 << CP0St_ERL)) {
1801 env->active_tc.PC = env->CP0_ErrorEPC;
1802 env->CP0_Status &= ~(1 << CP0St_ERL);
1804 env->active_tc.PC = env->CP0_EPC;
1805 env->CP0_Status &= ~(1 << CP0St_EXL);
1807 compute_hflags(env);
1808 if (loglevel & CPU_LOG_EXEC)
1810 env->CP0_LLAddr = 1;
1813 void do_deret (void)
1815 if (loglevel & CPU_LOG_EXEC)
1817 env->active_tc.PC = env->CP0_DEPC;
1818 env->hflags &= MIPS_HFLAG_DM;
1819 compute_hflags(env);
1820 if (loglevel & CPU_LOG_EXEC)
1822 env->CP0_LLAddr = 1;
1825 target_ulong do_rdhwr_cpunum(void)
1827 if ((env->hflags & MIPS_HFLAG_CP0) ||
1828 (env->CP0_HWREna & (1 << 0)))
1829 return env->CP0_EBase & 0x3ff;
1831 do_raise_exception(EXCP_RI);
1836 target_ulong do_rdhwr_synci_step(void)
1838 if ((env->hflags & MIPS_HFLAG_CP0) ||
1839 (env->CP0_HWREna & (1 << 1)))
1840 return env->SYNCI_Step;
1842 do_raise_exception(EXCP_RI);
1847 target_ulong do_rdhwr_cc(void)
1849 if ((env->hflags & MIPS_HFLAG_CP0) ||
1850 (env->CP0_HWREna & (1 << 2)))
1851 return env->CP0_Count;
1853 do_raise_exception(EXCP_RI);
1858 target_ulong do_rdhwr_ccres(void)
1860 if ((env->hflags & MIPS_HFLAG_CP0) ||
1861 (env->CP0_HWREna & (1 << 3)))
1864 do_raise_exception(EXCP_RI);
1869 /* Bitfield operations. */
1870 target_ulong do_ext(target_ulong t0, target_ulong t1, uint32_t pos, uint32_t size)
1872 return (int32_t)((t1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0));
1875 target_ulong do_ins(target_ulong t0, target_ulong t1, uint32_t pos, uint32_t size)
1877 target_ulong mask = ((size < 32) ? ((1 << size) - 1) : ~0) << pos;
1879 return (int32_t)((t0 & ~mask) | ((t1 << pos) & mask));
1882 target_ulong do_wsbh(target_ulong t0, target_ulong t1)
1884 return (int32_t)(((t1 << 8) & ~0x00FF00FF) | ((t1 >> 8) & 0x00FF00FF));
1887 #if defined(TARGET_MIPS64)
1888 target_ulong do_dext(target_ulong t0, target_ulong t1, uint32_t pos, uint32_t size)
1890 return (t1 >> pos) & ((size < 64) ? ((1ULL << size) - 1) : ~0ULL);
1893 target_ulong do_dins(target_ulong t0, target_ulong t1, uint32_t pos, uint32_t size)
1895 target_ulong mask = ((size < 64) ? ((1ULL << size) - 1) : ~0ULL) << pos;
1897 return (t0 & ~mask) | ((t1 << pos) & mask);
1900 target_ulong do_dsbh(target_ulong t0, target_ulong t1)
1902 return ((t1 << 8) & ~0x00FF00FF00FF00FFULL) | ((t1 >> 8) & 0x00FF00FF00FF00FFULL);
1905 target_ulong do_dshd(target_ulong t0, target_ulong t1)
1907 t1 = ((t1 << 16) & ~0x0000FFFF0000FFFFULL) | ((t1 >> 16) & 0x0000FFFF0000FFFFULL);
1908 return (t1 << 32) | (t1 >> 32);
1912 void do_pmon (int function)
1916 case 2: /* TODO: char inbyte(int waitflag); */
1917 if (env->active_tc.gpr[4] == 0)
1918 env->active_tc.gpr[2] = -1;
1920 case 11: /* TODO: char inbyte (void); */
1921 env->active_tc.gpr[2] = -1;
1925 printf("%c", (char)(env->active_tc.gpr[4] & 0xFF));
1931 unsigned char *fmt = (void *)(unsigned long)env->active_tc.gpr[4];
1941 do_raise_exception(EXCP_HLT);
1944 #if !defined(CONFIG_USER_ONLY)
1946 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr);
1948 #define MMUSUFFIX _mmu
1949 #define ALIGNED_ONLY
1952 #include "softmmu_template.h"
1955 #include "softmmu_template.h"
1958 #include "softmmu_template.h"
1961 #include "softmmu_template.h"
1963 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
1965 env->CP0_BadVAddr = addr;
1966 do_restore_state (retaddr);
1967 do_raise_exception ((is_write == 1) ? EXCP_AdES : EXCP_AdEL);
1970 void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
1972 TranslationBlock *tb;
1973 CPUState *saved_env;
1977 /* XXX: hack to restore env in all cases, even if not called from
1980 env = cpu_single_env;
1981 ret = cpu_mips_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
1984 /* now we have a real cpu fault */
1985 pc = (unsigned long)retaddr;
1986 tb = tb_find_pc(pc);
1988 /* the PC is inside the translated code. It means that we have
1989 a virtual CPU fault */
1990 cpu_restore_state(tb, env, pc, NULL);
1993 do_raise_exception_err(env->exception_index, env->error_code);
1998 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
2002 do_raise_exception(EXCP_IBE);
2004 do_raise_exception(EXCP_DBE);
2006 #endif /* !CONFIG_USER_ONLY */
2008 /* Complex FPU operations which may need stack space. */
2010 #define FLOAT_ONE32 make_float32(0x3f8 << 20)
2011 #define FLOAT_ONE64 make_float64(0x3ffULL << 52)
2012 #define FLOAT_TWO32 make_float32(1 << 30)
2013 #define FLOAT_TWO64 make_float64(1ULL << 62)
2014 #define FLOAT_QNAN32 0x7fbfffff
2015 #define FLOAT_QNAN64 0x7ff7ffffffffffffULL
2016 #define FLOAT_SNAN32 0x7fffffff
2017 #define FLOAT_SNAN64 0x7fffffffffffffffULL
2019 /* convert MIPS rounding mode in FCR31 to IEEE library */
2020 unsigned int ieee_rm[] = {
2021 float_round_nearest_even,
2022 float_round_to_zero,
2027 #define RESTORE_ROUNDING_MODE \
2028 set_float_rounding_mode(ieee_rm[env->fpu->fcr31 & 3], &env->fpu->fp_status)
2030 target_ulong do_cfc1 (uint32_t reg)
2036 t0 = (int32_t)env->fpu->fcr0;
2039 t0 = ((env->fpu->fcr31 >> 24) & 0xfe) | ((env->fpu->fcr31 >> 23) & 0x1);
2042 t0 = env->fpu->fcr31 & 0x0003f07c;
2045 t0 = (env->fpu->fcr31 & 0x00000f83) | ((env->fpu->fcr31 >> 22) & 0x4);
2048 t0 = (int32_t)env->fpu->fcr31;
2055 void do_ctc1 (target_ulong t0, uint32_t reg)
2059 if (t0 & 0xffffff00)
2061 env->fpu->fcr31 = (env->fpu->fcr31 & 0x017fffff) | ((t0 & 0xfe) << 24) |
2065 if (t0 & 0x007c0000)
2067 env->fpu->fcr31 = (env->fpu->fcr31 & 0xfffc0f83) | (t0 & 0x0003f07c);
2070 if (t0 & 0x007c0000)
2072 env->fpu->fcr31 = (env->fpu->fcr31 & 0xfefff07c) | (t0 & 0x00000f83) |
2076 if (t0 & 0x007c0000)
2078 env->fpu->fcr31 = t0;
2083 /* set rounding mode */
2084 RESTORE_ROUNDING_MODE;
2085 set_float_exception_flags(0, &env->fpu->fp_status);
2086 if ((GET_FP_ENABLE(env->fpu->fcr31) | 0x20) & GET_FP_CAUSE(env->fpu->fcr31))
2087 do_raise_exception(EXCP_FPE);
2090 static always_inline char ieee_ex_to_mips(char xcpt)
2092 return (xcpt & float_flag_inexact) >> 5 |
2093 (xcpt & float_flag_underflow) >> 3 |
2094 (xcpt & float_flag_overflow) >> 1 |
2095 (xcpt & float_flag_divbyzero) << 1 |
2096 (xcpt & float_flag_invalid) << 4;
2099 static always_inline char mips_ex_to_ieee(char xcpt)
2101 return (xcpt & FP_INEXACT) << 5 |
2102 (xcpt & FP_UNDERFLOW) << 3 |
2103 (xcpt & FP_OVERFLOW) << 1 |
2104 (xcpt & FP_DIV0) >> 1 |
2105 (xcpt & FP_INVALID) >> 4;
2108 static always_inline void update_fcr31(void)
2110 int tmp = ieee_ex_to_mips(get_float_exception_flags(&env->fpu->fp_status));
2112 SET_FP_CAUSE(env->fpu->fcr31, tmp);
2113 if (GET_FP_ENABLE(env->fpu->fcr31) & tmp)
2114 do_raise_exception(EXCP_FPE);
2116 UPDATE_FP_FLAGS(env->fpu->fcr31, tmp);
2120 Single precition routines have a "s" suffix, double precision a
2121 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2122 paired single lower "pl", paired single upper "pu". */
2124 #define FLOAT_OP(name, p) void do_float_##name##_##p(void)
2126 /* unary operations, modifying fp status */
2127 #define FLOAT_UNOP(name) \
2130 FDT2 = float64_ ## name(FDT0, &env->fpu->fp_status); \
2134 FST2 = float32_ ## name(FST0, &env->fpu->fp_status); \
2141 set_float_exception_flags(0, &env->fpu->fp_status);
2142 FDT2 = float32_to_float64(FST0, &env->fpu->fp_status);
2147 set_float_exception_flags(0, &env->fpu->fp_status);
2148 FDT2 = int32_to_float64(WT0, &env->fpu->fp_status);
2153 set_float_exception_flags(0, &env->fpu->fp_status);
2154 FDT2 = int64_to_float64(DT0, &env->fpu->fp_status);
2159 set_float_exception_flags(0, &env->fpu->fp_status);
2160 DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
2162 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2167 set_float_exception_flags(0, &env->fpu->fp_status);
2168 DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
2170 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2176 set_float_exception_flags(0, &env->fpu->fp_status);
2177 FST2 = int32_to_float32(WT0, &env->fpu->fp_status);
2178 FSTH2 = int32_to_float32(WTH0, &env->fpu->fp_status);
2183 set_float_exception_flags(0, &env->fpu->fp_status);
2184 WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
2185 WTH2 = float32_to_int32(FSTH0, &env->fpu->fp_status);
2187 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2192 set_float_exception_flags(0, &env->fpu->fp_status);
2193 FST2 = float64_to_float32(FDT0, &env->fpu->fp_status);
2198 set_float_exception_flags(0, &env->fpu->fp_status);
2199 FST2 = int32_to_float32(WT0, &env->fpu->fp_status);
2204 set_float_exception_flags(0, &env->fpu->fp_status);
2205 FST2 = int64_to_float32(DT0, &env->fpu->fp_status);
2210 set_float_exception_flags(0, &env->fpu->fp_status);
2216 set_float_exception_flags(0, &env->fpu->fp_status);
2222 set_float_exception_flags(0, &env->fpu->fp_status);
2223 WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
2225 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2230 set_float_exception_flags(0, &env->fpu->fp_status);
2231 WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
2233 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2239 set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
2240 DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
2241 RESTORE_ROUNDING_MODE;
2243 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2248 set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
2249 DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
2250 RESTORE_ROUNDING_MODE;
2252 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2257 set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
2258 WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
2259 RESTORE_ROUNDING_MODE;
2261 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2266 set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
2267 WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
2268 RESTORE_ROUNDING_MODE;
2270 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2276 DT2 = float64_to_int64_round_to_zero(FDT0, &env->fpu->fp_status);
2278 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2283 DT2 = float32_to_int64_round_to_zero(FST0, &env->fpu->fp_status);
2285 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2290 WT2 = float64_to_int32_round_to_zero(FDT0, &env->fpu->fp_status);
2292 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2297 WT2 = float32_to_int32_round_to_zero(FST0, &env->fpu->fp_status);
2299 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2305 set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
2306 DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
2307 RESTORE_ROUNDING_MODE;
2309 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2314 set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
2315 DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
2316 RESTORE_ROUNDING_MODE;
2318 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2323 set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
2324 WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
2325 RESTORE_ROUNDING_MODE;
2327 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2332 set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
2333 WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
2334 RESTORE_ROUNDING_MODE;
2336 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2342 set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
2343 DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
2344 RESTORE_ROUNDING_MODE;
2346 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2351 set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
2352 DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
2353 RESTORE_ROUNDING_MODE;
2355 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2360 set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
2361 WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
2362 RESTORE_ROUNDING_MODE;
2364 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2369 set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
2370 WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
2371 RESTORE_ROUNDING_MODE;
2373 if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
2377 /* unary operations, not modifying fp status */
2378 #define FLOAT_UNOP(name) \
2381 FDT2 = float64_ ## name(FDT0); \
2385 FST2 = float32_ ## name(FST0); \
2387 FLOAT_OP(name, ps) \
2389 FST2 = float32_ ## name(FST0); \
2390 FSTH2 = float32_ ## name(FSTH0); \
2396 /* MIPS specific unary operations */
2399 set_float_exception_flags(0, &env->fpu->fp_status);
2400 FDT2 = float64_div(FLOAT_ONE64, FDT0, &env->fpu->fp_status);
2405 set_float_exception_flags(0, &env->fpu->fp_status);
2406 FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
2412 set_float_exception_flags(0, &env->fpu->fp_status);
2413 FDT2 = float64_sqrt(FDT0, &env->fpu->fp_status);
2414 FDT2 = float64_div(FLOAT_ONE64, FDT2, &env->fpu->fp_status);
2419 set_float_exception_flags(0, &env->fpu->fp_status);
2420 FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
2421 FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
2427 set_float_exception_flags(0, &env->fpu->fp_status);
2428 FDT2 = float64_div(FLOAT_ONE64, FDT0, &env->fpu->fp_status);
2433 set_float_exception_flags(0, &env->fpu->fp_status);
2434 FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
2437 FLOAT_OP(recip1, ps)
2439 set_float_exception_flags(0, &env->fpu->fp_status);
2440 FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
2441 FSTH2 = float32_div(FLOAT_ONE32, FSTH0, &env->fpu->fp_status);
2447 set_float_exception_flags(0, &env->fpu->fp_status);
2448 FDT2 = float64_sqrt(FDT0, &env->fpu->fp_status);
2449 FDT2 = float64_div(FLOAT_ONE64, FDT2, &env->fpu->fp_status);
2454 set_float_exception_flags(0, &env->fpu->fp_status);
2455 FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
2456 FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
2459 FLOAT_OP(rsqrt1, ps)
2461 set_float_exception_flags(0, &env->fpu->fp_status);
2462 FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
2463 FSTH2 = float32_sqrt(FSTH0, &env->fpu->fp_status);
2464 FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
2465 FSTH2 = float32_div(FLOAT_ONE32, FSTH2, &env->fpu->fp_status);
2469 /* binary operations */
2470 #define FLOAT_BINOP(name) \
2473 set_float_exception_flags(0, &env->fpu->fp_status); \
2474 FDT2 = float64_ ## name (FDT0, FDT1, &env->fpu->fp_status); \
2476 if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID) \
2477 DT2 = FLOAT_QNAN64; \
2481 set_float_exception_flags(0, &env->fpu->fp_status); \
2482 FST2 = float32_ ## name (FST0, FST1, &env->fpu->fp_status); \
2484 if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID) \
2485 WT2 = FLOAT_QNAN32; \
2487 FLOAT_OP(name, ps) \
2489 set_float_exception_flags(0, &env->fpu->fp_status); \
2490 FST2 = float32_ ## name (FST0, FST1, &env->fpu->fp_status); \
2491 FSTH2 = float32_ ## name (FSTH0, FSTH1, &env->fpu->fp_status); \
2493 if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID) { \
2494 WT2 = FLOAT_QNAN32; \
2495 WTH2 = FLOAT_QNAN32; \
2504 /* ternary operations */
2505 #define FLOAT_TERNOP(name1, name2) \
2506 FLOAT_OP(name1 ## name2, d) \
2508 FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status); \
2509 FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status); \
2511 FLOAT_OP(name1 ## name2, s) \
2513 FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status); \
2514 FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status); \
2516 FLOAT_OP(name1 ## name2, ps) \
2518 FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status); \
2519 FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
2520 FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status); \
2521 FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2523 FLOAT_TERNOP(mul, add)
2524 FLOAT_TERNOP(mul, sub)
2527 /* negated ternary operations */
2528 #define FLOAT_NTERNOP(name1, name2) \
2529 FLOAT_OP(n ## name1 ## name2, d) \
2531 FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status); \
2532 FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status); \
2533 FDT2 = float64_chs(FDT2); \
2535 FLOAT_OP(n ## name1 ## name2, s) \
2537 FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status); \
2538 FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status); \
2539 FST2 = float32_chs(FST2); \
2541 FLOAT_OP(n ## name1 ## name2, ps) \
2543 FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status); \
2544 FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
2545 FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status); \
2546 FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2547 FST2 = float32_chs(FST2); \
2548 FSTH2 = float32_chs(FSTH2); \
2550 FLOAT_NTERNOP(mul, add)
2551 FLOAT_NTERNOP(mul, sub)
2552 #undef FLOAT_NTERNOP
2554 /* MIPS specific binary operations */
2557 set_float_exception_flags(0, &env->fpu->fp_status);
2558 FDT2 = float64_mul(FDT0, FDT2, &env->fpu->fp_status);
2559 FDT2 = float64_chs(float64_sub(FDT2, FLOAT_ONE64, &env->fpu->fp_status));
2564 set_float_exception_flags(0, &env->fpu->fp_status);
2565 FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
2566 FST2 = float32_chs(float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status));
2569 FLOAT_OP(recip2, ps)
2571 set_float_exception_flags(0, &env->fpu->fp_status);
2572 FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
2573 FSTH2 = float32_mul(FSTH0, FSTH2, &env->fpu->fp_status);
2574 FST2 = float32_chs(float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status));
2575 FSTH2 = float32_chs(float32_sub(FSTH2, FLOAT_ONE32, &env->fpu->fp_status));
2581 set_float_exception_flags(0, &env->fpu->fp_status);
2582 FDT2 = float64_mul(FDT0, FDT2, &env->fpu->fp_status);
2583 FDT2 = float64_sub(FDT2, FLOAT_ONE64, &env->fpu->fp_status);
2584 FDT2 = float64_chs(float64_div(FDT2, FLOAT_TWO64, &env->fpu->fp_status));
2589 set_float_exception_flags(0, &env->fpu->fp_status);
2590 FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
2591 FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status);
2592 FST2 = float32_chs(float32_div(FST2, FLOAT_TWO32, &env->fpu->fp_status));
2595 FLOAT_OP(rsqrt2, ps)
2597 set_float_exception_flags(0, &env->fpu->fp_status);
2598 FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
2599 FSTH2 = float32_mul(FSTH0, FSTH2, &env->fpu->fp_status);
2600 FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status);
2601 FSTH2 = float32_sub(FSTH2, FLOAT_ONE32, &env->fpu->fp_status);
2602 FST2 = float32_chs(float32_div(FST2, FLOAT_TWO32, &env->fpu->fp_status));
2603 FSTH2 = float32_chs(float32_div(FSTH2, FLOAT_TWO32, &env->fpu->fp_status));
2609 set_float_exception_flags(0, &env->fpu->fp_status);
2610 FST2 = float32_add (FST0, FSTH0, &env->fpu->fp_status);
2611 FSTH2 = float32_add (FST1, FSTH1, &env->fpu->fp_status);
2617 set_float_exception_flags(0, &env->fpu->fp_status);
2618 FST2 = float32_mul (FST0, FSTH0, &env->fpu->fp_status);
2619 FSTH2 = float32_mul (FST1, FSTH1, &env->fpu->fp_status);
2623 /* compare operations */
2624 #define FOP_COND_D(op, cond) \
2625 void do_cmp_d_ ## op (long cc) \
2630 SET_FP_COND(cc, env->fpu); \
2632 CLEAR_FP_COND(cc, env->fpu); \
2634 void do_cmpabs_d_ ## op (long cc) \
2637 FDT0 = float64_abs(FDT0); \
2638 FDT1 = float64_abs(FDT1); \
2642 SET_FP_COND(cc, env->fpu); \
2644 CLEAR_FP_COND(cc, env->fpu); \
2647 int float64_is_unordered(int sig, float64 a, float64 b STATUS_PARAM)
2649 if (float64_is_signaling_nan(a) ||
2650 float64_is_signaling_nan(b) ||
2651 (sig && (float64_is_nan(a) || float64_is_nan(b)))) {
2652 float_raise(float_flag_invalid, status);
2654 } else if (float64_is_nan(a) || float64_is_nan(b)) {
2661 /* NOTE: the comma operator will make "cond" to eval to false,
2662 * but float*_is_unordered() is still called. */
2663 FOP_COND_D(f, (float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status), 0))
2664 FOP_COND_D(un, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status))
2665 FOP_COND_D(eq, !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_eq(FDT0, FDT1, &env->fpu->fp_status))
2666 FOP_COND_D(ueq, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) || float64_eq(FDT0, FDT1, &env->fpu->fp_status))
2667 FOP_COND_D(olt, !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_lt(FDT0, FDT1, &env->fpu->fp_status))
2668 FOP_COND_D(ult, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) || float64_lt(FDT0, FDT1, &env->fpu->fp_status))
2669 FOP_COND_D(ole, !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_le(FDT0, FDT1, &env->fpu->fp_status))
2670 FOP_COND_D(ule, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) || float64_le(FDT0, FDT1, &env->fpu->fp_status))
2671 /* NOTE: the comma operator will make "cond" to eval to false,
2672 * but float*_is_unordered() is still called. */
2673 FOP_COND_D(sf, (float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status), 0))
2674 FOP_COND_D(ngle,float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status))
2675 FOP_COND_D(seq, !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_eq(FDT0, FDT1, &env->fpu->fp_status))
2676 FOP_COND_D(ngl, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) || float64_eq(FDT0, FDT1, &env->fpu->fp_status))
2677 FOP_COND_D(lt, !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_lt(FDT0, FDT1, &env->fpu->fp_status))
2678 FOP_COND_D(nge, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) || float64_lt(FDT0, FDT1, &env->fpu->fp_status))
2679 FOP_COND_D(le, !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_le(FDT0, FDT1, &env->fpu->fp_status))
2680 FOP_COND_D(ngt, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) || float64_le(FDT0, FDT1, &env->fpu->fp_status))
2682 #define FOP_COND_S(op, cond) \
2683 void do_cmp_s_ ## op (long cc) \
2688 SET_FP_COND(cc, env->fpu); \
2690 CLEAR_FP_COND(cc, env->fpu); \
2692 void do_cmpabs_s_ ## op (long cc) \
2695 FST0 = float32_abs(FST0); \
2696 FST1 = float32_abs(FST1); \
2700 SET_FP_COND(cc, env->fpu); \
2702 CLEAR_FP_COND(cc, env->fpu); \
2705 flag float32_is_unordered(int sig, float32 a, float32 b STATUS_PARAM)
2707 if (float32_is_signaling_nan(a) ||
2708 float32_is_signaling_nan(b) ||
2709 (sig && (float32_is_nan(a) || float32_is_nan(b)))) {
2710 float_raise(float_flag_invalid, status);
2712 } else if (float32_is_nan(a) || float32_is_nan(b)) {
2719 /* NOTE: the comma operator will make "cond" to eval to false,
2720 * but float*_is_unordered() is still called. */
2721 FOP_COND_S(f, (float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status), 0))
2722 FOP_COND_S(un, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status))
2723 FOP_COND_S(eq, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status))
2724 FOP_COND_S(ueq, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_eq(FST0, FST1, &env->fpu->fp_status))
2725 FOP_COND_S(olt, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status))
2726 FOP_COND_S(ult, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_lt(FST0, FST1, &env->fpu->fp_status))
2727 FOP_COND_S(ole, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status))
2728 FOP_COND_S(ule, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_le(FST0, FST1, &env->fpu->fp_status))
2729 /* NOTE: the comma operator will make "cond" to eval to false,
2730 * but float*_is_unordered() is still called. */
2731 FOP_COND_S(sf, (float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status), 0))
2732 FOP_COND_S(ngle,float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status))
2733 FOP_COND_S(seq, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status))
2734 FOP_COND_S(ngl, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_eq(FST0, FST1, &env->fpu->fp_status))
2735 FOP_COND_S(lt, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status))
2736 FOP_COND_S(nge, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_lt(FST0, FST1, &env->fpu->fp_status))
2737 FOP_COND_S(le, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status))
2738 FOP_COND_S(ngt, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_le(FST0, FST1, &env->fpu->fp_status))
2740 #define FOP_COND_PS(op, condl, condh) \
2741 void do_cmp_ps_ ## op (long cc) \
2747 SET_FP_COND(cc, env->fpu); \
2749 CLEAR_FP_COND(cc, env->fpu); \
2751 SET_FP_COND(cc + 1, env->fpu); \
2753 CLEAR_FP_COND(cc + 1, env->fpu); \
2755 void do_cmpabs_ps_ ## op (long cc) \
2758 FST0 = float32_abs(FST0); \
2759 FSTH0 = float32_abs(FSTH0); \
2760 FST1 = float32_abs(FST1); \
2761 FSTH1 = float32_abs(FSTH1); \
2766 SET_FP_COND(cc, env->fpu); \
2768 CLEAR_FP_COND(cc, env->fpu); \
2770 SET_FP_COND(cc + 1, env->fpu); \
2772 CLEAR_FP_COND(cc + 1, env->fpu); \
2775 /* NOTE: the comma operator will make "cond" to eval to false,
2776 * but float*_is_unordered() is still called. */
2777 FOP_COND_PS(f, (float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status), 0),
2778 (float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status), 0))
2779 FOP_COND_PS(un, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status),
2780 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status))
2781 FOP_COND_PS(eq, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status),
2782 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
2783 FOP_COND_PS(ueq, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_eq(FST0, FST1, &env->fpu->fp_status),
2784 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) || float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
2785 FOP_COND_PS(olt, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status),
2786 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
2787 FOP_COND_PS(ult, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_lt(FST0, FST1, &env->fpu->fp_status),
2788 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) || float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
2789 FOP_COND_PS(ole, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status),
2790 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
2791 FOP_COND_PS(ule, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) || float32_le(FST0, FST1, &env->fpu->fp_status),
2792 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) || float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
2793 /* NOTE: the comma operator will make "cond" to eval to false,
2794 * but float*_is_unordered() is still called. */
2795 FOP_COND_PS(sf, (float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status), 0),
2796 (float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status), 0))
2797 FOP_COND_PS(ngle,float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status),
2798 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status))
2799 FOP_COND_PS(seq, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status),
2800 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
2801 FOP_COND_PS(ngl, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_eq(FST0, FST1, &env->fpu->fp_status),
2802 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) || float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
2803 FOP_COND_PS(lt, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status),
2804 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
2805 FOP_COND_PS(nge, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_lt(FST0, FST1, &env->fpu->fp_status),
2806 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) || float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
2807 FOP_COND_PS(le, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status),
2808 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
2809 FOP_COND_PS(ngt, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) || float32_le(FST0, FST1, &env->fpu->fp_status),
2810 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) || float32_le(FSTH0, FSTH1, &env->fpu->fp_status))