B.1.12. Daisy-chained vectored interrupt service routine

Example B.12 gives an example of the daisy-chained vectored interrupt service routine code.

Example B.12. Daisy-chained vectored interrupt service routine

0x18   LDR    pc, [pc, #-0xff0]               ;  Load vector into PC

vector_handler      ;  Code to enable interrupt nesting. First, stack off registers you know will be corrupted      STMFD r13!, {r0-r3, r12, r14}      ;  Use r12 to stack off the spsr      MRS   r12, spsr   ; Copy spsr to r12      STMFD r13!, {r12} ; Stack spsr in r12       ;  Change from IRQ mode to System mode, and re-enable interrupts      MSR   cpsr_c, #0x1F       ;  Branch to the function that:      ;  1. Clears the peripheral interrupt. Do this first      ;  2. Performs the interrupt function
      ;  Stack the link register of System mode

      STMFD SP!, {lr}      BL some_interrupt_code      LDMFD SP!, {lr}       ;  When the interrupt has finished, disable interrupts so that you can update the VIC and your
      ;  mode without worrying about being interrupted      MSR   cpsr_c, #0x92     ;  Disable interrupts and return to IRQ mode      ;  Acknowledge that the IRQ has finished being serviced. You can do this because the interrupts
      ;  are now disabled, so the ARM core runs this section of code up until the end, uninterrupted      LDR   r12, =VectorAddr  ;  VectorAddr should be = 0xFFFFF030      STR   r0, [r12]         ;  Not important what r0 contains      ;  Stacking operations - first, restore the spsr using r12 as a temporary register      LDMFD r13!, {r12}       ;  Pop the spsr off the stack      MSR  spsr_cxsf, r12     ;  and restore it      ;  Pop remaining registers off the stack. This corresponds to the first STMFD of this function      LDMFD r13!, {r0-r3, r12, r14}      ;  Return from the interrupt handler      SUBS  pc, lr, #4
Copyright © 2000, 2003-2004 ARM Limited. All rights reserved.ARM DDI 0181E
Non-Confidential