本文將為大家分析關于ARM中斷宏定義的相關介紹。 MACRO
本文引用地址:http://m.butianyuan.cn/article/201611/319275.htm $HandlerLabel HANDLER $HandleLabel
$HandlerLabel
sub sp,sp,#4 ;decrement sp(to store jump address) 存貯PC跳轉(zhuǎn)地址
stmfd sp!,{r0} ;PUSH the work register to stack(lr does not push because it return to original address)
ldr r0,=$HandleLabel ;load the address of HandleXXX to r0
ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX
str r0,[sp,#4] ;store the contents(ISR) of HandleXXX to stack
ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)
MEND
上面是在匯編語言2440vectors.s中的一段完整的宏定義
MACRO相當于c中的#define
而$HandlerLabel 和 $HandleLabel是兩個參數(shù),大家注意,第一個參數(shù)和第二個參數(shù)是不一樣的,中間少了個r
而第一個參數(shù)在本宏中是一個標號,而第二個函數(shù)是一個入口地址
以下有定義:
HandlerFIQ HANDLER HandleFIQ
HandlerIRQ HANDLER HandleIRQ
HandlerUndef HANDLER HandleUndef
HandlerSWI HANDLER HandleSWI
HandlerDabort HANDLER HandleDabort
HandlerPabort HANDLER HandlePabort
拿HandlerSWI HANDLER HandleSWI說明:把它用宏給替換下來以后是:
$HandlerSWI
1:sub sp,sp,#4 ;decrement sp(to store jump address) 存貯PC跳轉(zhuǎn)地址
2:stmfd sp!,{r0} ;PUSH the work register to stack(lr does not push because it return to original address)
3:ldr r0,=$HandleSWI ;load the address of HandleXXX to r0
4:ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX
5:str r0,[sp,#4] ;store the contents(ISR) of HandleXXX to stack
6:ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)
達內(nèi)培訓小提問:
這段宏定義的作用是什么呢?是安裝SWI中斷,如何安裝的呢?
sub sp,sp,#4 是把SP的地址減4字節(jié),而這個地方需要存放跳轉(zhuǎn)地址也就是第5行的HandleSWI指向的內(nèi)容(ISR)
接下來是壓棧所需要的寄存器r0,因為接下來需要使用r0所以先壓棧r0,這也是為什么剛剛先把SP加四字節(jié)的原因,第6句話就是跳轉(zhuǎn)到剛剛第5句所壓棧的地址處,也就是HandleSWI指向的內(nèi)容(ISR)處
VectorsAddr
LDR PC, Reset_Addr
LDR PC, Undefined_Addr
LDR PC, SWI_Addr
LDR PC, Prefetch_Addr
LDR PC, Abort_Addr
NOP ; Reserved vector
LDR PC, IRQ_Addr
LDR PC, FIQ_Addr
EXPORT VectorsAddr
Reset_Addr DCD ResetHandler ;第一次地址轉(zhuǎn)換
Undefined_Addr DCD HandlerUndef
SWI_Addr DCD HandlerSWI
Prefetch_Addr DCD HandlerPabort
Abort_Addr DCD HandlerDabort
IRQ_Addr DCD HandlerIRQ
FIQ_Addr DCD HandlerFIQ
評論