panic_internal.h 3.0 KB

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