ARM Prolog and Epilog

The ARM prolog is a code segment that sets up the stack frame for a routine. The epilog removes the routine frame and returns from the routine.

To reconstruct the context that existed on entry to a routine, Structured Exception Handling (SEH) uses process called virtual unwinding to emulate a small subset of the instructions in prolog and epilog code. Starting with a context record and an instruction address, the unwinding process interprets instructions in the prolog or epilog to reconstruct the context, as it existed before the function call.

The following list shows the steps in the Virtual Unwinder process:

  1. Search the prolog for an instruction that saves any or all of R11, R12, R13, and R14. If present, this instruction saved all the permanent registers that the Virtual Unwinder must restore. If no such instruction is present, the link register contains the return address, and the Virtual Unwinder updates only the program counter.
  2. Search for an instruction in the prolog that writes R11, the ARM frame pointer. The unwinding process restores all the registers from this address down, starting from the lowest numbered register to the highest numbered register.
  3. Search for an instruction that writes the stack. If such an instruction exists, the unwinding process must reverse execute the stack link. The right operand to this subtract is the stack size, which is a constant immediate value that is optionally rotated right or R12.
  4. If execution stops inside a prolog, the Virtual Unwinder has to determine if an instruction that saves the permanent registers executed, and if a stack link executed. If the function has not saved the permanent registers, the Unwinder copies the value in the link register to the program counter register. If function saved the register values, and if no stack link executed, the Unwinder updates the permanent registers from the stack pointer. If execution stopped in a prolog with a linked stack, the Unwinder reverse-executes the prolog.

See Also

ARM Calling Sequence Specification | ARM Prolog | ARM Epilog | THUMB Prolog | THUMB Epilog | ARM Prolog and Epilog Coding Examples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.