GNU ARM汇编--(五)中断汇编之嵌套中断处理
时间:11-26
来源:互联网
点击:
在上篇《GNU ARM汇编--(四)中断汇编之非嵌套中断处理》中分析了最简单的中断处理的写法,再看TQ2440启动代码中的中断向量表的写法就一目了然了.今天抽时间对嵌套中断处理的学习做下整理.
嵌套中断处理的核心代码如下:
[cpp]view plaincopy
- ;/*
- ;*____________________________________________________________________
- ;*
- ;*Copyright(c)2004,AndrewN.Sloss,ChrisWrightandDominicSymes
- ;*Allrightsreserved.
- ;*____________________________________________________________________
- ;*
- ;*NON-COMMERCIALUSELicense
- ;*
- ;*Redistributionanduseinsourceandbinaryforms,withorwithout
- ;*modification,arepermittedprovidedthatthefollowingconditions
- ;*aremet:
- ;*
- ;*1.ForNON-COMMERCIALUSEonly.
- ;*
- ;*2.Redistributionsofsourcecodemustretaintheabovecopyright
- ;*notice,thislistofconditionsandthefollowingdisclaimer.
- ;*
- ;*3.Redistributionsinbinaryformmustreproducetheabove
- ;*copyrightnotice,thislistofconditionsandthefollowing
- ;*disclaimerinthedocumentationand/orothermaterialsprovided
- ;*withthedistribution.
- ;*
- ;*4.Alladvertisingmaterialsmentioningfeaturesoruseofthis
- ;*softwaremustdisplaythefollowingacknowledgement:
- ;*
- ;*ThisproductincludessoftwaredevelopedbyAndrewN.Sloss,
- ;*ChrisWrightandDominicSymes.
- ;*
- ;*THISSOFTWAREISPROVIDEDBYTHECONTRIBUTORS``ASISANDANY
- ;*EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE
- ;*IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULAR
- ;*PURPOSEAREDISCLAIMED.INNOEVENTSHALLTHECONTRIBUTORSBE
- ;*LIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,
- ;*ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,
- ;*PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,
- ;*ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANY
- ;*THEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
- ;*TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUT
- ;*OFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITY
- ;*OFSUCHDAMAGE.
- ;*
- ;*Ifyouhavequestionsaboutthislicenseorwouldlikeadifferent
- ;*licensepleaseemail:
- ;*
- ;*andrew@sloss.net
- ;*
- ;*
- ;*/
- ;/***********************************************************************
- ;*
- ;*Module:nih9_9.s
- ;*Descriptions:NestedInterruptHandler
- ;*Example:9.9
- ;*OS:generic
- ;*Platform:generic
- ;*History:
- ;*
- ;*31thDecember2003
- ;*-addedheader
- ;*
- ;***********************************************************************/
- EXPORTnestedInterruptHandler
- MaskmdEQU0x1f;processormodemask
- SVC32mdEQU0x13;SVCmode
- I_BitEQU0x80;IRQbit
- FRAME_R0EQU0x00
- FRAME_R1EQUFRAME_R0+4
- FRAME_R2EQUFRAME_R1+4
- FRAME_R3EQUFRAME_R2+4
- FRAME_R4EQUFRAME_R3+4
- FRAME_R5EQUFRAME_R4+4
- FRAME_R6EQUFRAME_R5+4
- FRAME_R7EQUFRAME_R6+4
- FRAME_R8EQUFRAME_R7+4
- FRAME_R9EQUFRAME_R8+4
- FRAME_R10EQUFRAME_R9+4
- FRAME_R11EQUFRAME_R10+4
- FRAME_R12EQUFRAME_R11+4
- FRAME_PSREQUFRAME_R12+4
- FRAME_LREQUFRAME_PSR+4
- FRAME_PCEQUFRAME_LR+4
- FRAME_SIZEEQUFRAME_PC+4
- AREAnih9_9,CODE,readonly
- nestedInterruptHandler;instructionstate:comment
- SUBr14,r14,#4;2:
- STMDBr13!,{r0-r3,r12,r14};2:savecontext
- ;
- BLread_RescheduleFlag;3:moreprocessing
- CMPr0,#0;3:ifprocessing?
- LDMNEIAr13!,{r0-r3,r12,pc}^;4:thenreturn
- MRSr2,SPSR;5:copySPSR_irq
- MOVr0,r13;5:copyr13_irq
- ADDr13,r13,#6*4;5:resetstack
- MRSr1,CPSR;6:copyCPSR
- BICr1,r1,#Maskmd;6:
- ORRr1,r1,#SVC32md;6:
- MSRCPSR_c,r1;6:changeSVCmode
- SUBr13,r13,#FRAME_SIZE-FRAME_R4;7:makestackspace
- STMIAr13,{r4-r11};7:saver4-r11
- LDMIAr0,{r4-r9};7:r4-r9IRQstack
- BICr1,r1,#I_Bit;8:
- MSRCPSR_c,r1;8:enableint
- STMDBr13!,{r4-r7};9:saver4-r7SVC
- STRr2,[r13,#FRAME_PSR];9:savePSR
- STRr8,[r13,#FRAME_R12];9:saver12
- STRr9,[r13,#FRAME_PC];9:savepc
- STRr14,[r13,#FRAME_LR];9:savelr
- ;
- LDMIAr13!,{r0-r12,r14};11:restorecontext
- MSRSPSR_cxsf,r14;11:restoreSPSR
- LDMIAr13!,{r14,pc}^;11:return
- read_RescheduleFlag
- ;
- MOVr0,#0;moreprocessing
- MOVpc,r14;return
- END
代码的关键就是在中断后切换到SVC模式下,利用svc mode的stack来实现中断嵌套过程的备份以及恢复操作.从
ARM汇编中断汇编中断处 相关文章:
- GNU ARM汇编--(四)中断汇编之非嵌套中断处理(11-26)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)