Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

D-26 Vol. 1
GUIDELINES FOR WRITING X87 FPU EXCEPTION HANDLERS
FPU owner. A more general flow for a DNA exception handler that handles this case is
shown in Figure D-5.
Numeric exceptions received while the kernel owns the x87 FPU for a state swap
must be discarded in the kernel without being dispatched to a handler. A flow for a
numeric exception dispatch routine is shown in Figure D-6.
It may at first glance seem that there is a possibility of floating-point exceptions
being lost because of exceptions that are discarded during state swaps. This is not
the case, as the exception will be re-issued when the floating-point state is reloaded.
Walking through state swaps both with and without pending numeric exceptions will
clarify the operation of these two handlers.
Figure D-5. General Program Flow for DNA Exception Handler
DNA Handler Entry
Current Thread
same as
FPU Owner?
FPU Owner := Kernel
FNSAVE to Old Thread’s
FP Save Area
(may cause numeric exception)
<other handler set up code>
<other handler code>
FPU Owner := Current Thread
FRSTOR from Current Thread’s
FP Save Area
CLTS (clears CR0.TS)
Exit DNA Handler
No
Yes
<handler final clean-up>