exception.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT AND BSD-3-Clause
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. /*This file is prepared for Doxygen automatic documentation generation.*/
  29. /*! \file *********************************************************************
  30. *
  31. * \brief Exception and interrupt vectors.
  32. *
  33. * This file maps all events supported by an AVR32UC.
  34. *
  35. * - Compiler: GNU GCC for AVR32
  36. * - Supported devices: All AVR32UC devices with an INTC module can be used.
  37. * - AppNote:
  38. *
  39. * \author Atmel Corporation (Now Microchip):
  40. * https://www.microchip.com \n
  41. * Support and FAQ: https://www.microchip.com/support/
  42. *
  43. ******************************************************************************/
  44. /*
  45. * Copyright (c) 2007, Atmel Corporation All rights reserved.
  46. *
  47. * Redistribution and use in source and binary forms, with or without
  48. * modification, are permitted provided that the following conditions are met:
  49. *
  50. * 1. Redistributions of source code must retain the above copyright notice,
  51. * this list of conditions and the following disclaimer.
  52. *
  53. * 2. Redistributions in binary form must reproduce the above copyright notice,
  54. * this list of conditions and the following disclaimer in the documentation
  55. * and/or other materials provided with the distribution.
  56. *
  57. * 3. The name of ATMEL may not be used to endorse or promote products derived
  58. * from this software without specific prior written permission.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
  61. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  62. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
  63. * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
  64. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  66. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  67. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  68. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  69. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70. */
  71. #include <avr32/io.h>
  72. #include "intc.h"
  73. //! @{
  74. //! \verbatim
  75. .section .exception, "ax", @progbits
  76. // Start of Exception Vector Table.
  77. // EVBA must be aligned with a power of two strictly greater than the EVBA-
  78. // relative offset of the last vector.
  79. .balign 0x200
  80. // Export symbol.
  81. .global _evba
  82. .type _evba, @function
  83. _evba:
  84. .org 0x000
  85. // Unrecoverable Exception.
  86. _handle_Unrecoverable_Exception:
  87. rjmp $
  88. .org 0x004
  89. // TLB Multiple Hit: UNUSED IN AVR32UC.
  90. _handle_TLB_Multiple_Hit:
  91. rjmp $
  92. .org 0x008
  93. // Bus Error Data Fetch.
  94. _handle_Bus_Error_Data_Fetch:
  95. rjmp $
  96. .org 0x00C
  97. // Bus Error Instruction Fetch.
  98. _handle_Bus_Error_Instruction_Fetch:
  99. rjmp $
  100. .org 0x010
  101. // NMI.
  102. _handle_NMI:
  103. rjmp $
  104. .org 0x014
  105. // Instruction Address.
  106. _handle_Instruction_Address:
  107. rjmp $
  108. .org 0x018
  109. // ITLB Protection.
  110. _handle_ITLB_Protection:
  111. rjmp $
  112. .org 0x01C
  113. // Breakpoint.
  114. _handle_Breakpoint:
  115. rjmp $
  116. .org 0x020
  117. // Illegal Opcode.
  118. _handle_Illegal_Opcode:
  119. rjmp $
  120. .org 0x024
  121. // Unimplemented Instruction.
  122. _handle_Unimplemented_Instruction:
  123. rjmp $
  124. .org 0x028
  125. // Privilege Violation.
  126. _handle_Privilege_Violation:
  127. rjmp $
  128. .org 0x02C
  129. // Floating-Point: UNUSED IN AVR32UC.
  130. _handle_Floating_Point:
  131. rjmp $
  132. .org 0x030
  133. // Coprocessor Absent: UNUSED IN AVR32UC.
  134. _handle_Coprocessor_Absent:
  135. rjmp $
  136. .org 0x034
  137. // Data Address (Read).
  138. _handle_Data_Address_Read:
  139. rjmp $
  140. .org 0x038
  141. // Data Address (Write).
  142. _handle_Data_Address_Write:
  143. rjmp $
  144. .org 0x03C
  145. // DTLB Protection (Read).
  146. _handle_DTLB_Protection_Read:
  147. rjmp $
  148. .org 0x040
  149. // DTLB Protection (Write).
  150. _handle_DTLB_Protection_Write:
  151. rjmp $
  152. .org 0x044
  153. // DTLB Modified: UNUSED IN AVR32UC.
  154. _handle_DTLB_Modified:
  155. rjmp $
  156. .org 0x050
  157. // ITLB Miss: UNUSED IN AVR32UC.
  158. _handle_ITLB_Miss:
  159. rjmp $
  160. .org 0x060
  161. // DTLB Miss (Read): UNUSED IN AVR32UC.
  162. _handle_DTLB_Miss_Read:
  163. rjmp $
  164. .org 0x070
  165. // DTLB Miss (Write): UNUSED IN AVR32UC.
  166. _handle_DTLB_Miss_Write:
  167. rjmp $
  168. .org 0x100
  169. // Supervisor Call.
  170. _handle_Supervisor_Call:
  171. lda.w pc, SCALLYield
  172. // Interrupt support.
  173. // The interrupt controller must provide the offset address relative to EVBA.
  174. // Important note:
  175. // All interrupts call a C function named _get_interrupt_handler.
  176. // This function will read group and interrupt line number to then return in
  177. // R12 a pointer to a user-provided interrupt handler.
  178. .balign 4
  179. _int0:
  180. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  181. // CPU upon interrupt entry.
  182. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  183. mfsr r12, AVR32_SR
  184. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  185. cp.w r12, 0b110
  186. brlo _int0_normal
  187. lddsp r12, sp[0 * 4]
  188. stdsp sp[6 * 4], r12
  189. lddsp r12, sp[1 * 4]
  190. stdsp sp[7 * 4], r12
  191. lddsp r12, sp[3 * 4]
  192. sub sp, -6 * 4
  193. rete
  194. _int0_normal:
  195. #endif
  196. mov r12, 0 // Pass the int_lev parameter to the _get_interrupt_handler function.
  197. call _get_interrupt_handler
  198. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  199. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  200. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  201. _int1:
  202. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  203. // CPU upon interrupt entry.
  204. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  205. mfsr r12, AVR32_SR
  206. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  207. cp.w r12, 0b110
  208. brlo _int1_normal
  209. lddsp r12, sp[0 * 4]
  210. stdsp sp[6 * 4], r12
  211. lddsp r12, sp[1 * 4]
  212. stdsp sp[7 * 4], r12
  213. lddsp r12, sp[3 * 4]
  214. sub sp, -6 * 4
  215. rete
  216. _int1_normal:
  217. #endif
  218. mov r12, 1 // Pass the int_lev 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. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  222. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  223. _int2:
  224. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  225. // CPU upon interrupt entry.
  226. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  227. mfsr r12, AVR32_SR
  228. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  229. cp.w r12, 0b110
  230. brlo _int2_normal
  231. lddsp r12, sp[0 * 4]
  232. stdsp sp[6 * 4], r12
  233. lddsp r12, sp[1 * 4]
  234. stdsp sp[7 * 4], r12
  235. lddsp r12, sp[3 * 4]
  236. sub sp, -6 * 4
  237. rete
  238. _int2_normal:
  239. #endif
  240. mov r12, 2 // Pass the int_lev parameter to the _get_interrupt_handler function.
  241. call _get_interrupt_handler
  242. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  243. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  244. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  245. _int3:
  246. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  247. // CPU upon interrupt entry.
  248. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  249. mfsr r12, AVR32_SR
  250. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  251. cp.w r12, 0b110
  252. brlo _int3_normal
  253. lddsp r12, sp[0 * 4]
  254. stdsp sp[6 * 4], r12
  255. lddsp r12, sp[1 * 4]
  256. stdsp sp[7 * 4], r12
  257. lddsp r12, sp[3 * 4]
  258. sub sp, -6 * 4
  259. rete
  260. _int3_normal:
  261. #endif
  262. mov r12, 3 // Pass the int_lev parameter to the _get_interrupt_handler function.
  263. call _get_interrupt_handler
  264. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  265. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  266. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  267. // Constant data area.
  268. .balign 4
  269. // Values to store in the interrupt priority registers for the various interrupt priority levels.
  270. // The interrupt priority registers contain the interrupt priority level and
  271. // the EVBA-relative interrupt vector offset.
  272. .global ipr_val
  273. .type ipr_val, @object
  274. ipr_val:
  275. .word (INT0 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int0 - _evba),\
  276. (INT1 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int1 - _evba),\
  277. (INT2 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int2 - _evba),\
  278. (INT3 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int3 - _evba)
  279. //! \endverbatim
  280. //! @}