1
votes

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
How exactly do you imagine things working if aborts or SWIs could be disabled? How is userspace code going to react to its syscalls being ignored? How is the CPU going to keep executing when the data/instruction it needs doesn't exist, if execution isn't diverted to a fault handler?Notlikethat
Hi Notlikethat, I don't know how ARM does these things. Please consider me as a beginner and I am not saying to disable them permanently. Want to know if they can be disabled, if so then how can it be done.Arunkumar S
Ah, my comment wasn't intended as criticism, just as a proof-by-contradiction thought experiment. Disregarding any ARM-specific details, consider that interrupts (which you know can be masked) are asynchronous, whereas the other things you're asking about are triggered by executing particular instructions. Masking an interrupt prevents it happening now, but it might have only happened later anyway; Now imagine masking a synchronous event, how would you then proceed to a point where you could unmask it later, if the code in between depends on that event happening? ;)Notlikethat
Yes, I understand now. Thank you.Arunkumar S

1 Answers

1
votes
  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 ?

No, these all depend on your code to be correct. For instance, a compiler will not normally generate an swi instruction.

  1. 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.

  1. 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
  1. 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.