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.
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:
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.
You cannot use any 16-bit Thumb instruction to return from exceptions because these are unable to restore the CPSR.