blob: ab3e15a73dff427f4ed32088a128931abfc1095b [file] [log] [blame]
Harry Liebel57bb6582013-12-19 13:30:58 +00001/*
Sandrine Bailleuxbf789e72018-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-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
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020010/*
11 * The log output macros print output to the console. These macros produce
Dan Handleycba2c502014-08-08 14:36:42 +010012 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
13 * make command line) is greater or equal than the level required for that
14 * type of log output.
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020015 *
Dan Handleycba2c502014-08-08 14:36:42 +010016 * The format expected is the same as for printf(). For example:
17 * INFO("Info %s.\n", "message") -> INFO: Info message.
18 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Harry Liebel57bb6582013-12-19 13:30:58 +000019 */
Dan Handleycba2c502014-08-08 14:36:42 +010020
21#define LOG_LEVEL_NONE 0
22#define LOG_LEVEL_ERROR 10
23#define LOG_LEVEL_NOTICE 20
24#define LOG_LEVEL_WARNING 30
25#define LOG_LEVEL_INFO 40
26#define LOG_LEVEL_VERBOSE 50
27
Soby Mathew6b28c572016-03-21 10:36:47 +000028#ifndef __ASSEMBLY__
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010029#include <cdefs.h>
Antonio Nino Diazd5876462018-08-23 15:13:58 +010030#include <console.h>
Soby Mathewf583a062017-09-04 11:45:52 +010031#include <stdarg.h>
Antonio Nino Diazd5876462018-08-23 15:13:58 +010032#include <stdbool.h>
Soby Mathew6b28c572016-03-21 10:36:47 +000033#include <stdio.h>
Dan Handleycba2c502014-08-08 14:36:42 +010034
Soby Mathewaaf15f52017-09-04 11:49:29 +010035/*
36 * Define Log Markers corresponding to each log level which will
37 * be embedded in the format string and is expected by tf_log() to determine
38 * the log level.
39 */
40#define LOG_MARKER_ERROR "\xa" /* 10 */
41#define LOG_MARKER_NOTICE "\x14" /* 20 */
42#define LOG_MARKER_WARNING "\x1e" /* 30 */
43#define LOG_MARKER_INFO "\x28" /* 40 */
44#define LOG_MARKER_VERBOSE "\x32" /* 50 */
45
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020046/*
47 * If the log output is too low then this macro is used in place of tf_log()
48 * below. The intent is to get the compiler to evaluate the function call for
49 * type checking and format specifier correctness but let it optimize it out.
50 */
51#define no_tf_log(fmt, ...) \
52 do { \
53 if (0) { \
54 tf_log(fmt, ##__VA_ARGS__); \
55 } \
56 } while (0)
57
Dan Handleycba2c502014-08-08 14:36:42 +010058#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathewaaf15f52017-09-04 11:49:29 +010059# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010060#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020061# define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010062#endif
63
64#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathewaaf15f52017-09-04 11:49:29 +010065# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010066#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020067# define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010068#endif
69
70#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathewaaf15f52017-09-04 11:49:29 +010071# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010072#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020073# define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010074#endif
75
76#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathewaaf15f52017-09-04 11:49:29 +010077# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010078#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020079# define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010080#endif
81
82#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathewaaf15f52017-09-04 11:49:29 +010083# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000084#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020085# define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000086#endif
87
Douglas Raillard77414632018-08-21 12:54:45 +010088#if ENABLE_BACKTRACE
89void backtrace(const char *cookie);
90#else
91#define backtrace(x)
92#endif
93
Dan Handleya17fefa2014-05-14 12:38:32 +010094void __dead2 do_panic(void);
Antonio Nino Diazd5876462018-08-23 15:13:58 +010095
96#define panic() \
97 do { \
98 backtrace(__func__); \
99 (void)console_flush(); \
100 do_panic(); \
101 } while (false)
Soby Mathew5e5c2072014-04-07 15:28:55 +0100102
Douglas Raillard306593d2017-02-24 18:14:15 +0000103/* Function called when stack protection check code detects a corrupted stack */
104void __dead2 __stack_chk_fail(void);
105
Soby Mathewaaf15f52017-09-04 11:49:29 +0100106void tf_log(const char *fmt, ...) __printflike(1, 2);
Soby Mathewaaf15f52017-09-04 11:49:29 +0100107void tf_log_set_max_level(unsigned int log_level);
Soby Mathewafe7e2f2014-06-12 17:23:58 +0100108
Soby Mathew6b28c572016-03-21 10:36:47 +0000109#endif /* __ASSEMBLY__ */
Antonio Nino Diazc0c8eb62018-08-15 17:02:28 +0100110#endif /* DEBUG_H */