2013年9月17日 星期二

ARM Exception Mechanism

最近要開始讀ARMv8 spec
想了一下對於做System來說要要讀到哪些重點
歸納如以下
1. States: instruction state, execution state, security state
2. Programming mode, register, datatype
3. Memory & protection
4. Interrrupt & exception vector table (ARM defines interrupt as a special type of exception)
5. I/O
6. Coprocessor


以上來說,對Exception機制概念非常模糊,所以就來讀ARM開發聖經 "ARM Developer's Guide"
翻到第九章 Exception And Interrupt Handler開始讀起


Exception就是阻斷程式正常運行的行為(異常發生),在ARM架構上通常exception發生時會切換到不同的processing mode做處理
而exception handler就是在對應的processing mode下處理異常的相對應動作
Exception的總類有: Reset, Data abort, FIQ, IRQ, Prefetch abort, SWI, Undefined (更新的架構或許還有)


Exception發生時,硬體會自動做出一些標準的動作
  • saves the cpsr to the spsr of the exception mode
  • saves the pc to the lr of the exception mode
  • sets the cpsr to the exception mode
  • sets pc to the address of the exception handler

上面這個圖可以看到不同exception發生時會切換到對應個processing mode


而系統中會存在一vector table當作exception發生時要去哪裡找handler
像是FIQ發生時,硬體做完標準動作後,就會去執行+0x1c的指令
而通常這個指令就是一個branch或是直接修改PC跳到我們想要的exception handler
寫exception handler時要記得我們要運用LR+bias存回PC來做結尾,其中bias在不同exception下會有不同


在ARM中的interrupt其實就是special的exception
共有三種: FIQ, IRQ, SWI
對於FIQ與IRQ我們可以program interrupt controller來決定要給IRQ或FIQ

對於interrupt handler最重要的就是要minimize interrupt latency
(Time between an external interrupt signal being raised and the first fetch of an ISR)
有兩種方法: Nested interrupt handler (top&buttom half), Interrupt prioritization


以上大概就是基本的exception mechanism,之後哪裡不足再去看spec囉~

0 意見:

張貼留言