Lecture 9 - Exception Handling
Lecture 9 - Exception Handling
Data Abort 1 - …
1 - IRQ 0x18
IRQ
Reserved 0x14
Pre-fetch 1 -
Data Abort 0x10
SWI Lowest priority 1 -
Prefetch Abort 0x0C
Undefined instructions Lowest priority 1 -
Software Interrupt 0x08
Undefined Instruction 0x04
Reset 0x00
Note: SWI and undefined instruction have the same level of priority
because they cannot occur simultaneously
What’s in LPC2300_v2.s?
Vectors LDR PC, Reset_Addr;0x00
LDR PC, Undef_Addr;0x04
LDR PC, SWI_Addr ;0x08
LDR PC, PAbt_Addr ;0x0C
LDR PC, DAbt_Addr ;0x0F
NOP ;0x14 Reserved Vector
LDR PC, IRQ_Addr ;0x18
;LDR PC, [PC, #-0x0120] ;0x18
LDR PC, FIQ_Addr ;0x1C
irq_handler
... ;code to handle the irq
...
...
SUBS PC, R14, #4 ;Restore and return
Exception Handlers
• Each exception has its own assigned memory address shown above.
• Each address contains information (an instruction) where each exception
handler is.
Reset handler
• Initializes the system, setting up stack pointers, memory,
external interrupt sources before enabling IRQ or FIQ, …
• It is the first thing executed by the processor. When it first
receives power or its reset is activated, 0x00000000 is put on
the address bus to access the memory where the first
instruction is.
• Once it finishes, the processor will go to the main routine
(code).
Undefined Instruction
• Instruction format that falls in Undefined group
• Specialty instructions that are only valid in certain
ARM process variants.
• This switches the CPU to FIQ mode and then sets the “I” and
“F” flags to disable further IRQ or FIQ interrupts
IRQ: IRQ handler will be entered if neither an FIQ exception nor Data abort exception occurs.
On entry, IRQ exception is disabled and should remain disabled for the handler.
Exception Handling
Exception Handlers
irq_handler
... ;code to handle the irq
...
...
SUBS PC, R14, #4 ;Restore and return
On an IRQ interrupt
On an IRQ interrupt, the processor will ...
• If the “I” bit in the CPSR is clear, the current instruction is
completed and then the ARM will
– Save the address of the next instruction plus 4 in r14_irq
– Save the CPSR in the SPSR_irq
– Force the CPSR mode bits M[4:0] to 10010 (binary)
• This switches the CPU to IRQ mode and then sets the “I” flag
to disable further IRQ interrupts.