xtensa_vector_defaults.S 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "xtensa_rtos.h"
  7. #include "esp_private/panic_reason.h"
  8. #include "sdkconfig.h"
  9. #include "soc/soc.h"
  10. /*
  11. This file contains the default handlers for the high interrupt levels as well as some specialized exceptions.
  12. The default behaviour is to just exit the interrupt or call the panic handler on the exceptions
  13. */
  14. #if XCHAL_HAVE_DEBUG
  15. .global xt_debugexception
  16. .weak xt_debugexception
  17. .set xt_debugexception, _xt_debugexception
  18. .section .iram1,"ax"
  19. .type _xt_debugexception,@function
  20. .align 4
  21. _xt_debugexception:
  22. #if (CONFIG_ESP32_ECO3_CACHE_LOCK_FIX && CONFIG_BTDM_CTRL_HLI)
  23. s32i a0, sp, XT_STK_EXIT
  24. #define XT_DEBUGCAUSE_DI (5)
  25. getcoreid a0
  26. #if (CONFIG_BTDM_CTRL_PINNED_TO_CORE == PRO_CPU_NUM)
  27. beqz a0, 1f
  28. #else
  29. bnez a0, 1f
  30. #endif
  31. rsr a0, DEBUGCAUSE
  32. extui a0, a0, XT_DEBUGCAUSE_DI, 1
  33. bnez a0, _xt_debug_di_exc
  34. 1:
  35. #endif //(CONFIG_ESP32_ECO3_CACHE_LOCK_FIX && CONFIG_BTDM_CTRL_HLI)
  36. movi a0,PANIC_RSN_DEBUGEXCEPTION
  37. wsr a0,EXCCAUSE
  38. /* _xt_panic assumes a level 1 exception. As we're
  39. crashing anyhow, copy EPC & EXCSAVE from DEBUGLEVEL
  40. to level 1. */
  41. rsr a0,(EPC + XCHAL_DEBUGLEVEL)
  42. wsr a0,EPC_1
  43. rsr a0,(EXCSAVE + XCHAL_DEBUGLEVEL)
  44. wsr a0,EXCSAVE_1
  45. #if CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  46. J _xt_panic_gdbstub /* For gdbstub we make jump */
  47. #else
  48. call0 _xt_panic /* does not return */
  49. #endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  50. rfi XCHAL_DEBUGLEVEL
  51. #if (CONFIG_ESP32_ECO3_CACHE_LOCK_FIX && CONFIG_BTDM_CTRL_HLI)
  52. .align 4
  53. _xt_debug_di_exc:
  54. /*
  55. The delay time can be calculated by the following formula:
  56. T = ceil(0.25 + max(t1, t2)) us
  57. t1 = 80 / f1, t2 = (1 + 14/N) * 20 / f2
  58. f1: PSRAM access frequency, unit: MHz.
  59. f2: Flash access frequency, unit: MHz.
  60. When flash is slow/fast read, N = 1.
  61. When flash is DOUT/DIO read, N = 2.
  62. When flash is QOUT/QIO read, N = 4.
  63. And after testing, when CPU frequency is 240 MHz, it will take 1us to loop 27 times.
  64. */
  65. #if defined(CONFIG_ESPTOOLPY_FLASHMODE_QIO) || defined(CONFIG_ESPTOOLPY_FLASHMODE_QOUT)
  66. # if defined(CONFIG_ESPTOOLPY_FLASHFREQ_80M) && defined(CONFIG_SPIRAM_SPEED_80M)
  67. movi a0, 54
  68. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_80M) && defined(CONFIG_SPIRAM_SPEED_40M)
  69. movi a0, 81
  70. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_40M) && defined(CONFIG_SPIRAM_SPEED_40M)
  71. movi a0, 81
  72. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_26M) && defined(CONFIG_SPIRAM_SPEED_40M)
  73. movi a0, 108
  74. # else
  75. movi a0, 135
  76. # endif
  77. #elif defined(CONFIG_ESPTOOLPY_FLASHMODE_DIO) || defined(CONFIG_ESPTOOLPY_FLASHMODE_DOUT)
  78. # if defined(CONFIG_ESPTOOLPY_FLASHFREQ_80M) && defined(CONFIG_SPIRAM_SPEED_80M)
  79. movi a0, 81
  80. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_80M) && defined(CONFIG_SPIRAM_SPEED_40M)
  81. movi a0, 81
  82. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_40M) && defined(CONFIG_SPIRAM_SPEED_40M)
  83. movi a0, 135
  84. # elif defined(CONFIG_ESPTOOLPY_FLASHFREQ_26M) && defined(CONFIG_SPIRAM_SPEED_40M)
  85. movi a0, 189
  86. # else
  87. movi a0, 243
  88. # endif
  89. #else
  90. movi a0, 243
  91. #endif
  92. 1: addi a0, a0, -1 /* delay_us(N) */
  93. .rept 4
  94. nop
  95. .endr
  96. bnez a0, 1b
  97. rsr a0, EXCSAVE+XCHAL_DEBUGLEVEL
  98. rfi XCHAL_DEBUGLEVEL
  99. #endif //(CONFIG_ESP32_ECO3_CACHE_LOCK_FIX && CONFIG_BTDM_CTRL_HLI)
  100. #endif /* Debug exception */
  101. #if XCHAL_NUM_INTLEVELS >=2 && XCHAL_EXCM_LEVEL <2 && XCHAL_DEBUGLEVEL !=2
  102. .global xt_highint2
  103. .weak xt_highint2
  104. .set xt_highint2, _xt_highint2
  105. .section .iram1,"ax"
  106. .type _xt_highint2,@function
  107. .align 4
  108. _xt_highint2:
  109. /* Default handler does nothing; just returns */
  110. .align 4
  111. .L_xt_highint2_exit:
  112. rsr a0, EXCSAVE_2 /* restore a0 */
  113. rfi 2
  114. #endif /* Level 2 */
  115. #if XCHAL_NUM_INTLEVELS >=3 && XCHAL_EXCM_LEVEL <3 && XCHAL_DEBUGLEVEL !=3
  116. .global xt_highint3
  117. .weak xt_highint3
  118. .set xt_highint3, _xt_highint3
  119. .section .iram1,"ax"
  120. .type _xt_highint3,@function
  121. .align 4
  122. _xt_highint3:
  123. /* Default handler does nothing; just returns */
  124. .align 4
  125. .L_xt_highint3_exit:
  126. rsr a0, EXCSAVE_3 /* restore a0 */
  127. rfi 3
  128. #endif /* Level 3 */
  129. #if XCHAL_NUM_INTLEVELS >=4 && XCHAL_EXCM_LEVEL <4 && XCHAL_DEBUGLEVEL !=4
  130. .global xt_highint4
  131. .weak xt_highint4
  132. .set xt_highint4, _xt_highint4
  133. .section .iram1,"ax"
  134. .type _xt_highint4,@function
  135. .align 4
  136. _xt_highint4:
  137. /* Default handler does nothing; just returns */
  138. .align 4
  139. .L_xt_highint4_exit:
  140. rsr a0, EXCSAVE_4 /* restore a0 */
  141. rfi 4
  142. #endif /* Level 4 */
  143. #if XCHAL_NUM_INTLEVELS >=5 && XCHAL_EXCM_LEVEL <5 && XCHAL_DEBUGLEVEL !=5
  144. .global xt_highint5
  145. .weak xt_highint5
  146. .set xt_highint5, _xt_highint5
  147. .section .iram1,"ax"
  148. .type _xt_highint5,@function
  149. .align 4
  150. _xt_highint5:
  151. /* Default handler does nothing; just returns */
  152. .align 4
  153. .L_xt_highint5_exit:
  154. rsr a0, EXCSAVE_5 /* restore a0 */
  155. rfi 5
  156. #endif /* Level 5 */
  157. #if XCHAL_NUM_INTLEVELS >=6 && XCHAL_EXCM_LEVEL <6 && XCHAL_DEBUGLEVEL !=6
  158. .global _xt_highint6
  159. .global xt_highint6
  160. .weak xt_highint6
  161. .set xt_highint6, _xt_highint6
  162. .section .iram1,"ax"
  163. .type _xt_highint6,@function
  164. .align 4
  165. _xt_highint6:
  166. /* Default handler does nothing; just returns */
  167. .align 4
  168. .L_xt_highint6_exit:
  169. rsr a0, EXCSAVE_6 /* restore a0 */
  170. rfi 6
  171. #endif /* Level 6 */
  172. #if XCHAL_HAVE_NMI
  173. .global _xt_nmi
  174. .global xt_nmi
  175. .weak xt_nmi
  176. .set xt_nmi, _xt_nmi
  177. .section .iram1,"ax"
  178. .type _xt_nmi,@function
  179. .align 4
  180. _xt_nmi:
  181. /* Default handler does nothing; just returns */
  182. .align 4
  183. .L_xt_nmi_exit:
  184. rsr a0, EXCSAVE + XCHAL_NMILEVEL /* restore a0 */
  185. rfi XCHAL_NMILEVEL
  186. #endif /* NMI */