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