本文将为我们剖析关于ARM中止宏界说的相关介绍。
MACRO
$HandlerLabel HANDLER $HandleLabel
$HandlerLabel
sub sp,sp,#4 ;decrement sp(to store jump address) 存贮PC跳转地址
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是两个参数,我们留意,第一个参数和第二个参数是不一样的,中心少了个r
而第一个参数在本宏中是一个标号,而第二个函数是一个进口地址
以下有界说:
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跳转地址
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)
达内培训小发问:
这段宏界说的效果是什么呢?是装置SWI中止,怎么装置的呢?
sub sp,sp,#4 是把SP的地址减4字节,而这个当地需求寄存跳转地址也便是第5行的HandleSWI指向的内容(ISR)
接下来是压栈所需求的寄存器r0,由于接下来需求运用r0所以先压栈r0,这也是为什么刚刚先把SP加四字节的原因,第6句话便是跳转到刚刚第5句所压栈的地址处,也便是HandleSWI指向的内容(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 ;第一次地址转化
Undefined_Addr DCD HandlerUndef
SWI_Addr DCD HandlerSWI
Prefetch_Addr DCD HandlerPabort
Abort_Addr DCD HandlerDabort
IRQ_Addr DCD HandlerIRQ
FIQ_Addr DCD HandlerFIQ
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/fpga/262926.html