微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > GNU ARM汇编--(五)中断汇编之嵌套中断处理

GNU ARM汇编--(五)中断汇编之嵌套中断处理

时间:11-26 来源:互联网 点击:
在上篇《GNU ARM汇编--(四)中断汇编之非嵌套中断处理》中分析了最简单的中断处理的写法,再看TQ2440启动代码中的中断向量表的写法就一目了然了.今天抽时间对嵌套中断处理的学习做下整理.

嵌套中断处理的核心代码如下:

[cpp]view plaincopy

  1. ;/*
  2. ;*____________________________________________________________________
  3. ;*
  4. ;*Copyright(c)2004,AndrewN.Sloss,ChrisWrightandDominicSymes
  5. ;*Allrightsreserved.
  6. ;*____________________________________________________________________
  7. ;*
  8. ;*NON-COMMERCIALUSELicense
  9. ;*
  10. ;*Redistributionanduseinsourceandbinaryforms,withorwithout
  11. ;*modification,arepermittedprovidedthatthefollowingconditions
  12. ;*aremet:
  13. ;*
  14. ;*1.ForNON-COMMERCIALUSEonly.
  15. ;*
  16. ;*2.Redistributionsofsourcecodemustretaintheabovecopyright
  17. ;*notice,thislistofconditionsandthefollowingdisclaimer.
  18. ;*
  19. ;*3.Redistributionsinbinaryformmustreproducetheabove
  20. ;*copyrightnotice,thislistofconditionsandthefollowing
  21. ;*disclaimerinthedocumentationand/orothermaterialsprovided
  22. ;*withthedistribution.
  23. ;*
  24. ;*4.Alladvertisingmaterialsmentioningfeaturesoruseofthis
  25. ;*softwaremustdisplaythefollowingacknowledgement:
  26. ;*
  27. ;*ThisproductincludessoftwaredevelopedbyAndrewN.Sloss,
  28. ;*ChrisWrightandDominicSymes.
  29. ;*
  30. ;*THISSOFTWAREISPROVIDEDBYTHECONTRIBUTORS``ASISANDANY
  31. ;*EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE
  32. ;*IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULAR
  33. ;*PURPOSEAREDISCLAIMED.INNOEVENTSHALLTHECONTRIBUTORSBE
  34. ;*LIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,
  35. ;*ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,
  36. ;*PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,
  37. ;*ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANY
  38. ;*THEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
  39. ;*TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUT
  40. ;*OFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITY
  41. ;*OFSUCHDAMAGE.
  42. ;*
  43. ;*Ifyouhavequestionsaboutthislicenseorwouldlikeadifferent
  44. ;*licensepleaseemail:
  45. ;*
  46. ;*andrew@sloss.net
  47. ;*
  48. ;*
  49. ;*/
  50. ;/***********************************************************************
  51. ;*
  52. ;*Module:nih9_9.s
  53. ;*Descriptions:NestedInterruptHandler
  54. ;*Example:9.9
  55. ;*OS:generic
  56. ;*Platform:generic
  57. ;*History:
  58. ;*
  59. ;*31thDecember2003
  60. ;*-addedheader
  61. ;*
  62. ;***********************************************************************/
  63. EXPORTnestedInterruptHandler
  64. MaskmdEQU0x1f;processormodemask
  65. SVC32mdEQU0x13;SVCmode
  66. I_BitEQU0x80;IRQbit
  67. FRAME_R0EQU0x00
  68. FRAME_R1EQUFRAME_R0+4
  69. FRAME_R2EQUFRAME_R1+4
  70. FRAME_R3EQUFRAME_R2+4
  71. FRAME_R4EQUFRAME_R3+4
  72. FRAME_R5EQUFRAME_R4+4
  73. FRAME_R6EQUFRAME_R5+4
  74. FRAME_R7EQUFRAME_R6+4
  75. FRAME_R8EQUFRAME_R7+4
  76. FRAME_R9EQUFRAME_R8+4
  77. FRAME_R10EQUFRAME_R9+4
  78. FRAME_R11EQUFRAME_R10+4
  79. FRAME_R12EQUFRAME_R11+4
  80. FRAME_PSREQUFRAME_R12+4
  81. FRAME_LREQUFRAME_PSR+4
  82. FRAME_PCEQUFRAME_LR+4
  83. FRAME_SIZEEQUFRAME_PC+4
  84. AREAnih9_9,CODE,readonly
  85. nestedInterruptHandler;instructionstate:comment
  86. SUBr14,r14,#4;2:
  87. STMDBr13!,{r0-r3,r12,r14};2:savecontext
  88. ;
  89. BLread_RescheduleFlag;3:moreprocessing
  90. CMPr0,#0;3:ifprocessing?
  91. LDMNEIAr13!,{r0-r3,r12,pc}^;4:thenreturn
  92. MRSr2,SPSR;5:copySPSR_irq
  93. MOVr0,r13;5:copyr13_irq
  94. ADDr13,r13,#6*4;5:resetstack
  95. MRSr1,CPSR;6:copyCPSR
  96. BICr1,r1,#Maskmd;6:
  97. ORRr1,r1,#SVC32md;6:
  98. MSRCPSR_c,r1;6:changeSVCmode
  99. SUBr13,r13,#FRAME_SIZE-FRAME_R4;7:makestackspace
  100. STMIAr13,{r4-r11};7:saver4-r11
  101. LDMIAr0,{r4-r9};7:r4-r9IRQstack
  102. BICr1,r1,#I_Bit;8:
  103. MSRCPSR_c,r1;8:enableint
  104. STMDBr13!,{r4-r7};9:saver4-r7SVC
  105. STRr2,[r13,#FRAME_PSR];9:savePSR
  106. STRr8,[r13,#FRAME_R12];9:saver12
  107. STRr9,[r13,#FRAME_PC];9:savepc
  108. STRr14,[r13,#FRAME_LR];9:savelr
  109. ;
  110. LDMIAr13!,{r0-r12,r14};11:restorecontext
  111. MSRSPSR_cxsf,r14;11:restoreSPSR
  112. LDMIAr13!,{r14,pc}^;11:return
  113. read_RescheduleFlag
  114. ;
  115. MOVr0,#0;moreprocessing
  116. MOVpc,r14;return
  117. END



代码的关键就是在中断后切换到SVC模式下,利用svc mode的stack来实现中断嵌套过程的备份以及恢复操作.从

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top