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 | |
Antonio Nino Diaz | c0c8eb6 | 2018-08-15 17:02:28 +0100 | [diff] [blame] | 7 | #ifndef DEBUG_H |
| 8 | #define DEBUG_H |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 14fabd0 | 2018-08-28 11:44:44 +0100 | [diff] [blame] | 10 | #include <utils_def.h> |
| 11 | |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 12 | /* |
| 13 | * The log output macros print output to the console. These macros produce |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 14 | * compiled log output only if the LOG_LEVEL defined in the makefile (or the |
| 15 | * make command line) is greater or equal than the level required for that |
| 16 | * type of log output. |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 17 | * |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 18 | * The format expected is the same as for printf(). For example: |
| 19 | * INFO("Info %s.\n", "message") -> INFO: Info message. |
| 20 | * WARN("Warning %s.\n", "message") -> WARNING: Warning message. |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 21 | */ |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 22 | |
Antonio Nino Diaz | 14fabd0 | 2018-08-28 11:44:44 +0100 | [diff] [blame] | 23 | #define LOG_LEVEL_NONE U(0) |
| 24 | #define LOG_LEVEL_ERROR U(10) |
| 25 | #define LOG_LEVEL_NOTICE U(20) |
| 26 | #define LOG_LEVEL_WARNING U(30) |
| 27 | #define LOG_LEVEL_INFO U(40) |
| 28 | #define LOG_LEVEL_VERBOSE U(50) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 29 | |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 30 | #ifndef __ASSEMBLY__ |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 31 | #include <cdefs.h> |
Antonio Nino Diaz | d587646 | 2018-08-23 15:13:58 +0100 | [diff] [blame] | 32 | #include <console.h> |
Soby Mathew | f583a06 | 2017-09-04 11:45:52 +0100 | [diff] [blame] | 33 | #include <stdarg.h> |
Antonio Nino Diaz | d587646 | 2018-08-23 15:13:58 +0100 | [diff] [blame] | 34 | #include <stdbool.h> |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 35 | #include <stdio.h> |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 36 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 37 | /* |
| 38 | * Define Log Markers corresponding to each log level which will |
| 39 | * be embedded in the format string and is expected by tf_log() to determine |
| 40 | * the log level. |
| 41 | */ |
| 42 | #define LOG_MARKER_ERROR "\xa" /* 10 */ |
| 43 | #define LOG_MARKER_NOTICE "\x14" /* 20 */ |
| 44 | #define LOG_MARKER_WARNING "\x1e" /* 30 */ |
| 45 | #define LOG_MARKER_INFO "\x28" /* 40 */ |
| 46 | #define LOG_MARKER_VERBOSE "\x32" /* 50 */ |
| 47 | |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 48 | /* |
| 49 | * If the log output is too low then this macro is used in place of tf_log() |
| 50 | * below. The intent is to get the compiler to evaluate the function call for |
| 51 | * type checking and format specifier correctness but let it optimize it out. |
| 52 | */ |
| 53 | #define no_tf_log(fmt, ...) \ |
| 54 | do { \ |
Antonio Nino Diaz | 14fabd0 | 2018-08-28 11:44:44 +0100 | [diff] [blame] | 55 | if (false) { \ |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 56 | tf_log(fmt, ##__VA_ARGS__); \ |
| 57 | } \ |
Antonio Nino Diaz | 14fabd0 | 2018-08-28 11:44:44 +0100 | [diff] [blame] | 58 | } while (false) |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 59 | |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 60 | #if LOG_LEVEL >= LOG_LEVEL_NOTICE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 61 | # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 62 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 63 | # define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #if LOG_LEVEL >= LOG_LEVEL_ERROR |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 67 | # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 68 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 69 | # define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #if LOG_LEVEL >= LOG_LEVEL_WARNING |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 73 | # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 74 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 75 | # define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 76 | #endif |
| 77 | |
| 78 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 79 | # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 80 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 81 | # define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__) |
Dan Handley | cba2c50 | 2014-08-08 14:36:42 +0100 | [diff] [blame] | 82 | #endif |
| 83 | |
| 84 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 85 | # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 86 | #else |
Sandrine Bailleux | bf789e7 | 2018-06-20 14:50:48 +0200 | [diff] [blame] | 87 | # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) |
Harry Liebel | 57bb658 | 2013-12-19 13:30:58 +0000 | [diff] [blame] | 88 | #endif |
| 89 | |
Douglas Raillard | 7741463 | 2018-08-21 12:54:45 +0100 | [diff] [blame] | 90 | #if ENABLE_BACKTRACE |
| 91 | void backtrace(const char *cookie); |
| 92 | #else |
| 93 | #define backtrace(x) |
| 94 | #endif |
| 95 | |
Dan Handley | a17fefa | 2014-05-14 12:38:32 +0100 | [diff] [blame] | 96 | void __dead2 do_panic(void); |
Antonio Nino Diaz | d587646 | 2018-08-23 15:13:58 +0100 | [diff] [blame] | 97 | |
| 98 | #define panic() \ |
| 99 | do { \ |
| 100 | backtrace(__func__); \ |
| 101 | (void)console_flush(); \ |
| 102 | do_panic(); \ |
| 103 | } while (false) |
Soby Mathew | 5e5c207 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 104 | |
Douglas Raillard | 306593d | 2017-02-24 18:14:15 +0000 | [diff] [blame] | 105 | /* Function called when stack protection check code detects a corrupted stack */ |
| 106 | void __dead2 __stack_chk_fail(void); |
| 107 | |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 108 | void tf_log(const char *fmt, ...) __printflike(1, 2); |
Soby Mathew | aaf15f5 | 2017-09-04 11:49:29 +0100 | [diff] [blame] | 109 | void tf_log_set_max_level(unsigned int log_level); |
Soby Mathew | afe7e2f | 2014-06-12 17:23:58 +0100 | [diff] [blame] | 110 | |
Soby Mathew | 6b28c57 | 2016-03-21 10:36:47 +0000 | [diff] [blame] | 111 | #endif /* __ASSEMBLY__ */ |
Antonio Nino Diaz | c0c8eb6 | 2018-08-15 17:02:28 +0100 | [diff] [blame] | 112 | #endif /* DEBUG_H */ |