exception_gcc.S 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* This file is part of the ATMEL AVR32-UC3-SoftwareFramework-1.6.0 Release */
  2. /*This file is prepared for Doxygen automatic documentation generation.*/
  3. /*! \file *********************************************************************
  4. *
  5. * \brief Exception and interrupt vectors.
  6. *
  7. * This file maps all events supported by an AVR32.
  8. *
  9. * - Compiler: GNU GCC for AVR32
  10. * - Supported devices: All AVR32 devices with an INTC module can be used.
  11. * - AppNote:
  12. *
  13. * \author Atmel Corporation: http://www.atmel.com \n
  14. * Support and FAQ: http://support.atmel.no/
  15. *
  16. ******************************************************************************/
  17. /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions are met:
  21. *
  22. * 1. Redistributions of source code must retain the above copyright notice, this
  23. * list of conditions and the following disclaimer.
  24. *
  25. * 2. Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials provided with the distribution.
  28. *
  29. * 3. The name of Atmel may not be used to endorse or promote products derived
  30. * from this software without specific prior written permission.
  31. *
  32. * 4. This software may only be redistributed and used in connection with an Atmel
  33. * AVR product.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  38. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  39. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  40. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  42. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  45. *
  46. */
  47. #if !__AVR32_UC__ && !__AVR32_AP__
  48. #error Implementation of the AVR32 architecture not supported by the INTC driver.
  49. #endif
  50. #include <avr32/io.h>
  51. //! @{
  52. //! \verbatim
  53. .section .exception, "ax", @progbits
  54. // Start of Exception Vector Table.
  55. // EVBA must be aligned with a power of two strictly greater than the EVBA-
  56. // relative offset of the last vector.
  57. .balign 0x200
  58. // Export symbol.
  59. .global _evba
  60. .type _evba, @function
  61. _evba:
  62. .org 0x000
  63. // Unrecoverable Exception.
  64. _handle_Unrecoverable_Exception:
  65. rjmp $
  66. .org 0x004
  67. // TLB Multiple Hit.
  68. _handle_TLB_Multiple_Hit:
  69. rjmp $
  70. .org 0x008
  71. // Bus Error Data Fetch.
  72. _handle_Bus_Error_Data_Fetch:
  73. rjmp $
  74. .org 0x00C
  75. // Bus Error Instruction Fetch.
  76. _handle_Bus_Error_Instruction_Fetch:
  77. rjmp $
  78. .org 0x010
  79. // NMI.
  80. _handle_NMI:
  81. rjmp $
  82. .org 0x014
  83. // Instruction Address.
  84. _handle_Instruction_Address:
  85. rjmp $
  86. .org 0x018
  87. // ITLB Protection.
  88. _handle_ITLB_Protection:
  89. rjmp $
  90. .org 0x01C
  91. // Breakpoint.
  92. _handle_Breakpoint:
  93. rjmp $
  94. .org 0x020
  95. // Illegal Opcode.
  96. _handle_Illegal_Opcode:
  97. rjmp $
  98. .org 0x024
  99. // Unimplemented Instruction.
  100. _handle_Unimplemented_Instruction:
  101. rjmp $
  102. .org 0x028
  103. // Privilege Violation.
  104. _handle_Privilege_Violation:
  105. rjmp $
  106. .org 0x02C
  107. // Floating-Point: UNUSED IN AVR32UC and AVR32AP.
  108. _handle_Floating_Point:
  109. rjmp $
  110. .org 0x030
  111. // Coprocessor Absent: UNUSED IN AVR32UC.
  112. _handle_Coprocessor_Absent:
  113. rjmp $
  114. .org 0x034
  115. // Data Address (Read).
  116. _handle_Data_Address_Read:
  117. rjmp $
  118. .org 0x038
  119. // Data Address (Write).
  120. _handle_Data_Address_Write:
  121. rjmp $
  122. .org 0x03C
  123. // DTLB Protection (Read).
  124. _handle_DTLB_Protection_Read:
  125. rjmp $
  126. .org 0x040
  127. // DTLB Protection (Write).
  128. _handle_DTLB_Protection_Write:
  129. rjmp $
  130. .org 0x044
  131. // DTLB Modified: UNUSED IN AVR32UC.
  132. _handle_DTLB_Modified:
  133. rjmp $
  134. .org 0x050
  135. // ITLB Miss.
  136. _handle_ITLB_Miss:
  137. rjmp $
  138. .org 0x060
  139. // DTLB Miss (Read).
  140. _handle_DTLB_Miss_Read:
  141. rjmp $
  142. .org 0x070
  143. // DTLB Miss (Write).
  144. _handle_DTLB_Miss_Write:
  145. rjmp $
  146. .org 0x100
  147. // Supervisor Call.
  148. _handle_Supervisor_Call:
  149. rjmp $
  150. // Interrupt support.
  151. // The interrupt controller must provide the offset address relative to EVBA.
  152. // Important note:
  153. // All interrupts call a C function named _get_interrupt_handler.
  154. // This function will read group and interrupt line number to then return in
  155. // R12 a pointer to a user-provided interrupt handler.
  156. .balign 4
  157. _int0:
  158. mov r12, 0 // Pass the int_level parameter to the _get_interrupt_handler function.
  159. call _get_interrupt_handler
  160. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  161. breq _spint0 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  162. call rt_interrupt_enter
  163. icall r12
  164. call rt_interrupt_leave
  165. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  166. lda.w r12, rt_interrupt_nest /* Is nested interrupt? */
  167. ld.w r11, r12[0]
  168. cp.w r11, 0
  169. brne _spint0
  170. lda.w r12, rt_thread_switch_interrupt_flag /* Is thread switch required? */
  171. ld.w r11, r12[0]
  172. cp.w r11, 1
  173. breq rt_hw_context_switch_interrupt_do
  174. _spint0:
  175. csrf AVR32_SR_GM_OFFSET /* Enable global interrupt */
  176. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  177. _int1:
  178. mov r12, 1 // Pass the int_level parameter to the _get_interrupt_handler function.
  179. call _get_interrupt_handler
  180. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  181. breq _spint1 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  182. call rt_interrupt_enter
  183. icall r12
  184. call rt_interrupt_leave
  185. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  186. lda.w r12, rt_interrupt_nest /* Is nested interrupt? */
  187. ld.w r11, r12[0]
  188. cp.w r11, 0
  189. brne _spint1
  190. lda.w r12, rt_thread_switch_interrupt_flag /* Is thread switch required? */
  191. ld.w r11, r12[0]
  192. cp.w r11, 1
  193. breq rt_hw_context_switch_interrupt_do
  194. _spint1:
  195. csrf AVR32_SR_GM_OFFSET /* Enable global interrupt */
  196. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  197. _int2:
  198. mov r12, 2 // Pass the int_level parameter to the _get_interrupt_handler function.
  199. call _get_interrupt_handler
  200. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  201. breq _spint2 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  202. call rt_interrupt_enter
  203. icall r12
  204. call rt_interrupt_leave
  205. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  206. lda.w r12, rt_interrupt_nest /* Is nested interrupt? */
  207. ld.w r11, r12[0]
  208. cp.w r11, 0
  209. brne _spint2
  210. lda.w r12, rt_thread_switch_interrupt_flag /* Is thread switch required? */
  211. ld.w r11, r12[0]
  212. cp.w r11, 1
  213. breq rt_hw_context_switch_interrupt_do
  214. _spint2:
  215. csrf AVR32_SR_GM_OFFSET /* Enable global interrupt */
  216. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  217. _int3:
  218. mov r12, 3 // Pass the int_level parameter to the _get_interrupt_handler function.
  219. call _get_interrupt_handler
  220. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  221. breq _spint3 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  222. call rt_interrupt_enter
  223. icall r12
  224. call rt_interrupt_leave
  225. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  226. lda.w r12, rt_interrupt_nest /* Is nested interrupt? */
  227. ld.w r11, r12[0]
  228. cp.w r11, 0
  229. brne _spint3
  230. lda.w r12, rt_thread_switch_interrupt_flag /* Is thread switch required? */
  231. ld.w r11, r12[0]
  232. cp.w r11, 1
  233. breq rt_hw_context_switch_interrupt_do
  234. _spint3:
  235. csrf AVR32_SR_GM_OFFSET /* Enable global interrupt */
  236. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  237. rt_hw_context_switch_interrupt_do:
  238. mov r11, 0
  239. st.w r12[0], r11 /* Clear rt_thread_switch_interrupt_flag */
  240. stm --sp, r0-r7 /* Push R0-R7 */
  241. lda.w r12, rt_interrupt_from_thread /* Get old thread SP */
  242. ld.w r12, r12[0]
  243. lda.w r11, rt_interrupt_to_thread /* Get new thread SP */
  244. ld.w r11, r11[0]
  245. st.w r12[0], sp /* Store old thread SP */
  246. ld.w sp, r11[0] /* Load new thread SP */
  247. ldm sp++, r0-r7 /* Pop R0-R7 (new thread) */
  248. rete /* RETE pops R8-R12, LR, PC, SR automatically */
  249. // Constant data area.
  250. .balign 4
  251. // Values to store in the interrupt priority registers for the various interrupt priority levels.
  252. // The interrupt priority registers contain the interrupt priority level and
  253. // the EVBA-relative interrupt vector offset.
  254. .global ipr_val
  255. .type ipr_val, @object
  256. ipr_val:
  257. .word (AVR32_INTC_INT0 << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (_int0 - _evba),\
  258. (AVR32_INTC_INT1 << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (_int1 - _evba),\
  259. (AVR32_INTC_INT2 << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (_int2 - _evba),\
  260. (AVR32_INTC_INT3 << AVR32_INTC_IPR_INTLEVEL_OFFSET) | (_int3 - _evba)
  261. //! \endverbatim
  262. //! @}