Chapter 4
SYSTEM PROGRAMMING MODEL
This chapter presents the interface of the Intel
Architecture MMX technology to the operating system.
This section describes the behavior of operating
systems during context switching.
Different operating systems take different approaches
for state-saving:
The existing task switch code for IA implementations
(including floating-point code) does not change for systems that
include MMX code.
In a cooperative operating system, application tasks
can predetermine when it is about to be switched out. Tasks can
prepare in advance for the switch.
Application programmers must know whether the operating
system performs a state save or whether it is their responsibility
to perform a state save.
In a preemptive multitasking operating system, the
application cannot know when it is preempted. Applications cannot
prepare in advance for task switching. The operating system is
responsible for saving and restoring the state when necessary.
The IA MMX technology was defined
to support the same state-saving and restoring techniques as the
floating-point state-saving and restoring techniques. Existing
operating systems can continue to run without modifications.
Figure 41 illustrates an example of an
operating system implementing floating-point or MMX state saving.
Detecting when to save the FP or MMX
state needs to be saved is the same process used for detecting
when the floating-point state needs to be saved. If CR0.TS=1
(task switch bit in control register 0), then the next FP or MMX
instruction generates exception Int 7.
4.1 CONTEXT SWITCHING
4.1.1 Cooperative Multitasking Operating System
4.1.2 Preemptive Multitasking Operating System
MMX instructions do not generate numeric exceptions or affect the processor architecture status flags. Previously pending floating-point numeric errors are reported.
The MMX instructions can generate the following exceptions:
The MMX instructions are accessible from all operation modes of IA: Protected mode, Real address mode, and Virtual 8086 mode.
The MMX state is aliased on the floating-point state:
MMX registers map to the physical locations of floating-point registers. MMX register mapping is fixed and does not change when the TOS (Top Of Stack field in the floating-point status word, bits 11-13) changes.
The value of the TOS is set to 0 after each MMX instruction.
In the floating-point context, STn refers to the relative location of a FP register, n, to the TOS. However, the FP tag bits refer to the physical locations of the FP register. The MMX registers always refer to the physical location.
In Figure 43, the inner circle refers to the physical location of the FP and MMXTM registers. The outer circle refers to FP register's relative location to the current TOS.
When the TOS=0 (case a in Figure 43), ST0 points to the physical location 0 on the floating-point stack. MM0 maps to ST0, MM1 maps to ST1, and so on.
When the TOS=2 (case b in Figure 43), ST0 points to the physical location 2. MM0 maps to ST6, MM1 maps to ST7, MM2 maps to ST0, and so on.
Using an MMX instruction (except EMMS) validates (sets to 00s) the entire floating-point tag word.
The EMMS instruction sets the entire FP tag bits register to empty (11s in each tag field).
FSAVE and FSTENV instructions read the FP tag word and store the contents of the FP tag word in memory. Executing these instructions calculates the precise values of the FP tag word fields based on the current contents of the registers. After executing these instructions, all tag bit values are valid for MMX instructions: Valid, Zero, Special, Empty. The value of the FP tag word does not affect the MMX registers or execution of MMX instructions.
Table 41 summarizes the effect of FP or MMX instructions and FSAVE/ FSTENV instructions on the tag bit fields in an FP or MMX register and defines their value in memory.
| |||
MMX | All (except EMMS) | All registers' tags are set to zeros (00). | 00, 01, 10 |
MMX | EMMS | All registers' tags are set to ones (11). | 11 |
FP | All (except FRSTOR, FLDENV) | Individual register tag is set to 00 or 11. | Each register's tags are set to 00, 11, 01 or 10. |
FP | FRSTOR, FLDENV | All registers' tags are set to 00 or 11 or 01 or 10. | Each register's tags are set to 00, 11, 01 or 10. |
4.3.2.1 ALIASING SUMMARY
Table 42 summarizes the effects of the MMXTM instructions on the floating-point state.
| |||||
|
|
|
|
| |
MMX register read from MMX register (MMn) | All fields set to 00 (Valid) | 000 | Unchanged | Unchanged | Unchanged |
MMX register write to MMX register (MMn) | All fields set to 00 (Valid) | 000 | Unchanged | Set to ones (11) | Overwritten |
EMMS | All fields set to 11 (Empty) | 000 | Unchanged | Unchanged | Unchanged |
Note: MMn refers to one MMX register.
If the task switch bit (TS) in control register 0 (CR0) is set (CR0.TS=1), the first FP or MMX instruction that executes will trigger Int 7, Device not available (DNA). Causing a DNA fault enables an operating system to save the context of the FP or MMX registers with the same code currently used to save the FP state. Both the FSAVE (Store FP state) and FRSTOR (Restore FP state) instructions are used to save and restore either the FP or MMX state.
See Section X_ContextSwitching4.1. for more details on context switching.
When floating-point exceptions are enabled and a FP exception is pending, subsequent MMX instruction execution reports an FP error (Int 16 and/or FERR# signal). The pending exception is handled by the FP exception handler. Execution resumes at the interrupted MMX instruction.
Before the MMX instruction is executed, the FP state is maintained and is visible to the FP exception handler.
See Section 3.3.6 for more detail.
The debug features for Intel Architecture implementations operate in the same manner on the MMX instruction set. This enables debuggers to debug code that uses the MMX technology.
There is no emulation support for microprocessors that support the MMX technology.
The CR0.EM bit used to emulate floating-point instructions cannot be used in the same way for MMX instruction emulation. If an MMX instruction executes when the CR0.EM bit is set, an invalid opcode exception (Int 6) is generated.
This section specifies system exceptions. Exception handling in MMX code is discussed in Section 3.3.6.
An invalid opcode exception (Int 6) can occur due to MMX instruction execution two cases:
The CR0.EM bit is used to emulate the
FP instructions in software. In this case,
the operating system does not save the FP hardware state on task
switches and does not save the MMX state. An invalid opcode exception
is generated to flag this event to the operating system, and prevent
application errors from occurring.
Legal Stuff © 1997 Intel Corporation