THUMB Epilog (Windows CE 5.0)
The THUMB epilog is a contiguous sequence of instructions that does the following:
- Restores the saved permanent registers
- Resets the stack pointer to its value on function entry
- Returns to the function's calling function
The following list shows important information about an epilog.
If a frame pointer has been set up by the prolog, the epilog restores the stack pointer from the frame pointer. It uses a single mov instruction to copy R7 to R13. This copy restores R13 to the value it had just after the prolog linked the stack.
Unlinking the stack restores R13.If {R4-R7} are to be restored, and if high registers are not to be restored, the epilog must contain an instruction to pop {R4-R7}. This instruction updates the stack pointer. If the Unwinder restores high registers, it also restores R4-R7.
The epilog contains a sequence of zero or two instructions that pop the link register from the stack into R3.
If the routine is a leaf or if the routine restores high registers, the epilog omits this sequence.
If the epilog restores high registers, it uses a branch and link to call a restore-register routine that restores R4 through R7 and the link register. It also restores the stack pointer to the value it held just after the prolog saved {R0-R3}, or to the value the stack pointer held on entry of the function if {R0-R3} were saved.
In a non-interworking routine that does not need to save registers other than {R4-R7, LR}, the epilog ends with pop {R4-R7, PC} or pop {PC} if {R4-R7} do not need to be saved. If a noninterworking routine needs to save other registers, the epilog ends with a copy of R3 to the PC.
In an interworking routine, the epilog ends with a branch and exchange (BX) to R3.
Example
The following examples show a variety of THUMB epilogs.
THUMB Epilog with no frame.
ADD SP, SP, #4 ; Stack link (as needed) POP {r4-r7} POP {r3} ; POP link register into r3 ADD SP, SP, #16 ; POP r0-r3 as needed MOV PC, r3
THUMB Epilog with frame in R7.
MOV r13, r7 ADD SP, SP, #4 ; Stack unlink (as needed) POP {r4-r7} POP {r3} ; POP link register into r3 ADD SP, SP, #16 ; POP r0-r3 as needed MOV PC, r3
THUMB Epilog restoring high registers.
ADD SP, SP, #4 ; Stack link (as needed) BL __restgpr_9 ADD SP, SP, #16 ; POP r0-r3 as needed BX LR
THUMB Epilog with a large stack frame.
LDR r7, [PC, #4] ADD SP, r7 POP {r7} MOV PC, LR
See Also
SEH in RISC Environments | THUMB Prolog
Send Feedback on this topic to the authors