debug.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DEBUG_H
  7. #define DEBUG_H
  8. #include <lib/utils_def.h>
  9. /*
  10. * The log output macros print output to the console. These macros produce
  11. * compiled log output only if the LOG_LEVEL defined in the makefile (or the
  12. * make command line) is greater or equal than the level required for that
  13. * type of log output.
  14. *
  15. * The format expected is the same as for printf(). For example:
  16. * INFO("Info %s.\n", "message") -> INFO: Info message.
  17. * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
  18. */
  19. #define LOG_LEVEL_NONE U(0)
  20. #define LOG_LEVEL_ERROR U(10)
  21. #define LOG_LEVEL_NOTICE U(20)
  22. #define LOG_LEVEL_WARNING U(30)
  23. #define LOG_LEVEL_INFO U(40)
  24. #define LOG_LEVEL_VERBOSE U(50)
  25. #ifndef __ASSEMBLER__
  26. #include <cdefs.h>
  27. #include <stdarg.h>
  28. #include <stdbool.h>
  29. #include <stdio.h>
  30. #include <drivers/console.h>
  31. /*
  32. * Define Log Markers corresponding to each log level which will
  33. * be embedded in the format string and is expected by tf_log() to determine
  34. * the log level.
  35. */
  36. #define LOG_MARKER_ERROR "\xa" /* 10 */
  37. #define LOG_MARKER_NOTICE "\x14" /* 20 */
  38. #define LOG_MARKER_WARNING "\x1e" /* 30 */
  39. #define LOG_MARKER_INFO "\x28" /* 40 */
  40. #define LOG_MARKER_VERBOSE "\x32" /* 50 */
  41. /*
  42. * If the log output is too low then this macro is used in place of tf_log()
  43. * below. The intent is to get the compiler to evaluate the function call for
  44. * type checking and format specifier correctness but let it optimize it out.
  45. */
  46. #define no_tf_log(fmt, ...) \
  47. do { \
  48. if (false) { \
  49. tf_log(fmt, ##__VA_ARGS__); \
  50. } \
  51. } while (false)
  52. #if LOG_LEVEL >= LOG_LEVEL_ERROR
  53. # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
  54. # define ERROR_NL() tf_log_newline(LOG_MARKER_ERROR)
  55. #else
  56. # define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
  57. # define ERROR_NL()
  58. #endif
  59. #if LOG_LEVEL >= LOG_LEVEL_NOTICE
  60. # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
  61. #else
  62. # define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
  63. #endif
  64. #if LOG_LEVEL >= LOG_LEVEL_WARNING
  65. # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
  66. #else
  67. # define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
  68. #endif
  69. #if LOG_LEVEL >= LOG_LEVEL_INFO
  70. # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
  71. #else
  72. # define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
  73. #endif
  74. #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
  75. # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
  76. #else
  77. # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
  78. #endif
  79. const char *get_el_str(unsigned int el);
  80. #if ENABLE_BACKTRACE
  81. void backtrace(const char *cookie);
  82. #else
  83. #define backtrace(x)
  84. #endif
  85. void __dead2 el3_panic(void);
  86. void __dead2 elx_panic(void);
  87. #define panic() \
  88. do { \
  89. backtrace(__func__); \
  90. console_flush(); \
  91. el3_panic(); \
  92. } while (false)
  93. #if CRASH_REPORTING
  94. /* --------------------------------------------------------------------
  95. * do_lower_el_panic assumes it's called due to a panic from a lower EL
  96. * This call will not return.
  97. * --------------------------------------------------------------------
  98. */
  99. #define lower_el_panic() \
  100. do { \
  101. console_flush(); \
  102. elx_panic(); \
  103. } while (false)
  104. #else
  105. #define lower_el_panic()
  106. #endif
  107. /* Function called when stack protection check code detects a corrupted stack */
  108. void __dead2 __stack_chk_fail(void);
  109. void tf_log(const char *fmt, ...) __printflike(1, 2);
  110. void tf_log_newline(const char log_fmt[2]);
  111. void tf_log_set_max_level(unsigned int log_level);
  112. #endif /* __ASSEMBLER__ */
  113. #endif /* DEBUG_H */