Partager via


SH-4 Epilog

The SH-4 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 calling function. In addition, the Virtual Unwinder requires the epilog to have three specific parts

The following list shows the required parts, listed in reverse execution order.

  1. A single add instruction immediately preceding the sequence of instructions defined in part 2, which adds a value to the frame pointer, usually R14.

    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 immediately preceding the rts instruction of part 1, all of which have the following qualities:

    • Are lds, mov, fmov, fschg, 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.

    This item is optional. It does not appear in 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 considered part of the epilog but is not required to conform to the rules listed for item 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 prolog or epilog. If the current point of control lies in either of these areas, the Virtual Unwinder must take 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 SZ, PR, and FR bits of the FPSCR register must always be set to zero on entering and exiting the prolog and epilog. The PR and FR bits must not be modified within the prolog or epilog. This condition enables the Virtual Unwinder to correctly reverse-execute floating-point instructions.

See Also

SH-4 Prolog and Epilog | SH-4 Prolog | SH-4 Prolog and Epilog Examples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.