1 /* 2 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef DEBUG_H 8 #define DEBUG_H 9 10 #include <utils_def.h> 11 12 /* 13 * The log output macros print output to the console. These macros produce 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. 17 * 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. 21 */ 22 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) 29 30 #ifndef __ASSEMBLY__ 31 #include <cdefs.h> 32 #include <console.h> 33 #include <stdarg.h> 34 #include <stdbool.h> 35 #include <stdio.h> 36 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 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 { \ 55 if (false) { \ 56 tf_log(fmt, ##__VA_ARGS__); \ 57 } \ 58 } while (false) 59 60 #if LOG_LEVEL >= LOG_LEVEL_NOTICE 61 # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) 62 #else 63 # define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__) 64 #endif 65 66 #if LOG_LEVEL >= LOG_LEVEL_ERROR 67 # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__) 68 #else 69 # define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__) 70 #endif 71 72 #if LOG_LEVEL >= LOG_LEVEL_WARNING 73 # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__) 74 #else 75 # define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__) 76 #endif 77 78 #if LOG_LEVEL >= LOG_LEVEL_INFO 79 # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__) 80 #else 81 # define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__) 82 #endif 83 84 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE 85 # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) 86 #else 87 # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) 88 #endif 89 90 #if ENABLE_BACKTRACE 91 void backtrace(const char *cookie); 92 #else 93 #define backtrace(x) 94 #endif 95 96 void __dead2 do_panic(void); 97 98 #define panic() \ 99 do { \ 100 backtrace(__func__); \ 101 (void)console_flush(); \ 102 do_panic(); \ 103 } while (false) 104 105 /* Function called when stack protection check code detects a corrupted stack */ 106 void __dead2 __stack_chk_fail(void); 107 108 void tf_log(const char *fmt, ...) __printflike(1, 2); 109 void tf_log_set_max_level(unsigned int log_level); 110 111 #endif /* __ASSEMBLY__ */ 112 #endif /* DEBUG_H */ 113