Search code examples
linux-kerneloperating-systemarminterrupt

why does arm-linux switch to SVC mode to handle exception?


arm doc reads

This is because a fresh interrupt could occur at any time, which would cause the core to store the return address of the new interrupt and overwrite the original interrupt. When the original interrupt attempts to return to the main program, it will cause the system to fail. The nested handler must change into an alternative kernel mode before re-enabling interrupts in order to prevent this.

enter image description here

according to the context, the main reason is that new-coming irq would overwrite R14(LR), so that the first irq cannot return to main program.

In my understanding, to solve this problem, I just need to push R14(LR_irq), SPSR_irq to R13(SP_irq) before next irq raising.

enter image description here

There is no need for nested handler to switch to alternative mode before re-enabling interrupts.

Thank you!


Solution

  • Consider this situation:

    When you're in a IRQ handler and then perform a C function call, at this point the LR has been changed; so, if you then nest an IRQ right away, the LR will be corrupt.