I am trying to understand how interrupts work in an ARM architecture(ARM7TDMI to be specific). I know that there are seven exceptions (Reset,Data Abort, FIQ, IRQ, Pre-fetch abort, SWI and Undefined instruction) and they execute in particular modes(Supervisor, Abort, FIQ, IRQ, Abort, Supervisor and Undefined respectively). I have the following questions.
1. When the I and F bits in CPSR(status register) are set to 1 to disable external and fast interrupt, does the other 5 exceptions are also disabled ?
2. If the SWI is not disabled when I and F bits are enabled then, is it possible to intentionally trigger a SWI exception within ISR of an external interrupt?
3.When any interrupt is triggered saving the CPSR to SPSR, changing the mode is done by the processor itself. So, is it enough to write the ISR handler function and update the vector table with the handler addresses(I don't want to save r0 to r12 general purpose registers) ?
4. Whenever the mode of execution is changed does context saving happens internally by the processor(even when we change the mode manually)?
5. How to mask/disable a SWI exception?
Thank you.
1 Answers
- When the I and F bits in CPSR(status register) are set to 1 to disable external and fast interrupt, does the other 5 exceptions are also disabled ?
No, these all depend on your code to be correct. For instance, a compiler will not normally generate an swi
instruction.
- If the SWI is not disabled when I and F bits are enabled then, is it possible to intentionally trigger a SWI exception within ISR of an external interrupt?
Yes, it is possible. You may check the mode of the SPSR in your swi
handler and abort (or whatever is appropriate) if you want.
3.When any interrupt is triggered saving the CPSR to SPSR, changing the mode is done by the processor itself. So, is it enough to write the ISR handler function and update the vector table with the handler addresses(I don't want to save r0 to r12 general purpose registers) ?
No one wants to save registers. However, if you use r0 to r12 then the main code will become corrupt. The banked sp
is made to store these registers. Also, the vector table is not a handler address but an instruction/code.
- Whenever the mode of execution is changed does context saving happens internally by the processor(even when we change the mode manually)?
No, the instruction/code in the vector page is responsible for saving the context. If you have a pre-emptable OS then you need to save the context for the process and restore later. You may have 1000s of processes. So a CPU could not do this automatically. Your context save area may be rooted in the super mode
stack; you can use the ISR/FIQ sp
as a temporary register in this case. For instance, the switch_to
function in ARM Linux maybe helpful. thread_info
is rooted in the supervisor stack for the kernel management of the user space process/thread. The minimum code (with features removed) is,
__switch_to:
add ip, r1, #TI_CPU_SAVE @ Get save area to `ip`.
stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack
add r4, r2, #TI_CPU_SAVE @ Get restore area to `r4`
ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously
@ note the last instruction returns to a previous
@ switch_to call by the destination thread/process
- How to mask/disable a SWI exception?
You can not do this. You could write an swi
handler that does nothing but increment the PC and/or you could just jump to the undefined handler depending on what it does.