User Guide

General-Purpose Programming 89
24592—Rev. 3.15—November 2009 AMD64 Technology
Figure 3-16. Procedure Stack, Interrupt to Same Privilege
Interrupt to More Privilege or in Long Mode. When an interrupt to a more-privileged handler
occurs or the processor is operating in long mode the processor locates the handler’s stack pointer from
the TSS. The old stack pointer (SS:rSP) is pushed onto the new stack, along with a copy of the
rFLAGS register. The return pointer (CS:rIP) to the interrupted program is then copied to the stack. If
the interrupt generates an error code, it is pushed onto the stack as the last item. Control is then
transferred to the interrupt handler. Figure 3-17 shows an example of a stack switch resulting from an
interrupt with a change in privilege.
Figure 3-17. Procedure Stack, Interrupt to Higher Privilege
Interrupt Returns. The IRET, IRETD, and IRETQ instructions are used to return from an interrupt
handler. Prior to executing an IRET, the interrupt handler must pop the error code off of the stack if one
was pushed by the interrupt or exception. IRET restores the interrupted program’s rIP, CS, and
rFLAGS by popping their saved values off of the stack and into their respective registers. If a privilege
change occurs or IRET is executed in 64-bit mode, the interrupted program’s stack pointer (SS:rSP) is
also popped off of the stack. Control is then transferred back to the interrupted program.
513-182.eps
Old rSP
Interrupt
Handler
Stack
New rSP
Return CS
Return rIP
rFLAGS
Error Code
513-181.eps
Old
Procedure
Stack
Old SS:rSP
Interrupt
Handler
Stack
New SS:rSP
Return CS
Return rIP
rFLAGS
Return SS
Return rSP
Error Code