5.8 Return from an exception handler

After it has handled an exception, the exception handler must return execution to the main program. The method used to return depends on whether or not the exception handler uses stack operations.

In both cases, to return execution to the place where the exception occurred, an exception handler must:

  • restore the CPSR from the appropriate SPSR

  • restore the PC using the return address from the appropriate LR.

For a simple return that does not require the destination mode registers to be restored from the stack, the exception handler carries out these operations by performing a data processing instruction with:The return instruction required depends on the type of exception.

  • the S flag set

  • the PC as the destination register.

Note:

You do not have to return from the reset handler because the reset handler executes your main code directly.

If the exception handler entry code uses the stack to store registers that must be preserved while it handles the exception, it can return using a load multiple instruction with the ^ qualifier. For example, an exception handler can return in one instruction using:

    LDMFD sp!,{R0-R12,pc}^

To do this, the exception handler must save the following onto the stack:

  • all the work registers in use when the handler is invoked

  • the link register, modified to produce the same effect as the data processing instructions.

The ^ qualifier specifies that the CPSR is restored from the SPSR. It must be used only from a privileged mode.

Note:

You cannot use any 16-bit Thumb instruction to return from exceptions because these are unable to restore the CPSR.

Non-ConfidentialPDF file icon PDF versionARM DUI0471M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.