#define EFLG_MBS (1<<1)
#define EFLG_CF (1<<0)
+/* Floating point status word definitions. */
+#define FSW_ES (1U << 7)
+
/* MXCSR bit definitions. */
#define MXCSR_MM (1U << 17)
(_fic)->exn_raised); \
} while (0)
+static inline bool fpu_check_write(void)
+{
+ uint16_t fsw;
+
+ asm ( "fnstsw %0" : "=am" (fsw) );
+
+ return !(fsw & FSW_ES);
+}
+
#define emulate_fpu_insn(_op) \
asm volatile ( \
"movb $2f-1f,%0 \n" \
default:
generate_exception(EXC_UD);
}
+ /*
+ * Control instructions can't raise FPU exceptions, so we need
+ * to consider suppressing writes only for non-control ones. All
+ * of them in this group have data width 4.
+ */
+ if ( dst.type == OP_MEM && dst.bytes == 4 && !fpu_check_write() )
+ dst.type = OP_NONE;
}
put_fpu(&fic);
break;
case 7: /* fstp m80fp */
fail_if(!ops->write);
emulate_fpu_insn_memdst("fstpt", *mmvalp);
- if ( (rc = ops->write(ea.mem.seg, ea.mem.off, mmvalp,
+ if ( fpu_check_write() &&
+ (rc = ops->write(ea.mem.seg, ea.mem.off, mmvalp,
10, ctxt)) != X86EMUL_OKAY )
goto done;
dst.type = OP_NONE;
default:
generate_exception(EXC_UD);
}
+ if ( dst.type == OP_MEM && !fpu_check_write() )
+ dst.type = OP_NONE;
}
put_fpu(&fic);
break;
default:
generate_exception(EXC_UD);
}
+ /*
+ * Control instructions can't raise FPU exceptions, so we need
+ * to consider suppressing writes only for non-control ones. All
+ * of them in this group have data width 8.
+ */
+ if ( dst.type == OP_MEM && dst.bytes == 8 && !fpu_check_write() )
+ dst.type = OP_NONE;
}
put_fpu(&fic);
break;
case 6: /* fbstp packed bcd */
fail_if(!ops->write);
emulate_fpu_insn_memdst("fbstp", *mmvalp);
- if ( (rc = ops->write(ea.mem.seg, ea.mem.off, mmvalp,
+ if ( fpu_check_write() &&
+ (rc = ops->write(ea.mem.seg, ea.mem.off, mmvalp,
10, ctxt)) != X86EMUL_OKAY )
goto done;
dst.type = OP_NONE;
dst.bytes = 8;
break;
}
+ if ( dst.type == OP_MEM && !fpu_check_write() )
+ dst.type = OP_NONE;
}
put_fpu(&fic);
break;