xtruntime-frames.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. * Copyright (c) 2002-2012 Tensilica Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef _XTRUNTIME_FRAMES_H_
  26. #define _XTRUNTIME_FRAMES_H_
  27. #include <xtensa/config/core.h>
  28. /* Macros that help define structures for both C and assembler: */
  29. #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__)
  30. #ifdef __clang__
  31. #define STRUCT_BEGIN .set XT_STRUCT_OFFSET, 0
  32. #define STRUCT_FIELD(ctype,size,pre,name) .set pre##name, XT_STRUCT_OFFSET; .set XT_STRUCT_OFFSET, pre##name + size
  33. #define STRUCT_AFIELD(ctype,size,pre,name,n) .set pre##name, XT_STRUCT_OFFSET;\
  34. .set XT_STRUCT_OFFSET, pre##name + (size)*(n);
  35. #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) .set pre##name, XT_STRUCT_OFFSET\
  36. .ifgt (align-1); .set pre##name, XT_STRUCT_OFFSET + (align - (XT_STRUCT_OFFSET & (align-1))); .endif\
  37. .set XT_STRUCT_OFFSET, pre##name + (size)*(n);
  38. #define STRUCT_END(sname) .set sname##Size, XT_STRUCT_OFFSET;
  39. #else /* __clang__ */
  40. #define STRUCT_BEGIN .pushsection .text; .struct 0
  41. #define STRUCT_FIELD(ctype,size,pre,name) pre##name: .space size
  42. #define STRUCT_AFIELD(ctype,size,pre,name,n) pre##name: .if n ; .space (size)*(n) ; .endif
  43. #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) .balign align ; pre##name: .if n ; .space (size)*(n) ; .endif
  44. #define STRUCT_END(sname) sname##Size:; .popsection
  45. #endif /* __clang__ */
  46. #else /*_ASMLANGUAGE||__ASSEMBLER__*/
  47. #define STRUCT_BEGIN typedef struct {
  48. #define STRUCT_FIELD(ctype,size,pre,name) ctype name;
  49. #define STRUCT_AFIELD(ctype,size,pre,name,n) ctype name[n];
  50. #define STRUCT_AFIELD_A(ctype,size,align,pre,name,n) ctype name[n] __attribute__((aligned(align)));
  51. #define STRUCT_END(sname) } sname;
  52. #endif /*_ASMLANGUAGE||__ASSEMBLER__*/
  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. * User vector mode exception stack frame:
  79. *
  80. * WARNING: if you modify this structure, you MUST modify the
  81. * computation of the pad size (ALIGNPAD) accordingly.
  82. */
  83. STRUCT_BEGIN
  84. STRUCT_FIELD (long,4,UEXC_,pc)
  85. STRUCT_FIELD (long,4,UEXC_,ps)
  86. STRUCT_FIELD (long,4,UEXC_,sar)
  87. STRUCT_FIELD (long,4,UEXC_,vpri)
  88. #ifdef __XTENSA_CALL0_ABI__
  89. STRUCT_FIELD (long,4,UEXC_,a0)
  90. #endif
  91. STRUCT_FIELD (long,4,UEXC_,a2)
  92. STRUCT_FIELD (long,4,UEXC_,a3)
  93. STRUCT_FIELD (long,4,UEXC_,a4)
  94. STRUCT_FIELD (long,4,UEXC_,a5)
  95. #ifdef __XTENSA_CALL0_ABI__
  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. #endif
  107. STRUCT_FIELD (long,4,UEXC_,exccause) /* NOTE: can probably rid of this one (pass direct) */
  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. #endif
  113. #if XCHAL_HAVE_MAC16
  114. STRUCT_FIELD (long,4,UEXC_,acclo)
  115. STRUCT_FIELD (long,4,UEXC_,acchi)
  116. STRUCT_AFIELD(long,4,UEXC_,mr, 4)
  117. #endif
  118. /* ALIGNPAD is the 16-byte alignment padding. */
  119. #ifdef __XTENSA_CALL0_ABI__
  120. # define CALL0_ABI 1
  121. #else
  122. # define CALL0_ABI 0
  123. #endif
  124. #define ALIGNPAD ((3 + XCHAL_HAVE_LOOPS*1 + XCHAL_HAVE_MAC16*2 + CALL0_ABI*1) & 3)
  125. #if ALIGNPAD
  126. STRUCT_AFIELD(long,4,UEXC_,pad, ALIGNPAD) /* 16-byte alignment padding */
  127. #endif
  128. /*STRUCT_AFIELD_A(char,1,XCHAL_CPEXTRA_SA_ALIGN,UEXC_,ureg, (XCHAL_CPEXTRA_SA_SIZE+3)&-4)*/ /* not used */
  129. STRUCT_END(UserFrame)
  130. #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__)
  131. /* Check for UserFrameSize small enough not to require rounding...: */
  132. /* Skip 16-byte save area, then 32-byte space for 8 regs of call12
  133. * (which overlaps with 16-byte GCC nested func chaining area),
  134. * then exception stack frame: */
  135. .set UserFrameTotalSize, 16+32+UserFrameSize
  136. /* Greater than 112 bytes? (max range of ADDI, both signs, when aligned to 16 bytes): */
  137. .ifgt UserFrameTotalSize-112
  138. /* Round up to 256-byte multiple to accelerate immediate adds: */
  139. .set UserFrameTotalSize, ((UserFrameTotalSize+255) & 0xFFFFFF00)
  140. .endif
  141. # define ESF_TOTALSIZE UserFrameTotalSize
  142. #endif /* _ASMLANGUAGE || __ASSEMBLER__ */
  143. #if XCHAL_NUM_CONTEXTS > 1
  144. /* Structure of info stored on new context's stack for setup: */
  145. STRUCT_BEGIN
  146. STRUCT_FIELD (long,4,INFO_,sp)
  147. STRUCT_FIELD (long,4,INFO_,arg1)
  148. STRUCT_FIELD (long,4,INFO_,funcpc)
  149. STRUCT_FIELD (long,4,INFO_,prevps)
  150. STRUCT_END(SetupInfo)
  151. #endif
  152. #define KERNELSTACKSIZE 1024
  153. #endif /* _XTRUNTIME_FRAMES_H_ */