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 #define GETPC() (__builtin_return_address(0))
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;
40 void do_raise_exception (uint32_t exception)
42 do_raise_exception_err(exception, 0);
45 void do_restore_state (void *pc_ptr)
48 unsigned long pc = (unsigned long) pc_ptr;
51 cpu_restore_state (tb, env, pc, NULL);
54 void do_raise_exception_direct_err (uint32_t exception, int error_code)
56 do_restore_state (GETPC ());
57 do_raise_exception_err (exception, error_code);
60 void do_raise_exception_direct (uint32_t exception)
62 do_raise_exception_direct_err (exception, 0);
65 #define MEMSUFFIX _raw
66 #include "op_helper_mem.c"
68 #if !defined(CONFIG_USER_ONLY)
69 #define MEMSUFFIX _user
70 #include "op_helper_mem.c"
72 #define MEMSUFFIX _kernel
73 #include "op_helper_mem.c"
78 #if TARGET_LONG_BITS > HOST_LONG_BITS
79 /* Those might call libgcc functions. */
92 T0 = (int64_t)T0 >> T1;
97 T0 = (int64_t)T0 >> (T1 + 32);
105 void do_dsrl32 (void)
107 T0 = T0 >> (T1 + 32);
115 tmp = T0 << (0x40 - T1);
116 T0 = (T0 >> T1) | tmp;
120 void do_drotr32 (void)
125 tmp = T0 << (0x40 - (32 + T1));
126 T0 = (T0 >> (32 + T1)) | tmp;
132 T0 = T1 << (T0 & 0x3F);
137 T0 = (int64_t)T1 >> (T0 & 0x3F);
142 T0 = T1 >> (T0 & 0x3F);
145 void do_drotrv (void)
151 tmp = T1 << (0x40 - T0);
152 T0 = (T1 >> T0) | tmp;
156 #endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
157 #endif /* TARGET_MIPS64 */
159 /* 64 bits arithmetic for 32 bits hosts */
160 #if TARGET_LONG_BITS > HOST_LONG_BITS
161 static inline uint64_t get_HILO (void)
163 return (env->HI << 32) | (uint32_t)env->LO;
166 static inline void set_HILO (uint64_t HILO)
168 env->LO = (int32_t)HILO;
169 env->HI = (int32_t)(HILO >> 32);
174 set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
179 set_HILO((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
186 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
187 set_HILO((int64_t)get_HILO() + tmp);
194 tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
195 set_HILO(get_HILO() + tmp);
202 tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
203 set_HILO((int64_t)get_HILO() - tmp);
210 tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
211 set_HILO(get_HILO() - tmp);
215 #if HOST_LONG_BITS < 64
218 /* 64bit datatypes because we may see overflow/underflow. */
220 env->LO = (int32_t)((int64_t)(int32_t)T0 / (int32_t)T1);
221 env->HI = (int32_t)((int64_t)(int32_t)T0 % (int32_t)T1);
230 lldiv_t res = lldiv((int64_t)T0, (int64_t)T1);
236 #if TARGET_LONG_BITS > HOST_LONG_BITS
245 #endif /* TARGET_MIPS64 */
247 #if defined(CONFIG_USER_ONLY)
248 void do_mfc0_random (void)
250 cpu_abort(env, "mfc0 random\n");
253 void do_mfc0_count (void)
255 cpu_abort(env, "mfc0 count\n");
258 void cpu_mips_store_count(CPUState *env, uint32_t value)
260 cpu_abort(env, "mtc0 count\n");
263 void cpu_mips_store_compare(CPUState *env, uint32_t value)
265 cpu_abort(env, "mtc0 compare\n");
268 void cpu_mips_update_irq(CPUState *env)
270 cpu_abort(env, "mtc0 status / mtc0 cause\n");
273 void do_mtc0_status_debug(uint32_t old, uint32_t val)
275 cpu_abort(env, "mtc0 status debug\n");
278 void do_mtc0_status_irqraise_debug (void)
280 cpu_abort(env, "mtc0 status irqraise debug\n");
283 void cpu_mips_tlb_flush (CPUState *env, int flush_global)
285 cpu_abort(env, "mips_tlb_flush\n");
291 void do_mfc0_random (void)
293 T0 = (int32_t)cpu_mips_get_random(env);
296 void do_mfc0_count (void)
298 T0 = (int32_t)cpu_mips_get_count(env);
301 void do_mtc0_status_debug(uint32_t old, uint32_t val)
303 fprintf(logfile, "Status %08x (%08x) => %08x (%08x) Cause %08x",
304 old, old & env->CP0_Cause & CP0Ca_IP_mask,
305 val, val & env->CP0_Cause & CP0Ca_IP_mask,
307 (env->hflags & MIPS_HFLAG_UM) ? fputs(", UM\n", logfile)
308 : fputs("\n", logfile);
311 void do_mtc0_status_irqraise_debug(void)
313 fprintf(logfile, "Raise pending IRQs\n");
316 void fpu_handle_exception(void)
318 #ifdef CONFIG_SOFTFLOAT
319 int flags = get_float_exception_flags(&env->fp_status);
320 unsigned int cpuflags = 0, enable, cause = 0;
322 enable = GET_FP_ENABLE(env->fcr31);
324 /* determine current flags */
325 if (flags & float_flag_invalid) {
326 cpuflags |= FP_INVALID;
327 cause |= FP_INVALID & enable;
329 if (flags & float_flag_divbyzero) {
331 cause |= FP_DIV0 & enable;
333 if (flags & float_flag_overflow) {
334 cpuflags |= FP_OVERFLOW;
335 cause |= FP_OVERFLOW & enable;
337 if (flags & float_flag_underflow) {
338 cpuflags |= FP_UNDERFLOW;
339 cause |= FP_UNDERFLOW & enable;
341 if (flags & float_flag_inexact) {
342 cpuflags |= FP_INEXACT;
343 cause |= FP_INEXACT & enable;
345 SET_FP_FLAGS(env->fcr31, cpuflags);
346 SET_FP_CAUSE(env->fcr31, cause);
348 SET_FP_FLAGS(env->fcr31, 0);
349 SET_FP_CAUSE(env->fcr31, 0);
354 void cpu_mips_tlb_flush (CPUState *env, int flush_global)
356 /* Flush qemu's TLB and discard all shadowed entries. */
357 tlb_flush (env, flush_global);
358 env->tlb_in_use = env->nb_tlb;
361 static void r4k_mips_tlb_flush_extra (CPUState *env, int first)
363 /* Discard entries from env->tlb[first] onwards. */
364 while (env->tlb_in_use > first) {
365 r4k_invalidate_tlb(env, --env->tlb_in_use, 0);
369 static void r4k_fill_tlb (int idx)
373 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
374 tlb = &env->mmu.r4k.tlb[idx];
375 tlb->VPN = env->CP0_EntryHi & (TARGET_PAGE_MASK << 1);
377 tlb->VPN &= 0xC00000FFFFFFFFFFULL;
379 tlb->ASID = env->CP0_EntryHi & 0xFF;
380 tlb->PageMask = env->CP0_PageMask;
381 tlb->G = env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1;
382 tlb->V0 = (env->CP0_EntryLo0 & 2) != 0;
383 tlb->D0 = (env->CP0_EntryLo0 & 4) != 0;
384 tlb->C0 = (env->CP0_EntryLo0 >> 3) & 0x7;
385 tlb->PFN[0] = (env->CP0_EntryLo0 >> 6) << 12;
386 tlb->V1 = (env->CP0_EntryLo1 & 2) != 0;
387 tlb->D1 = (env->CP0_EntryLo1 & 4) != 0;
388 tlb->C1 = (env->CP0_EntryLo1 >> 3) & 0x7;
389 tlb->PFN[1] = (env->CP0_EntryLo1 >> 6) << 12;
392 void r4k_do_tlbwi (void)
394 /* Discard cached TLB entries. We could avoid doing this if the
395 tlbwi is just upgrading access permissions on the current entry;
396 that might be a further win. */
397 r4k_mips_tlb_flush_extra (env, env->nb_tlb);
399 r4k_invalidate_tlb(env, env->CP0_Index % env->nb_tlb, 0);
400 r4k_fill_tlb(env->CP0_Index % env->nb_tlb);
403 void r4k_do_tlbwr (void)
405 int r = cpu_mips_get_random(env);
407 r4k_invalidate_tlb(env, r, 1);
411 void r4k_do_tlbp (void)
420 ASID = env->CP0_EntryHi & 0xFF;
421 for (i = 0; i < env->nb_tlb; i++) {
422 tlb = &env->mmu.r4k.tlb[i];
423 /* 1k pages are not supported. */
424 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
425 tag = env->CP0_EntryHi & ~mask;
426 VPN = tlb->VPN & ~mask;
427 /* Check ASID, virtual page number & size */
428 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
434 if (i == env->nb_tlb) {
435 /* No match. Discard any shadow entries, if any of them match. */
436 for (i = env->nb_tlb; i < env->tlb_in_use; i++) {
437 tlb = &env->mmu.r4k.tlb[i];
438 /* 1k pages are not supported. */
439 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
440 tag = env->CP0_EntryHi & ~mask;
441 VPN = tlb->VPN & ~mask;
442 /* Check ASID, virtual page number & size */
443 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
444 r4k_mips_tlb_flush_extra (env, i);
449 env->CP0_Index |= 0x80000000;
453 void r4k_do_tlbr (void)
458 ASID = env->CP0_EntryHi & 0xFF;
459 tlb = &env->mmu.r4k.tlb[env->CP0_Index % env->nb_tlb];
461 /* If this will change the current ASID, flush qemu's TLB. */
462 if (ASID != tlb->ASID)
463 cpu_mips_tlb_flush (env, 1);
465 r4k_mips_tlb_flush_extra(env, env->nb_tlb);
467 env->CP0_EntryHi = tlb->VPN | tlb->ASID;
468 env->CP0_PageMask = tlb->PageMask;
469 env->CP0_EntryLo0 = tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) |
470 (tlb->C0 << 3) | (tlb->PFN[0] >> 6);
471 env->CP0_EntryLo1 = tlb->G | (tlb->V1 << 1) | (tlb->D1 << 2) |
472 (tlb->C1 << 3) | (tlb->PFN[1] >> 6);
475 #endif /* !CONFIG_USER_ONLY */
477 void dump_ldst (const unsigned char *func)
480 fprintf(logfile, "%s => " TARGET_FMT_lx " " TARGET_FMT_lx "\n", __func__, T0, T1);
486 fprintf(logfile, "%s " TARGET_FMT_lx " at " TARGET_FMT_lx " (" TARGET_FMT_lx ")\n", __func__,
487 T1, T0, env->CP0_LLAddr);
491 void debug_pre_eret (void)
493 fprintf(logfile, "ERET: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
494 env->PC, env->CP0_EPC);
495 if (env->CP0_Status & (1 << CP0St_ERL))
496 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
497 if (env->hflags & MIPS_HFLAG_DM)
498 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
499 fputs("\n", logfile);
502 void debug_post_eret (void)
504 fprintf(logfile, " => PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
505 env->PC, env->CP0_EPC);
506 if (env->CP0_Status & (1 << CP0St_ERL))
507 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
508 if (env->hflags & MIPS_HFLAG_DM)
509 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
510 if (env->hflags & MIPS_HFLAG_UM)
511 fputs(", UM\n", logfile);
513 fputs("\n", logfile);
516 void do_pmon (int function)
520 case 2: /* TODO: char inbyte(int waitflag); */
521 if (env->gpr[4] == 0)
524 case 11: /* TODO: char inbyte (void); */
529 printf("%c", (char)(env->gpr[4] & 0xFF));
535 unsigned char *fmt = (void *)(unsigned long)env->gpr[4];
542 #if !defined(CONFIG_USER_ONLY)
544 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr);
546 #define MMUSUFFIX _mmu
550 #include "softmmu_template.h"
553 #include "softmmu_template.h"
556 #include "softmmu_template.h"
559 #include "softmmu_template.h"
561 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
563 env->CP0_BadVAddr = addr;
564 do_restore_state (retaddr);
565 do_raise_exception ((is_write == 1) ? EXCP_AdES : EXCP_AdEL);
568 void tlb_fill (target_ulong addr, int is_write, int is_user, void *retaddr)
570 TranslationBlock *tb;
575 /* XXX: hack to restore env in all cases, even if not called from
578 env = cpu_single_env;
579 ret = cpu_mips_handle_mmu_fault(env, addr, is_write, is_user, 1);
582 /* now we have a real cpu fault */
583 pc = (unsigned long)retaddr;
586 /* the PC is inside the translated code. It means that we have
587 a virtual CPU fault */
588 cpu_restore_state(tb, env, pc, NULL);
591 do_raise_exception_err(env->exception_index, env->error_code);
598 /* Complex FPU operations which may need stack space. */
600 /* convert MIPS rounding mode in FCR31 to IEEE library */
601 unsigned int ieee_rm[] = {
602 float_round_nearest_even,
608 #define RESTORE_ROUNDING_MODE \
609 set_float_rounding_mode(ieee_rm[env->fcr31 & 3], &env->fp_status)
617 env->fcr31 = (env->fcr31 & 0x017fffff) | ((T0 & 0xfe) << 24) |
623 env->fcr31 = (env->fcr31 & 0xfffc0f83) | (T0 & 0x0003f07c);
628 env->fcr31 = (env->fcr31 & 0xfefff07c) | (T0 & 0x00000f83) |
639 /* set rounding mode */
640 RESTORE_ROUNDING_MODE;
641 set_float_exception_flags(0, &env->fp_status);
642 if ((GET_FP_ENABLE(env->fcr31) | 0x20) & GET_FP_CAUSE(env->fcr31))
643 do_raise_exception(EXCP_FPE);
646 inline char ieee_ex_to_mips(char xcpt)
648 return (xcpt & float_flag_inexact) >> 5 |
649 (xcpt & float_flag_underflow) >> 3 |
650 (xcpt & float_flag_overflow) >> 1 |
651 (xcpt & float_flag_divbyzero) << 1 |
652 (xcpt & float_flag_invalid) << 4;
655 inline char mips_ex_to_ieee(char xcpt)
657 return (xcpt & FP_INEXACT) << 5 |
658 (xcpt & FP_UNDERFLOW) << 3 |
659 (xcpt & FP_OVERFLOW) << 1 |
660 (xcpt & FP_DIV0) >> 1 |
661 (xcpt & FP_INVALID) >> 4;
664 inline void update_fcr31(void)
666 int tmp = ieee_ex_to_mips(get_float_exception_flags(&env->fp_status));
668 SET_FP_CAUSE(env->fcr31, tmp);
669 if (GET_FP_ENABLE(env->fcr31) & tmp)
670 do_raise_exception(EXCP_FPE);
672 UPDATE_FP_FLAGS(env->fcr31, tmp);
675 #define FLOAT_OP(name, p) void do_float_##name##_##p(void)
679 set_float_exception_flags(0, &env->fp_status);
680 FDT2 = float32_to_float64(FST0, &env->fp_status);
685 set_float_exception_flags(0, &env->fp_status);
686 FDT2 = int32_to_float64(WT0, &env->fp_status);
691 set_float_exception_flags(0, &env->fp_status);
692 FDT2 = int64_to_float64(DT0, &env->fp_status);
697 set_float_exception_flags(0, &env->fp_status);
698 DT2 = float64_to_int64(FDT0, &env->fp_status);
700 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
701 DT2 = 0x7fffffffffffffffULL;
705 set_float_exception_flags(0, &env->fp_status);
706 DT2 = float32_to_int64(FST0, &env->fp_status);
708 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
709 DT2 = 0x7fffffffffffffffULL;
714 set_float_exception_flags(0, &env->fp_status);
715 FST2 = int32_to_float32(WT0, &env->fp_status);
716 FSTH2 = int32_to_float32(WTH0, &env->fp_status);
721 set_float_exception_flags(0, &env->fp_status);
722 WT2 = float32_to_int32(FST0, &env->fp_status);
723 WTH2 = float32_to_int32(FSTH0, &env->fp_status);
725 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
730 set_float_exception_flags(0, &env->fp_status);
731 FST2 = float64_to_float32(FDT0, &env->fp_status);
736 set_float_exception_flags(0, &env->fp_status);
737 FST2 = int32_to_float32(WT0, &env->fp_status);
742 set_float_exception_flags(0, &env->fp_status);
743 FST2 = int64_to_float32(DT0, &env->fp_status);
748 set_float_exception_flags(0, &env->fp_status);
754 set_float_exception_flags(0, &env->fp_status);
760 set_float_exception_flags(0, &env->fp_status);
761 WT2 = float32_to_int32(FST0, &env->fp_status);
763 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
768 set_float_exception_flags(0, &env->fp_status);
769 WT2 = float64_to_int32(FDT0, &env->fp_status);
771 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
777 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
778 DT2 = float64_round_to_int(FDT0, &env->fp_status);
779 RESTORE_ROUNDING_MODE;
781 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
782 DT2 = 0x7fffffffffffffffULL;
786 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
787 DT2 = float32_round_to_int(FST0, &env->fp_status);
788 RESTORE_ROUNDING_MODE;
790 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
791 DT2 = 0x7fffffffffffffffULL;
795 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
796 WT2 = float64_round_to_int(FDT0, &env->fp_status);
797 RESTORE_ROUNDING_MODE;
799 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
804 set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
805 WT2 = float32_round_to_int(FST0, &env->fp_status);
806 RESTORE_ROUNDING_MODE;
808 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
814 DT2 = float64_to_int64_round_to_zero(FDT0, &env->fp_status);
816 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
817 DT2 = 0x7fffffffffffffffULL;
821 DT2 = float32_to_int64_round_to_zero(FST0, &env->fp_status);
823 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
824 DT2 = 0x7fffffffffffffffULL;
828 WT2 = float64_to_int32_round_to_zero(FDT0, &env->fp_status);
830 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
835 WT2 = float32_to_int32_round_to_zero(FST0, &env->fp_status);
837 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
843 set_float_rounding_mode(float_round_up, &env->fp_status);
844 DT2 = float64_round_to_int(FDT0, &env->fp_status);
845 RESTORE_ROUNDING_MODE;
847 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
848 DT2 = 0x7fffffffffffffffULL;
852 set_float_rounding_mode(float_round_up, &env->fp_status);
853 DT2 = float32_round_to_int(FST0, &env->fp_status);
854 RESTORE_ROUNDING_MODE;
856 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
857 DT2 = 0x7fffffffffffffffULL;
861 set_float_rounding_mode(float_round_up, &env->fp_status);
862 WT2 = float64_round_to_int(FDT0, &env->fp_status);
863 RESTORE_ROUNDING_MODE;
865 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
870 set_float_rounding_mode(float_round_up, &env->fp_status);
871 WT2 = float32_round_to_int(FST0, &env->fp_status);
872 RESTORE_ROUNDING_MODE;
874 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
880 set_float_rounding_mode(float_round_down, &env->fp_status);
881 DT2 = float64_round_to_int(FDT0, &env->fp_status);
882 RESTORE_ROUNDING_MODE;
884 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
885 DT2 = 0x7fffffffffffffffULL;
889 set_float_rounding_mode(float_round_down, &env->fp_status);
890 DT2 = float32_round_to_int(FST0, &env->fp_status);
891 RESTORE_ROUNDING_MODE;
893 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
894 DT2 = 0x7fffffffffffffffULL;
898 set_float_rounding_mode(float_round_down, &env->fp_status);
899 WT2 = float64_round_to_int(FDT0, &env->fp_status);
900 RESTORE_ROUNDING_MODE;
902 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
907 set_float_rounding_mode(float_round_down, &env->fp_status);
908 WT2 = float32_round_to_int(FST0, &env->fp_status);
909 RESTORE_ROUNDING_MODE;
911 if (GET_FP_CAUSE(env->fcr31) & (FP_OVERFLOW | FP_INVALID))
915 /* unary operations, MIPS specific, s and d */
916 #define FLOAT_UNOP(name) \
919 set_float_exception_flags(0, &env->fp_status); \
920 /* XXX: not implemented */ \
921 /* FDT2 = float64_ ## name (FDT0, &env->fp_status);*/ \
922 do_raise_exception(EXCP_RI); \
927 set_float_exception_flags(0, &env->fp_status); \
928 /* XXX: not implemented */ \
929 /* FST2 = float32_ ## name (FST0, &env->fp_status);*/ \
930 do_raise_exception(EXCP_RI); \
937 /* unary operations, MIPS specific, s, d and ps */
938 #define FLOAT_UNOP(name) \
941 set_float_exception_flags(0, &env->fp_status); \
942 /* XXX: not implemented */ \
943 /* FDT2 = float64_ ## name (FDT0, &env->fp_status);*/ \
944 do_raise_exception(EXCP_RI); \
949 set_float_exception_flags(0, &env->fp_status); \
950 /* XXX: not implemented */ \
951 /* FST2 = float32_ ## name (FST0, &env->fp_status);*/ \
952 do_raise_exception(EXCP_RI); \
957 set_float_exception_flags(0, &env->fp_status); \
958 /* XXX: not implemented */ \
959 /* FST2 = float32_ ## name (FST0, &env->fp_status);*/ \
960 /* FSTH2 = float32_ ## name (FSTH0, &env->fp_status);*/ \
961 do_raise_exception(EXCP_RI); \
968 /* binary operations */
969 #define FLOAT_BINOP(name) \
972 set_float_exception_flags(0, &env->fp_status); \
973 FDT2 = float64_ ## name (FDT0, FDT1, &env->fp_status); \
975 if (GET_FP_CAUSE(env->fcr31) & FP_INVALID) \
976 FDT2 = 0x7ff7ffffffffffffULL; \
977 else if (GET_FP_CAUSE(env->fcr31) & FP_UNDERFLOW) { \
978 if ((env->fcr31 & 0x3) == 0) \
979 FDT2 &= 0x8000000000000000ULL; \
984 set_float_exception_flags(0, &env->fp_status); \
985 FST2 = float32_ ## name (FST0, FST1, &env->fp_status); \
987 if (GET_FP_CAUSE(env->fcr31) & FP_INVALID) \
989 else if (GET_FP_CAUSE(env->fcr31) & FP_UNDERFLOW) { \
990 if ((env->fcr31 & 0x3) == 0) \
991 FST2 &= 0x80000000ULL; \
996 set_float_exception_flags(0, &env->fp_status); \
997 FST2 = float32_ ## name (FST0, FST1, &env->fp_status); \
998 FSTH2 = float32_ ## name (FSTH0, FSTH1, &env->fp_status); \
1000 if (GET_FP_CAUSE(env->fcr31) & FP_INVALID) { \
1001 FST2 = 0x7fbfffff; \
1002 FSTH2 = 0x7fbfffff; \
1003 } else if (GET_FP_CAUSE(env->fcr31) & FP_UNDERFLOW) { \
1004 if ((env->fcr31 & 0x3) == 0) { \
1005 FST2 &= 0x80000000ULL; \
1006 FSTH2 &= 0x80000000ULL; \
1016 /* binary operations, MIPS specific */
1017 #define FLOAT_BINOP(name) \
1020 set_float_exception_flags(0, &env->fp_status); \
1021 /* XXX: not implemented */ \
1022 /* FDT2 = float64_ ## name (FDT0, FDT1, &env->fp_status);*/ \
1023 do_raise_exception(EXCP_RI); \
1028 set_float_exception_flags(0, &env->fp_status); \
1029 /* XXX: not implemented */ \
1030 /* FST2 = float32_ ## name (FST0, FST1, &env->fp_status);*/ \
1031 do_raise_exception(EXCP_RI); \
1034 FLOAT_OP(name, ps) \
1036 set_float_exception_flags(0, &env->fp_status); \
1037 /* XXX: not implemented */ \
1038 /* FST2 = float32_ ## name (FST0, FST1, &env->fp_status);*/ \
1039 /* FSTH2 = float32_ ## name (FSTH0, FSTH1, &env->fp_status);*/ \
1040 do_raise_exception(EXCP_RI); \
1049 set_float_exception_flags(0, &env->fp_status);
1050 FST2 = float32_add (FST0, FSTH0, &env->fp_status);
1051 FSTH2 = float32_add (FST1, FSTH1, &env->fp_status);
1057 set_float_exception_flags(0, &env->fp_status);
1058 FST2 = float32_mul (FST0, FSTH0, &env->fp_status);
1059 FSTH2 = float32_mul (FST1, FSTH1, &env->fp_status);
1063 #define FOP_COND_D(op, cond) \
1064 void do_cmp_d_ ## op (long cc) \
1069 SET_FP_COND(cc, env); \
1071 CLEAR_FP_COND(cc, env); \
1073 void do_cmpabs_d_ ## op (long cc) \
1076 FDT0 &= ~(1ULL << 63); \
1077 FDT1 &= ~(1ULL << 63); \
1081 SET_FP_COND(cc, env); \
1083 CLEAR_FP_COND(cc, env); \
1086 int float64_is_unordered(int sig, float64 a, float64 b STATUS_PARAM)
1088 if (float64_is_signaling_nan(a) ||
1089 float64_is_signaling_nan(b) ||
1090 (sig && (float64_is_nan(a) || float64_is_nan(b)))) {
1091 float_raise(float_flag_invalid, status);
1093 } else if (float64_is_nan(a) || float64_is_nan(b)) {
1100 /* NOTE: the comma operator will make "cond" to eval to false,
1101 * but float*_is_unordered() is still called. */
1102 FOP_COND_D(f, (float64_is_unordered(0, FDT1, FDT0, &env->fp_status), 0))
1103 FOP_COND_D(un, float64_is_unordered(0, FDT1, FDT0, &env->fp_status))
1104 FOP_COND_D(eq, !float64_is_unordered(0, FDT1, FDT0, &env->fp_status) && float64_eq(FDT0, FDT1, &env->fp_status))
1105 FOP_COND_D(ueq, float64_is_unordered(0, FDT1, FDT0, &env->fp_status) || float64_eq(FDT0, FDT1, &env->fp_status))
1106 FOP_COND_D(olt, !float64_is_unordered(0, FDT1, FDT0, &env->fp_status) && float64_lt(FDT0, FDT1, &env->fp_status))
1107 FOP_COND_D(ult, float64_is_unordered(0, FDT1, FDT0, &env->fp_status) || float64_lt(FDT0, FDT1, &env->fp_status))
1108 FOP_COND_D(ole, !float64_is_unordered(0, FDT1, FDT0, &env->fp_status) && float64_le(FDT0, FDT1, &env->fp_status))
1109 FOP_COND_D(ule, float64_is_unordered(0, FDT1, FDT0, &env->fp_status) || float64_le(FDT0, FDT1, &env->fp_status))
1110 /* NOTE: the comma operator will make "cond" to eval to false,
1111 * but float*_is_unordered() is still called. */
1112 FOP_COND_D(sf, (float64_is_unordered(1, FDT1, FDT0, &env->fp_status), 0))
1113 FOP_COND_D(ngle,float64_is_unordered(1, FDT1, FDT0, &env->fp_status))
1114 FOP_COND_D(seq, !float64_is_unordered(1, FDT1, FDT0, &env->fp_status) && float64_eq(FDT0, FDT1, &env->fp_status))
1115 FOP_COND_D(ngl, float64_is_unordered(1, FDT1, FDT0, &env->fp_status) || float64_eq(FDT0, FDT1, &env->fp_status))
1116 FOP_COND_D(lt, !float64_is_unordered(1, FDT1, FDT0, &env->fp_status) && float64_lt(FDT0, FDT1, &env->fp_status))
1117 FOP_COND_D(nge, float64_is_unordered(1, FDT1, FDT0, &env->fp_status) || float64_lt(FDT0, FDT1, &env->fp_status))
1118 FOP_COND_D(le, !float64_is_unordered(1, FDT1, FDT0, &env->fp_status) && float64_le(FDT0, FDT1, &env->fp_status))
1119 FOP_COND_D(ngt, float64_is_unordered(1, FDT1, FDT0, &env->fp_status) || float64_le(FDT0, FDT1, &env->fp_status))
1121 #define FOP_COND_S(op, cond) \
1122 void do_cmp_s_ ## op (long cc) \
1127 SET_FP_COND(cc, env); \
1129 CLEAR_FP_COND(cc, env); \
1131 void do_cmpabs_s_ ## op (long cc) \
1134 FST0 &= ~(1 << 31); \
1135 FST1 &= ~(1 << 31); \
1139 SET_FP_COND(cc, env); \
1141 CLEAR_FP_COND(cc, env); \
1144 flag float32_is_unordered(int sig, float32 a, float32 b STATUS_PARAM)
1146 if (float32_is_signaling_nan(a) ||
1147 float32_is_signaling_nan(b) ||
1148 (sig && (float32_is_nan(a) || float32_is_nan(b)))) {
1149 float_raise(float_flag_invalid, status);
1151 } else if (float32_is_nan(a) || float32_is_nan(b)) {
1158 /* NOTE: the comma operator will make "cond" to eval to false,
1159 * but float*_is_unordered() is still called. */
1160 FOP_COND_S(f, (float32_is_unordered(0, FST1, FST0, &env->fp_status), 0))
1161 FOP_COND_S(un, float32_is_unordered(0, FST1, FST0, &env->fp_status))
1162 FOP_COND_S(eq, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_eq(FST0, FST1, &env->fp_status))
1163 FOP_COND_S(ueq, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_eq(FST0, FST1, &env->fp_status))
1164 FOP_COND_S(olt, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_lt(FST0, FST1, &env->fp_status))
1165 FOP_COND_S(ult, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_lt(FST0, FST1, &env->fp_status))
1166 FOP_COND_S(ole, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_le(FST0, FST1, &env->fp_status))
1167 FOP_COND_S(ule, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_le(FST0, FST1, &env->fp_status))
1168 /* NOTE: the comma operator will make "cond" to eval to false,
1169 * but float*_is_unordered() is still called. */
1170 FOP_COND_S(sf, (float32_is_unordered(1, FST1, FST0, &env->fp_status), 0))
1171 FOP_COND_S(ngle,float32_is_unordered(1, FST1, FST0, &env->fp_status))
1172 FOP_COND_S(seq, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_eq(FST0, FST1, &env->fp_status))
1173 FOP_COND_S(ngl, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_eq(FST0, FST1, &env->fp_status))
1174 FOP_COND_S(lt, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_lt(FST0, FST1, &env->fp_status))
1175 FOP_COND_S(nge, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_lt(FST0, FST1, &env->fp_status))
1176 FOP_COND_S(le, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_le(FST0, FST1, &env->fp_status))
1177 FOP_COND_S(ngt, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_le(FST0, FST1, &env->fp_status))
1179 #define FOP_COND_PS(op, condl, condh) \
1180 void do_cmp_ps_ ## op (long cc) \
1186 SET_FP_COND(cc, env); \
1188 CLEAR_FP_COND(cc, env); \
1190 SET_FP_COND(cc + 1, env); \
1192 CLEAR_FP_COND(cc + 1, env); \
1194 void do_cmpabs_ps_ ## op (long cc) \
1197 FST0 &= ~(1 << 31); \
1198 FSTH0 &= ~(1 << 31); \
1199 FST1 &= ~(1 << 31); \
1200 FSTH1 &= ~(1 << 31); \
1205 SET_FP_COND(cc, env); \
1207 CLEAR_FP_COND(cc, env); \
1209 SET_FP_COND(cc + 1, env); \
1211 CLEAR_FP_COND(cc + 1, env); \
1214 /* NOTE: the comma operator will make "cond" to eval to false,
1215 * but float*_is_unordered() is still called. */
1216 FOP_COND_PS(f, (float32_is_unordered(0, FST1, FST0, &env->fp_status), 0),
1217 (float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status), 0))
1218 FOP_COND_PS(un, float32_is_unordered(0, FST1, FST0, &env->fp_status),
1219 float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status))
1220 FOP_COND_PS(eq, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_eq(FST0, FST1, &env->fp_status),
1221 !float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) && float32_eq(FSTH0, FSTH1, &env->fp_status))
1222 FOP_COND_PS(ueq, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_eq(FST0, FST1, &env->fp_status),
1223 float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) || float32_eq(FSTH0, FSTH1, &env->fp_status))
1224 FOP_COND_PS(olt, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_lt(FST0, FST1, &env->fp_status),
1225 !float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) && float32_lt(FSTH0, FSTH1, &env->fp_status))
1226 FOP_COND_PS(ult, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_lt(FST0, FST1, &env->fp_status),
1227 float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) || float32_lt(FSTH0, FSTH1, &env->fp_status))
1228 FOP_COND_PS(ole, !float32_is_unordered(0, FST1, FST0, &env->fp_status) && float32_le(FST0, FST1, &env->fp_status),
1229 !float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) && float32_le(FSTH0, FSTH1, &env->fp_status))
1230 FOP_COND_PS(ule, float32_is_unordered(0, FST1, FST0, &env->fp_status) || float32_le(FST0, FST1, &env->fp_status),
1231 float32_is_unordered(0, FSTH1, FSTH0, &env->fp_status) || float32_le(FSTH0, FSTH1, &env->fp_status))
1232 /* NOTE: the comma operator will make "cond" to eval to false,
1233 * but float*_is_unordered() is still called. */
1234 FOP_COND_PS(sf, (float32_is_unordered(1, FST1, FST0, &env->fp_status), 0),
1235 (float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status), 0))
1236 FOP_COND_PS(ngle,float32_is_unordered(1, FST1, FST0, &env->fp_status),
1237 float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status))
1238 FOP_COND_PS(seq, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_eq(FST0, FST1, &env->fp_status),
1239 !float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) && float32_eq(FSTH0, FSTH1, &env->fp_status))
1240 FOP_COND_PS(ngl, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_eq(FST0, FST1, &env->fp_status),
1241 float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) || float32_eq(FSTH0, FSTH1, &env->fp_status))
1242 FOP_COND_PS(lt, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_lt(FST0, FST1, &env->fp_status),
1243 !float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) && float32_lt(FSTH0, FSTH1, &env->fp_status))
1244 FOP_COND_PS(nge, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_lt(FST0, FST1, &env->fp_status),
1245 float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) || float32_lt(FSTH0, FSTH1, &env->fp_status))
1246 FOP_COND_PS(le, !float32_is_unordered(1, FST1, FST0, &env->fp_status) && float32_le(FST0, FST1, &env->fp_status),
1247 !float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) && float32_le(FSTH0, FSTH1, &env->fp_status))
1248 FOP_COND_PS(ngt, float32_is_unordered(1, FST1, FST0, &env->fp_status) || float32_le(FST0, FST1, &env->fp_status),
1249 float32_is_unordered(1, FSTH1, FSTH0, &env->fp_status) || float32_le(FSTH0, FSTH1, &env->fp_status))