1 /* xtruntime-frames.h - exception stack frames for single-threaded run-time */ 2 /* $Id: //depot/rel/Foxhill/dot.8/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 #define STRUCT_BEGIN .pushsection .text; .struct 0 35 #define STRUCT_FIELD(ctype,size,pre,name) pre##name: .space size 36 #define STRUCT_AFIELD(ctype,size,pre,name,n) pre##name: .if n ; .space (size)*(n) ; .endif 37 #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) .balign align ; pre##name: .if n ; .space (size)*(n) ; .endif 38 #define STRUCT_END(sname) sname##Size:; .popsection 39 #else /*_ASMLANGUAGE||__ASSEMBLER__*/ 40 #define STRUCT_BEGIN typedef struct { 41 #define STRUCT_FIELD(ctype,size,pre,name) ctype name; 42 #define STRUCT_AFIELD(ctype,size,pre,name,n) ctype name[n]; 43 #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) ctype name[n] __attribute__((aligned(align))); 44 #define STRUCT_END(sname) } sname; 45 #endif /*_ASMLANGUAGE||__ASSEMBLER__*/ 46 47 /* Coprocessors masks. 48 * NOTE: currently only 2 supported. 49 */ 50 #define CP0_MASK (1 << 0) 51 #define CP1_MASK (1 << 1) 52 53 /* 54 * Kernel vector mode exception stack frame. 55 * 56 * NOTE: due to the limited range of addi used in the current 57 * kernel exception vector, and the fact that historically 58 * the vector is limited to 12 bytes, the size of this 59 * stack frame is limited to 128 bytes (currently at 64). 60 */ 61 STRUCT_BEGIN 62 STRUCT_FIELD (long,4,KEXC_,pc) /* "parm" */ 63 STRUCT_FIELD (long,4,KEXC_,ps) 64 STRUCT_AFIELD(long,4,KEXC_,areg, 4) /* a12 .. a15 */ 65 STRUCT_FIELD (long,4,KEXC_,sar) /* "save" */ 66 #if XCHAL_HAVE_LOOPS 67 STRUCT_FIELD (long,4,KEXC_,lcount) 68 STRUCT_FIELD (long,4,KEXC_,lbeg) 69 STRUCT_FIELD (long,4,KEXC_,lend) 70 #endif 71 #if XCHAL_HAVE_MAC16 72 STRUCT_FIELD (long,4,KEXC_,acclo) 73 STRUCT_FIELD (long,4,KEXC_,acchi) 74 STRUCT_AFIELD(long,4,KEXC_,mr, 4) 75 #endif 76 STRUCT_END(KernelFrame) 77 78 79 /* 80 * User vector mode exception stack frame: 81 * 82 * WARNING: if you modify this structure, you MUST modify the 83 * computation of the pad size (ALIGNPAD) accordingly. 84 */ 85 STRUCT_BEGIN 86 STRUCT_FIELD (long,4,UEXC_,pc) 87 STRUCT_FIELD (long,4,UEXC_,ps) 88 STRUCT_FIELD (long,4,UEXC_,sar) 89 STRUCT_FIELD (long,4,UEXC_,vpri) 90 STRUCT_FIELD (long,4,UEXC_,a0) 91 STRUCT_FIELD (long,4,UEXC_,a1) 92 STRUCT_FIELD (long,4,UEXC_,a2) 93 STRUCT_FIELD (long,4,UEXC_,a3) 94 STRUCT_FIELD (long,4,UEXC_,a4) 95 STRUCT_FIELD (long,4,UEXC_,a5) 96 STRUCT_FIELD (long,4,UEXC_,a6) 97 STRUCT_FIELD (long,4,UEXC_,a7) 98 STRUCT_FIELD (long,4,UEXC_,a8) 99 STRUCT_FIELD (long,4,UEXC_,a9) 100 STRUCT_FIELD (long,4,UEXC_,a10) 101 STRUCT_FIELD (long,4,UEXC_,a11) 102 STRUCT_FIELD (long,4,UEXC_,a12) 103 STRUCT_FIELD (long,4,UEXC_,a13) 104 STRUCT_FIELD (long,4,UEXC_,a14) 105 STRUCT_FIELD (long,4,UEXC_,a15) 106 STRUCT_FIELD (long,4,UEXC_,exccause) /* NOTE: can probably rid of this one (pass direct) */ 107 STRUCT_FIELD (long,4,UEXC_,align1) /* alignment to 8 bytes */ 108 #if XCHAL_HAVE_LOOPS 109 STRUCT_FIELD (long,4,UEXC_,lcount) 110 STRUCT_FIELD (long,4,UEXC_,lbeg) 111 STRUCT_FIELD (long,4,UEXC_,lend) 112 STRUCT_FIELD (long,4,UEXC_,align2) /* alignment to 8 bytes */ 113 #endif 114 #if XCHAL_HAVE_MAC16 115 STRUCT_FIELD (long,4,UEXC_,acclo) 116 STRUCT_FIELD (long,4,UEXC_,acchi) 117 STRUCT_AFIELD(long,4,UEXC_,mr, 4) 118 #endif 119 #if (XCHAL_CP_MASK & CP0_MASK) 120 STRUCT_AFIELD (long,4,UEXC_,cp0, XCHAL_CP0_SA_SIZE / 4) 121 #endif 122 #if (XCHAL_CP_MASK & CP1_MASK) 123 STRUCT_AFIELD (long,4,UEXC_,cp1, XCHAL_CP1_SA_SIZE / 4) 124 #endif 125 /* ALIGNPAD is the 16-byte alignment padding. */ 126 #define ALIGNPAD ((2 + XCHAL_HAVE_MAC16*2 + ((XCHAL_CP0_SA_SIZE%16)/4) + ((XCHAL_CP1_SA_SIZE%16)/4)) & 3) 127 #if ALIGNPAD 128 STRUCT_AFIELD(long,4,UEXC_,pad, ALIGNPAD) /* 16-byte alignment padding */ 129 #endif 130 /*STRUCT_AFIELD_A(char,1,XCHAL_CPEXTRA_SA_ALIGN,UEXC_,ureg, (XCHAL_CPEXTRA_SA_SIZE+3)&-4)*/ /* not used */ 131 STRUCT_END(UserFrame) 132 133 /* 134 * xtos_structures_pointers contains ptrs to all structures created for 135 * each processor individually. 136 * 137 * To access the core specific structure from ASM (after threadptr is set): 138 * xtos_addr_percore a13, xtos_interrupt_table 139 */ 140 STRUCT_BEGIN 141 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_enabled) 142 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_intstruct) 143 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_interrupt_table) 144 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_interrupt_mask_table) 145 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_stack_for_interrupt_1) 146 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_stack_for_interrupt_2) 147 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_stack_for_interrupt_3) 148 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_stack_for_interrupt_4) 149 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_stack_for_interrupt_5) 150 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_interrupt_ctx) 151 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_saved_ctx) 152 STRUCT_FIELD(void*,4,XTOS_PTR_TO_,xtos_saved_sp) 153 STRUCT_END(xtos_structures_pointers) 154 155 /* 156 * xtos_task_context contains information about currently 157 * executed task 158 */ 159 160 #define XTOS_TASK_CONTEXT_OWN_STACK 1 161 162 STRUCT_BEGIN 163 STRUCT_FIELD (UserFrame*,4,TC_,stack_pointer) 164 STRUCT_FIELD (void*,4,TC_,stack_base) 165 STRUCT_FIELD (long,4,TC_,stack_size) 166 STRUCT_FIELD (long,4,TC_,flags) 167 STRUCT_END(xtos_task_context) 168 169 #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__) 170 171 172 /* Check for UserFrameSize small enough not to require rounding...: */ 173 /* Skip 16-byte save area, then 32-byte space for 8 regs of call12 174 * (which overlaps with 16-byte GCC nested func chaining area), 175 * then exception stack frame: */ 176 .set UserFrameTotalSize, 16+32+UserFrameSize 177 /* Greater than 112 bytes? (max range of ADDI, both signs, when aligned to 16 bytes): */ 178 .ifgt UserFrameTotalSize-112 179 /* Round up to 256-byte multiple to accelerate immediate adds: */ 180 .set UserFrameTotalSize, ((UserFrameTotalSize+255) & 0xFFFFFF00) 181 .endif 182 # define ESF_TOTALSIZE UserFrameTotalSize 183 184 #endif /* _ASMLANGUAGE || __ASSEMBLER__ */ 185 186 187 #if XCHAL_NUM_CONTEXTS > 1 188 /* Structure of info stored on new context's stack for setup: */ 189 STRUCT_BEGIN 190 STRUCT_FIELD (long,4,INFO_,sp) 191 STRUCT_FIELD (long,4,INFO_,arg1) 192 STRUCT_FIELD (long,4,INFO_,funcpc) 193 STRUCT_FIELD (long,4,INFO_,prevps) 194 STRUCT_END(SetupInfo) 195 #endif 196 197 198 #define KERNELSTACKSIZE 1024 199 200 201 #endif /* _XTRUNTIME_FRAMES_H_ */ 202 203