rvruntime-frames.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef __RVRUNTIME_FRAMES_H__
  15. #define __RVRUNTIME_FRAMES_H__
  16. /* Align a value up to nearest n-byte boundary, where n is a power of 2. */
  17. #define ALIGNUP(n, val) (((val) + (n) - 1) & -(n))
  18. #ifdef STRUCT_BEGIN
  19. #undef STRUCT_BEGIN
  20. #undef STRUCT_FIELD
  21. #undef STRUCT_AFIELD
  22. #undef STRUCT_END
  23. #endif
  24. #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__)
  25. #define STRUCT_BEGIN .pushsection .text; .struct 0
  26. #define STRUCT_FIELD(ctype,size,asname,name) asname: .space size
  27. #define STRUCT_AFIELD(ctype,size,asname,name,n) asname: .space (size)*(n)
  28. #define STRUCT_END(sname) sname##Size:; .popsection
  29. #else
  30. #define STRUCT_BEGIN typedef struct {
  31. #define STRUCT_FIELD(ctype,size,asname,name) ctype name;
  32. #define STRUCT_AFIELD(ctype,size,asname,name,n) ctype name[n];
  33. #define STRUCT_END(sname) } sname;
  34. #endif
  35. /*
  36. -------------------------------------------------------------------------------
  37. INTERRUPT/EXCEPTION STACK FRAME FOR A EXCEPTION OR NESTED INTERRUPT
  38. -------------------------------------------------------------------------------
  39. */
  40. STRUCT_BEGIN
  41. STRUCT_FIELD (long, 4, RV_STK_MEPC, mepc) /* Machine Exception Program Counter */
  42. STRUCT_FIELD (long, 4, RV_STK_RA, ra) /* Return address */
  43. STRUCT_FIELD (long, 4, RV_STK_SP, sp) /* Stack pointer */
  44. STRUCT_FIELD (long, 4, RV_STK_GP, gp) /* Global pointer */
  45. STRUCT_FIELD (long, 4, RV_STK_TP, tp) /* Thread pointer */
  46. STRUCT_FIELD (long, 4, RV_STK_T0, t0) /* Temporary/alternate link register */
  47. STRUCT_FIELD (long, 4, RV_STK_T1, t1) /* t1-2: Temporaries */
  48. STRUCT_FIELD (long, 4, RV_STK_T2, t2)
  49. STRUCT_FIELD (long, 4, RV_STK_S0, s0) /* Saved register/frame pointer */
  50. STRUCT_FIELD (long, 4, RV_STK_S1, s1) /* Saved register */
  51. STRUCT_FIELD (long, 4, RV_STK_A0, a0) /* a0-1: Function arguments/return address */
  52. STRUCT_FIELD (long, 4, RV_STK_A1, a1)
  53. STRUCT_FIELD (long, 4, RV_STK_A2, a2) /* a2-7: Function arguments */
  54. STRUCT_FIELD (long, 4, RV_STK_A3, a3)
  55. STRUCT_FIELD (long, 4, RV_STK_A4, a4)
  56. STRUCT_FIELD (long, 4, RV_STK_A5, a5)
  57. STRUCT_FIELD (long, 4, RV_STK_A6, a6)
  58. STRUCT_FIELD (long, 4, RV_STK_A7, a7)
  59. STRUCT_FIELD (long, 4, RV_STK_S2, s2) /* s2-11: Saved registers */
  60. STRUCT_FIELD (long, 4, RV_STK_S3, s3)
  61. STRUCT_FIELD (long, 4, RV_STK_S4, s4)
  62. STRUCT_FIELD (long, 4, RV_STK_S5, s5)
  63. STRUCT_FIELD (long, 4, RV_STK_S6, s6)
  64. STRUCT_FIELD (long, 4, RV_STK_S7, s7)
  65. STRUCT_FIELD (long, 4, RV_STK_S8, s8)
  66. STRUCT_FIELD (long, 4, RV_STK_S9, s9)
  67. STRUCT_FIELD (long, 4, RV_STK_S10, s10)
  68. STRUCT_FIELD (long, 4, RV_STK_S11, s11)
  69. STRUCT_FIELD (long, 4, RV_STK_T3, t3) /* t3-6: Temporaries */
  70. STRUCT_FIELD (long, 4, RV_STK_T4, t4)
  71. STRUCT_FIELD (long, 4, RV_STK_T5, t5)
  72. STRUCT_FIELD (long, 4, RV_STK_T6, t6)
  73. STRUCT_FIELD (long, 4, RV_STK_MSTATUS, mstatus) /* Machine Status */
  74. STRUCT_FIELD (long, 4, RV_STK_MTVEC, mtvec) /* Machine Trap-Vector Base Address */
  75. STRUCT_FIELD (long, 4, RV_STK_MCAUSE, mcause) /* Machine Trap Cause */
  76. STRUCT_FIELD (long, 4, RV_STK_MTVAL, mtval) /* Machine Trap Value */
  77. STRUCT_FIELD (long, 4, RV_STK_MHARTID, mhartid) /* Hardware Thread ID in machine mode */
  78. STRUCT_END(RvExcFrame)
  79. #if defined(_ASMLANGUAGE) || defined(__ASSEMBLER__)
  80. #define RV_STK_SZ1 RvExcFrameSize
  81. #else
  82. #define RV_STK_SZ1 sizeof(RvExcFrame)
  83. #endif
  84. /*
  85. * Exception stack frame size, after align up to 16 bytes boundary
  86. */
  87. #define RV_STK_FRMSZ (ALIGNUP(0x10, RV_STK_SZ1))
  88. #endif /* #ifndef __RVRUNTIME_FRAMES_H__ */