ARM VERSION 1.2 Guide de l'utilisateur Page 62

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 133
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 61
MOV r4,#0x80000000
LDR r0,[r4,#0]
SUB sp,sp,#4
CMP r0,#1
BLEQ C_int_handler
MOV r0,#0
STR r0,[r4,#4]
ADD sp,sp,#4
LDMFD sp!,{r0-r4,r12,lr}
SUBS pc,lr,#4
ENDP
Compare this with the result when the __irq keyword is not used:
IRQHandler PROC
STMFD sp!,{r4,lr}
MOV r4,#0x80000000
LDR r0,[r4,#0]
CMP r0,#1
BLEQ C_int_handler
MOV r0,#0
STR r0,[r4,#4]
LDMFD sp!,{r4,pc}
ENDP
5.5.2 Reentrant interrupt handlers
Note
The following method works for both IRQ and FIQ interrupts. However, because FIQ interrupts are meant to be
serviced as quickly as possible there will normally be only one interrupt source, so it may not be necessary to allow
for reentrancy.
If an interrupt handler re-enables interrupts, then calls a subroutine, and another interrupt occurs, the return address
of the subroutine (stored in lr_IRQ) is corrupted when the second IRQ is taken. Using the __irq keyword in C does
not cause the SPSR to be saved and restored, as required by reentrant interrupt handlers, so you must write your top
level interrupt handler in assembly language.
A reentrant interrupt handler must save the IRQ state, switch processor modes, and save the state for the new
processor mode before branching to a nested subroutine or C function.
In ARM architecture v4 or later you can switch to System mode. System mode uses the User mode registers, and
allows privileged access that may be required by your exception handler. See System mode for more information. In
ARM architectures prior to ARM architecture v4 you must switch to Supervisor mode instead.
The steps needed to safely re-enable interrupts in an IRQ handler are:
1. Construct return address and save on the IRQ stack.
2. Save the work registers and spsr_IRQ.
3. Clear the source of the interrupt.
4. Switch to System mode and re-enable interrupts.
5. Save User mode link register and non callee-saved registers.
6. Call the C interrupt handler function.
7. When the C interrupt handler returns, restore User mode registers and disable interrupts.
8. Switch to IRQ mode, disabling interrupts.
9. Restore work registers and spsr_IRQ.
10. Return from the IRQ.
Example 5-14 shows how this works for System mode. Registers r12 and r14 are used as temporary work registers
after lr_IRQ is pushed on the stack.
Example 5-14
AREA INTERRUPT, CODE, READONLY
IMPORT C_irq_handler
IRQ
SUB lr, lr, #4 ; construct the return address
STMFD sp!, {lr} ; and push the adjusted lr_IRQ
MRS r14, SPSR ; copy spsr_IRQ to r14
STMFD sp!, {r12, r14} ; save work regs and spsr_IRQ
Handling Processor Exceptions
Copyright ?1999 2001 ARM Limited 5-15
Vue de la page 61
1 2 ... 57 58 59 60 61 62 63 64 65 66 67 ... 132 133

Commentaires sur ces manuels

Pas de commentaire