The actions performed by REX on entering and leaving an interrupt are discussed in this chapter.
The ARM has two interrupts, FIQ and IRQ. The discussion in this chapter pertains to handling the
IRQ interrupt on ARM. The handling of the FIQ interrupt is much simpler, since currently context
switches are not allowed in a handler that services an FIQ interrupt.
A function programmed into the exception vector table—IRQ_Handler(), written in ARM
assembly—gets control as soon as the interrupt is asserted. This function then invokes the interrupt
trampoline function. The trampoline function, which is defined outside of REX, typically detects
which interrupt source has asserted an interrupt and calls the corresponding service routine. It is
installed using rex_set_interrupt_vector() (see Section 8.19 for a detailed description). When
an interrupt occurs, the ARM processor changes mode to IRQ and switches to a different bank of
registers. The following actions are performed in IRQ_Handler:
1. Some registers will be trashed by the interrupt trampoline function. Save the registers that might
be overwritten by the trampoline function on the interrupt stack. Since this function is a C routine,
the registers saved are r0-r3, r10, r12, and r14. Save the SPSR as well since this register
may be trashed by a subsequent nested interrupt.
2. Increment the interrupt nesting level counter.
3. Switch to System mode and save the System mode link register, which gets overwritten later.
4. Call the registered trampoline function.
5. On return from the trampoline function, restore the System mode link register and switch back to
IRQ mode.
6. Decrement the interrupt nesting level counter.
7. Determine whether a task swap is required. A swap is needed only if the nesting level counter is
zero and rex_best_task is not the same as rex_curr_task.
8. If a task swap is required, do the following:
a. Restore the SPSR and saved registers from the IRQ mode stack.
b. Switch to Supervisor mode.
c. Save the context of the current task on its stack. 27 Interrupt Handling Real-Time Executive (REX)
d. Save the Supervisor mode stack pointer in the task’s TCB.
e. Set rex_curr_task to rex_best_task.
f. Restore the context of rex_curr_task.
9. If a task swap is not required, restore the SPSR from the interrupt stack, restore the other registers
saved on the interrupt stack, and return, switching back to Supervisor mode in the process.
NOTE In some versions of IRQ_Handler, there is no switch to System mode before calling the trampoline
function. Versions of IRQ_Handler that do not support nested interrupts do not keep track of the
interrupt nesting level.
This sequence of actions achieves preemption since control is returned to the highest priority ready 8
task rather than the task that was running when the interrupt occurred.