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-2015 Cadence Design Systems 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      *  Macro to store all non-coprocessor (extra) custom TIE and optional state
5862306a36Sopenharmony_ci      *  (not including zero-overhead loop registers).
5962306a36Sopenharmony_ci      *  Required parameters:
6062306a36Sopenharmony_ci      *      ptr         Save area pointer address register (clobbered)
6162306a36Sopenharmony_ci      *                  (register must contain a 4 byte aligned address).
6262306a36Sopenharmony_ci      *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
6362306a36Sopenharmony_ci      *                  registers are clobbered, the remaining are unused).
6462306a36Sopenharmony_ci      *  Optional parameters:
6562306a36Sopenharmony_ci      *      continue    If macro invoked as part of a larger store sequence, set to 1
6662306a36Sopenharmony_ci      *                  if this is not the first in the sequence.  Defaults to 0.
6762306a36Sopenharmony_ci      *      ofs         Offset from start of larger sequence (from value of first ptr
6862306a36Sopenharmony_ci      *                  in sequence) at which to store.  Defaults to next available space
6962306a36Sopenharmony_ci      *                  (or 0 if <continue> is 0).
7062306a36Sopenharmony_ci      *      select      Select what category(ies) of registers to store, as a bitmask
7162306a36Sopenharmony_ci      *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
7262306a36Sopenharmony_ci      *      alloc       Select what category(ies) of registers to allocate; if any
7362306a36Sopenharmony_ci      *                  category is selected here that is not in <select>, space for
7462306a36Sopenharmony_ci      *                  the corresponding registers is skipped without doing any store.
7562306a36Sopenharmony_ci      */
7662306a36Sopenharmony_ci    .macro xchal_ncp_store  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
7762306a36Sopenharmony_ci	xchal_sa_start	\continue, \ofs
7862306a36Sopenharmony_ci	// Optional caller-saved registers used by default by the compiler:
7962306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
8062306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
8162306a36Sopenharmony_ci	rsr.ACCLO	\at1		// MAC16 option
8262306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+0
8362306a36Sopenharmony_ci	rsr.ACCHI	\at1		// MAC16 option
8462306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+4
8562306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
8662306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
8762306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
8862306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
8962306a36Sopenharmony_ci	.endif
9062306a36Sopenharmony_ci	// Optional caller-saved registers not used by default by the compiler:
9162306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
9262306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
9362306a36Sopenharmony_ci	rsr.SCOMPARE1	\at1		// conditional store option
9462306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+0
9562306a36Sopenharmony_ci	rsr.M0	\at1		// MAC16 option
9662306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+4
9762306a36Sopenharmony_ci	rsr.M1	\at1		// MAC16 option
9862306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+8
9962306a36Sopenharmony_ci	rsr.M2	\at1		// MAC16 option
10062306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+12
10162306a36Sopenharmony_ci	rsr.M3	\at1		// MAC16 option
10262306a36Sopenharmony_ci	s32i	\at1, \ptr, .Lxchal_ofs_+16
10362306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
10462306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
10562306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
10662306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
10762306a36Sopenharmony_ci	.endif
10862306a36Sopenharmony_ci    .endm	// xchal_ncp_store
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci    /*
11162306a36Sopenharmony_ci      *  Macro to load all non-coprocessor (extra) custom TIE and optional state
11262306a36Sopenharmony_ci      *  (not including zero-overhead loop registers).
11362306a36Sopenharmony_ci      *  Required parameters:
11462306a36Sopenharmony_ci      *      ptr         Save area pointer address register (clobbered)
11562306a36Sopenharmony_ci      *                  (register must contain a 4 byte aligned address).
11662306a36Sopenharmony_ci      *      at1..at4    Four temporary address registers (first XCHAL_NCP_NUM_ATMPS
11762306a36Sopenharmony_ci      *                  registers are clobbered, the remaining are unused).
11862306a36Sopenharmony_ci      *  Optional parameters:
11962306a36Sopenharmony_ci      *      continue    If macro invoked as part of a larger load sequence, set to 1
12062306a36Sopenharmony_ci      *                  if this is not the first in the sequence.  Defaults to 0.
12162306a36Sopenharmony_ci      *      ofs         Offset from start of larger sequence (from value of first ptr
12262306a36Sopenharmony_ci      *                  in sequence) at which to load.  Defaults to next available space
12362306a36Sopenharmony_ci      *                  (or 0 if <continue> is 0).
12462306a36Sopenharmony_ci      *      select      Select what category(ies) of registers to load, as a bitmask
12562306a36Sopenharmony_ci      *                  (see XTHAL_SAS_xxx constants).  Defaults to all registers.
12662306a36Sopenharmony_ci      *      alloc       Select what category(ies) of registers to allocate; if any
12762306a36Sopenharmony_ci      *                  category is selected here that is not in <select>, space for
12862306a36Sopenharmony_ci      *                  the corresponding registers is skipped without doing any load.
12962306a36Sopenharmony_ci      */
13062306a36Sopenharmony_ci    .macro xchal_ncp_load  ptr at1 at2 at3 at4  continue=0 ofs=-1 select=XTHAL_SAS_ALL alloc=0
13162306a36Sopenharmony_ci	xchal_sa_start	\continue, \ofs
13262306a36Sopenharmony_ci	// Optional caller-saved registers used by default by the compiler:
13362306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\select)
13462306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
13562306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+0
13662306a36Sopenharmony_ci	wsr.ACCLO	\at1		// MAC16 option
13762306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+4
13862306a36Sopenharmony_ci	wsr.ACCHI	\at1		// MAC16 option
13962306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
14062306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_CC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
14162306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1016, 4, 4
14262306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 8
14362306a36Sopenharmony_ci	.endif
14462306a36Sopenharmony_ci	// Optional caller-saved registers not used by default by the compiler:
14562306a36Sopenharmony_ci	.ifeq (XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\select)
14662306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
14762306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+0
14862306a36Sopenharmony_ci	wsr.SCOMPARE1	\at1		// conditional store option
14962306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+4
15062306a36Sopenharmony_ci	wsr.M0	\at1		// MAC16 option
15162306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+8
15262306a36Sopenharmony_ci	wsr.M1	\at1		// MAC16 option
15362306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+12
15462306a36Sopenharmony_ci	wsr.M2	\at1		// MAC16 option
15562306a36Sopenharmony_ci	l32i	\at1, \ptr, .Lxchal_ofs_+16
15662306a36Sopenharmony_ci	wsr.M3	\at1		// MAC16 option
15762306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
15862306a36Sopenharmony_ci	.elseif ((XTHAL_SAS_OPT | XTHAL_SAS_NOCC | XTHAL_SAS_CALR) & ~(\alloc)) == 0
15962306a36Sopenharmony_ci	xchal_sa_align	\ptr, 0, 1004, 4, 4
16062306a36Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + 20
16162306a36Sopenharmony_ci	.endif
16262306a36Sopenharmony_ci    .endm	// xchal_ncp_load
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci#define XCHAL_NCP_NUM_ATMPS	1
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define XCHAL_SA_NUM_ATMPS	1
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#endif /*_XTENSA_CORE_TIE_ASM_H*/
17062306a36Sopenharmony_ci
171