什麼叫異常
Exceptions are generated by internal and external sources to cause the processor to handle an event,
意思就是因爲一些內部的或者外部的原因,導致處理器去處理這個原因所觸發的事件
什麼叫異常向量
The ARM architecture supports seven types of exception. When an exception occurs, execution is forced from a fixed
memory address corresponding to the type of exception. These fixed addresses are called the exception
vectors.
意思就是,ARM共支持七種類型的異常。當一個異常發生時,ARM會跳轉到對應的異常的固定地址去執行異常的處理程序,這個固定的地址就叫做異常向量。
而由異常向量與其處理函數所對應的關係表就是異常向量表了
.text
.global _start
_start:
b reset
ldr pc _undifined_instruction
ldr pc _software_interrupt
ldr pc _prefetch_abotr
ldr pc _data_abort
ldr pc _not_used
ldr pc _irq
ldr pc _fiq
_undifined_instruction: .word undifined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abotr: .word prefetch_abotr
_data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word fiq
undifined_instruction:
nop
software_interrupt:
nop
prefetch_abotr:
nop
data_abort:
nop
not_used:
nop
irq:
nop
fiq:
nop
reset:
nop
下面解析這段代碼:
b reset
ldr pc _undifined_instruction
ldr pc _software_interrupt
ldr pc _prefetch_abotr
ldr pc _data_abort
ldr pc _not_used
ldr pc _irq
ldr pc _fiq
這段代碼就是異常下向量表
按照表中所示,0x00000000處是reset的處理程序,所以跳轉到reset處,也就是b reset
後面的是ldr指令,以ldr pc _undifined_instruction爲例,也就是將_undifined_instruction處內存的值放入pc中,而_undifined_instruction中的值是undifined_instruction,也就是未定義指令異常處理程序所在的內存地址,這樣就實現了程序的跳轉。
後面以此類推,就完成了整個程序的異常向量表!!!!