]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/AVR32_UC3/exception.S
Add AVR32 port and demo files.
[freertos] / Source / portable / GCC / AVR32_UC3 / exception.S
1 /******************************************************************************
2  * Exception and interrupt vectors.
3  *
4  * This file has been built from the Newlib exception.S. It maps all events
5  * supported by a UC3.
6  *
7  * - Compiler:           GNU GCC for AVR32
8  * - Supported devices:  All AVR32A devices with an INTC module can be used.
9  * - AppNote:
10  *
11  * - author              Atmel Corporation: http://www.atmel.com \n
12  *                       Support email: avr32@atmel.com
13  *
14  ******************************************************************************/
15
16 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright notice,
22  * this list of conditions and the following disclaimer.
23  *
24  * 2. Redistributions in binary form must reproduce the above copyright notice,
25  * this list of conditions and the following disclaimer in the documentation
26  * and/or other materials provided with the distribution.
27  *
28  * 3. The name of ATMEL may not be used to endorse or promote products derived
29  * from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
34  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42
43
44 #include <avr32/io.h>
45 #include "intc.h"
46
47
48   .section  .exception, "ax"
49
50
51 // Start of Exception Vector Table.
52
53   // EVBA must be aligned with a power of two strictly greater than the EVBA-
54   // relative offset of the last vector.
55   .balign 0x200
56
57   // Export symbol.
58   .global _evba
59 _evba:
60
61         .org  0x000
62         // Unrecoverable Exception.
63 _handle_Unrecoverable_Exception:
64         rjmp $
65
66         .org  0x004
67         // TLB Multiple Hit: UNUSED IN AVR32A.
68 _handle_TLB_Multiple_Hit:
69         rjmp $
70
71         .org  0x008
72         // Bus Error Data Fetch.
73 _handle_Bus_Error_Data_Fetch:
74         rjmp $
75
76         .org  0x00C
77          // Bus Error Instruction Fetch.
78 _handle_Bus_Error_Instruction_Fetch:
79         rjmp $
80
81         .org  0x010
82         // NMI.
83 _handle_NMI:
84         rjmp $
85
86         .org  0x014
87         // Instruction Address.
88 _handle_Instruction_Address:
89         rjmp $
90
91         .org  0x018
92         // ITLB Protection.
93 _handle_ITLB_Protection:
94         rjmp $
95
96         .org  0x01C
97         // Breakpoint.
98 _handle_Breakpoint:
99         rjmp $
100
101         .org  0x020
102         // Illegal Opcode.
103 _handle_Illegal_Opcode:
104         rjmp $
105
106         .org  0x024
107         // Unimplemented Instruction.
108 _handle_Unimplemented_Instruction:
109         rjmp $
110
111         .org  0x028
112         // Privilege Violation.
113 _handle_Privilege_Violation:
114         rjmp $
115
116         .org  0x02C
117         // Floating-Point: UNUSED IN AVR32A.
118 _handle_Floating_Point:
119         rjmp $
120
121         .org  0x030
122         // Coprocessor Absent: UNUSED IN AVR32A.
123 _handle_Coprocessor_Absent:
124         rjmp $
125
126         .org  0x034
127         // Data Address (Read).
128 _handle_Data_Address_Read:
129         rjmp $
130
131         .org  0x038
132         // Data Address (Write).
133 _handle_Data_Address_Write:
134         rjmp $
135
136         .org  0x03C
137         // DTLB Protection (Read).
138 _handle_DTLB_Protection_Read:
139         rjmp $
140
141         .org  0x040
142         // DTLB Protection (Write).
143 _handle_DTLB_Protection_Write:
144         rjmp $
145
146         .org  0x044
147         // DTLB Modified: UNUSED IN AVR32A.
148 _handle_DTLB_Modified:
149         rjmp $
150
151         .org  0x050
152         // ITLB Miss: UNUSED IN AVR32A.
153 _handle_ITLB_Miss:
154         rjmp $
155
156         .org  0x060
157         // DTLB Miss (Read): UNUSED IN AVR32A.
158 _handle_DTLB_Miss_Read:
159         rjmp $
160
161         .org  0x070
162         // DTLB Miss (Write): UNUSED IN AVR32A.
163 _handle_DTLB_Miss_Write:
164         rjmp $
165
166         .org  0x100
167         // Supervisor Call.
168 _handle_Supervisor_Call:
169         lda.w   pc, SCALLYield
170
171
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
179   .balign 4
180
181 _int0:
182   // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
183   // CPU upon interrupt entry.
184 #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
185   mfsr    r12, AVR32_SR
186   bfextu  r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
187   cp.w    r12, 0b110
188   brlo    _int0_normal
189   lddsp   r12, sp[0 * 4]
190   stdsp   sp[6 * 4], r12
191   lddsp   r12, sp[1 * 4]
192   stdsp   sp[7 * 4], r12
193   lddsp   r12, sp[3 * 4]
194   sub     sp, -6 * 4
195   rete
196 _int0_normal:
197 #endif
198   mov     r12, 0  // Pass the int_lev 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   movne   pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
202   rete            // If this was a spurious interrupt (R12 == NULL), return from event handler.
203
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, 0b110
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   call    _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
227 _int2:
228   // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
229   // CPU upon interrupt entry.
230 #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
231   mfsr    r12, AVR32_SR
232   bfextu  r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
233   cp.w    r12, 0b110
234   brlo    _int2_normal
235   lddsp   r12, sp[0 * 4]
236   stdsp   sp[6 * 4], r12
237   lddsp   r12, sp[1 * 4]
238   stdsp   sp[7 * 4], r12
239   lddsp   r12, sp[3 * 4]
240   sub     sp, -6 * 4
241   rete
242 _int2_normal:
243 #endif
244   mov     r12, 2  // Pass the int_lev parameter to the _get_interrupt_handler function.
245   call    _get_interrupt_handler
246   cp.w    r12, 0  // Get the pointer to the interrupt handler returned by the function.
247   movne   pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
248   rete            // If this was a spurious interrupt (R12 == NULL), return from event handler.
249
250 _int3:
251   // R8-R12, LR, PC and SR are automatically pushed onto the system stack by the
252   // CPU upon interrupt entry.
253 #if 1 // B1832: interrupt stack changed to exception stack if exception is detected.
254   mfsr    r12, AVR32_SR
255   bfextu  r12, r12, AVR32_SR_M0_OFFSET, AVR32_SR_M0_SIZE + AVR32_SR_M1_SIZE + AVR32_SR_M2_SIZE
256   cp.w    r12, 0b110
257   brlo    _int3_normal
258   lddsp   r12, sp[0 * 4]
259   stdsp   sp[6 * 4], r12
260   lddsp   r12, sp[1 * 4]
261   stdsp   sp[7 * 4], r12
262   lddsp   r12, sp[3 * 4]
263   sub     sp, -6 * 4
264   rete
265 _int3_normal:
266 #endif
267   mov     r12, 3  // Pass the int_lev parameter to the _get_interrupt_handler function.
268   call    _get_interrupt_handler
269   cp.w    r12, 0  // Get the pointer to the interrupt handler returned by the function.
270   movne   pc, r12 // If this was not a spurious interrupt (R12 != NULL), jump to the handler.
271   rete            // If this was a spurious interrupt (R12 == NULL), return from event handler.
272
273
274 // Constant data area.
275
276   .balign 4
277
278   // Values to store in the interrupt priority registers for the various interrupt priority levels.
279   // The interrupt priority registers contain the interrupt priority level and
280   // the EVBA-relative interrupt vector offset.
281   .global ipr_val
282 ipr_val:
283   .word (INT0 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int0 - _evba),\
284         (INT1 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int1 - _evba),\
285         (INT2 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int2 - _evba),\
286         (INT3 << AVR32_INTC_IPR0_INTLEV_OFFSET) | (_int3 - _evba)