Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 1 | /* |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, 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 | |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 10 | /* 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 Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 17 | */ |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 18 | |
| 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 Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 26 | #ifndef __ASSEMBLY__ |
Soby Mathew | f583a06 | 2017-09-04 11:45:52 +0100 | [diff] [blame] | 27 | #include <stdarg.h> |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 29 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 30 | /* |
| 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 Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 41 | #if LOG_LEVEL >= LOG_LEVEL_NOTICE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 42 | # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 43 | #else |
| 44 | # define NOTICE(...) |
| 45 | #endif |
| 46 | |
| 47 | #if LOG_LEVEL >= LOG_LEVEL_ERROR |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 48 | # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 49 | #else |
| 50 | # define ERROR(...) |
| 51 | #endif |
| 52 | |
| 53 | #if LOG_LEVEL >= LOG_LEVEL_WARNING |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 54 | # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 55 | #else |
| 56 | # define WARN(...) |
| 57 | #endif |
| 58 | |
| 59 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 60 | # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 61 | #else |
| 62 | # define INFO(...) |
| 63 | #endif |
| 64 | |
| 65 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 66 | # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 67 | #else |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 68 | # define VERBOSE(...) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Dan Handley | a17fefa | 2014-05-14 12:38:32 +0100 | [diff] [blame] | 71 | void __dead2 do_panic(void); |
Soby Mathew | 5e5c207 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 72 | #define panic() do_panic() |
| 73 | |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 74 | /* Function called when stack protection check code detects a corrupted stack */ |
| 75 | void __dead2 __stack_chk_fail(void); |
| 76 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 77 | void tf_log(const char *fmt, ...) __printflike(1, 2); |
Sandrine Bailleux | 8723adf | 2015-02-05 15:42:31 +0000 | [diff] [blame] | 78 | void tf_printf(const char *fmt, ...) __printflike(1, 2); |
Antonio Nino Diaz | 9c107fa | 2017-05-17 15:34:22 +0100 | [diff] [blame] | 79 | 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] | 80 | void tf_vprintf(const char *fmt, va_list args); |
| 81 | void tf_string_print(const char *str); |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 82 | void tf_log_set_max_level(unsigned int log_level); |
Soby Mathew | afe7e2f | 2014-06-12 17:23:58 +0100 | [diff] [blame] | 83 | |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 84 | #endif /* __ASSEMBLY__ */ |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 85 | #endif /* __DEBUG_H__ */ |