blob: 99f402c0842e9a37a68d4feebedd015a23913353 [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
7#ifndef __DEBUG_H__
8#define __DEBUG_H__
9
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__
Soby Mathewf583a062017-09-04 11:45:52 +010029#include <stdarg.h>
Soby Mathew6b28c572016-03-21 10:36:47 +000030#include <stdio.h>
Dan Handleycba2c502014-08-08 14:36:42 +010031
Soby Mathewaaf15f52017-09-04 11:49:29 +010032/*
33 * Define Log Markers corresponding to each log level which will
34 * be embedded in the format string and is expected by tf_log() to determine
35 * the log level.
36 */
37#define LOG_MARKER_ERROR "\xa" /* 10 */
38#define LOG_MARKER_NOTICE "\x14" /* 20 */
39#define LOG_MARKER_WARNING "\x1e" /* 30 */
40#define LOG_MARKER_INFO "\x28" /* 40 */
41#define LOG_MARKER_VERBOSE "\x32" /* 50 */
42
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020043/*
44 * If the log output is too low then this macro is used in place of tf_log()
45 * below. The intent is to get the compiler to evaluate the function call for
46 * type checking and format specifier correctness but let it optimize it out.
47 */
48#define no_tf_log(fmt, ...) \
49 do { \
50 if (0) { \
51 tf_log(fmt, ##__VA_ARGS__); \
52 } \
53 } while (0)
54
Dan Handleycba2c502014-08-08 14:36:42 +010055#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathewaaf15f52017-09-04 11:49:29 +010056# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010057#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020058# define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010059#endif
60
61#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathewaaf15f52017-09-04 11:49:29 +010062# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010063#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020064# define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010065#endif
66
67#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathewaaf15f52017-09-04 11:49:29 +010068# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010069#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020070# define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010071#endif
72
73#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathewaaf15f52017-09-04 11:49:29 +010074# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010075#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020076# define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010077#endif
78
79#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathewaaf15f52017-09-04 11:49:29 +010080# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000081#else
Sandrine Bailleuxbf789e72018-06-20 14:50:48 +020082# define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000083#endif
84
Dan Handleya17fefa2014-05-14 12:38:32 +010085void __dead2 do_panic(void);
Soby Mathew5e5c2072014-04-07 15:28:55 +010086#define panic() do_panic()
87
Douglas Raillard306593d2017-02-24 18:14:15 +000088/* Function called when stack protection check code detects a corrupted stack */
89void __dead2 __stack_chk_fail(void);
90
Soby Mathewaaf15f52017-09-04 11:49:29 +010091void tf_log(const char *fmt, ...) __printflike(1, 2);
Sandrine Bailleux8723adf2015-02-05 15:42:31 +000092void tf_printf(const char *fmt, ...) __printflike(1, 2);
Antonio Nino Diaz9c107fa2017-05-17 15:34:22 +010093int tf_snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
Soby Mathewf583a062017-09-04 11:45:52 +010094void tf_vprintf(const char *fmt, va_list args);
95void tf_string_print(const char *str);
Soby Mathewaaf15f52017-09-04 11:49:29 +010096void tf_log_set_max_level(unsigned int log_level);
Soby Mathewafe7e2f2014-06-12 17:23:58 +010097
Soby Mathew6b28c572016-03-21 10:36:47 +000098#endif /* __ASSEMBLY__ */
Harry Liebel57bb6582013-12-19 13:30:58 +000099#endif /* __DEBUG_H__ */