panic_handler.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stdlib.h>
  14. #include "freertos/xtensa_context.h"
  15. #include "freertos/FreeRTOS.h"
  16. #include "freertos/task.h"
  17. #include "esp_spi_flash.h"
  18. #include "esp_private/panic_reason.h"
  19. #include "esp_private/system_internal.h"
  20. #include "esp_debug_helpers.h"
  21. #include "soc/soc_memory_layout.h"
  22. #include "soc/cpu.h"
  23. #include "soc/soc_caps.h"
  24. #include "soc/rtc.h"
  25. #include "hal/soc_hal.h"
  26. #include "hal/cpu_hal.h"
  27. #include "hal/wdt_types.h"
  28. #include "hal/wdt_hal.h"
  29. #include "sdkconfig.h"
  30. #if CONFIG_IDF_TARGET_ESP32
  31. #include "esp32/cache_err_int.h"
  32. #include "esp32/dport_access.h"
  33. #include "esp32/rom/uart.h"
  34. #elif CONFIG_IDF_TARGET_ESP32S2
  35. #include "esp32s2/cache_err_int.h"
  36. #include "esp32s2/rom/uart.h"
  37. #include "esp32s2/memprot.h"
  38. #include "soc/extmem_reg.h"
  39. #include "soc/cache_memory.h"
  40. #include "soc/rtc_cntl_reg.h"
  41. #endif
  42. #include "panic_internal.h"
  43. extern int _invalid_pc_placeholder;
  44. extern void esp_panic_handler(panic_info_t*);
  45. static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
  46. static XtExcFrame *xt_exc_frames[SOC_CPU_CORES_NUM] = {NULL};
  47. /*
  48. Panic handlers; these get called when an unhandled exception occurs or the assembly-level
  49. task switching / interrupt code runs into an unrecoverable error. The default task stack
  50. overflow handler and abort handler are also in here.
  51. */
  52. /*
  53. Note: The linker script will put everything in this file in IRAM/DRAM, so it also works with flash cache disabled.
  54. */
  55. static void print_illegal_instruction_details(const void *f)
  56. {
  57. XtExcFrame *frame = (XtExcFrame *) f;
  58. /* Print out memory around the instruction word */
  59. uint32_t epc = frame->pc;
  60. epc = (epc & ~0x3) - 4;
  61. /* check that the address was sane */
  62. if (epc < SOC_IROM_MASK_LOW || epc >= SOC_IROM_HIGH) {
  63. return;
  64. }
  65. volatile uint32_t *pepc = (uint32_t *)epc;
  66. panic_print_str("Memory dump at 0x");
  67. panic_print_hex(epc);
  68. panic_print_str(": ");
  69. panic_print_hex(*pepc);
  70. panic_print_str(" ");
  71. panic_print_hex(*(pepc + 1));
  72. panic_print_str(" ");
  73. panic_print_hex(*(pepc + 2));
  74. }
  75. static void print_debug_exception_details(const void *f)
  76. {
  77. int debug_rsn;
  78. asm("rsr.debugcause %0":"=r"(debug_rsn));
  79. panic_print_str("Debug exception reason: ");
  80. if (debug_rsn & XCHAL_DEBUGCAUSE_ICOUNT_MASK) {
  81. panic_print_str("SingleStep ");
  82. }
  83. if (debug_rsn & XCHAL_DEBUGCAUSE_IBREAK_MASK) {
  84. panic_print_str("HwBreakpoint ");
  85. }
  86. if (debug_rsn & XCHAL_DEBUGCAUSE_DBREAK_MASK) {
  87. //Unlike what the ISA manual says, this core seemingly distinguishes from a DBREAK
  88. //reason caused by watchdog 0 and one caused by watchdog 1 by setting bit 8 of the
  89. //debugcause if the cause is watchpoint 1 and clearing it if it's watchpoint 0.
  90. if (debug_rsn & (1 << 8)) {
  91. #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
  92. int core = 0;
  93. #if !CONFIG_FREERTOS_UNICORE
  94. if (f == xt_exc_frames[1]) {
  95. core = 1;
  96. }
  97. #endif
  98. const char *name = pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(core));
  99. panic_print_str("Stack canary watchpoint triggered (");
  100. panic_print_str(name);
  101. panic_print_str(") ");
  102. #else
  103. panic_print_str("Watchpoint 1 triggered ");
  104. #endif
  105. } else {
  106. panic_print_str("Watchpoint 0 triggered ");
  107. }
  108. }
  109. if (debug_rsn & XCHAL_DEBUGCAUSE_BREAK_MASK) {
  110. panic_print_str("BREAK instr ");
  111. }
  112. if (debug_rsn & XCHAL_DEBUGCAUSE_BREAKN_MASK) {
  113. panic_print_str("BREAKN instr ");
  114. }
  115. if (debug_rsn & XCHAL_DEBUGCAUSE_DEBUGINT_MASK) {
  116. panic_print_str("DebugIntr ");
  117. }
  118. }
  119. static void print_backtrace_entry(uint32_t pc, uint32_t sp)
  120. {
  121. panic_print_str("0x");
  122. panic_print_hex(pc);
  123. panic_print_str(":0x");
  124. panic_print_hex(sp);
  125. }
  126. static void print_backtrace(const void *f, int core)
  127. {
  128. XtExcFrame *frame = (XtExcFrame *) f;
  129. int depth = 100;
  130. //Initialize stk_frame with first frame of stack
  131. esp_backtrace_frame_t stk_frame = {.pc = frame->pc, .sp = frame->a1, .next_pc = frame->a0};
  132. panic_print_str("\r\nBacktrace:");
  133. print_backtrace_entry(esp_cpu_process_stack_pc(stk_frame.pc), stk_frame.sp);
  134. //Check if first frame is valid
  135. bool corrupted = !(esp_stack_ptr_is_sane(stk_frame.sp) &&
  136. (esp_ptr_executable((void *)esp_cpu_process_stack_pc(stk_frame.pc)) ||
  137. /* Ignore the first corrupted PC in case of InstrFetchProhibited */
  138. frame->exccause == EXCCAUSE_INSTR_PROHIBITED));
  139. uint32_t i = ((depth <= 0) ? INT32_MAX : depth) - 1; //Account for stack frame that's already printed
  140. while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted) {
  141. if (!esp_backtrace_get_next_frame(&stk_frame)) { //Get next stack frame
  142. corrupted = true;
  143. }
  144. panic_print_str(" ");
  145. print_backtrace_entry(esp_cpu_process_stack_pc(stk_frame.pc), stk_frame.sp);
  146. }
  147. //Print backtrace termination marker
  148. if (corrupted) {
  149. panic_print_str(" |<-CORRUPTED");
  150. } else if (stk_frame.next_pc != 0) { //Backtrace continues
  151. panic_print_str(" |<-CONTINUES");
  152. }
  153. }
  154. static void print_registers(const void *f, int core)
  155. {
  156. XtExcFrame *frame = (XtExcFrame *) f;
  157. int *regs = (int *)frame;
  158. int x, y;
  159. const char *sdesc[] = {
  160. "PC ", "PS ", "A0 ", "A1 ", "A2 ", "A3 ", "A4 ", "A5 ",
  161. "A6 ", "A7 ", "A8 ", "A9 ", "A10 ", "A11 ", "A12 ", "A13 ",
  162. "A14 ", "A15 ", "SAR ", "EXCCAUSE", "EXCVADDR", "LBEG ", "LEND ", "LCOUNT "
  163. };
  164. /* only dump registers for 'real' crashes, if crashing via abort()
  165. the register window is no longer useful.
  166. */
  167. panic_print_str("Core ");
  168. panic_print_dec(core);
  169. panic_print_str(" register dump:");
  170. for (x = 0; x < 24; x += 4) {
  171. panic_print_str("\r\n");
  172. for (y = 0; y < 4; y++) {
  173. if (sdesc[x + y][0] != 0) {
  174. panic_print_str(sdesc[x + y]);
  175. panic_print_str(": 0x");
  176. panic_print_hex(regs[x + y + 1]);
  177. panic_print_str(" ");
  178. }
  179. }
  180. }
  181. // If the core which triggers the interrupt watchpoint was in ISR context, dump the epc registers.
  182. if (xPortInterruptedFromISRContext()
  183. #if !CONFIG_FREERTOS_UNICORE
  184. && ((core == 0 && frame->exccause == PANIC_RSN_INTWDT_CPU0) ||
  185. (core == 1 && frame->exccause == PANIC_RSN_INTWDT_CPU1))
  186. #endif //!CONFIG_FREERTOS_UNICORE
  187. ) {
  188. panic_print_str("\r\n");
  189. uint32_t __value;
  190. panic_print_str("Core ");
  191. panic_print_dec(core);
  192. panic_print_str(" was running in ISR context:\r\n");
  193. __asm__("rsr.epc1 %0" : "=a"(__value));
  194. panic_print_str("EPC1 : 0x");
  195. panic_print_hex(__value);
  196. __asm__("rsr.epc2 %0" : "=a"(__value));
  197. panic_print_str(" EPC2 : 0x");
  198. panic_print_hex(__value);
  199. __asm__("rsr.epc3 %0" : "=a"(__value));
  200. panic_print_str(" EPC3 : 0x");
  201. panic_print_hex(__value);
  202. __asm__("rsr.epc4 %0" : "=a"(__value));
  203. panic_print_str(" EPC4 : 0x");
  204. panic_print_hex(__value);
  205. }
  206. }
  207. static void print_state_for_core(const void *f, int core)
  208. {
  209. if (!g_panic_abort) {
  210. print_registers(f, core);
  211. panic_print_str("\r\n");
  212. }
  213. print_backtrace(f, core);
  214. }
  215. static void print_state(const void *f)
  216. {
  217. #if !CONFIG_FREERTOS_UNICORE
  218. int err_core = f == xt_exc_frames[0] ? 0 : 1;
  219. #else
  220. int err_core = 0;
  221. #endif
  222. print_state_for_core(f, err_core);
  223. panic_print_str("\r\n");
  224. #if !CONFIG_FREERTOS_UNICORE
  225. // If there are other frame info, print them as well
  226. for (int i = 0; i < SOC_CPU_CORES_NUM; i++) {
  227. // `f` is the frame for the offending core, see note above.
  228. if (err_core != i && xt_exc_frames[i] != NULL) {
  229. print_state_for_core(xt_exc_frames[i], i);
  230. panic_print_str("\r\n");
  231. }
  232. }
  233. #endif
  234. }
  235. #if CONFIG_IDF_TARGET_ESP32S2
  236. static inline void print_cache_err_details(const void *f)
  237. {
  238. uint32_t vaddr = 0, size = 0;
  239. uint32_t status[2];
  240. status[0] = REG_READ(EXTMEM_CACHE_DBG_STATUS0_REG);
  241. status[1] = REG_READ(EXTMEM_CACHE_DBG_STATUS1_REG);
  242. for (int i = 0; i < 32; i++) {
  243. switch (status[0] & BIT(i)) {
  244. case EXTMEM_IC_SYNC_SIZE_FAULT_ST:
  245. vaddr = REG_READ(EXTMEM_PRO_ICACHE_MEM_SYNC0_REG);
  246. size = REG_READ(EXTMEM_PRO_ICACHE_MEM_SYNC1_REG);
  247. panic_print_str("Icache sync parameter configuration error, the error address and size is 0x");
  248. panic_print_hex(vaddr);
  249. panic_print_str("(0x");
  250. panic_print_hex(size);
  251. panic_print_str(")\r\n");
  252. break;
  253. case EXTMEM_IC_PRELOAD_SIZE_FAULT_ST:
  254. vaddr = REG_READ(EXTMEM_PRO_ICACHE_PRELOAD_ADDR_REG);
  255. size = REG_READ(EXTMEM_PRO_ICACHE_PRELOAD_SIZE_REG);
  256. panic_print_str("Icache preload parameter configuration error, the error address and size is 0x");
  257. panic_print_hex(vaddr);
  258. panic_print_str("(0x");
  259. panic_print_hex(size);
  260. panic_print_str(")\r\n");
  261. break;
  262. case EXTMEM_ICACHE_REJECT_ST:
  263. vaddr = REG_READ(EXTMEM_PRO_ICACHE_REJECT_VADDR_REG);
  264. panic_print_str("Icache reject error occurred while accessing the address 0x");
  265. panic_print_hex(vaddr);
  266. if (REG_READ(EXTMEM_PRO_CACHE_MMU_FAULT_CONTENT_REG) & MMU_INVALID) {
  267. panic_print_str(" (invalid mmu entry)");
  268. }
  269. panic_print_str("\r\n");
  270. break;
  271. default:
  272. break;
  273. }
  274. switch (status[1] & BIT(i)) {
  275. case EXTMEM_DC_SYNC_SIZE_FAULT_ST:
  276. vaddr = REG_READ(EXTMEM_PRO_DCACHE_MEM_SYNC0_REG);
  277. size = REG_READ(EXTMEM_PRO_DCACHE_MEM_SYNC1_REG);
  278. panic_print_str("Dcache sync parameter configuration error, the error address and size is 0x");
  279. panic_print_hex(vaddr);
  280. panic_print_str("(0x");
  281. panic_print_hex(size);
  282. panic_print_str(")\r\n");
  283. break;
  284. case EXTMEM_DC_PRELOAD_SIZE_FAULT_ST:
  285. vaddr = REG_READ(EXTMEM_PRO_DCACHE_PRELOAD_ADDR_REG);
  286. size = REG_READ(EXTMEM_PRO_DCACHE_PRELOAD_SIZE_REG);
  287. panic_print_str("Dcache preload parameter configuration error, the error address and size is 0x");
  288. panic_print_hex(vaddr);
  289. panic_print_str("(0x");
  290. panic_print_hex(size);
  291. panic_print_str(")\r\n");
  292. break;
  293. case EXTMEM_DCACHE_WRITE_FLASH_ST:
  294. panic_print_str("Write back error occurred while dcache tries to write back to flash\r\n");
  295. break;
  296. case EXTMEM_DCACHE_REJECT_ST:
  297. vaddr = REG_READ(EXTMEM_PRO_DCACHE_REJECT_VADDR_REG);
  298. panic_print_str("Dcache reject error occurred while accessing the address 0x");
  299. panic_print_hex(vaddr);
  300. if (REG_READ(EXTMEM_PRO_CACHE_MMU_FAULT_CONTENT_REG) & MMU_INVALID) {
  301. panic_print_str(" (invalid mmu entry)");
  302. }
  303. panic_print_str("\r\n");
  304. break;
  305. case EXTMEM_MMU_ENTRY_FAULT_ST:
  306. vaddr = REG_READ(EXTMEM_PRO_CACHE_MMU_FAULT_VADDR_REG);
  307. panic_print_str("MMU entry fault error occurred while accessing the address 0x");
  308. panic_print_hex(vaddr);
  309. if (REG_READ(EXTMEM_PRO_CACHE_MMU_FAULT_CONTENT_REG) & MMU_INVALID) {
  310. panic_print_str(" (invalid mmu entry)");
  311. }
  312. panic_print_str("\r\n");
  313. break;
  314. default:
  315. break;
  316. }
  317. }
  318. }
  319. static inline void print_memprot_err_details(const void *f)
  320. {
  321. uint32_t *fault_addr;
  322. uint32_t op_type, op_subtype;
  323. mem_type_prot_t mem_type = esp_memprot_get_intr_memtype();
  324. esp_memprot_get_fault_status( mem_type, &fault_addr, &op_type, &op_subtype );
  325. char *operation_type = "Write";
  326. if ( op_type == 0 ) {
  327. operation_type = (mem_type == MEMPROT_IRAM0 && op_subtype == 0) ? "Instruction fetch" : "Read";
  328. }
  329. panic_print_str( operation_type );
  330. panic_print_str( " operation at address 0x" );
  331. panic_print_hex( (uint32_t)fault_addr );
  332. panic_print_str(" not permitted.\r\n");
  333. }
  334. #endif
  335. static void frame_to_panic_info(XtExcFrame *frame, panic_info_t *info, bool pseudo_excause)
  336. {
  337. info->core = cpu_hal_get_core_id();
  338. info->exception = PANIC_EXCEPTION_FAULT;
  339. info->details = NULL;
  340. if (pseudo_excause) {
  341. if (frame->exccause == PANIC_RSN_INTWDT_CPU0) {
  342. info->core = 0;
  343. info->exception = PANIC_EXCEPTION_IWDT;
  344. } else if (frame->exccause == PANIC_RSN_INTWDT_CPU1) {
  345. info->core = 1;
  346. info->exception = PANIC_EXCEPTION_IWDT;
  347. } else if (frame->exccause == PANIC_RSN_CACHEERR) {
  348. info->core = esp_cache_err_get_cpuid();
  349. } else {}
  350. //Please keep in sync with PANIC_RSN_* defines
  351. static const char *pseudo_reason[] = {
  352. "Unknown reason",
  353. "Unhandled debug exception",
  354. "Double exception",
  355. "Unhandled kernel exception",
  356. "Coprocessor exception",
  357. "Interrupt wdt timeout on CPU0",
  358. "Interrupt wdt timeout on CPU1",
  359. #if CONFIG_IDF_TARGET_ESP32
  360. "Cache disabled but cached memory region accessed",
  361. #elif CONFIG_IDF_TARGET_ESP32S2
  362. "Cache exception",
  363. #endif
  364. };
  365. info->reason = pseudo_reason[0];
  366. info->description = NULL;
  367. if (frame->exccause <= PANIC_RSN_MAX) {
  368. info->reason = pseudo_reason[frame->exccause];
  369. }
  370. if (frame->exccause == PANIC_RSN_DEBUGEXCEPTION) {
  371. info->details = print_debug_exception_details;
  372. info->exception = PANIC_EXCEPTION_DEBUG;
  373. }
  374. #if CONFIG_IDF_TARGET_ESP32S2
  375. if (frame->exccause == PANIC_RSN_CACHEERR) {
  376. if ( esp_memprot_is_assoc_intr_any() ) {
  377. info->details = print_memprot_err_details;
  378. info->reason = "Memory protection fault";
  379. } else {
  380. info->details = print_cache_err_details;
  381. }
  382. }
  383. #endif
  384. } else {
  385. static const char *reason[] = {
  386. "IllegalInstruction", "Syscall", "InstructionFetchError", "LoadStoreError",
  387. "Level1Interrupt", "Alloca", "IntegerDivideByZero", "PCValue",
  388. "Privileged", "LoadStoreAlignment", "res", "res",
  389. "InstrPDAddrError", "LoadStorePIFDataError", "InstrPIFAddrError", "LoadStorePIFAddrError",
  390. "InstTLBMiss", "InstTLBMultiHit", "InstFetchPrivilege", "res",
  391. "InstrFetchProhibited", "res", "res", "res",
  392. "LoadStoreTLBMiss", "LoadStoreTLBMultihit", "LoadStorePrivilege", "res",
  393. "LoadProhibited", "StoreProhibited", "res", "res",
  394. "Cp0Dis", "Cp1Dis", "Cp2Dis", "Cp3Dis",
  395. "Cp4Dis", "Cp5Dis", "Cp6Dis", "Cp7Dis"
  396. };
  397. if (frame->exccause < (sizeof(reason) / sizeof(char *))) {
  398. info->reason = (reason[frame->exccause]);
  399. } else {
  400. info->reason = "Unknown";
  401. }
  402. info->description = "Exception was unhandled.";
  403. if (frame->exccause == EXCCAUSE_ILLEGAL) {
  404. info->details = print_illegal_instruction_details;
  405. }
  406. }
  407. info->state = print_state;
  408. info->addr = ((void *) ((XtExcFrame *) frame)->pc);
  409. info->frame = frame;
  410. }
  411. static void panic_handler(XtExcFrame *frame, bool pseudo_excause)
  412. {
  413. /*
  414. * Setup environment and perform necessary architecture/chip specific
  415. * steps here prior to the system panic handler.
  416. * */
  417. int core_id = cpu_hal_get_core_id();
  418. // If multiple cores arrive at panic handler, save frames for all of them
  419. xt_exc_frames[core_id] = frame;
  420. #if !CONFIG_FREERTOS_UNICORE
  421. // These are cases where both CPUs both go into panic handler. The following code ensures
  422. // only one core proceeds to the system panic handler.
  423. if (pseudo_excause) {
  424. #define BUSY_WAIT_IF_TRUE(b) { if (b) while(1); }
  425. // For WDT expiry, pause the non-offending core - offending core handles panic
  426. BUSY_WAIT_IF_TRUE(frame->exccause == PANIC_RSN_INTWDT_CPU0 && core_id == 1);
  427. BUSY_WAIT_IF_TRUE(frame->exccause == PANIC_RSN_INTWDT_CPU1 && core_id == 0);
  428. // For cache error, pause the non-offending core - offending core handles panic
  429. if (frame->exccause == PANIC_RSN_CACHEERR && core_id != esp_cache_err_get_cpuid()) {
  430. // Only print the backtrace for the offending core in case of the cache error
  431. xt_exc_frames[core_id] = NULL;
  432. while (1) {
  433. ;
  434. }
  435. }
  436. }
  437. ets_delay_us(1);
  438. SOC_HAL_STALL_OTHER_CORES();
  439. #endif
  440. #if CONFIG_IDF_TARGET_ESP32
  441. esp_dport_access_int_abort();
  442. #endif
  443. #if !CONFIG_ESP_PANIC_HANDLER_IRAM
  444. // Re-enable CPU cache for current CPU if it was disabled
  445. if (!spi_flash_cache_enabled()) {
  446. spi_flash_enable_cache(core_id);
  447. panic_print_str("Re-enable cpu cache.\r\n");
  448. }
  449. #endif
  450. if (esp_cpu_in_ocd_debug_mode()) {
  451. if (!(esp_ptr_executable(cpu_ll_pc_to_ptr(frame->pc)) && (frame->pc & 0xC0000000U))) {
  452. /* Xtensa ABI sets the 2 MSBs of the PC according to the windowed call size
  453. * Incase the PC is invalid, GDB will fail to translate addresses to function names
  454. * Hence replacing the PC to a placeholder address in case of invalid PC
  455. */
  456. frame->pc = (uint32_t)&_invalid_pc_placeholder;
  457. }
  458. if (frame->exccause == PANIC_RSN_INTWDT_CPU0 ||
  459. frame->exccause == PANIC_RSN_INTWDT_CPU1) {
  460. wdt_hal_write_protect_disable(&wdt0_context);
  461. wdt_hal_handle_intr(&wdt0_context);
  462. wdt_hal_write_protect_enable(&wdt0_context);
  463. }
  464. }
  465. // Convert architecture exception frame into abstracted panic info
  466. panic_info_t info;
  467. frame_to_panic_info(frame, &info, pseudo_excause);
  468. // Call the system panic handler
  469. esp_panic_handler(&info);
  470. }
  471. void panicHandler(XtExcFrame *frame)
  472. {
  473. // This panic handler gets called for when the double exception vector,
  474. // kernel exception vector gets used; as well as handling interrupt-based
  475. // faults cache error, wdt expiry. EXCAUSE register gets written with
  476. // one of PANIC_RSN_* values.
  477. panic_handler(frame, true);
  478. }
  479. void xt_unhandled_exception(XtExcFrame *frame)
  480. {
  481. panic_handler(frame, false);
  482. }
  483. void __attribute__((noreturn)) panic_restart(void)
  484. {
  485. bool digital_reset_needed = false;
  486. #ifdef CONFIG_IDF_TARGET_ESP32
  487. // On the ESP32, cache error status can only be cleared by system reset
  488. if (esp_cache_err_get_cpuid() != -1) {
  489. digital_reset_needed = true;
  490. }
  491. #endif
  492. #if CONFIG_IDF_TARGET_ESP32S2
  493. if (esp_memprot_is_intr_ena_any() || esp_memprot_is_locked_any()) {
  494. digital_reset_needed = true;
  495. }
  496. #endif
  497. if (digital_reset_needed) {
  498. esp_restart_noos_dig();
  499. }
  500. esp_restart_noos();
  501. }