debug.h 2.93 KB
Newer Older
Harry Liebel's avatar
Harry Liebel committed
1
/*
2
 * Copyright (c) 2013-2018, 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
11
/*
 * The log output macros print output to the console. These macros produce
12
13
14
 * 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.
15
 *
16
17
18
 * 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
19
 */
20
21
22
23
24
25
26
27

#define LOG_LEVEL_NONE			0
#define LOG_LEVEL_ERROR			10
#define LOG_LEVEL_NOTICE		20
#define LOG_LEVEL_WARNING		30
#define LOG_LEVEL_INFO			40
#define LOG_LEVEL_VERBOSE		50

28
#ifndef __ASSEMBLY__
29
#include <cdefs.h>
30
#include <console.h>
31
#include <stdarg.h>
32
#include <stdbool.h>
33
#include <stdio.h>
34

Soby Mathew's avatar
Soby Mathew committed
35
36
37
38
39
40
41
42
43
44
45
/*
 * 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 */

46
47
48
49
50
51
52
53
54
55
56
57
/*
 * 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 {						\
		if (0) {				\
			tf_log(fmt, ##__VA_ARGS__);	\
		}					\
	} while (0)

58
#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathew's avatar
Soby Mathew committed
59
# define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
60
#else
61
# define NOTICE(...)	no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
62
63
64
#endif

#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathew's avatar
Soby Mathew committed
65
# define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
66
#else
67
# define ERROR(...)	no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
68
69
70
#endif

#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathew's avatar
Soby Mathew committed
71
# define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
72
#else
73
# define WARN(...)	no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
74
75
76
#endif

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

#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathew's avatar
Soby Mathew committed
83
# define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel's avatar
Harry Liebel committed
84
#else
85
# define VERBOSE(...)	no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel's avatar
Harry Liebel committed
86
87
#endif

88
89
90
91
92
93
#if ENABLE_BACKTRACE
void backtrace(const char *cookie);
#else
#define backtrace(x)
#endif

94
void __dead2 do_panic(void);
95
96
97
98
99
100
101

#define panic()				\
	do {				\
		backtrace(__func__);	\
		(void)console_flush();	\
		do_panic();		\
	} while (false)
102

103
104
105
/* Function called when stack protection check code detects a corrupted stack */
void __dead2 __stack_chk_fail(void);

Soby Mathew's avatar
Soby Mathew committed
106
107
void tf_log(const char *fmt, ...) __printflike(1, 2);
void tf_log_set_max_level(unsigned int log_level);
108

109
#endif /* __ASSEMBLY__ */
110
#endif /* DEBUG_H */