17.5 Interrupt Service Routine Context Switching

When using Cortex-M devices, the hardware saves and restores the argument registers (r0 to r3), the IP register (r12) the link register (r14), the return address, and the program status registers when the interrupt occurs and returns. Other registers must be preserved by the interrupt handler function, as with any other function. The compiler will do this automatically for C functions. If you write your own handler in assembly, be sure to follow the procedure call standard.

It is possible for other exceptions to occur during the context switch. The work for this is handled in hardware. Details of this can be found in the appropriate architecture reference manual, but in essence, the context switching does not occur twice. Instead, the higher priority interrupt is run with the other interrupt set to pending.