exception.s82 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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: IAR EWAVR32
  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. // Start of Exception Vector Table.
  76. // EVBA must be aligned with a power of two strictly greater than the EVBA-
  77. // relative offset of the last vector.
  78. COMMON EVTAB:CODE:ROOT(9)
  79. // Force EVBA initialization.
  80. EXTERN ??init_EVBA
  81. REQUIRE ??init_EVBA
  82. // Export symbol.
  83. PUBLIC ??EVBA
  84. PUBLIC _evba
  85. ??EVBA:
  86. _evba:
  87. ORG 0x000
  88. // Unrecoverable Exception.
  89. _handle_Unrecoverable_Exception:
  90. rjmp $
  91. ORG 0x004
  92. // TLB Multiple Hit: UNUSED IN AVR32UC.
  93. _handle_TLB_Multiple_Hit:
  94. rjmp $
  95. ORG 0x008
  96. // Bus Error Data Fetch.
  97. _handle_Bus_Error_Data_Fetch:
  98. rjmp $
  99. ORG 0x00C
  100. // Bus Error Instruction Fetch.
  101. _handle_Bus_Error_Instruction_Fetch:
  102. rjmp $
  103. ORG 0x010
  104. // NMI.
  105. _handle_NMI:
  106. rjmp $
  107. ORG 0x014
  108. // Instruction Address.
  109. _handle_Instruction_Address:
  110. rjmp $
  111. ORG 0x018
  112. // ITLB Protection.
  113. _handle_ITLB_Protection:
  114. rjmp $
  115. ORG 0x01C
  116. // Breakpoint.
  117. _handle_Breakpoint:
  118. rjmp $
  119. ORG 0x020
  120. // Illegal Opcode.
  121. _handle_Illegal_Opcode:
  122. rjmp $
  123. ORG 0x024
  124. // Unimplemented Instruction.
  125. _handle_Unimplemented_Instruction:
  126. rjmp $
  127. ORG 0x028
  128. // Privilege Violation.
  129. _handle_Privilege_Violation:
  130. rjmp $
  131. ORG 0x02C
  132. // Floating-Point: UNUSED IN AVR32UC.
  133. _handle_Floating_Point:
  134. rjmp $
  135. ORG 0x030
  136. // Coprocessor Absent: UNUSED IN AVR32UC.
  137. _handle_Coprocessor_Absent:
  138. rjmp $
  139. ORG 0x034
  140. // Data Address (Read).
  141. _handle_Data_Address_Read:
  142. rjmp $
  143. ORG 0x038
  144. // Data Address (Write).
  145. _handle_Data_Address_Write:
  146. rjmp $
  147. ORG 0x03C
  148. // DTLB Protection (Read).
  149. _handle_DTLB_Protection_Read:
  150. rjmp $
  151. ORG 0x040
  152. // DTLB Protection (Write).
  153. _handle_DTLB_Protection_Write:
  154. rjmp $
  155. ORG 0x044
  156. // DTLB Modified: UNUSED IN AVR32UC.
  157. _handle_DTLB_Modified:
  158. rjmp $
  159. ORG 0x050
  160. // ITLB Miss: UNUSED IN AVR32UC.
  161. _handle_ITLB_Miss:
  162. rjmp $
  163. ORG 0x060
  164. // DTLB Miss (Read): UNUSED IN AVR32UC.
  165. _handle_DTLB_Miss_Read:
  166. rjmp $
  167. ORG 0x070
  168. // DTLB Miss (Write): UNUSED IN AVR32UC.
  169. _handle_DTLB_Miss_Write:
  170. rjmp $
  171. ORG 0x100
  172. // Supervisor Call.
  173. _handle_Supervisor_Call:
  174. lddpc pc, __SCALLYield
  175. // Interrupt support.
  176. // The interrupt controller must provide the offset address relative to EVBA.
  177. // Important note:
  178. // All interrupts call a C function named _get_interrupt_handler.
  179. // This function will read group and interrupt line number to then return in
  180. // R12 a pointer to a user-provided interrupt handler.
  181. ALIGN 2
  182. _int0:
  183. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  184. // CPU upon interrupt entry.
  185. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  186. mfsr r12, AVR32_SR
  187. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  188. cp.w r12, 110b
  189. brlo _int0_normal
  190. lddsp r12, sp[0 * 4]
  191. stdsp sp[6 * 4], r12
  192. lddsp r12, sp[1 * 4]
  193. stdsp sp[7 * 4], r12
  194. lddsp r12, sp[3 * 4]
  195. sub sp, -6 * 4
  196. rete
  197. _int0_normal:
  198. #endif
  199. mov r12, 0 // Pass the int_lev parameter to the _get_interrupt_handler function.
  200. mcall __get_interrupt_handler
  201. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  202. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  203. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  204. _int1:
  205. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  206. // CPU upon interrupt entry.
  207. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  208. mfsr r12, AVR32_SR
  209. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  210. cp.w r12, 110b
  211. brlo _int1_normal
  212. lddsp r12, sp[0 * 4]
  213. stdsp sp[6 * 4], r12
  214. lddsp r12, sp[1 * 4]
  215. stdsp sp[7 * 4], r12
  216. lddsp r12, sp[3 * 4]
  217. sub sp, -6 * 4
  218. rete
  219. _int1_normal:
  220. #endif
  221. mov r12, 1 // Pass the int_lev parameter to the _get_interrupt_handler function.
  222. mcall __get_interrupt_handler
  223. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  224. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  225. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  226. _int2:
  227. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  228. // CPU upon interrupt entry.
  229. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  230. mfsr r12, AVR32_SR
  231. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  232. cp.w r12, 110b
  233. brlo _int2_normal
  234. lddsp r12, sp[0 * 4]
  235. stdsp sp[6 * 4], r12
  236. lddsp r12, sp[1 * 4]
  237. stdsp sp[7 * 4], r12
  238. lddsp r12, sp[3 * 4]
  239. sub sp, -6 * 4
  240. rete
  241. _int2_normal:
  242. #endif
  243. mov r12, 2 // Pass the int_lev parameter to the _get_interrupt_handler function.
  244. mcall __get_interrupt_handler
  245. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  246. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  247. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  248. _int3:
  249. // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
  250. // CPU upon interrupt entry.
  251. #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
  252. mfsr r12, AVR32_SR
  253. bfextu r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
  254. cp.w r12, 110b
  255. brlo _int3_normal
  256. lddsp r12, sp[0 * 4]
  257. stdsp sp[6 * 4], r12
  258. lddsp r12, sp[1 * 4]
  259. stdsp sp[7 * 4], r12
  260. lddsp r12, sp[3 * 4]
  261. sub sp, -6 * 4
  262. rete
  263. _int3_normal:
  264. #endif
  265. mov r12, 3 // Pass the int_lev parameter to the _get_interrupt_handler function.
  266. mcall __get_interrupt_handler
  267. cp.w r12, 0 // Get the pointer to the interrupt handler returned by the function.
  268. movne pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
  269. rete // If this was a spurious interrupt (R12 == NULL), return from event handler.
  270. // Constant data area.
  271. ALIGN 2
  272. // Import symbols.
  273. EXTERN SCALLYield
  274. EXTERN _get_interrupt_handler
  275. __SCALLYield:
  276. DC32 SCALLYield
  277. __get_interrupt_handler:
  278. DC32 _get_interrupt_handler
  279. // Values to store in the interrupt priority registers for the various interrupt priority levels.
  280. // The interrupt priority registers contain the interrupt priority level and
  281. // the EVBA-relative interrupt vector offset.
  282. PUBLIC ipr_val
  283. ipr_val:
  284. DC32 (INT0 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int0 - _evba),\
  285. (INT1 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int1 - _evba),\
  286. (INT2 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int2 - _evba),\
  287. (INT3 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int3 - _evba)
  288. END
  289. //! \endverbatim
  290. //! @}