Intel IA-32 Manuale Utente

Pagina di 636
Vol. 3A 5-17
INTERRUPT AND EXCEPTION HANDLING
To return from an exception- or interrupt-handler procedure, the handler must use the IRET (or
IRETD) instruction. The IRET instruction is similar to the RET instruction except that it restores
the saved flags into the EFLAGS register. The IOPL field of the EFLAGS register is restored
only if the CPL is 0. The IF flag is changed only if the CPL is less than or equal to the IOPL.
See Chapter 3, “Instruction Set Reference, A-M,” of the IA-32 Intel® Architecture Software
Developer’s Manual, Volume 2A,
 for a description of the complete operation performed by the
IRET instruction.
If a stack switch occurred when calling the handler procedure, the IRET instruction switches
back to the interrupted procedure’s stack on the return.
5.12.1.1
Protection of Exception- and Interrupt-Handler Procedures
The privilege-level protection for exception- and interrupt-handler procedures is similar to that
used for ordinary procedure calls when called through a call gate (see Section 4.8.4, “Accessing
a Code Segment Through a Call Gate”). The pr
ocessor does not permit transfer of execution to
an exception- or interrupt-handler procedure in a less privileged code segment (numerically
greater privilege level) than the CPL. 
Figure 5-4.  Stack Usage on Transfers to Interrupt and Exception-Handling Routines
 CS
Error Code
EFLAGS
CS
 EIP
ESP After
Transfer to Handler
Error Code
ESP Before
Transfer to Handler
 EFLAGS
 EIP
 SS
 ESP
Stack Usage with No
Privilege-Level Change
Stack Usage with
Privilege-Level Change
Interrupted Procedure’s 
Interrupted Procedure’s
and Handler’s Stack
Handler’s Stack
ESP After
Transfer to Handler
Transfer to Handler
ESP Before
Stack