ARM Epilog (Windows Embedded CE 6.0)

1/5/2010

The ARM 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 the guidelines for implementing an epilog:

  • All parts are immediately contiguous, with no intervening instructions.
  • If a frame pointer is set up, the epilog is a single instruction that uses the frame as the base and updates all nonvolatile registers, including the Program Counter and the stack.
    If no frame is set up, the epilog consists of a stack unlink, if needed, followed by an instruction to restore multiple registers or to copy the link register R14 to the program counter.
    If the function establishes a frame pointer (which has the value of R11 for an ARM epilog), the function must not modify the pointer value during the interval between the completion of the prolog's last instruction and the beginning of the execution of the first instruction of the epilog.
    If the function does not establish a frame pointer (which has the value of R13), the function must not modify the stack pointer during the interval between the completion of the prolog's last instruction and the beginning of the execution of the first instruction of the epilog.
  • In a routine that does not modify nonvolatile registers and is not interworking, the epilog contains only a copy of the link register to the program counter.
  • A routine whose last instruction is a branch to another routine can have an empty epilog if it does not modify nonvolatile registers.
  • The address contained in the stack pointer, which always has the value of R13, must never be greater than the lowest address of any unrestored register value in the Register Save Area.
    This prevents the preserved values of the permanent registers from being corrupted by a context switch or any other asynchronous event that might occur during the execution of a prolog or epilog.

Example

The following examples show a variety of ARM epilogs.

  • ARM Epilog with frame in R11.

    <no stack unlink>
    LDMDB  r11, {r4-r11, r13, r15}
    
  • ARM Epilog with no frame.

    <stack unlink if needed>
    LDMIA  r13, {r4-R11, r13, r15}
    
  • ARM Epilog with interworking return.

    <stack unlink if needed>
    LDMIA   r13, {r4-r11, r13, LR}
    BX      LR
    

See Also

Concepts

SEH in RISC Environments
ARM Prolog

Other Resources

ARM Prolog and Epilog