Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 1 | /* |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 2 | * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __DEBUG_H__ |
| 8 | #define __DEBUG_H__ |
| 9 | |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 10 | /* |
| 11 | * The log output macros print output to the console. These macros produce |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 12 | * 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 Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 15 | * |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 16 | * 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 Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 19 | */ |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 20 | |
| 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 Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 28 | #ifndef __ASSEMBLY__ |
Soby Mathew | f583a06 | 2017-09-04 11:45:52 +0100 | [diff] [blame] | 29 | #include <stdarg.h> |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 30 | #include <stdio.h> |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 31 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 32 | /* |
| 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 Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 43 | /* |
| 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 Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 55 | #if LOG_LEVEL >= LOG_LEVEL_NOTICE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 56 | # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 57 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 58 | # define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 59 | #endif |
| 60 | |
| 61 | #if LOG_LEVEL >= LOG_LEVEL_ERROR |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 62 | # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 63 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 64 | # define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | #if LOG_LEVEL >= LOG_LEVEL_WARNING |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 68 | # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 69 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 70 | # define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 71 | #endif |
| 72 | |
| 73 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 74 | # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 75 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 76 | # define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 80 | # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 81 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 82 | # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 83 | #endif |
| 84 | |
Dan Handley | a17fefa | 2014-05-14 12:38:32 +0100 | [diff] [blame] | 85 | void __dead2 do_panic(void); |
Soby Mathew | 5e5c207 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 86 | #define panic() do_panic() |
| 87 | |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 88 | /* Function called when stack protection check code detects a corrupted stack */ |
| 89 | void __dead2 __stack_chk_fail(void); |
| 90 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 91 | void tf_log(const char *fmt, ...) __printflike(1, 2); |
Sandrine Bailleux | 8723adf | 2015-02-05 15:42:31 +0000 | [diff] [blame] | 92 | void tf_printf(const char *fmt, ...) __printflike(1, 2); |
Antonio Nino Diaz | 9c107fa | 2017-05-17 15:34:22 +0100 | [diff] [blame] | 93 | int tf_snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4); |
Soby Mathew | f583a06 | 2017-09-04 11:45:52 +0100 | [diff] [blame] | 94 | void tf_vprintf(const char *fmt, va_list args); |
| 95 | void tf_string_print(const char *str); |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 96 | void tf_log_set_max_level(unsigned int log_level); |
Soby Mathew | afe7e2f | 2014-06-12 17:23:58 +0100 | [diff] [blame] | 97 | |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 98 | #endif /* __ASSEMBLY__ */ |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 99 | #endif /* __DEBUG_H__ */ |