SPRAB89A September 2011 – March 2014
Abstractly, all unwinding sequences take the following form:
Step 1: Restore SP
An actual epilog does not restore SP until after the callee-saved registers are restored, but because stack unwinding is a virtual operation, the simulated unwinding of TDEH may perform the SP restore first. This simplifies the restoration of the other callee-saved registers.
SP will be restored by either copying from FP or incrementing by a constant. In the latter case, in addition to the explicit increment, the SP is implicitly incremented to account for the size of the callee-saved area. If SP is restored from FP, this additional increment is not implied.
Step 2: Restore B3
The return address must be in B3 before the return occurs. If it is stored in a callee-saved register (say “R”), then B3 needs to be restored from R before step 3 restores R itself.
Step 3: Restore Registers
Abstractly, the callee-saved registers are restored in register safe debug order (Section 4.5.2) starting with the location pointed to by (the old) SP and moving to lower addresses. TDEH forces the safe debug ordering except when using the C6000_push_rts layout (Section 4.5.4).
For stack frames created using the compact frame method (Section 4.5.4), there may be gaps between the saved registers due to the optimization favoring compressible instructions. The unwinder must be aware of the algorithm used to lay out the registers and adjust the register locations accordingly.
In big-endian mode, to facilitate the use of LDDW and STDW, if the two registers in a pair occupy the same aligned double word, the order of the pair is swapped. This is computed after the safe debug ordering is used to determine the layout, so some register pairs will not be swapped.
Generally the SP (B15) is not restored by the explicit register restores; it is explicitly restored for DATA_MEM_BANK layout (Section 4.5.3) when an FP is not available.
Step 4: Return
Every unwinding sequence ends with an implicit or explicit "RET B3", which indicates that unwinding is complete for the current frame.