background image

Vol. 3A 6-5

INTERRUPT AND EXCEPTION HANDLING

Faults — A fault is an exception that can generally be corrected and that, once corrected, allows the program 
to be restarted with no loss of continuity. When a fault is reported, the processor restores the machine state to 
the state prior to the beginning of execution of the faulting instruction. The return address (saved contents of 
the CS and EIP registers) for the fault handler points to the faulting instruction, rather than to the instruction 
following the faulting instruction.

Traps — A trap is an exception that is reported immediately following the execution of the trapping instruction. 
Traps allow execution of a program or task to be continued without loss of program continuity. The return 
address for the trap handler points to the instruction to be executed after the trapping instruction.

Aborts — An abort is an exception that does not always report the precise location of the instruction causing 
the exception and does not allow a restart of the program or task that caused the exception. Aborts are used 
to report severe errors, such as hardware errors and inconsistent or illegal values in system tables.

NOTE

One exception subset normally reported as a fault is not restartable. Such exceptions result in loss 
of some processor state. For example, executing a POPAD instruction where the stack frame 
crosses over the end of the stack segment causes a fault to be reported. In this situation, the 
exception handler sees that the instruction pointer (CS:EIP) has been restored as if the POPAD 
instruction had not been executed. However, internal processor state (the general-purpose 
registers) will have been modified. Such cases are considered programming errors. An application 
causing this class of exceptions should be terminated by the operating system.

6.6 

PROGRAM OR TASK RESTART

To allow the restarting of program or task following the handling of an exception or an interrupt, all exceptions 
(except aborts) are guaranteed to report exceptions on an instruction boundary. All interrupts are guaranteed to be 
taken on an instruction boundary.
For fault-class exceptions, the return instruction pointer (saved when the processor generates an exception) points 
to the faulting instruction. So, when a program or task is restarted following the handling of a fault, the faulting 
instruction is restarted (re-executed). Restarting the faulting instruction is commonly used to handle exceptions 
that are generated when access to an operand is blocked. The most common example of this type of fault is a page-
fault exception (#PF) that occurs when a program or task references an operand located on a page that is not in 
memory. When a page-fault exception occurs, the exception handler can load the page into memory and resume 
execution of the program or task by restarting the faulting instruction. To insure that the restart is handled trans-
parently to the currently executing program or task, the processor saves the necessary registers and stack pointers 
to allow a restart to the state prior to the execution of the faulting instruction.
For trap-class exceptions, the return instruction pointer points to the instruction following the trapping instruction. 
If a trap is detected during an instruction which transfers execution, the return instruction pointer reflects the 
transfer. For example, if a trap is detected while executing a JMP instruction, the return instruction pointer points 
to the destination of the JMP instruction, not to the next address past the JMP instruction. All trap exceptions allow 
program or task restart with no loss of continuity. For example, the overflow exception is a trap exception. Here, 
the return instruction pointer points to the instruction following the INTO instruction that tested EFLAGS.OF (over-
flow) flag. The trap handler for this exception resolves the overflow condition. Upon return from the trap handler, 
program or task execution continues at the instruction following the INTO instruction.
The abort-class exceptions do not support reliable restarting of the program or task. Abort handlers are designed 
to collect diagnostic information about the state of the processor when the abort exception occurred and then shut 
down the application and system as gracefully as possible.
Interrupts rigorously support restarting of interrupted programs and tasks without loss of continuity. The return 
instruction pointer saved for an interrupt points to the next instruction to be executed at the instruction boundary 
where the processor took the interrupt. If the instruction just executed has a repeat prefix, the interrupt is taken 
at the end of the current iteration with the registers set to execute the next iteration. 
The ability of a P6 family processor to speculatively execute instructions does not affect the taking of interrupts by 
the processor. Interrupts are taken at instruction boundaries located during the retirement phase of instruction 
execution; so they are always taken in the “in-order” instruction stream. See Chapter 2, “Intel® 64 and IA-32