unwind-c6x.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* C6X EABI compliant unwinding routines.
  2. Copyright (C) 2011-2022 Free Software Foundation, Inc.
  3. This file is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 3, or (at your option) any
  6. later version.
  7. This file is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #include "unwind.h"
  19. /* Misc constants. */
  20. #define NUM_SAVED_REGS 32
  21. #define R_B0 16
  22. #define R_B3 (R_B0 + 3)
  23. #define R_B15 (R_B0 + 15)
  24. #define R_SP R_B15
  25. #define R_LR R_B3
  26. #define R_PC 33
  27. #define VRS_PC(vrs) ((vrs)->core.pc)
  28. #define VRS_SP(vrs) ((vrs)->core.reg[R_SP])
  29. #define VRS_RETURN(vrs) ((vrs)->core.reg[R_B3])
  30. struct core_regs
  31. {
  32. _uw reg[NUM_SAVED_REGS];
  33. _uw pc;
  34. };
  35. typedef struct
  36. {
  37. /* The first fields must be the same as a phase2_vrs. */
  38. _uw demand_save_flags; /* Currently always zero. */
  39. struct core_regs core;
  40. _uw prev_sp; /* Only valid during forced unwinding. */
  41. } phase1_vrs;
  42. /* This must match the structure created by the assembly wrappers. */
  43. typedef struct
  44. {
  45. _uw demand_save_flags;
  46. struct core_regs core;
  47. } phase2_vrs;
  48. /* Coprocessor register state manipulation functions. */
  49. /* Restore coprocessor state after phase1 unwinding. */
  50. static void
  51. restore_non_core_regs (phase1_vrs * vrs __attribute__((unused)))
  52. {
  53. }
  54. #include "unwind-arm-common.inc"
  55. /* ABI defined personality routines. */
  56. extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr0 (_Unwind_State,
  57. _Unwind_Control_Block *, _Unwind_Context *);// __attribute__((weak));
  58. extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr1 (_Unwind_State,
  59. _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
  60. extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr2 (_Unwind_State,
  61. _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
  62. extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr3 (_Unwind_State,
  63. _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
  64. extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr4 (_Unwind_State,
  65. _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
  66. /* ABI defined routine to store a virtual register to memory. */
  67. _Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context,
  68. _Unwind_VRS_RegClass regclass,
  69. _uw regno,
  70. _Unwind_VRS_DataRepresentation representation,
  71. void *valuep)
  72. {
  73. phase1_vrs *vrs = (phase1_vrs *) context;
  74. switch (regclass)
  75. {
  76. case _UVRSC_CORE:
  77. if (representation != _UVRSD_UINT32)
  78. return _UVRSR_FAILED;
  79. if (regno == R_PC)
  80. {
  81. *(_uw *) valuep = vrs->core.pc;
  82. return _UVRSR_OK;
  83. }
  84. if (regno >= NUM_SAVED_REGS)
  85. return _UVRSR_FAILED;
  86. *(_uw *) valuep = vrs->core.reg[regno];
  87. return _UVRSR_OK;
  88. default:
  89. return _UVRSR_FAILED;
  90. }
  91. }
  92. /* ABI defined function to load a virtual register from memory. */
  93. _Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context,
  94. _Unwind_VRS_RegClass regclass,
  95. _uw regno,
  96. _Unwind_VRS_DataRepresentation representation,
  97. void *valuep)
  98. {
  99. phase1_vrs *vrs = (phase1_vrs *) context;
  100. switch (regclass)
  101. {
  102. case _UVRSC_CORE:
  103. if (representation != _UVRSD_UINT32)
  104. return _UVRSR_FAILED;
  105. if (regno == R_PC)
  106. {
  107. vrs->core.pc = *(_uw *) valuep;
  108. return _UVRSR_OK;
  109. }
  110. if (regno >= NUM_SAVED_REGS)
  111. return _UVRSR_FAILED;
  112. vrs->core.reg[regno] = *(_uw *) valuep;
  113. return _UVRSR_OK;
  114. default:
  115. return _UVRSR_FAILED;
  116. }
  117. }
  118. /* Core unwinding functions. */
  119. /* Calculate the address encoded by a 31-bit self-relative offset at address
  120. P. */
  121. static inline _uw
  122. selfrel_offset31 (const _uw *p)
  123. {
  124. _uw offset;
  125. offset = *p << 1;
  126. return offset + (_uw) p;
  127. }
  128. static _uw
  129. __gnu_unwind_get_pr_addr (int idx)
  130. {
  131. switch (idx)
  132. {
  133. case 0:
  134. return (_uw) &__c6xabi_unwind_cpp_pr0;
  135. case 1:
  136. return (_uw) &__c6xabi_unwind_cpp_pr1;
  137. case 2:
  138. return (_uw) &__c6xabi_unwind_cpp_pr2;
  139. case 3:
  140. return (_uw) &__c6xabi_unwind_cpp_pr3;
  141. case 4:
  142. return (_uw) &__c6xabi_unwind_cpp_pr4;
  143. default:
  144. return 0;
  145. }
  146. }
  147. /* ABI defined personality routine entry points. */
  148. _Unwind_Reason_Code
  149. __c6xabi_unwind_cpp_pr0 (_Unwind_State state,
  150. _Unwind_Control_Block *ucbp,
  151. _Unwind_Context *context)
  152. {
  153. return __gnu_unwind_pr_common (state, ucbp, context, 0);
  154. }
  155. _Unwind_Reason_Code
  156. __c6xabi_unwind_cpp_pr1 (_Unwind_State state,
  157. _Unwind_Control_Block *ucbp,
  158. _Unwind_Context *context)
  159. {
  160. return __gnu_unwind_pr_common (state, ucbp, context, 1);
  161. }
  162. _Unwind_Reason_Code
  163. __c6xabi_unwind_cpp_pr2 (_Unwind_State state,
  164. _Unwind_Control_Block *ucbp,
  165. _Unwind_Context *context)
  166. {
  167. return __gnu_unwind_pr_common (state, ucbp, context, 2);
  168. }
  169. _Unwind_Reason_Code
  170. __c6xabi_unwind_cpp_pr3 (_Unwind_State state,
  171. _Unwind_Control_Block *ucbp,
  172. _Unwind_Context *context)
  173. {
  174. return __gnu_unwind_pr_common (state, ucbp, context, 3);
  175. }
  176. _Unwind_Reason_Code
  177. __c6xabi_unwind_cpp_pr4 (_Unwind_State state,
  178. _Unwind_Control_Block *ucbp,
  179. _Unwind_Context *context)
  180. {
  181. return __gnu_unwind_pr_common (state, ucbp, context, 4);
  182. }