blob: 5ea541da0b3ffb4bde1aab6609a212e0e9d14a60 [file] [log] [blame]
Harry Liebel57bb6582013-12-19 13:30:58 +00001/*
Govindraj Rajaabf9fb92023-01-16 15:11:47 +00002 * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
Harry Liebel57bb6582013-12-19 13:30:58 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Harry Liebel57bb6582013-12-19 13:30:58 +00005 */
6
Antonio Nino Diazc0c8eb62018-08-15 17:02:28 +01007#ifndef DEBUG_H
8#define DEBUG_H
Harry Liebel57bb6582013-12-19 13:30:58 +00009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/utils_def.h>
Antonio Nino Diaz14fabd02018-08-28 11:44:44 +010011
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020012/*
13 * The log output macros print output to the console. These macros produce
Dan Handleycba2c502014-08-08 14:36:42 +010014 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
15 * make command line) is greater or equal than the level required for that
16 * type of log output.
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020017 *
Dan Handleycba2c502014-08-08 14:36:42 +010018 * The format expected is the same as for printf(). For example:
19 * INFO("Info %s.\n", "message") -> INFO: Info message.
20 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Harry Liebel57bb6582013-12-19 13:30:58 +000021 */
Dan Handleycba2c502014-08-08 14:36:42 +010022
Antonio Nino Diaz14fabd02018-08-28 11:44:44 +010023#define LOG_LEVEL_NONE U(0)
24#define LOG_LEVEL_ERROR U(10)
25#define LOG_LEVEL_NOTICE U(20)
26#define LOG_LEVEL_WARNING U(30)
27#define LOG_LEVEL_INFO U(40)
28#define LOG_LEVEL_VERBOSE U(50)
Dan Handleycba2c502014-08-08 14:36:42 +010029
Julius Werner53456fc2019-07-09 13:49:11 -070030#ifndef __ASSEMBLER__
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000031
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010032#include <cdefs.h>
Soby Mathewf583a062017-09-04 11:45:52 +010033#include <stdarg.h>
Antonio Nino Diazd5876462018-08-23 15:13:58 +010034#include <stdbool.h>
Soby Mathew6b28c572016-03-21 10:36:47 +000035#include <stdio.h>
Dan Handleycba2c502014-08-08 14:36:42 +010036
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000037#include <drivers/console.h>
38
Soby Mathewaaf15f52017-09-04 11:49:29 +010039/*
40 * Define Log Markers corresponding to each log level which will
41 * be embedded in the format string and is expected by tf_log() to determine
42 * the log level.
43 */
44#define LOG_MARKER_ERROR "\xa" /* 10 */
45#define LOG_MARKER_NOTICE "\x14" /* 20 */
46#define LOG_MARKER_WARNING "\x1e" /* 30 */
47#define LOG_MARKER_INFO "\x28" /* 40 */
48#define LOG_MARKER_VERBOSE "\x32" /* 50 */
49
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020050/*
51 * If the log output is too low then this macro is used in place of tf_log()
52 * below. The intent is to get the compiler to evaluate the function call for
53 * type checking and format specifier correctness but let it optimize it out.
54 */
55#define no_tf_log(fmt, ...) \
56 do { \
Antonio Nino Diaz14fabd02018-08-28 11:44:44 +010057 if (false) { \
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020058 tf_log(fmt, ##__VA_ARGS__); \
59 } \
Antonio Nino Diaz14fabd02018-08-28 11:44:44 +010060 } while (false)
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020061
Dan Handleycba2c502014-08-08 14:36:42 +010062#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathewaaf15f52017-09-04 11:49:29 +010063# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Pali Rohárb6cfd032021-07-20 23:57:47 +020064# define ERROR_NL() tf_log_newline(LOG_MARKER_ERROR)
Dan Handleycba2c502014-08-08 14:36:42 +010065#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020066# define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Pali Rohárb6cfd032021-07-20 23:57:47 +020067# define ERROR_NL()
Dan Handleycba2c502014-08-08 14:36:42 +010068#endif
69
John Tsichritzise75b9a52018-09-07 14:42:09 +010070#if LOG_LEVEL >= LOG_LEVEL_NOTICE
71# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
72#else
73# define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
74#endif
75
Dan Handleycba2c502014-08-08 14:36:42 +010076#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathewaaf15f52017-09-04 11:49:29 +010077# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010078#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020079# define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010080#endif
81
82#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathewaaf15f52017-09-04 11:49:29 +010083# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010084#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020085# define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010086#endif
87
88#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathewaaf15f52017-09-04 11:49:29 +010089# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000090#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020091# define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000092#endif
93
Manish Pandey2ff5dc32022-11-01 16:16:55 +000094const char *get_el_str(unsigned int el);
95
Douglas Raillard77414632018-08-21 12:54:45 +010096#if ENABLE_BACKTRACE
97void backtrace(const char *cookie);
98#else
99#define backtrace(x)
100#endif
101
Govindraj Rajaa796b1b2023-01-16 17:35:07 +0000102void __dead2 el3_panic(void);
Govindraj Rajab6709b02023-02-21 17:43:55 +0000103void __dead2 elx_panic(void);
Antonio Nino Diazd5876462018-08-23 15:13:58 +0100104
105#define panic() \
106 do { \
107 backtrace(__func__); \
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500108 console_flush(); \
Govindraj Rajaa796b1b2023-01-16 17:35:07 +0000109 el3_panic(); \
Antonio Nino Diazd5876462018-08-23 15:13:58 +0100110 } while (false)
Soby Mathew5e5c2072014-04-07 15:28:55 +0100111
Govindraj Rajaabf9fb92023-01-16 15:11:47 +0000112#if CRASH_REPORTING
113/* --------------------------------------------------------------------
114 * do_lower_el_panic assumes it's called due to a panic from a lower EL
115 * This call will not return.
116 * --------------------------------------------------------------------
117 */
118#define lower_el_panic() \
119 do { \
120 console_flush(); \
Govindraj Rajab6709b02023-02-21 17:43:55 +0000121 elx_panic(); \
Govindraj Rajaabf9fb92023-01-16 15:11:47 +0000122 } while (false)
123#else
124#define lower_el_panic()
125#endif
126
Douglas Raillard306593d2017-02-24 18:14:15 +0000127/* Function called when stack protection check code detects a corrupted stack */
128void __dead2 __stack_chk_fail(void);
129
Soby Mathewaaf15f52017-09-04 11:49:29 +0100130void tf_log(const char *fmt, ...) __printflike(1, 2);
Pali Rohárb6cfd032021-07-20 23:57:47 +0200131void tf_log_newline(const char log_fmt[2]);
Soby Mathewaaf15f52017-09-04 11:49:29 +0100132void tf_log_set_max_level(unsigned int log_level);
Soby Mathewafe7e2f2014-06-12 17:23:58 +0100133
Julius Werner53456fc2019-07-09 13:49:11 -0700134#endif /* __ASSEMBLER__ */
Antonio Nino Diazc0c8eb62018-08-15 17:02:28 +0100135#endif /* DEBUG_H */