User Guide

General-Purpose Programming 77
24592—Rev. 3.15—November 2009 AMD64 Technology
Figure 3-9 shows the relationship of the four privilege-levels to each other. The protection scheme is
implemented using the segmented memory-management mechanism described in “Segmented Virtual
Memory” in Volume 2.
Figure 3-9. Privilege-Level Relationships
3.7.3 Procedure Stack
A procedure stack is often used by control transfer operations, particularly those that change privilege
levels. Information from the calling program is passed to the target program on the procedure stack.
CALL instructions, interrupts, and exceptions all push information onto the procedure stack. The
pushed information includes a return pointer to the calling program and, for call instructions,
optionally includes parameters. When a privilege-level change occurs, the calling program’s stack
pointer (the pointer to the top of the stack) is pushed onto the stack. Interrupts and exceptions also push
a copy of the calling program’s rFLAGs register and, in some cases, an error code associated with the
interrupt or exception.
The RET or IRET control-transfer instructions reverse the operation of CALLs, interrupts, and
exceptions. These return instructions pop the return pointer off the stack and transfer control back to
the calling program. If the calling program’s stack pointer was pushed, it is restored by popping the
saved values off the stack and into the SS and rSP registers.
Stack Alignment. Control-transfer performance can degrade significantly when the stack pointer is
not aligned properly. Stack pointers should be word aligned in 16-bit segments, doubleword aligned in
32-bit segments, and quadword aligned in 64-bit mode.
Stack Operand-Size in 64-Bit Mode. In 64-bit mode, the stack pointer size is always 64 bits. The
stack size is not controlled by the default-size (B) bit in the SS descriptor, as it is in compatibility and
legacy modes, nor can it be overridden by an instruction prefix. Address-size overrides are ignored for
implicit stack references.
513-236.eps
Application Programs
Memory Management
File Allocation
Interrupt Handling
Device-Drivers
Library Routines
Privilege
0
Privilege 1
Privilege 2
Privilege 3