blob: 8ee55b8828b572a0cdc57139e3767011c56df24c [file] [log] [blame]
Harry Liebel57bb6582013-12-19 13:30:58 +00001/*
Sandrine Bailleuxcf242292018-06-20 14:50:48 +02002 * Copyright (c) 2013-2018, 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 Diaz5a22e462018-08-28 11:44:44 +010010#include <utils_def.h>
11
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
Soby Mathew1319e7b2016-03-21 10:36:47 +000030#ifndef __ASSEMBLY__
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +010031#include <cdefs.h>
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +010032#include <console.h>
Soby Mathew2d7e8282017-09-04 11:45:52 +010033#include <stdarg.h>
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +010034#include <stdbool.h>
Soby Mathew1319e7b2016-03-21 10:36:47 +000035#include <stdio.h>
Dan Handley289c28a2014-08-08 14:36:42 +010036
Soby Mathew7f56e9a2017-09-04 11:49:29 +010037/*
38 * Define Log Markers corresponding to each log level which will
39 * be embedded in the format string and is expected by tf_log() to determine
40 * the log level.
41 */
42#define LOG_MARKER_ERROR "\xa" /* 10 */
43#define LOG_MARKER_NOTICE "\x14" /* 20 */
44#define LOG_MARKER_WARNING "\x1e" /* 30 */
45#define LOG_MARKER_INFO "\x28" /* 40 */
46#define LOG_MARKER_VERBOSE "\x32" /* 50 */
47
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020048/*
49 * If the log output is too low then this macro is used in place of tf_log()
50 * below. The intent is to get the compiler to evaluate the function call for
51 * type checking and format specifier correctness but let it optimize it out.
52 */
53#define no_tf_log(fmt, ...) \
54 do { \
Antonio Nino Diaz5a22e462018-08-28 11:44:44 +010055 if (false) { \
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020056 tf_log(fmt, ##__VA_ARGS__); \
57 } \
Antonio Nino Diaz5a22e462018-08-28 11:44:44 +010058 } while (false)
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020059
Dan Handley289c28a2014-08-08 14:36:42 +010060#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathew7f56e9a2017-09-04 11:49:29 +010061# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000062#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020063# define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000064#endif
65
Dan Handley289c28a2014-08-08 14:36:42 +010066#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathew7f56e9a2017-09-04 11:49:29 +010067# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010068#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020069# define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010070#endif
71
72#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathew7f56e9a2017-09-04 11:49:29 +010073# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010074#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020075# define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010076#endif
77
78#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathew7f56e9a2017-09-04 11:49:29 +010079# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010080#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020081# define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010082#endif
83
84#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathew7f56e9a2017-09-04 11:49:29 +010085# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010086#else
Sandrine Bailleuxcf242292018-06-20 14:50:48 +020087# define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Dan Handley289c28a2014-08-08 14:36:42 +010088#endif
89
Douglas Raillard0c628832018-08-21 12:54:45 +010090#if ENABLE_BACKTRACE
91void backtrace(const char *cookie);
92#else
93#define backtrace(x)
94#endif
95
Dan Handleyc6bc0712014-05-14 12:38:32 +010096void __dead2 do_panic(void);
Antonio Nino Diaz3e530d82018-08-23 15:13:58 +010097
98#define panic() \
99 do { \
100 backtrace(__func__); \
101 (void)console_flush(); \
102 do_panic(); \
103 } while (false)
Soby Mathewa43d4312014-04-07 15:28:55 +0100104
Douglas Raillard51faada2017-02-24 18:14:15 +0000105/* Function called when stack protection check code detects a corrupted stack */
106void __dead2 __stack_chk_fail(void);
107
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100108void tf_log(const char *fmt, ...) __printflike(1, 2);
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100109void tf_log_set_max_level(unsigned int log_level);
Soby Mathewb79af932014-06-12 17:23:58 +0100110
Soby Mathew1319e7b2016-03-21 10:36:47 +0000111#endif /* __ASSEMBLY__ */
Antonio Nino Diaz870ce3d2018-08-15 17:02:28 +0100112#endif /* DEBUG_H */