panic_internal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "esp_macros.h"
  10. #include "soc/soc_caps.h"
  11. #include "sdkconfig.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. extern bool g_panic_abort;
  16. extern char *g_panic_abort_details;
  17. extern void *g_exc_frames[SOC_CPU_CORES_NUM];
  18. // Function to print longer amounts of information such as the details
  19. // and backtrace field of panic_info_t. These functions should limit themselves
  20. // to printing to the console and should do other more involved processing,
  21. // and must be aware that the main logic in panic.c has a watchdog timer active.
  22. typedef void (*panic_info_dump_fn_t)(const void* frame);
  23. // Non architecture specific exceptions (generally valid for all targets).
  24. // Can be used to convey to the main logic what exception is being
  25. // dealt with to perform some actions, without knowing the underlying
  26. // architecture/chip-specific exception.
  27. typedef enum {
  28. PANIC_EXCEPTION_DEBUG,
  29. PANIC_EXCEPTION_IWDT,
  30. PANIC_EXCEPTION_TWDT,
  31. PANIC_EXCEPTION_ABORT,
  32. PANIC_EXCEPTION_FAULT, // catch-all for all types of faults
  33. } panic_exception_t;
  34. typedef struct {
  35. int core; // core which triggered panic
  36. panic_exception_t exception; // non-architecture-specific exception code
  37. const char* reason; // exception string
  38. const char* description; // short description of the exception
  39. panic_info_dump_fn_t details; // more details on the exception
  40. panic_info_dump_fn_t state; // processor state, usually the contents of the registers
  41. const void* addr; // instruction address that triggered the exception
  42. const void* frame; // reference to the frame
  43. bool pseudo_excause; // flag indicating that exception cause has special meaning
  44. } panic_info_t;
  45. #define PANIC_INFO_DUMP(info, dump_fn) {if ((info)->dump_fn) (*(info)->dump_fn)((info->frame));}
  46. // Create own print functions, since printf might be broken, and can be silenced
  47. // when CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  48. #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
  49. void panic_print_char(char c);
  50. void panic_print_str(const char *str);
  51. void panic_print_dec(int d);
  52. void panic_print_hex(int h);
  53. #else
  54. #define panic_print_char(c) ESP_UNUSED(c)
  55. #define panic_print_str(str) ESP_UNUSED(str)
  56. #define panic_print_dec(d) ESP_UNUSED(d)
  57. #define panic_print_hex(h) ESP_UNUSED(h)
  58. #endif
  59. void __attribute__((__noreturn__)) panic_abort(const char *details);
  60. void panic_arch_fill_info(void *frame, panic_info_t *info);
  61. void panic_soc_fill_info(void *frame, panic_info_t *info);
  62. void panic_print_registers(const void *frame, int core);
  63. void panic_print_backtrace(const void *frame, int core);
  64. uint32_t panic_get_address(const void* frame);
  65. void panic_set_address(void *frame, uint32_t addr);
  66. uint32_t panic_get_cause(const void* frame);
  67. #ifdef __cplusplus
  68. }
  69. #endif