blob: 3f0f84a1ba465fa97db6c4cecfbc82c22cdfb322 [file] [log] [blame]
Harry Liebel57bb6582013-12-19 13:30:58 +00001/*
Douglas Raillard306593d2017-02-24 18:14:15 +00002 * Copyright (c) 2013-2017, 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
Dan Handleycba2c502014-08-08 14:36:42 +010010/* The log output macros print output to the console. These macros produce
11 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
12 * make command line) is greater or equal than the level required for that
13 * type of log output.
14 * The format expected is the same as for printf(). For example:
15 * INFO("Info %s.\n", "message") -> INFO: Info message.
16 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Harry Liebel57bb6582013-12-19 13:30:58 +000017 */
Dan Handleycba2c502014-08-08 14:36:42 +010018
19#define LOG_LEVEL_NONE 0
20#define LOG_LEVEL_ERROR 10
21#define LOG_LEVEL_NOTICE 20
22#define LOG_LEVEL_WARNING 30
23#define LOG_LEVEL_INFO 40
24#define LOG_LEVEL_VERBOSE 50
25
Soby Mathew6b28c572016-03-21 10:36:47 +000026#ifndef __ASSEMBLY__
Soby Mathewf583a062017-09-04 11:45:52 +010027#include <stdarg.h>
Soby Mathew6b28c572016-03-21 10:36:47 +000028#include <stdio.h>
Dan Handleycba2c502014-08-08 14:36:42 +010029
Soby Mathewaaf15f52017-09-04 11:49:29 +010030/*
31 * Define Log Markers corresponding to each log level which will
32 * be embedded in the format string and is expected by tf_log() to determine
33 * the log level.
34 */
35#define LOG_MARKER_ERROR "\xa" /* 10 */
36#define LOG_MARKER_NOTICE "\x14" /* 20 */
37#define LOG_MARKER_WARNING "\x1e" /* 30 */
38#define LOG_MARKER_INFO "\x28" /* 40 */
39#define LOG_MARKER_VERBOSE "\x32" /* 50 */
40
Dan Handleycba2c502014-08-08 14:36:42 +010041#if LOG_LEVEL >= LOG_LEVEL_NOTICE
Soby Mathewaaf15f52017-09-04 11:49:29 +010042# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010043#else
44# define NOTICE(...)
45#endif
46
47#if LOG_LEVEL >= LOG_LEVEL_ERROR
Soby Mathewaaf15f52017-09-04 11:49:29 +010048# define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010049#else
50# define ERROR(...)
51#endif
52
53#if LOG_LEVEL >= LOG_LEVEL_WARNING
Soby Mathewaaf15f52017-09-04 11:49:29 +010054# define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010055#else
56# define WARN(...)
57#endif
58
59#if LOG_LEVEL >= LOG_LEVEL_INFO
Soby Mathewaaf15f52017-09-04 11:49:29 +010060# define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__)
Dan Handleycba2c502014-08-08 14:36:42 +010061#else
62# define INFO(...)
63#endif
64
65#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
Soby Mathewaaf15f52017-09-04 11:49:29 +010066# define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
Harry Liebel57bb6582013-12-19 13:30:58 +000067#else
Dan Handleycba2c502014-08-08 14:36:42 +010068# define VERBOSE(...)
Harry Liebel57bb6582013-12-19 13:30:58 +000069#endif
70
Dan Handleya17fefa2014-05-14 12:38:32 +010071void __dead2 do_panic(void);
Soby Mathew5e5c2072014-04-07 15:28:55 +010072#define panic() do_panic()
73
Douglas Raillard306593d2017-02-24 18:14:15 +000074/* Function called when stack protection check code detects a corrupted stack */
75void __dead2 __stack_chk_fail(void);
76
Soby Mathewaaf15f52017-09-04 11:49:29 +010077void tf_log(const char *fmt, ...) __printflike(1, 2);
Sandrine Bailleux8723adf2015-02-05 15:42:31 +000078void tf_printf(const char *fmt, ...) __printflike(1, 2);
Antonio Nino Diaz9c107fa2017-05-17 15:34:22 +010079int tf_snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
Soby Mathewf583a062017-09-04 11:45:52 +010080void tf_vprintf(const char *fmt, va_list args);
81void tf_string_print(const char *str);
Soby Mathewaaf15f52017-09-04 11:49:29 +010082void tf_log_set_max_level(unsigned int log_level);
Soby Mathewafe7e2f2014-06-12 17:23:58 +010083
Soby Mathew6b28c572016-03-21 10:36:47 +000084#endif /* __ASSEMBLY__ */
Harry Liebel57bb6582013-12-19 13:30:58 +000085#endif /* __DEBUG_H__ */