blob: 6d7f2c6f14d5d411e6dc59614c262f969cfd7d8d [file] [log] [blame]
Harry Liebel57bb6582013-12-19 13:30:58 +00001/*
Yann Gautierae770fe2024-01-16 19:39:31 +01002 * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
Harry Liebel57bb6582013-12-19 13:30:58 +00003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Harry Liebel57bb6582013-12-19 13:30:58 +00005 */
6
Antonio Nino Diaz870ce3d2018-08-15 17:02:28 +01007#ifndef DEBUG_H
8#define DEBUG_H
Harry Liebel57bb6582013-12-19 13:30:58 +00009
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000010#include <lib/utils_def.h>
Antonio Nino Diaz5a22e462018-08-28 11:44:44 +010011
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020012/*
13 * The log output macros print output to the console. These macros produce
Dan Handley289c28a2014-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 Bailleuxcf242292018-06-20 14:50:48 +020017 *
Dan Handley289c28a2014-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 Handley289c28a2014-08-08 14:36:42 +010022
Antonio Nino Diaz5a22e462018-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 Handley289c28a2014-08-08 14:36:42 +010029
Julius Wernerd5dfdeb2019-07-09 13:49:11 -070030#ifndef __ASSEMBLER__
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000031
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +010032#include <cdefs.h>
Soby Mathew2d7e8282017-09-04 11:45:52 +010033#include <stdarg.h>
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +010034#include <stdbool.h>
Maheedhar Bollapallif3ecd832024-04-24 18:43:34 +053035#include <stdint.h>
Soby Mathew1319e7b2016-03-21 10:36:47 +000036#include <stdio.h>
Dan Handley289c28a2014-08-08 14:36:42 +010037
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000038#include <drivers/console.h>
39
Soby Mathew7f56e9a2017-09-04 11:49:29 +010040/*
41 * Define Log Markers corresponding to each log level which will
42 * be embedded in the format string and is expected by tf_log() to determine
43 * the log level.
44 */
45#define LOG_MARKER_ERROR "\xa" /* 10 */
46#define LOG_MARKER_NOTICE "\x14" /* 20 */
47#define LOG_MARKER_WARNING "\x1e" /* 30 */
48#define LOG_MARKER_INFO "\x28" /* 40 */
49#define LOG_MARKER_VERBOSE "\x32" /* 50 */
50
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020051/*
52 * If the log output is too low then this macro is used in place of tf_log()
53 * below. The intent is to get the compiler to evaluate the function call for
54 * type checking and format specifier correctness but let it optimize it out.
55 */
56#define no_tf_log(fmt, ...) \
57 do { \
Antonio Nino Diaz5a22e462018-08-28 11:44:44 +010058 if (false) { \
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020059 tf_log(fmt, ##__VA_ARGS__); \
60 } \
Antonio Nino Diaz5a22e462018-08-28 11:44:44 +010061 } while (false)
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020062
Dan Handley289c28a2014-08-08 14:36:42 +010063#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathew7f56e9a2017-09-04 11:49:29 +010064# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Pali Rohárfd1360a2021-07-20 23:57:47 +020065# define ERROR_NL() tf_log_newline(LOG_MARKER_ERROR)
Dan Handley289c28a2014-08-08 14:36:42 +010066#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020067# define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Pali Rohárfd1360a2021-07-20 23:57:47 +020068# define ERROR_NL()
Dan Handley289c28a2014-08-08 14:36:42 +010069#endif
70
John Tsichritzis701b4982018-09-07 14:42:09 +010071#if LOG_LEVEL >= LOG_LEVEL_NOTICE
72# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
73#else
74# define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
75#endif
76
Dan Handley289c28a2014-08-08 14:36:42 +010077#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathew7f56e9a2017-09-04 11:49:29 +010078# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010079#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020080# define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010081#endif
82
83#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathew7f56e9a2017-09-04 11:49:29 +010084# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010085#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020086# define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010087#endif
88
89#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathew7f56e9a2017-09-04 11:49:29 +010090# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010091#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020092# define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010093#endif
94
Yann Gautierae770fe2024-01-16 19:39:31 +010095#if EARLY_CONSOLE
96#define EARLY_ERROR(...) ERROR(__VA_ARGS__)
97#else /* !EARLY_CONSOLE */
98#define EARLY_ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
99#endif /* EARLY_CONSOLE */
100
Manish Pandey0ae4a3a2022-11-01 16:16:55 +0000101const char *get_el_str(unsigned int el);
102
Douglas Raillard0c628832018-08-21 12:54:45 +0100103#if ENABLE_BACKTRACE
104void backtrace(const char *cookie);
105#else
106#define backtrace(x)
107#endif
108
Govindraj Rajabd62ce92023-01-16 17:35:07 +0000109void __dead2 el3_panic(void);
Govindraj Raja17d07a52023-02-21 17:43:55 +0000110void __dead2 elx_panic(void);
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +0100111
112#define panic() \
113 do { \
114 backtrace(__func__); \
Jimmy Brisson831b0e92020-08-05 13:44:05 -0500115 console_flush(); \
Govindraj Rajabd62ce92023-01-16 17:35:07 +0000116 el3_panic(); \
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +0100117 } while (false)
Soby Mathewa43d4312014-04-07 15:28:55 +0100118
Govindraj Raja7e619ec2023-01-16 15:11:47 +0000119#if CRASH_REPORTING
120/* --------------------------------------------------------------------
121 * do_lower_el_panic assumes it's called due to a panic from a lower EL
122 * This call will not return.
123 * --------------------------------------------------------------------
124 */
125#define lower_el_panic() \
126 do { \
127 console_flush(); \
Govindraj Raja17d07a52023-02-21 17:43:55 +0000128 elx_panic(); \
Govindraj Raja7e619ec2023-01-16 15:11:47 +0000129 } while (false)
130#else
131#define lower_el_panic()
132#endif
133
Douglas Raillard51faada2017-02-24 18:14:15 +0000134/* Function called when stack protection check code detects a corrupted stack */
135void __dead2 __stack_chk_fail(void);
136
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100137void tf_log(const char *fmt, ...) __printflike(1, 2);
Pali Rohárfd1360a2021-07-20 23:57:47 +0200138void tf_log_newline(const char log_fmt[2]);
Maheedhar Bollapallif3ecd832024-04-24 18:43:34 +0530139void tf_log_set_max_level(uint32_t log_level);
Soby Mathewb79af932014-06-12 17:23:58 +0100140
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700141#endif /* __ASSEMBLER__ */
Antonio Nino Diaz870ce3d2018-08-15 17:02:28 +0100142#endif /* DEBUG_H */