Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / athos / src / xtos / user-vector.S
1 // user-vector.S  -  User Vector for General Exceptions
2 // $Id: //depot/rel/Cottonwood/Xtensa/OS/xtos/user-vector.S#3 $
3
4 // Copyright (c) 1998-2010 Tensilica Inc.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included
15 // in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 #include <xtensa/coreasm.h>
26 #include <xtensa/config/system.h>
27 #include "xtos-internal.h"
28
29 #if XCHAL_HAVE_EXCEPTIONS
30
31         // Vector code
32         .section                .UserExceptionVector.text, "ax"
33         .align 4
34         .global _UserExceptionVector
35 _UserExceptionVector:
36 # if ((XSHAL_USER_VECTOR_SIZE >= 28) && XCHAL_HAVE_ADDX) || (XSHAL_USER_VECTOR_SIZE >= 36) || XSHAL_VECTORS_PACKED
37         //  There is space to dispatch right at the vector:
38
39         addi    a1, a1, -ESF_TOTALSIZE  // allocate exception stack frame, etc.
40         s32i    a2, a1, UEXC_a2
41         s32i    a3, a1, UEXC_a3
42         movi    a3, _xtos_exc_handler_table
43         rsr     a2, EXCCAUSE            // get exception cause
44         //interlock
45         addx4   a3, a2, a3
46         l32i    a3, a3, 0
47         s32i    a4, a1, UEXC_a4
48         jx      a3                      // jump to cause-specific handler
49
50         .size   _UserExceptionVector, . - _UserExceptionVector
51
52 # else
53         //  The vector may be as small as 12 bytes:
54
55         addi    a1, a1, -ESF_TOTALSIZE          // allocate exception stack frame, etc.
56         s32i    a2, a1, UEXC_a2
57         movi    a2, _UserExceptionFromVector    // load user exception handler address
58         //interlock
59         jx      a2                              // jump to handler
60
61         .size   _UserExceptionVector, . - _UserExceptionVector
62
63         //  Dispatch outside vector:
64         .text
65         //.subsection 2
66         .align  4
67         .global _UserExceptionFromVector
68 _UserExceptionFromVector:
69         s32i    a3, a1, UEXC_a3
70         movi    a3, _xtos_exc_handler_table
71         rsr     a2, EXCCAUSE            // get exception cause
72         s32i    a4, a1, UEXC_a4
73         addx4   a3, a2, a3
74         l32i    a3, a3, 0
75         jx      a3                      // jump to cause-specific handler
76
77         .size   _UserExceptionFromVector, . - _UserExceptionFromVector
78
79 # endif /*XEA2*/
80
81
82         .weak   _xtos_cause3_handler
83
84         /*
85          *  Table of assembly-level general-exception handlers
86          *  (quickly entered) for user vectored exceptions.
87          *  Provides entries for all possible 64 exception causes
88          *  currently allowed for in the EXCCAUSE register.
89          *
90          *  NOTE:  entries that have a corresponding C handler
91          *  (registered at run-time) point to _xtos_c_wrapper_handler;
92          *  entries that have no handler point to _xtos_unhandled_exception.
93          */
94         .data
95         .global _xtos_exc_handler_table
96         .align 4
97 _xtos_exc_handler_table:
98         .word   _xtos_unhandled_exception       // 0 IllegalInstruction
99         .word   _xtos_syscall_handler           // 1 Syscall
100         .word   _xtos_unhandled_exception       // 2 InstructionFetchError
101         .word   _xtos_unhandled_exception       // 3 LoadStoreError
102 # if XCHAL_HAVE_INTERRUPTS
103         .word   _xtos_l1int_handler             // 4 Level1Interrupt
104 # else
105         .word   _xtos_unhandled_exception       // 4 Level1Interrupt (not configured)
106 # endif
107         .word   _xtos_alloca_handler            // 5 Alloca (MOVSP)
108         .word   _xtos_unhandled_exception       // 6 IntegerDivideByZero
109         .word   _xtos_unhandled_exception       // 7 Speculation
110         .word   _xtos_unhandled_exception       // 8 Privileged
111         .word   _xtos_unhandled_exception       // 9 Unaligned
112         .word   _xtos_unhandled_exception       //10 (reserved for Tensilica)
113         .word   _xtos_unhandled_exception       //11 (reserved for Tensilica)
114         .word   _xtos_cause3_handler            //12 PIF data error on fetch
115         .word   _xtos_cause3_handler            //13 PIF data error on ld/st
116         .word   _xtos_cause3_handler            //14 PIF address error on fetch
117         .word   _xtos_cause3_handler            //15 PIF address error on ld/st
118         .word   _xtos_unhandled_exception       //16 InstTLBMiss
119         .word   _xtos_unhandled_exception       //17 InstTLBMultiHit
120         .word   _xtos_unhandled_exception       //18 InstFetchPrivilege
121         .word   _xtos_unhandled_exception       //19 (reserved for Tensilica)
122         .word   _xtos_unhandled_exception       //20 InstFetchProhibited
123         .word   _xtos_unhandled_exception       //21 (reserved for Tensilica)
124         .word   _xtos_unhandled_exception       //22 (reserved for Tensilica)
125         .word   _xtos_unhandled_exception       //23 (reserved for Tensilica)
126         .word   _xtos_unhandled_exception       //24 LoadStoreTLBMiss
127         .word   _xtos_unhandled_exception       //25 LoadStoreTLBMultiHit
128         .word   _xtos_unhandled_exception       //26 LoadStorePrivilege
129         .word   _xtos_unhandled_exception       //27 (reserved for Tensilica)
130         .word   _xtos_unhandled_exception       //28 LoadProhibited
131         .word   _xtos_unhandled_exception       //29 StoreProhibited
132         .word   _xtos_unhandled_exception       //30 (reserved for Tensilica)
133         .word   _xtos_unhandled_exception       //31 (reserved for Tensilica)
134         .rept   8
135         .word   _xtos_unhandled_exception       //32-39 Coprocessor<n>Disabled (n = 0..7)
136         .endr
137
138         .rept   XCHAL_EXCCAUSE_NUM-40
139         .word   _xtos_unhandled_exception       //40-63 (reserved for TIE)
140         .endr
141
142         .text
143
144
145         //  NOTES:
146         //
147         //  Here are alternative vectors.  They will NOT work with
148         //  the handlers currently provided with XTOS.  However they
149         //  might be useful to someone writing their own handlers
150         //  from scratch.  Note that XSR is only available on T1040
151         //  and later hardware.
152         //
153 //***  The typical tiny 9-byte vector:  ***
154 //      wsr     a3, EXCSAVE_1                   // save user a3
155 //      movi    a3, _UserExceptionFromVector    // load user exception handler address
156 //      jx      a3
157 //
158 //***  Minimizing EXCCAUSE-dispatch delay, not assuming valid SP:  ***
159 //      wsr     a0, DEPC        // save a0 (double exceptions fatal here, so not expected)
160 //      rsr     a0, EXCCAUSE
161 //      xsr     a1, EXCSAVE_1   // EXCSAVE_1 always contains &exception_handlers[0]
162 //      //interlock
163 //      addx4   a0, a0, a1
164 //      l32i    a0, a0, TABLE_OFS + EXC_CODE_KERNEL*4
165 //      xsr     a1, EXCSAVE_1   // restore a1 (DEPC contains original a0)
166 //      jx      a0              // jump to cause-specific handler
167 //
168 //***  Doing EXCCAUSE-dispatch with table in EXCSAVE_1:  ***
169 //      addi    a1, a1, -ESF_TOTALSIZE  // allocate exception stack frame, etc.
170 //      s32i    a2, a1, UEXC_a2
171 //      rsr     a2, EXCCAUSE
172 //      xsr     a4, EXCSAVE_1   // EXCSAVE_1 always contains &exception_handlers[0]
173 //      s32i    a3, a1, UEXC_a3
174 //      addx4   a2, a2, a4
175 //      l32i    a2, a2, TABLE_OFS + EXC_CODE_KERNEL*4
176 //      xsr     a4, EXCSAVE_1   // restore a1 (DEPC contains original a0)
177 //      jx      a2              // jump to cause-specific handler
178
179 #endif /* XCHAL_HAVE_EXCEPTIONS */
180