Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 8-47
PROGRAMMING WITH THE X87 FPU
FPU can be saved with the FSTENV/FNSTENV or FSAVE/FNSAVE instructions (see
Section 8.1.10, “Saving the x87 FPU’s State with FSTENV/FNSTENV and
FSAVE/FNSAVE”).
If the faulting floating-point instruction is followed by one or more non-floating-point
instructions, it may not be useful to re-execute the faulting instruction. See Section
8.6, “x87 FPU Exception Synchronization,” for more information on synchronizing
floating-point exceptions.
In cases where the handler needs to restart program execution with the faulting
instruction, the IRET instruction cannot be used directly. The reason for this is that
because the exception is not generated until the next floating-point or WAIT/FWAIT
instruction following the faulting floating-point instruction, the return instruction
pointer on the stack may not point to the faulting instruction. To restart program
execution at the faulting instruction, the exception handler must obtain a pointer to
the instruction from the saved x87 FPU state information, load it into the return
instruction pointer location on the stack, and then execute the IRET instruction.
See Section D.3.4, “x87 FPU Exception Handling Examples,” for general examples of
floating-point exception handlers and for specific examples of how to write a floating-
point exception handler when using the MS-DOS compatibility mode.