Intel 64 and IA-32 Architectures Software Developers Manual Volume 3A, System Programming Guide, Part 1
5-48 Vol. 3A
INTERRUPT AND EXCEPTION HANDLING
Interrupt 12—Stack Fault Exception (#SS)
Exception Class Fault.
Description
Indicates that one of the following stack related conditions was detected:
• A limit violation is detected during an operation that refers to the SS register.
Operations that can cause a limit violation include stack-oriented instructions
such as POP, PUSH, CALL, RET, IRET, ENTER, and LEAVE, as well as other memory
references which implicitly or explicitly use the SS register (for example, MOV
AX, [BP+6] or MOV AX, SS:[EAX+6]). The ENTER instruction generates this
exception when there is not enough stack space for allocating local variables.
• A not-present stack segment is detected when attempting to load the SS register.
This violation can occur during the execution of a task switch, a CALL instruction
to a different privilege level, a return to a different privilege level, an LSS
instruction, or a MOV or POP instruction to the SS register.
Recovery from this fault is possible by either extending the limit of the stack segment
(in the case of a limit violation) or loading the missing stack segment into memory (in
the case of a not-present violation.
Exception Error Code
If the exception is caused by a not-present stack segment or by overflow of the new
stack during an inter-privilege-level call, the error code contains a segment selector
for the segment that caused the exception. Here, the exception handler can test the
present flag in the segment descriptor pointed to by the segment selector to deter-
mine the cause of the exception. For a normal limit violation (on a stack segment
already in use) the error code is set to 0.
Saved Instruction Pointer
The saved contents of CS and EIP registers generally point to the instruction that
generated the exception. However, when the exception results from attempting to
load a not-present stack segment during a task switch, the CS and EIP registers point
to the first instruction of the new task.
Program State Change
A program-state change does not generally accompany a stack-fault exception,
because the instruction that generated the fault is not executed. Here, the instruction
can be restarted after the exception handler has corrected the stack fault condition.
If a stack fault occurs during a task switch, it occurs after the commit-to-new-task
point (see Section 6.3, “Task Switching”). Here, the processor loads all the state
information from the new TSS (without performing any additional limit, present, or
type checks) before it generates the exception. The stack fault handler should thus