1 /*
2  * tie-asm.h -- compile-time HAL assembler definitions dependent on CORE & TIE
3  *
4  *  NOTE:  This header file is not meant to be included directly.
5  */
6 
7 /* This header file contains assembly-language definitions (assembly
8    macros, etc.) for this specific Xtensa processor's TIE extensions
9    and options.  It is customized to this Xtensa processor configuration.
10 
11    Customer ID=12445; Build=0x700c0; Copyright (c) 1999-2017 Cadence Design Systems Inc.
12 
13    Permission is hereby granted, free of charge, to any person obtaining
14    a copy of this software and associated documentation files (the
15    "Software"), to deal in the Software without restriction, including
16    without limitation the rights to use, copy, modify, merge, publish,
17    distribute, sublicense, and/or sell copies of the Software, and to
18    permit persons to whom the Software is furnished to do so, subject to
19    the following conditions:
20 
21    The above copyright notice and this permission notice shall be included
22    in all copies or substantial portions of the Software.
23 
24    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
31 
32 #ifndef _XTENSA_CORE_TIE_ASM_H
33 #define _XTENSA_CORE_TIE_ASM_H
34 
35 /*  Selection parameter values for save-area save/restore macros:  */
36 /*  Option vs. TIE:  */
37 #define XTHAL_SAS_TIE	0x0001	/* custom extension or coprocessor */
38 #define XTHAL_SAS_OPT	0x0002	/* optional (and not a coprocessor) */
39 #define XTHAL_SAS_ANYOT	0x0003	/* both of the above */
40 /*  Whether used automatically by compiler:  */
41 #define XTHAL_SAS_NOCC	0x0004	/* not used by compiler w/o special opts/code */
42 #define XTHAL_SAS_CC	0x0008	/* used by compiler without special opts/code */
43 #define XTHAL_SAS_ANYCC	0x000C	/* both of the above */
44 /*  ABI handling across function calls:  */
45 #define XTHAL_SAS_CALR	0x0010	/* caller-saved */
46 #define XTHAL_SAS_CALE	0x0020	/* callee-saved */
47 #define XTHAL_SAS_GLOB	0x0040	/* global across function calls (in thread) */
48 #define XTHAL_SAS_ANYABI	0x0070	/* all of the above three */
49 /*  Misc  */
50 #define XTHAL_SAS_ALL	0xFFFF	/* include all default NCP contents */
51 #define XTHAL_SAS3(optie,ccuse,abi)	( ((optie) & XTHAL_SAS_ANYOT)  \
52 					| ((ccuse) & XTHAL_SAS_ANYCC)  \
53 					| ((abi)   & XTHAL_SAS_ANYABI) )
54 
55 
56     /*
57       *  Macro to store all non-coprocessor (extra) custom TIE and optional state
58       *  (not including zero-overhead loop registers).
59       *  Required parameters:
60       *      ptr         Save area pointer address register (clobbered)
61       *                  (register must contain a 4 byte aligned address).
62       *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
63       *                  registers are clobbered, the remaining are unused).
64       *  Optional parameters:
65       *      continue    If macro invoked as part of a larger store sequence, set to 1
66       *                  if this is not the first in the sequence.  Defaults to 0.
67       *      ofs         Offset from start of larger sequence (from value of first ptr
68       *                  in sequence) at which to store.  Defaults to next available space
69       *                  (or 0 if <continue> is 0).
70       *      select      Select what category(ies) of registers to store, as a bitmask
71       *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
72       *      alloc       Select what category(ies) of registers to allocate; if any
73       *                  category is selected here that is not in <select>, space for
74       *                  the corresponding registers is skipped without doing any store.
75       */
76     .macro xchal_ncp_store  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
77 	xchal_sa_start	\continue, \ofs
78 	// Optional global registers used by default by the compiler:
79 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
80 	xchal_sa_align	\ptr, 0, 1016, 4, 4
81 	rur.THREADPTR	\at1		// threadptr option
82 	s32i	\at1, \ptr, .Lxchal_ofs_+0
83 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
84 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
85 	xchal_sa_align	\ptr, 0, 1016, 4, 4
86 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
87 	.endif
88 	// Optional caller-saved registers not used by default by the compiler:
89 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
90 	xchal_sa_align	\ptr, 0, 1012, 4, 4
91 	rsr.BR	\at1		// boolean option
92 	s32i	\at1, \ptr, .Lxchal_ofs_+0
93 	rsr.SCOMPARE1	\at1		// conditional store option
94 	s32i	\at1, \ptr, .Lxchal_ofs_+4
95 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
96 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
97 	xchal_sa_align	\ptr, 0, 1012, 4, 4
98 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
99 	.endif
100     .endm	// xchal_ncp_store
101 
102     /*
103       *  Macro to load all non-coprocessor (extra) custom TIE and optional state
104       *  (not including zero-overhead loop registers).
105       *  Required parameters:
106       *      ptr         Save area pointer address register (clobbered)
107       *                  (register must contain a 4 byte aligned address).
108       *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
109       *                  registers are clobbered, the remaining are unused).
110       *  Optional parameters:
111       *      continue    If macro invoked as part of a larger load sequence, set to 1
112       *                  if this is not the first in the sequence.  Defaults to 0.
113       *      ofs         Offset from start of larger sequence (from value of first ptr
114       *                  in sequence) at which to load.  Defaults to next available space
115       *                  (or 0 if <continue> is 0).
116       *      select      Select what category(ies) of registers to load, as a bitmask
117       *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
118       *      alloc       Select what category(ies) of registers to allocate; if any
119       *                  category is selected here that is not in <select>, space for
120       *                  the corresponding registers is skipped without doing any load.
121       */
122     .macro xchal_ncp_load  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
123 	xchal_sa_start	\continue, \ofs
124 	// Optional global registers used by default by the compiler:
125 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
126 	xchal_sa_align	\ptr, 0, 1016, 4, 4
127 	l32i	\at1, \ptr, .Lxchal_ofs_+0
128 	wur.THREADPTR	\at1		// threadptr option
129 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
130 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
131 	xchal_sa_align	\ptr, 0, 1016, 4, 4
132 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
133 	.endif
134 	// Optional caller-saved registers not used by default by the compiler:
135 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
136 	xchal_sa_align	\ptr, 0, 1012, 4, 4
137 	l32i	\at1, \ptr, .Lxchal_ofs_+0
138 	wsr.BR	\at1		// boolean option
139 	l32i	\at1, \ptr, .Lxchal_ofs_+4
140 	wsr.SCOMPARE1	\at1		// conditional store option
141 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
142 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
143 	xchal_sa_align	\ptr, 0, 1012, 4, 4
144 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
145 	.endif
146     .endm	// xchal_ncp_load
147 
148 
149 #define XCHAL_NCP_NUM_ATMPS	1
150 
151     /*
152      *  Macro to store the state of TIE coprocessor AudioEngineLX.
153      *  Required parameters:
154      *      ptr         Save area pointer address register (clobbered)
155      *                  (register must contain a 8 byte aligned address).
156      *      at1..at4    Four temporary address registers (first XCHAL_CP1_NUM_ATMPS
157      *                  registers are clobbered, the remaining are unused).
158      *  Optional parameters are the same as for xchal_ncp_store.
159      */
160 #define xchal_cp_AudioEngineLX_store	xchal_cp1_store
161     .macro	xchal_cp1_store  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
162 	xchal_sa_start \continue, \ofs
163 	// Custom caller-saved registers not used by default by the compiler:
164 	.ifeq (XTHAL_SAS_TIE | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
165 	xchal_sa_align	\ptr, 0, 0, 8, 8
166 	ae_s64.i	aed0, \ptr, .Lxchal_ofs_+40
167 	ae_s64.i	aed1, \ptr, .Lxchal_ofs_+48
168 	ae_s64.i	aed2, \ptr, .Lxchal_ofs_+56
169 	addi	\ptr, \ptr, 64
170 	ae_s64.i	aed3, \ptr, .Lxchal_ofs_+0
171 	ae_s64.i	aed4, \ptr, .Lxchal_ofs_+8
172 	ae_s64.i	aed5, \ptr, .Lxchal_ofs_+16
173 	ae_s64.i	aed6, \ptr, .Lxchal_ofs_+24
174 	ae_s64.i	aed7, \ptr, .Lxchal_ofs_+32
175 	ae_s64.i	aed8, \ptr, .Lxchal_ofs_+40
176 	ae_s64.i	aed9, \ptr, .Lxchal_ofs_+48
177 	ae_s64.i	aed10, \ptr, .Lxchal_ofs_+56
178 	addi	\ptr, \ptr, 64
179 	ae_s64.i	aed11, \ptr, .Lxchal_ofs_+0
180 	ae_s64.i	aed12, \ptr, .Lxchal_ofs_+8
181 	ae_s64.i	aed13, \ptr, .Lxchal_ofs_+16
182 	ae_s64.i	aed14, \ptr, .Lxchal_ofs_+24
183 	ae_s64.i	aed15, \ptr, .Lxchal_ofs_+32
184 	ae_movae	\at1, aep0
185 	s8i	\at1, \ptr, .Lxchal_ofs_+40
186 	ae_movae	\at1, aep1
187 	s8i	\at1, \ptr, .Lxchal_ofs_+41
188 	ae_movae	\at1, aep2
189 	s8i	\at1, \ptr, .Lxchal_ofs_+42
190 	ae_movae	\at1, aep3
191 	s8i	\at1, \ptr, .Lxchal_ofs_+43
192 	ae_salign64.i	u0, \ptr, .Lxchal_ofs_+48
193 	ae_salign64.i	u1, \ptr, .Lxchal_ofs_+56
194 	addi	\ptr, \ptr, 64
195 	ae_salign64.i	u2, \ptr, .Lxchal_ofs_+0
196 	ae_salign64.i	u3, \ptr, .Lxchal_ofs_+8
197 	addi	\ptr, \ptr, -192
198 	ae_movvfcrfsr	aed0		// ureg FCR_FSR
199 	ae_s64.i	aed0, \ptr, .Lxchal_ofs_+0 + 0
200 	rur.AE_OVF_SAR	\at1		// ureg 240
201 	s32i	\at1, \ptr, .Lxchal_ofs_+8
202 	rur.AE_BITHEAD	\at1		// ureg 241
203 	s32i	\at1, \ptr, .Lxchal_ofs_+12
204 	rur.AE_TS_FTS_BU_BP	\at1		// ureg 242
205 	s32i	\at1, \ptr, .Lxchal_ofs_+16
206 	rur.AE_CW_SD_NO	\at1		// ureg 243
207 	s32i	\at1, \ptr, .Lxchal_ofs_+20
208 	rur.AE_CBEGIN0	\at1		// ureg 246
209 	s32i	\at1, \ptr, .Lxchal_ofs_+24
210 	rur.AE_CEND0	\at1		// ureg 247
211 	s32i	\at1, \ptr, .Lxchal_ofs_+28
212 	rur.AE_CBEGIN1	\at1		// ureg 248
213 	s32i	\at1, \ptr, .Lxchal_ofs_+32
214 	rur.AE_CEND1	\at1		// ureg 249
215 	s32i	\at1, \ptr, .Lxchal_ofs_+36
216 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 208
217 	.elseif ((XTHAL_SAS_TIE | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
218 	xchal_sa_align	\ptr, 0, 0, 8, 8
219 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 208
220 	.endif
221     .endm	// xchal_cp1_store
222 
223     /*
224      *  Macro to load the state of TIE coprocessor AudioEngineLX.
225      *  Required parameters:
226      *      ptr         Save area pointer address register (clobbered)
227      *                  (register must contain a 8 byte aligned address).
228      *      at1..at4    Four temporary address registers (first XCHAL_CP1_NUM_ATMPS
229      *                  registers are clobbered, the remaining are unused).
230      *  Optional parameters are the same as for xchal_ncp_load.
231      */
232 #define xchal_cp_AudioEngineLX_load	xchal_cp1_load
233     .macro	xchal_cp1_load  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
234 	xchal_sa_start \continue, \ofs
235 	// Custom caller-saved registers not used by default by the compiler:
236 	.ifeq (XTHAL_SAS_TIE | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
237 	xchal_sa_align	\ptr, 0, 0, 8, 8
238 	ae_l64.i	aed0, \ptr, .Lxchal_ofs_+0 + 0		// ureg FCR_FSR
239 	ae_movfcrfsrv	aed0
240 	l32i	\at1, \ptr, .Lxchal_ofs_+8
241 	wur.AE_OVF_SAR	\at1		// ureg 240
242 	l32i	\at1, \ptr, .Lxchal_ofs_+12
243 	wur.AE_BITHEAD	\at1		// ureg 241
244 	l32i	\at1, \ptr, .Lxchal_ofs_+16
245 	wur.AE_TS_FTS_BU_BP	\at1		// ureg 242
246 	l32i	\at1, \ptr, .Lxchal_ofs_+20
247 	wur.AE_CW_SD_NO	\at1		// ureg 243
248 	l32i	\at1, \ptr, .Lxchal_ofs_+24
249 	wur.AE_CBEGIN0	\at1		// ureg 246
250 	l32i	\at1, \ptr, .Lxchal_ofs_+28
251 	wur.AE_CEND0	\at1		// ureg 247
252 	l32i	\at1, \ptr, .Lxchal_ofs_+32
253 	wur.AE_CBEGIN1	\at1		// ureg 248
254 	l32i	\at1, \ptr, .Lxchal_ofs_+36
255 	wur.AE_CEND1	\at1		// ureg 249
256 	ae_l64.i	aed0, \ptr, .Lxchal_ofs_+40
257 	ae_l64.i	aed1, \ptr, .Lxchal_ofs_+48
258 	ae_l64.i	aed2, \ptr, .Lxchal_ofs_+56
259 	addi	\ptr, \ptr, 64
260 	ae_l64.i	aed3, \ptr, .Lxchal_ofs_+0
261 	ae_l64.i	aed4, \ptr, .Lxchal_ofs_+8
262 	ae_l64.i	aed5, \ptr, .Lxchal_ofs_+16
263 	ae_l64.i	aed6, \ptr, .Lxchal_ofs_+24
264 	ae_l64.i	aed7, \ptr, .Lxchal_ofs_+32
265 	ae_l64.i	aed8, \ptr, .Lxchal_ofs_+40
266 	ae_l64.i	aed9, \ptr, .Lxchal_ofs_+48
267 	ae_l64.i	aed10, \ptr, .Lxchal_ofs_+56
268 	addi	\ptr, \ptr, 64
269 	ae_l64.i	aed11, \ptr, .Lxchal_ofs_+0
270 	ae_l64.i	aed12, \ptr, .Lxchal_ofs_+8
271 	ae_l64.i	aed13, \ptr, .Lxchal_ofs_+16
272 	ae_l64.i	aed14, \ptr, .Lxchal_ofs_+24
273 	ae_l64.i	aed15, \ptr, .Lxchal_ofs_+32
274 	addi	\ptr, \ptr, 40
275 	l8ui	\at1, \ptr, .Lxchal_ofs_+0
276 	ae_movea	aep0, \at1
277 	l8ui	\at1, \ptr, .Lxchal_ofs_+1
278 	ae_movea	aep1, \at1
279 	l8ui	\at1, \ptr, .Lxchal_ofs_+2
280 	ae_movea	aep2, \at1
281 	l8ui	\at1, \ptr, .Lxchal_ofs_+3
282 	ae_movea	aep3, \at1
283 	addi	\ptr, \ptr, 8
284 	ae_lalign64.i	u0, \ptr, .Lxchal_ofs_+0
285 	ae_lalign64.i	u1, \ptr, .Lxchal_ofs_+8
286 	ae_lalign64.i	u2, \ptr, .Lxchal_ofs_+16
287 	ae_lalign64.i	u3, \ptr, .Lxchal_ofs_+24
288 	.set	.Lxchal_pofs_, .Lxchal_pofs_ + 176
289 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 32
290 	.elseif ((XTHAL_SAS_TIE | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
291 	xchal_sa_align	\ptr, 0, 0, 8, 8
292 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 208
293 	.endif
294     .endm	// xchal_cp1_load
295 
296 #define XCHAL_CP1_NUM_ATMPS	1
297 #define XCHAL_SA_NUM_ATMPS	1
298 
299 	/*  Empty macros for unconfigured coprocessors:  */
300 	.macro xchal_cp0_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
301 	.macro xchal_cp0_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
302 	.macro xchal_cp2_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
303 	.macro xchal_cp2_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
304 	.macro xchal_cp3_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
305 	.macro xchal_cp3_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
306 	.macro xchal_cp4_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
307 	.macro xchal_cp4_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
308 	.macro xchal_cp5_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
309 	.macro xchal_cp5_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
310 	.macro xchal_cp6_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
311 	.macro xchal_cp6_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
312 	.macro xchal_cp7_store	p a b c d continue=0 ofs=-1 select=-1 ; .endm
313 	.macro xchal_cp7_load	p a b c d continue=0 ofs=-1 select=-1 ; .endm
314 
315 #endif /*_XTENSA_CORE_TIE_ASM_H*/
316 
317