SH-4 Prolog

The SH-4 prolog contains four parts that are immediately contiguous with no intervening instructions. The following list shows the required parts.

  1. A sequence of zero or more instructions that save the incoming argument values in R4 through R7 and FR4 through FR11 to the argument home locations. This sequence typically uses the movto-register-displacement instruction with R15 as the base address register. These instructions, mov register-to-register, or fmov instructions that save incoming argument values to permanent registers may appear just before the end of the prolog, after part 4. This sequence will not change the stack pointer, R15.

    In addition, floating-point argument registers can be stored onto the stack using the fmov instruction with the register-indirect and register-indirect-pre-decrement addressing modes. A sequence of one or more such fmov instructions may be preceded by a two-instruction address register setup sequence composed of a constant move to a general register, followed by an add of the sp to the register. For example:

    mov #36, r0
    add sp, r0
    fmov fr5, @r0
    fmov fr4, @-r0
    
  2. A sequence of zero or more instructions that push all permanent registers to be saved and the PR, if it is to be saved, onto the stack using the pre-decrement indirect register addressing mode with R15 as the address register. If a permanent register such as R14 is to be used as the frame pointer, it is pushed first. If the PR, or return address, is to be saved, it is pushed last. The prolog uses mov.l instructions to save registers other than the return address, and the sts.l instruction to save the return address. It uses the fmov.s instruction to save floating-point registers, and may invoke double-precision and move-extension fmov instructions by first setting the SZ bit in the FPSCR.

  3. A sequence of one or more instructions that set up the frame pointer, if one is to be established. The frame pointer can be established in one of two ways:

    • Copy R15 to the frame pointer register, and add or subtract the offset to the frame pointer address from the frame pointer register. If the frame pointer address is less than the current value in R15, the prolog subtracts the offset to the frame pointer address from R15, and copies R15 to the frame pointer register. If this method is used, the routine must take the size of the decrement to R15 into account in part 4.
    • If the routine is not a leaf routine, the function must use a permanent register, typically R14, as the frame pointer. Otherwise, a temporary register may be used.
  4. A sequence of zero or more instructions that allocate the remaining stack frame space for local variables, compiler-generated temporaries, and the argument-build area by subtracting a 4-byte aligned offset from R15.

The Virtual Unwinder considers the last instruction in this sequence the last instruction of the prolog.

The mov immediate-to-register, mov register-to-register, add immediate-to-register, add register-to-register, and sub register-to-register instructions may be used in sequences 3 and 4. The temporary register R1 is typically used to hold an offset too large to be represented in the immediate field of an add instruction.

See Also

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

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.