1 /* xtruntime-frames.h - exception stack frames for single-threaded run-time */ 2 /* $Id: //depot/rel/Foxhill/dot.9/Xtensa/OS/include/xtensa/xtruntime-frames.h#1 $ */ 3 4 /* 5 * Copyright (c) 2002-2012 Tensilica Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included 16 * in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 27 #ifndef _XTRUNTIME_FRAMES_H_ 28 #define _XTRUNTIME_FRAMES_H_ 29 30 #include <xtensa/config/core.h> 31 32 /* Macros that help define structures for both C and assembler: */ 33 #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__) 34 35 #ifdef __clang__ 36 #define STRUCT_BEGIN .set XT_STRUCT_OFFSET, 0 37 #define STRUCT_FIELD(ctype,size,pre,name) .set pre##name, XT_STRUCT_OFFSET; .set XT_STRUCT_OFFSET, pre##name + size 38 #define STRUCT_AFIELD(ctype,size,pre,name,n) .set pre##name, XT_STRUCT_OFFSET;\ 39 .set XT_STRUCT_OFFSET, pre##name + (size)*(n); 40 #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) .set pre##name, XT_STRUCT_OFFSET\ 41 .ifgt (align-1); .set pre##name, XT_STRUCT_OFFSET + (align - (XT_STRUCT_OFFSET & (align-1))); .endif\ 42 .set XT_STRUCT_OFFSET, pre##name + (size)*(n); 43 #define STRUCT_END(sname) .set sname##Size, XT_STRUCT_OFFSET; 44 #else /* __clang__ */ 45 #define STRUCT_BEGIN .pushsection .text; .struct 0 46 #define STRUCT_FIELD(ctype,size,pre,name) pre##name: .space size 47 #define STRUCT_AFIELD(ctype,size,pre,name,n) pre##name: .if n ; .space (size)*(n) ; .endif 48 #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) .balign align ; pre##name: .if n ; .space (size)*(n) ; .endif 49 #define STRUCT_END(sname) sname##Size:; .popsection 50 #endif /* __clang__ */ 51 52 #else /*_ASMLANGUAGE||__ASSEMBLER__*/ 53 #define STRUCT_BEGIN typedef struct { 54 #define STRUCT_FIELD(ctype,size,pre,name) ctype name; 55 #define STRUCT_AFIELD(ctype,size,pre,name,n) ctype name[n]; 56 #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) ctype name[n] __attribute__((aligned(align))); 57 #define STRUCT_END(sname) } sname; 58 #endif /*_ASMLANGUAGE||__ASSEMBLER__*/ 59 60 61 /* 62 * Kernel vector mode exception stack frame. 63 * 64 * NOTE: due to the limited range of addi used in the current 65 * kernel exception vector, and the fact that historically 66 * the vector is limited to 12 bytes, the size of this 67 * stack frame is limited to 128 bytes (currently at 64). 68 */ 69 STRUCT_BEGIN 70 STRUCT_FIELD (long,4,KEXC_,pc) /* "parm" */ 71 STRUCT_FIELD (long,4,KEXC_,ps) 72 STRUCT_AFIELD(long,4,KEXC_,areg, 4) /* a12 .. a15 */ 73 STRUCT_FIELD (long,4,KEXC_,sar) /* "save" */ 74 #if XCHAL_HAVE_LOOPS 75 STRUCT_FIELD (long,4,KEXC_,lcount) 76 STRUCT_FIELD (long,4,KEXC_,lbeg) 77 STRUCT_FIELD (long,4,KEXC_,lend) 78 #endif 79 #if XCHAL_HAVE_MAC16 80 STRUCT_FIELD (long,4,KEXC_,acclo) 81 STRUCT_FIELD (long,4,KEXC_,acchi) 82 STRUCT_AFIELD(long,4,KEXC_,mr, 4) 83 #endif 84 STRUCT_END(KernelFrame) 85 86 87 /* 88 * User vector mode exception stack frame: 89 * 90 * WARNING: if you modify this structure, you MUST modify the 91 * computation of the pad size (ALIGNPAD) accordingly. 92 */ 93 STRUCT_BEGIN 94 STRUCT_FIELD (long,4,UEXC_,pc) 95 STRUCT_FIELD (long,4,UEXC_,ps) 96 STRUCT_FIELD (long,4,UEXC_,sar) 97 STRUCT_FIELD (long,4,UEXC_,vpri) 98 #ifdef __XTENSA_CALL0_ABI__ 99 STRUCT_FIELD (long,4,UEXC_,a0) 100 #endif 101 STRUCT_FIELD (long,4,UEXC_,a2) 102 STRUCT_FIELD (long,4,UEXC_,a3) 103 STRUCT_FIELD (long,4,UEXC_,a4) 104 STRUCT_FIELD (long,4,UEXC_,a5) 105 #ifdef __XTENSA_CALL0_ABI__ 106 STRUCT_FIELD (long,4,UEXC_,a6) 107 STRUCT_FIELD (long,4,UEXC_,a7) 108 STRUCT_FIELD (long,4,UEXC_,a8) 109 STRUCT_FIELD (long,4,UEXC_,a9) 110 STRUCT_FIELD (long,4,UEXC_,a10) 111 STRUCT_FIELD (long,4,UEXC_,a11) 112 STRUCT_FIELD (long,4,UEXC_,a12) 113 STRUCT_FIELD (long,4,UEXC_,a13) 114 STRUCT_FIELD (long,4,UEXC_,a14) 115 STRUCT_FIELD (long,4,UEXC_,a15) 116 #endif 117 STRUCT_FIELD (long,4,UEXC_,exccause) /* NOTE: can probably rid of this one (pass direct) */ 118 #if XCHAL_HAVE_LOOPS 119 STRUCT_FIELD (long,4,UEXC_,lcount) 120 STRUCT_FIELD (long,4,UEXC_,lbeg) 121 STRUCT_FIELD (long,4,UEXC_,lend) 122 #endif 123 #if XCHAL_HAVE_MAC16 124 STRUCT_FIELD (long,4,UEXC_,acclo) 125 STRUCT_FIELD (long,4,UEXC_,acchi) 126 STRUCT_AFIELD(long,4,UEXC_,mr, 4) 127 #endif 128 /* ALIGNPAD is the 16-byte alignment padding. */ 129 #ifdef __XTENSA_CALL0_ABI__ 130 # define CALL0_ABI 1 131 #else 132 # define CALL0_ABI 0 133 #endif 134 #define ALIGNPAD ((3 + XCHAL_HAVE_LOOPS*1 + XCHAL_HAVE_MAC16*2 + CALL0_ABI*1) & 3) 135 #if ALIGNPAD 136 STRUCT_AFIELD(long,4,UEXC_,pad, ALIGNPAD) /* 16-byte alignment padding */ 137 #endif 138 /*STRUCT_AFIELD_A(char,1,XCHAL_CPEXTRA_SA_ALIGN,UEXC_,ureg, (XCHAL_CPEXTRA_SA_SIZE+3)&-4)*/ /* not used */ 139 STRUCT_END(UserFrame) 140 141 142 #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__) 143 144 145 /* Check for UserFrameSize small enough not to require rounding...: */ 146 /* Skip 16-byte save area, then 32-byte space for 8 regs of call12 147 * (which overlaps with 16-byte GCC nested func chaining area), 148 * then exception stack frame: */ 149 .set UserFrameTotalSize, 16+32+UserFrameSize 150 /* Greater than 112 bytes? (max range of ADDI, both signs, when aligned to 16 bytes): */ 151 .ifgt UserFrameTotalSize-112 152 /* Round up to 256-byte multiple to accelerate immediate adds: */ 153 .set UserFrameTotalSize, ((UserFrameTotalSize+255) & 0xFFFFFF00) 154 .endif 155 # define ESF_TOTALSIZE UserFrameTotalSize 156 157 #endif /* _ASMLANGUAGE || __ASSEMBLER__ */ 158 159 160 #if XCHAL_NUM_CONTEXTS > 1 161 /* Structure of info stored on new context's stack for setup: */ 162 STRUCT_BEGIN 163 STRUCT_FIELD (long,4,INFO_,sp) 164 STRUCT_FIELD (long,4,INFO_,arg1) 165 STRUCT_FIELD (long,4,INFO_,funcpc) 166 STRUCT_FIELD (long,4,INFO_,prevps) 167 STRUCT_END(SetupInfo) 168 #endif 169 170 171 #define KERNELSTACKSIZE 1024 172 173 174 #endif /* _XTRUNTIME_FRAMES_H_ */ 175