162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * tie-asm.h -- compile-time HAL assembler definitions dependent on CORE & TIE
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  NOTE:  This header file is not meant to be included directly.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* This header file contains assembly-language definitions (assembly
862306a36Sopenharmony_ci   macros, etc.) for this specific Xtensa processor's TIE extensions
962306a36Sopenharmony_ci   and options.  It is customized to this Xtensa processor configuration.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci   Copyright (c) 1999-2010 Tensilica Inc.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci   Permission is hereby granted, free of charge, to any person obtaining
1462306a36Sopenharmony_ci   a copy of this software and associated documentation files (the
1562306a36Sopenharmony_ci   "Software"), to deal in the Software without restriction, including
1662306a36Sopenharmony_ci   without limitation the rights to use, copy, modify, merge, publish,
1762306a36Sopenharmony_ci   distribute, sublicense, and/or sell copies of the Software, and to
1862306a36Sopenharmony_ci   permit persons to whom the Software is furnished to do so, subject to
1962306a36Sopenharmony_ci   the following conditions:
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci   The above copyright notice and this permission notice shall be included
2262306a36Sopenharmony_ci   in all copies or substantial portions of the Software.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2562306a36Sopenharmony_ci   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2662306a36Sopenharmony_ci   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2762306a36Sopenharmony_ci   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2862306a36Sopenharmony_ci   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2962306a36Sopenharmony_ci   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
3062306a36Sopenharmony_ci   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#ifndef _XTENSA_CORE_TIE_ASM_H
3362306a36Sopenharmony_ci#define _XTENSA_CORE_TIE_ASM_H
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/*  Selection parameter values for save-area save/restore macros:  */
3662306a36Sopenharmony_ci/*  Option vs. TIE:  */
3762306a36Sopenharmony_ci#define XTHAL_SAS_TIE	0x0001	/* custom extension or coprocessor */
3862306a36Sopenharmony_ci#define XTHAL_SAS_OPT	0x0002	/* optional (and not a coprocessor) */
3962306a36Sopenharmony_ci#define XTHAL_SAS_ANYOT	0x0003	/* both of the above */
4062306a36Sopenharmony_ci/*  Whether used automatically by compiler:  */
4162306a36Sopenharmony_ci#define XTHAL_SAS_NOCC	0x0004	/* not used by compiler w/o special opts/code */
4262306a36Sopenharmony_ci#define XTHAL_SAS_CC	0x0008	/* used by compiler without special opts/code */
4362306a36Sopenharmony_ci#define XTHAL_SAS_ANYCC	0x000C	/* both of the above */
4462306a36Sopenharmony_ci/*  ABI handling across function calls:  */
4562306a36Sopenharmony_ci#define XTHAL_SAS_CALR	0x0010	/* caller-saved */
4662306a36Sopenharmony_ci#define XTHAL_SAS_CALE	0x0020	/* callee-saved */
4762306a36Sopenharmony_ci#define XTHAL_SAS_GLOB	0x0040	/* global across function calls (in thread) */
4862306a36Sopenharmony_ci#define XTHAL_SAS_ANYABI 0x0070	/* all of the above three */
4962306a36Sopenharmony_ci/*  Misc  */
5062306a36Sopenharmony_ci#define XTHAL_SAS_ALL	0xFFFF	/* include all default NCP contents */
5162306a36Sopenharmony_ci#define XTHAL_SAS3(optie,ccuse,abi)	( ((optie) & XTHAL_SAS_ANYOT)  \
5262306a36Sopenharmony_ci					| ((ccuse) & XTHAL_SAS_ANYCC)  \
5362306a36Sopenharmony_ci					| ((abi)   & XTHAL_SAS_ANYABI) )
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci    /*
5862306a36Sopenharmony_ci     *  Macro to save all non-coprocessor (extra) custom TIE and optional state
5962306a36Sopenharmony_ci     *  (not including zero-overhead loop registers).
6062306a36Sopenharmony_ci     *  Required parameters:
6162306a36Sopenharmony_ci     *      ptr		Save area pointer address register (clobbered)
6262306a36Sopenharmony_ci     *			(register must contain a 4 byte aligned address).
6362306a36Sopenharmony_ci     *      at1..at4	Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
6462306a36Sopenharmony_ci     *			registers are clobbered, the remaining are unused).
6562306a36Sopenharmony_ci     *  Optional parameters:
6662306a36Sopenharmony_ci     *      continue	If macro invoked as part of a larger store sequence, set to 1
6762306a36Sopenharmony_ci     *			if this is not the first in the sequence.  Defaults to 0.
6862306a36Sopenharmony_ci     *      ofs		Offset from start of larger sequence (from value of first ptr
6962306a36Sopenharmony_ci     *			in sequence) at which to store.  Defaults to next available space
7062306a36Sopenharmony_ci     *			(or 0 if <continue> is 0).
7162306a36Sopenharmony_ci     *      select	Select what category(ies) of registers to store, as a bitmask
7262306a36Sopenharmony_ci     *			(see XTHAL_SAS_xxx constants).  Defaults to all registers.
7362306a36Sopenharmony_ci     *      alloc	Select what category(ies) of registers to allocate; if any
7462306a36Sopenharmony_ci     *			category is selected here that is not in <select>, space for
7562306a36Sopenharmony_ci     *			the corresponding registers is skipped without doing any store.
7662306a36Sopenharmony_ci     */
7762306a36Sopenharmony_ci    .macro xchal_ncp_store  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
7862306a36Sopenharmony_ci	xchal_sa_start	\continue, \ofs
7962306a36Sopenharmony_ci	// Optional global register used by default by the compiler:
8062306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
8162306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1020, 4, 4
8262306a36Sopenharmony_ci	rur.THREADPTR	\at1		// threadptr option
8362306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+0
8462306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
8562306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
8662306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1020, 4, 4
8762306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
8862306a36Sopenharmony_ci	.endif
8962306a36Sopenharmony_ci	// Optional caller-saved registers used by default by the compiler:
9062306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
9162306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
9262306a36Sopenharmony_ci	rsr	\at1, ACCLO			// MAC16 option
9362306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+0
9462306a36Sopenharmony_ci	rsr	\at1, ACCHI			// MAC16 option
9562306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+4
9662306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
9762306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
9862306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
9962306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
10062306a36Sopenharmony_ci	.endif
10162306a36Sopenharmony_ci	// Optional caller-saved registers not used by default by the compiler:
10262306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
10362306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
10462306a36Sopenharmony_ci	rsr	\at1, M0			// MAC16 option
10562306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+0
10662306a36Sopenharmony_ci	rsr	\at1, M1			// MAC16 option
10762306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+4
10862306a36Sopenharmony_ci	rsr	\at1, M2			// MAC16 option
10962306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+8
11062306a36Sopenharmony_ci	rsr	\at1, M3			// MAC16 option
11162306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+12
11262306a36Sopenharmony_ci	rsr	\at1, SCOMPARE1			// conditional store option
11362306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+16
11462306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
11562306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
11662306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
11762306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
11862306a36Sopenharmony_ci	.endif
11962306a36Sopenharmony_ci    .endm	// xchal_ncp_store
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci    /*
12262306a36Sopenharmony_ci     *  Macro to restore all non-coprocessor (extra) custom TIE and optional state
12362306a36Sopenharmony_ci     *  (not including zero-overhead loop registers).
12462306a36Sopenharmony_ci     *  Required parameters:
12562306a36Sopenharmony_ci     *      ptr		Save area pointer address register (clobbered)
12662306a36Sopenharmony_ci     *			(register must contain a 4 byte aligned address).
12762306a36Sopenharmony_ci     *      at1..at4	Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
12862306a36Sopenharmony_ci     *			registers are clobbered, the remaining are unused).
12962306a36Sopenharmony_ci     *  Optional parameters:
13062306a36Sopenharmony_ci     *      continue	If macro invoked as part of a larger load sequence, set to 1
13162306a36Sopenharmony_ci     *			if this is not the first in the sequence.  Defaults to 0.
13262306a36Sopenharmony_ci     *      ofs		Offset from start of larger sequence (from value of first ptr
13362306a36Sopenharmony_ci     *			in sequence) at which to load.  Defaults to next available space
13462306a36Sopenharmony_ci     *			(or 0 if <continue> is 0).
13562306a36Sopenharmony_ci     *      select	Select what category(ies) of registers to load, as a bitmask
13662306a36Sopenharmony_ci     *			(see XTHAL_SAS_xxx constants).  Defaults to all registers.
13762306a36Sopenharmony_ci     *      alloc	Select what category(ies) of registers to allocate; if any
13862306a36Sopenharmony_ci     *			category is selected here that is not in <select>, space for
13962306a36Sopenharmony_ci     *			the corresponding registers is skipped without doing any load.
14062306a36Sopenharmony_ci     */
14162306a36Sopenharmony_ci    .macro xchal_ncp_load  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
14262306a36Sopenharmony_ci	xchal_sa_start	\continue, \ofs
14362306a36Sopenharmony_ci	// Optional global register used by default by the compiler:
14462306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\select)
14562306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1020, 4, 4
14662306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+0
14762306a36Sopenharmony_ci	wur.THREADPTR	\at1		// threadptr option
14862306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
14962306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_GLOB) & ~(\alloc)) == 0
15062306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1020, 4, 4
15162306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 4
15262306a36Sopenharmony_ci	.endif
15362306a36Sopenharmony_ci	// Optional caller-saved registers used by default by the compiler:
15462306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
15562306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
15662306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+0
15762306a36Sopenharmony_ci	wsr	\at1, ACCLO			// MAC16 option
15862306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+4
15962306a36Sopenharmony_ci	wsr	\at1, ACCHI			// MAC16 option
16062306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
16162306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
16262306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
16362306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
16462306a36Sopenharmony_ci	.endif
16562306a36Sopenharmony_ci	// Optional caller-saved registers not used by default by the compiler:
16662306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
16762306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
16862306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+0
16962306a36Sopenharmony_ci	wsr	\at1, M0			// MAC16 option
17062306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+4
17162306a36Sopenharmony_ci	wsr	\at1, M1			// MAC16 option
17262306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+8
17362306a36Sopenharmony_ci	wsr	\at1, M2			// MAC16 option
17462306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+12
17562306a36Sopenharmony_ci	wsr	\at1, M3			// MAC16 option
17662306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+16
17762306a36Sopenharmony_ci	wsr	\at1, SCOMPARE1			// conditional store option
17862306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
17962306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
18062306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
18162306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
18262306a36Sopenharmony_ci	.endif
18362306a36Sopenharmony_ci    .endm	// xchal_ncp_load
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci#define XCHAL_NCP_NUM_ATMPS	1
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define XCHAL_SA_NUM_ATMPS	1
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#endif /*_XTENSA_CORE_TIE_ASM_H*/
19362306a36Sopenharmony_ci
194