10.9.1.5 Stack Error Trap
The stack is initialized to the start of the data RAM address (0x4000) during Reset. A stack error trap is generated if the Stack Pointer effective address (EA) is less than the initial stack value (0x4000). Stack underflow detection is provided to protect the SFR space from being modified by the Stack Pointer. A Stack Limit register (SPLIM) associated with the Stack Pointer is uninitialized at Reset. The stack overflow check is not enabled until a word is written to the SPLIM register.
The Stack Error Status bit (STKERR) in the INTCON1 register is set whenever a stack error occurs. To avoid re-entry into the Trap Service Routine (TSR), the STKERR status flag must be cleared in software.
The stack error trap will be triggered only when the following circumstances occur:
- A Stack Pointer (W15) based access is attempted with an EA that is less than the start address of data RAM.
- Stack overflow protection is enabled, and a Stack Pointer-based access is attempted with an EA that is greater than the (user- programmable) limit value written into the SPLIM register.
- A pre/post increment/decrement operation is performed on W15 (including Stack Pointer modification during exception processing) that results in EA[1:0] != 2’b00 (i.e., not long word aligned). This will detect byte and word pre/post increment /decrement operations that are otherwise considered aligned but would result in a misaligned Stack Pointer.