xref: /openbmc/linux/arch/xtensa/variants/csp/include/variant/tie-asm.h (revision 0cce284537fb42d9c28b9b31038ffc9b464555f5)
1*23c2b932SScott Telford /*
2*23c2b932SScott Telford  * tie-asm.h -- compile-time HAL assembler definitions dependent on CORE & TIE
3*23c2b932SScott Telford  *
4*23c2b932SScott Telford  *  NOTE:  This header file is not meant to be included directly.
5*23c2b932SScott Telford  */
6*23c2b932SScott Telford 
7*23c2b932SScott Telford /* This header file contains assembly-language definitions (assembly
8*23c2b932SScott Telford    macros, etc.) for this specific Xtensa processor's TIE extensions
9*23c2b932SScott Telford    and options.  It is customized to this Xtensa processor configuration.
10*23c2b932SScott Telford 
11*23c2b932SScott Telford    Copyright (c) 1999-2015 Cadence Design Systems Inc.
12*23c2b932SScott Telford 
13*23c2b932SScott Telford    Permission is hereby granted, free of charge, to any person obtaining
14*23c2b932SScott Telford    a copy of this software and associated documentation files (the
15*23c2b932SScott Telford    "Software"), to deal in the Software without restriction, including
16*23c2b932SScott Telford    without limitation the rights to use, copy, modify, merge, publish,
17*23c2b932SScott Telford    distribute, sublicense, and/or sell copies of the Software, and to
18*23c2b932SScott Telford    permit persons to whom the Software is furnished to do so, subject to
19*23c2b932SScott Telford    the following conditions:
20*23c2b932SScott Telford 
21*23c2b932SScott Telford    The above copyright notice and this permission notice shall be included
22*23c2b932SScott Telford    in all copies or substantial portions of the Software.
23*23c2b932SScott Telford 
24*23c2b932SScott Telford    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25*23c2b932SScott Telford    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26*23c2b932SScott Telford    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27*23c2b932SScott Telford    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28*23c2b932SScott Telford    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29*23c2b932SScott Telford    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30*23c2b932SScott Telford    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
31*23c2b932SScott Telford 
32*23c2b932SScott Telford #ifndef _XTENSA_CORE_TIE_ASM_H
33*23c2b932SScott Telford #define _XTENSA_CORE_TIE_ASM_H
34*23c2b932SScott Telford 
35*23c2b932SScott Telford /*  Selection parameter values for save-area save/restore macros:  */
36*23c2b932SScott Telford /*  Option vs. TIE:  */
37*23c2b932SScott Telford #define XTHAL_SAS_TIE	0x0001	/* custom extension or coprocessor */
38*23c2b932SScott Telford #define XTHAL_SAS_OPT	0x0002	/* optional (and not a coprocessor) */
39*23c2b932SScott Telford #define XTHAL_SAS_ANYOT	0x0003	/* both of the above */
40*23c2b932SScott Telford /*  Whether used automatically by compiler:  */
41*23c2b932SScott Telford #define XTHAL_SAS_NOCC	0x0004	/* not used by compiler w/o special opts/code */
42*23c2b932SScott Telford #define XTHAL_SAS_CC	0x0008	/* used by compiler without special opts/code */
43*23c2b932SScott Telford #define XTHAL_SAS_ANYCC	0x000C	/* both of the above */
44*23c2b932SScott Telford /*  ABI handling across function calls:  */
45*23c2b932SScott Telford #define XTHAL_SAS_CALR	0x0010	/* caller-saved */
46*23c2b932SScott Telford #define XTHAL_SAS_CALE	0x0020	/* callee-saved */
47*23c2b932SScott Telford #define XTHAL_SAS_GLOB	0x0040	/* global across function calls (in thread) */
48*23c2b932SScott Telford #define XTHAL_SAS_ANYABI	0x0070	/* all of the above three */
49*23c2b932SScott Telford /*  Misc  */
50*23c2b932SScott Telford #define XTHAL_SAS_ALL	0xFFFF	/* include all default NCP contents */
51*23c2b932SScott Telford #define XTHAL_SAS3(optie,ccuse,abi)	( ((optie) & XTHAL_SAS_ANYOT)  \
52*23c2b932SScott Telford 					| ((ccuse) & XTHAL_SAS_ANYCC)  \
53*23c2b932SScott Telford 					| ((abi)   & XTHAL_SAS_ANYABI) )
54*23c2b932SScott Telford 
55*23c2b932SScott Telford 
56*23c2b932SScott Telford     /*
57*23c2b932SScott Telford       *  Macro to store all non-coprocessor (extra) custom TIE and optional state
58*23c2b932SScott Telford       *  (not including zero-overhead loop registers).
59*23c2b932SScott Telford       *  Required parameters:
60*23c2b932SScott Telford       *      ptr         Save area pointer address register (clobbered)
61*23c2b932SScott Telford       *                  (register must contain a 4 byte aligned address).
62*23c2b932SScott Telford       *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
63*23c2b932SScott Telford       *                  registers are clobbered, the remaining are unused).
64*23c2b932SScott Telford       *  Optional parameters:
65*23c2b932SScott Telford       *      continue    If macro invoked as part of a larger store sequence, set to 1
66*23c2b932SScott Telford       *                  if this is not the first in the sequence.  Defaults to 0.
67*23c2b932SScott Telford       *      ofs         Offset from start of larger sequence (from value of first ptr
68*23c2b932SScott Telford       *                  in sequence) at which to store.  Defaults to next available space
69*23c2b932SScott Telford       *                  (or 0 if <continue> is 0).
70*23c2b932SScott Telford       *      select      Select what category(ies) of registers to store, as a bitmask
71*23c2b932SScott Telford       *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
72*23c2b932SScott Telford       *      alloc       Select what category(ies) of registers to allocate; if any
73*23c2b932SScott Telford       *                  category is selected here that is not in <select>, space for
74*23c2b932SScott Telford       *                  the corresponding registers is skipped without doing any store.
75*23c2b932SScott Telford       */
76*23c2b932SScott Telford     .macro xchal_ncp_store  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
77*23c2b932SScott Telford 	xchal_sa_start	\continue, \ofs
78*23c2b932SScott Telford 	// Optional global registers used by default by the compiler:
79*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
80*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1020, 4, 4
81*23c2b932SScott Telford 	rur.THREADPTR	\at1		// threadptr option
82*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+0
83*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
84*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
85*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1020, 4, 4
86*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
87*23c2b932SScott Telford 	.endif
88*23c2b932SScott Telford 	// Optional caller-saved registers used by default by the compiler:
89*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
90*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1016, 4, 4
91*23c2b932SScott Telford 	rsr.ACCLO	\at1		// MAC16 option
92*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+0
93*23c2b932SScott Telford 	rsr.ACCHI	\at1		// MAC16 option
94*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+4
95*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
96*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
97*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1016, 4, 4
98*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
99*23c2b932SScott Telford 	.endif
100*23c2b932SScott Telford 	// Optional caller-saved registers not used by default by the compiler:
101*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
102*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1000, 4, 4
103*23c2b932SScott Telford 	rsr.BR	\at1		// boolean option
104*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+0
105*23c2b932SScott Telford 	rsr.SCOMPARE1	\at1		// conditional store option
106*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+4
107*23c2b932SScott Telford 	rsr.M0	\at1		// MAC16 option
108*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+8
109*23c2b932SScott Telford 	rsr.M1	\at1		// MAC16 option
110*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+12
111*23c2b932SScott Telford 	rsr.M2	\at1		// MAC16 option
112*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+16
113*23c2b932SScott Telford 	rsr.M3	\at1		// MAC16 option
114*23c2b932SScott Telford 	s32i	\at1, \ptr, .Lxchal_ofs_+20
115*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 24
116*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
117*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1000, 4, 4
118*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 24
119*23c2b932SScott Telford 	.endif
120*23c2b932SScott Telford     .endm	// xchal_ncp_store
121*23c2b932SScott Telford 
122*23c2b932SScott Telford     /*
123*23c2b932SScott Telford       *  Macro to load all non-coprocessor (extra) custom TIE and optional state
124*23c2b932SScott Telford       *  (not including zero-overhead loop registers).
125*23c2b932SScott Telford       *  Required parameters:
126*23c2b932SScott Telford       *      ptr         Save area pointer address register (clobbered)
127*23c2b932SScott Telford       *                  (register must contain a 4 byte aligned address).
128*23c2b932SScott Telford       *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
129*23c2b932SScott Telford       *                  registers are clobbered, the remaining are unused).
130*23c2b932SScott Telford       *  Optional parameters:
131*23c2b932SScott Telford       *      continue    If macro invoked as part of a larger load sequence, set to 1
132*23c2b932SScott Telford       *                  if this is not the first in the sequence.  Defaults to 0.
133*23c2b932SScott Telford       *      ofs         Offset from start of larger sequence (from value of first ptr
134*23c2b932SScott Telford       *                  in sequence) at which to load.  Defaults to next available space
135*23c2b932SScott Telford       *                  (or 0 if <continue> is 0).
136*23c2b932SScott Telford       *      select      Select what category(ies) of registers to load, as a bitmask
137*23c2b932SScott Telford       *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
138*23c2b932SScott Telford       *      alloc       Select what category(ies) of registers to allocate; if any
139*23c2b932SScott Telford       *                  category is selected here that is not in <select>, space for
140*23c2b932SScott Telford       *                  the corresponding registers is skipped without doing any load.
141*23c2b932SScott Telford       */
142*23c2b932SScott Telford     .macro xchal_ncp_load  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
143*23c2b932SScott Telford 	xchal_sa_start	\continue, \ofs
144*23c2b932SScott Telford 	// Optional global registers used by default by the compiler:
145*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
146*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1020, 4, 4
147*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+0
148*23c2b932SScott Telford 	wur.THREADPTR	\at1		// threadptr option
149*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
150*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
151*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1020, 4, 4
152*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
153*23c2b932SScott Telford 	.endif
154*23c2b932SScott Telford 	// Optional caller-saved registers used by default by the compiler:
155*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
156*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1016, 4, 4
157*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+0
158*23c2b932SScott Telford 	wsr.ACCLO	\at1		// MAC16 option
159*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+4
160*23c2b932SScott Telford 	wsr.ACCHI	\at1		// MAC16 option
161*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
162*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
163*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1016, 4, 4
164*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
165*23c2b932SScott Telford 	.endif
166*23c2b932SScott Telford 	// Optional caller-saved registers not used by default by the compiler:
167*23c2b932SScott Telford 	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
168*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1000, 4, 4
169*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+0
170*23c2b932SScott Telford 	wsr.BR	\at1		// boolean option
171*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+4
172*23c2b932SScott Telford 	wsr.SCOMPARE1	\at1		// conditional store option
173*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+8
174*23c2b932SScott Telford 	wsr.M0	\at1		// MAC16 option
175*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+12
176*23c2b932SScott Telford 	wsr.M1	\at1		// MAC16 option
177*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+16
178*23c2b932SScott Telford 	wsr.M2	\at1		// MAC16 option
179*23c2b932SScott Telford 	l32i	\at1, \ptr, .Lxchal_ofs_+20
180*23c2b932SScott Telford 	wsr.M3	\at1		// MAC16 option
181*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 24
182*23c2b932SScott Telford 	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
183*23c2b932SScott Telford 	xchal_sa_align	\ptr, 0, 1000, 4, 4
184*23c2b932SScott Telford 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 24
185*23c2b932SScott Telford 	.endif
186*23c2b932SScott Telford     .endm	// xchal_ncp_load
187*23c2b932SScott Telford 
188*23c2b932SScott Telford 
189*23c2b932SScott Telford #define XCHAL_NCP_NUM_ATMPS	1
190*23c2b932SScott Telford 
191*23c2b932SScott Telford #define XCHAL_SA_NUM_ATMPS	1
192*23c2b932SScott Telford 
193*23c2b932SScott Telford #endif /*_XTENSA_CORE_TIE_ASM_H*/
194*23c2b932SScott Telford 
195