background image

9-6 Vol. 3A

PROCESSOR MANAGEMENT AND INITIALIZATION

A hardware reset places the x87 FPU in the state shown in Table 9-1. This state is different from the state the x87 
FPU is placed in following the execution of an FINIT or FNINIT instruction (also shown in Table 9-1). If the x87 FPU 
is to be used, the software-initialization code should execute an FINIT/FNINIT instruction following a hardware 
reset. These instructions, tag all data registers as empty, clear all the exception masks, set the TOP-of-stack value 
to 0, and select the default rounding and precision controls setting (round to nearest and 64-bit precision).
If the processor is reset by asserting the INIT# pin, the x87 FPU state is not changed.

9.2.1 Configuring 

the 

x87 FPU Environment

Initialization code must load the appropriate values into the MP, EM, and NE flags of control register CR0. These bits 
are cleared on hardware reset of the processor. Figure 9-3 shows the suggested settings for these flags, depending 
on the IA-32 processor being initialized. Initialization code can test for the type of processor present before setting 
or clearing these flags.

The EM flag determines whether floating-point instructions are executed by the x87 FPU (EM is cleared) or a 
device-not-available exception (#NM) is generated for all floating-point instructions so that an exception handler 
can emulate the floating-point operation (EM = 1). Ordinarily, the EM flag is cleared when an x87 FPU or math 
coprocessor is present and set if they are not present. If the EM flag is set and no x87 FPU, math coprocessor, or 
floating-point emulator is present, the processor will hang when a floating-point instruction is executed.
The MP flag determines whether WAIT/FWAIT instructions react to the setting of the TS flag. If the MP flag is clear, 
WAIT/FWAIT instructions ignore the setting of the TS flag; if the MP flag is set, they will generate a device-not-
available exception (#NM) if the TS flag is set. Generally, the MP flag should be set for processors with an inte-
grated x87 FPU and clear for processors without an integrated x87 FPU and without a math coprocessor present. 
However, an operating system can choose to save the floating-point context at every context switch, in which case 
there would be no need to set the MP bit. 
Table 2-2 shows the actions taken for floating-point and WAIT/FWAIT instructions based on the settings of the EM, 
MP, and TS flags.
The NE flag determines whether unmasked floating-point exceptions are handled by generating a floating-point 
error exception internally (NE is set, native mode) or through an external interrupt (NE is cleared). In systems 
where an external interrupt controller is used to invoke numeric exception handlers (such as MS-DOS-based 
systems), the NE bit should be cleared.

9.2.2 

Setting the Processor for x87 FPU Software Emulation

Setting the EM flag causes the processor to generate a device-not-available exception (#NM) and trap to a software 
exception handler whenever it encounters a floating-point instruction. (Table 9-3 shows when it is appropriate to 
use this flag.) Setting this flag has two functions:

It allows x87 FPU code to run on an IA-32 processor that has neither an integrated x87 FPU nor is connected to 
an external math coprocessor, by using a floating-point emulator. 

It allows floating-point code to be executed using a special or nonstandard floating-point emulator, selected for 
a particular application, regardless of whether an x87 FPU or math coprocessor is present. 

Table 9-3.  Recommended Settings of EM and MP Flags on IA-32 Processors

EM

MP

NE

IA-32 processor

1

0

1

Intel486™ SX, Intel386™ DX, and Intel386™ SX processors only, without the presence of a math 

coprocessor.

0

1

1  or  0

*

Pentium 4, Intel Xeon, P6 family, Pentium, Intel486™ DX, and Intel 487 SX processors, and 

Intel386 DX and Intel386 SX processors when a companion math coprocessor is present.

0

1

1  or  0

*

More recent Intel 64 or IA-32 processors

NOTE:

* The setting of the NE flag depends on the operating system being used.