debug.h 2.36 KB
Newer Older
Harry Liebel's avatar
Harry Liebel committed
1
/*
2
 * Copyright (c) 2013-2017, 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
9
 */

#ifndef __DEBUG_H__
#define __DEBUG_H__

10
11
12
13
14
15
16
/* The log output macros print output to the console. These macros produce
 * 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.
 * 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
17
 */
18
19
20
21
22
23
24
25

#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

26
#ifndef __ASSEMBLY__
27
#include <stdarg.h>
28
#include <stdio.h>
29

Soby Mathew's avatar
Soby Mathew committed
30
31
32
33
34
35
36
37
38
39
40
/*
 * 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 */

41
#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathew's avatar
Soby Mathew committed
42
# define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
43
44
45
46
47
#else
# define NOTICE(...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathew's avatar
Soby Mathew committed
48
# define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
49
50
51
52
53
#else
# define ERROR(...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathew's avatar
Soby Mathew committed
54
# define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
55
56
57
58
59
#else
# define WARN(...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathew's avatar
Soby Mathew committed
60
# define INFO(...)	tf_log(LOG_MARKER_INFO __VA_ARGS__)
61
62
63
64
65
#else
# define INFO(...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathew's avatar
Soby Mathew committed
66
# define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel's avatar
Harry Liebel committed
67
#else
68
# define VERBOSE(...)
Harry Liebel's avatar
Harry Liebel committed
69
70
#endif

71
void __dead2 do_panic(void);
72
73
#define panic()	do_panic()

74
75
76
/* Function called when stack protection check code detects a corrupted stack */
void __dead2 __stack_chk_fail(void);

Soby Mathew's avatar
Soby Mathew committed
77
void tf_log(const char *fmt, ...) __printflike(1, 2);
78
void tf_printf(const char *fmt, ...) __printflike(1, 2);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
79
int tf_snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
80
81
void tf_vprintf(const char *fmt, va_list args);
void tf_string_print(const char *str);
Soby Mathew's avatar
Soby Mathew committed
82
void tf_log_set_max_level(unsigned int log_level);
83

84
#endif /* __ASSEMBLY__ */
Harry Liebel's avatar
Harry Liebel committed
85
#endif /* __DEBUG_H__ */