Share via


SH-3 Epilog

The SH-3 epilog is a contiguous sequence of instructions that restores the saved permanent registers, resets the stack pointer to its value on function entry, and returns to the function's caller. In addition, the Virtual Unwinder requires the epilog to have the three specific, immediately contiguous parts.

The following list shows the three parts in the order of their execution:

  1. A single add instruction that immediately precedes the sequence of instructions defined in part 2, which adds a value to the frame pointer that is usually R14 but may be another register.

    Part 1 is optional. It provides for an efficient epilog in functions that establish a frame pointer. This add is used to reorient the frame pointer so that it points to the base of the RSA before being copied to the stack pointer in the first instruction of part 2.

  2. A sequence of instructions that immediately precede the rts instruction of part 3, all of which have the following qualities:

    • Are lds, mov, or add instructions.
    • Modify R15 by referencing it in the destination operand of the instruction or in a post-increment memory address operand of the instruction.

    Part 2 is optional. It will not appear in functions such as simple leaf functions that have no RSA area to restore.

  3. The rts instruction and its delay slot instruction. The instruction in the delay slot of the rts is not required to conform to the rules listed for part 2. For example, it is acceptable for the delay slot to hold a nop instruction.

When unwinding out of a function, the Virtual Unwinder must determine if the currently executing instruction is in the function prolog or epilog. If the current point of control lies in either of these areas, the Virtual Unwinder uses special measures to unwind out of the function.

The following list shows three conditions that the Virtual Unwinder must maintain:

  • If the function establishes a frame pointer, which is usually R14 but may be some other register, the function may not modify the frame pointer value during the interval between the completion of the last prolog instruction and the beginning of the first instruction of the epilog.
  • If the function does not establish a frame pointer, the value of R15, the stack pointer, the function must not modify value in R15 during the interval between the completion of the last prolog instruction and the beginning of the first instruction of the epilog.
  • The address contained in the stack pointer, which is always R15, must never be greater than the lowest address of any unrestored register value in the Register Save Area.

The first two conditions enable the Virtual Unwinder to determine the value of the stack pointer or frame pointer at the end of the prolog so that it may emulate the execution of the prolog in reverse. The third condition prevents a context switch, or other asynchronous event that might occur during the execution of a prolog or epilog, from corrupting the preserved values of the permanent registers.

See Also

SH-3 Calling Sequence Specification | SH-3 Prolog and Epilog | SH-3 Prolog | SH-3 Prolog and Epilog Examples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.