]> begriffs open source - freertos/blob - portable/ThirdParty/XCC/Xtensa/xtensa_intr_asm.S
moved XMOS ports to thirdparty
[freertos] / portable / ThirdParty / XCC / Xtensa / xtensa_intr_asm.S
1
2 /*
3  * Copyright (c) 2015-2019 Cadence Design Systems, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Xtensa interrupt handling data and assembly routines.
27  * Also see xtensa_intr.c and xtensa_vectors.S.
28  */
29
30 #include <xtensa/hal.h>
31 #include <xtensa/config/core.h>
32
33 #include "xtensa_context.h"
34
35 #if XCHAL_HAVE_INTERRUPTS
36
37 /*
38 -------------------------------------------------------------------------------
39   INTENABLE virtualization information.
40 -------------------------------------------------------------------------------
41 */
42
43     .data
44     .global _xt_intdata
45     .align  8
46 _xt_intdata:
47     .global _xt_intenable
48     .type   _xt_intenable,@object
49     .size   _xt_intenable,4
50     .global _xt_vpri_mask
51     .type   _xt_vpri_mask,@object
52     .size   _xt_vpri_mask,4
53
54 _xt_intenable:     .word   0             /* Virtual INTENABLE     */
55 _xt_vpri_mask:     .word   0xFFFFFFFF    /* Virtual priority mask */
56
57
58 /*
59 -------------------------------------------------------------------------------
60   Table of C-callable interrupt handlers for each interrupt. Note that not all
61   slots can be filled, because interrupts at level > EXCM_LEVEL will not be
62   dispatched to a C handler by default.
63 -------------------------------------------------------------------------------
64 */
65
66     .data
67     .global _xt_interrupt_table
68     .align  8
69
70 _xt_interrupt_table:
71
72     .set    i, 0
73     .rept   XCHAL_NUM_INTERRUPTS
74     .word   xt_unhandled_interrupt      /* handler address               */
75     .word   i                           /* handler arg (default: intnum) */
76     .set    i, i+1
77     .endr
78
79 #endif /* XCHAL_HAVE_INTERRUPTS */
80
81
82 #if XCHAL_HAVE_EXCEPTIONS
83
84 /*
85 -------------------------------------------------------------------------------
86   Table of C-callable exception handlers for each exception. Note that not all
87   slots will be active, because some exceptions (e.g. coprocessor exceptions)
88   are always handled by the OS and cannot be hooked by user handlers.
89 -------------------------------------------------------------------------------
90 */
91
92     .data
93     .global _xt_exception_table
94     .align  4
95
96 _xt_exception_table:
97     .rept   XCHAL_EXCCAUSE_NUM
98     .word   xt_unhandled_exception    /* handler address */
99     .endr
100
101 #endif
102
103
104 /*
105 -------------------------------------------------------------------------------
106   unsigned int xt_ints_on ( unsigned int mask )
107
108   Enables a set of interrupts. Does not simply set INTENABLE directly, but
109   computes it as a function of the current virtual priority.
110   Can be called from interrupt handlers.
111 -------------------------------------------------------------------------------
112 */
113
114     .text
115     .align  4
116     .global xt_ints_on
117     .type   xt_ints_on,@function
118
119 xt_ints_on:
120
121     ENTRY0
122 #if XCHAL_HAVE_INTERRUPTS
123     movi    a3, 0
124     movi    a4, _xt_intdata
125     xsr     a3, INTENABLE        /* Disables all interrupts   */
126     rsync
127     l32i    a3, a4, 0            /* a3 = _xt_intenable        */
128     l32i    a6, a4, 4            /* a6 = _xt_vpri_mask        */
129     or      a5, a3, a2           /* a5 = _xt_intenable | mask */
130     s32i    a5, a4, 0            /* _xt_intenable |= mask     */
131     and     a5, a5, a6           /* a5 = _xt_intenable & _xt_vpri_mask */
132     wsr     a5, INTENABLE        /* Reenable interrupts       */
133     mov     a2, a3               /* Previous mask             */
134 #else
135     movi    a2, 0                /* Return zero */
136 #endif
137     RET0
138
139     .size   xt_ints_on, . - xt_ints_on
140
141
142 /*
143 -------------------------------------------------------------------------------
144   unsigned int xt_ints_off ( unsigned int mask )
145
146   Disables a set of interrupts. Does not simply set INTENABLE directly,
147   but computes it as a function of the current virtual priority.
148   Can be called from interrupt handlers.
149 -------------------------------------------------------------------------------
150 */
151
152     .text
153     .align  4
154     .global xt_ints_off
155     .type   xt_ints_off,@function
156
157 xt_ints_off:
158
159     ENTRY0
160 #if XCHAL_HAVE_INTERRUPTS
161     movi    a3, 0
162     movi    a4, _xt_intdata
163     xsr     a3, INTENABLE        /* Disables all interrupts    */
164     rsync
165     l32i    a3, a4, 0            /* a3 = _xt_intenable         */
166     l32i    a6, a4, 4            /* a6 = _xt_vpri_mask         */
167     or      a5, a3, a2           /* a5 = _xt_intenable | mask  */
168     xor     a5, a5, a2           /* a5 = _xt_intenable & ~mask */
169     s32i    a5, a4, 0            /* _xt_intenable &= ~mask     */
170     and     a5, a5, a6           /* a5 = _xt_intenable & _xt_vpri_mask */
171     wsr     a5, INTENABLE        /* Reenable interrupts        */
172     mov     a2, a3               /* Previous mask              */
173 #else
174     movi    a2, 0                /* return zero */
175 #endif
176     RET0
177
178     .size   xt_ints_off, . - xt_ints_off
179
180