panic_handler_asm.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "freertos/xtensa_rtos.h"
  2. #include "esp_private/panic_reason.h"
  3. #include "soc/soc.h"
  4. #include "sdkconfig.h"
  5. /*
  6. --------------------------------------------------------------------------------
  7. Panic handler.
  8. Should be reached by call0 (preferable) or jump only. If call0, a0 says where
  9. from. If on simulator, display panic message and abort, else loop indefinitely.
  10. --------------------------------------------------------------------------------
  11. */
  12. .section .iram1,"ax"
  13. .global panicHandler
  14. .global _xt_panic
  15. .type _xt_panic,@function
  16. .align 4
  17. .literal_position
  18. .align 4
  19. _xt_panic:
  20. /* Allocate exception frame and save minimal context. */
  21. mov a0, sp
  22. addi sp, sp, -XT_STK_FRMSZ
  23. s32i a0, sp, XT_STK_A1
  24. #if XCHAL_HAVE_WINDOWED
  25. s32e a0, sp, -12 /* for debug backtrace */
  26. #endif
  27. rsr a0, PS /* save interruptee's PS */
  28. s32i a0, sp, XT_STK_PS
  29. rsr a0, EPC_1 /* save interruptee's PC */
  30. s32i a0, sp, XT_STK_PC
  31. #if XCHAL_HAVE_WINDOWED
  32. s32e a0, sp, -16 /* for debug backtrace */
  33. #endif
  34. s32i a12, sp, XT_STK_A12 /* _xt_context_save requires A12- */
  35. s32i a13, sp, XT_STK_A13 /* A13 to have already been saved */
  36. call0 _xt_context_save
  37. /* Save exc cause and vaddr into exception frame */
  38. rsr a0, EXCCAUSE
  39. s32i a0, sp, XT_STK_EXCCAUSE
  40. rsr a0, EXCVADDR
  41. s32i a0, sp, XT_STK_EXCVADDR
  42. /* _xt_context_save seems to save the current a0, but we need the interuptees a0. Fix this. */
  43. rsr a0, EXCSAVE_1 /* save interruptee's a0 */
  44. s32i a0, sp, XT_STK_A0
  45. /* Set up PS for C, disable all interrupts except NMI and debug, and clear EXCM. */
  46. movi a0, PS_INTLEVEL(5) | PS_UM | PS_WOE
  47. wsr a0, PS
  48. //Call panic handler
  49. mov a6,sp
  50. call4 panicHandler
  51. ret