debug.h 3.14 KB
Newer Older
Harry Liebel's avatar
Harry Liebel committed
1
/*
Alexei Fedorov's avatar
Alexei Fedorov committed
2
 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Harry Liebel's avatar
Harry Liebel committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Harry Liebel's avatar
Harry Liebel committed
5
6
 */

7
8
#ifndef DEBUG_H
#define DEBUG_H
Harry Liebel's avatar
Harry Liebel committed
9

10
#include <lib/utils_def.h>
11

12
13
/*
 * The log output macros print output to the console. These macros produce
14
15
16
 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
 * make command line) is greater or equal than the level required for that
 * type of log output.
17
 *
18
19
20
 * The format expected is the same as for printf(). For example:
 * INFO("Info %s.\n", "message")    -> INFO:    Info message.
 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Harry Liebel's avatar
Harry Liebel committed
21
 */
22

23
24
25
26
27
28
#define LOG_LEVEL_NONE			U(0)
#define LOG_LEVEL_ERROR			U(10)
#define LOG_LEVEL_NOTICE		U(20)
#define LOG_LEVEL_WARNING		U(30)
#define LOG_LEVEL_INFO			U(40)
#define LOG_LEVEL_VERBOSE		U(50)
29

30
#ifndef __ASSEMBLER__
31

32
#include <cdefs.h>
33
#include <stdarg.h>
34
#include <stdbool.h>
35
#include <stdio.h>
36

37
38
#include <drivers/console.h>

Soby Mathew's avatar
Soby Mathew committed
39
40
41
42
43
44
45
46
47
48
49
/*
 * Define Log Markers corresponding to each log level which will
 * be embedded in the format string and is expected by tf_log() to determine
 * the log level.
 */
#define LOG_MARKER_ERROR		"\xa"	/* 10 */
#define LOG_MARKER_NOTICE		"\x14"	/* 20 */
#define LOG_MARKER_WARNING		"\x1e"	/* 30 */
#define LOG_MARKER_INFO			"\x28"	/* 40 */
#define LOG_MARKER_VERBOSE		"\x32"	/* 50 */

50
51
52
53
54
55
56
/*
 * If the log output is too low then this macro is used in place of tf_log()
 * below. The intent is to get the compiler to evaluate the function call for
 * type checking and format specifier correctness but let it optimize it out.
 */
#define no_tf_log(fmt, ...)				\
	do {						\
57
		if (false) {				\
58
59
			tf_log(fmt, ##__VA_ARGS__);	\
		}					\
60
	} while (false)
61

62
#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathew's avatar
Soby Mathew committed
63
# define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
64
# define ERROR_NL()	tf_log_newline(LOG_MARKER_ERROR)
65
#else
66
# define ERROR(...)	no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
67
# define ERROR_NL()
68
69
70
71
72
73
#endif

#if LOG_LEVEL >= LOG_LEVEL_NOTICE
# define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
#else
# define NOTICE(...)	no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
74
75
76
#endif

#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathew's avatar
Soby Mathew committed
77
# define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
78
#else
79
# define WARN(...)	no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
80
81
82
#endif

#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathew's avatar
Soby Mathew committed
83
# define INFO(...)	tf_log(LOG_MARKER_INFO __VA_ARGS__)
84
#else
85
# define INFO(...)	no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
86
87
88
#endif

#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathew's avatar
Soby Mathew committed
89
# define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel's avatar
Harry Liebel committed
90
#else
91
# define VERBOSE(...)	no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel's avatar
Harry Liebel committed
92
93
#endif

94
95
#if ENABLE_BACKTRACE
void backtrace(const char *cookie);
Alexei Fedorov's avatar
Alexei Fedorov committed
96
const char *get_el_str(unsigned int el);
97
98
99
100
#else
#define backtrace(x)
#endif

101
void __dead2 do_panic(void);
102
103
104
105

#define panic()				\
	do {				\
		backtrace(__func__);	\
106
		console_flush();	\
107
108
		do_panic();		\
	} while (false)
109

110
111
112
/* Function called when stack protection check code detects a corrupted stack */
void __dead2 __stack_chk_fail(void);

Soby Mathew's avatar
Soby Mathew committed
113
void tf_log(const char *fmt, ...) __printflike(1, 2);
114
void tf_log_newline(const char log_fmt[2]);
Soby Mathew's avatar
Soby Mathew committed
115
void tf_log_set_max_level(unsigned int log_level);
116

117
#endif /* __ASSEMBLER__ */
118
#endif /* DEBUG_H */