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 /* 11 * The log output macros print output to the console. These macros produce 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. 15 * 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. 19 */ 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 28 #ifndef __ASSEMBLY__ 29 #include <cdefs.h> 30 #include <console.h> 31 #include <stdarg.h> 32 #include <stdbool.h> 33 #include <stdio.h> 34 35 /* 36 * Define Log Markers corresponding to each log level which will 37 * be embedded in the format string and is expected by tf_log() to determine 38 * the log level. 39 */ 40 #define LOG_MARKER_ERROR "\xa" /* 10 */ 41 #define LOG_MARKER_NOTICE "\x14" /* 20 */ 42 #define LOG_MARKER_WARNING "\x1e" /* 30 */ 43 #define LOG_MARKER_INFO "\x28" /* 40 */ 44 #define LOG_MARKER_VERBOSE "\x32" /* 50 */ 45 46 /* 47 * If the log output is too low then this macro is used in place of tf_log() 48 * below. The intent is to get the compiler to evaluate the function call for 49 * type checking and format specifier correctness but let it optimize it out. 50 */ 51 #define no_tf_log(fmt, ...) \ 52 do { \ 53 if (0) { \ 54 tf_log(fmt, ##__VA_ARGS__); \ 55 } \ 56 } while (0) 57 58 #if LOG_LEVEL >= LOG_LEVEL_NOTICE 59 # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) 60 #else 61 # define NOTICE(...) no_tf_log(LOG_MARKER_NOTICE __VA_ARGS__) 62 #endif 63 64 #if LOG_LEVEL >= LOG_LEVEL_ERROR 65 # define ERROR(...) tf_log(LOG_MARKER_ERROR __VA_ARGS__) 66 #else 67 # define ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__) 68 #endif 69 70 #if LOG_LEVEL >= LOG_LEVEL_WARNING 71 # define WARN(...) tf_log(LOG_MARKER_WARNING __VA_ARGS__) 72 #else 73 # define WARN(...) no_tf_log(LOG_MARKER_WARNING __VA_ARGS__) 74 #endif 75 76 #if LOG_LEVEL >= LOG_LEVEL_INFO 77 # define INFO(...) tf_log(LOG_MARKER_INFO __VA_ARGS__) 78 #else 79 # define INFO(...) no_tf_log(LOG_MARKER_INFO __VA_ARGS__) 80 #endif 81 82 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE 83 # define VERBOSE(...) tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) 84 #else 85 # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) 86 #endif 87 88 #if ENABLE_BACKTRACE 89 void backtrace(const char *cookie); 90 #else 91 #define backtrace(x) 92 #endif 93 94 void __dead2 do_panic(void); 95 96 #define panic() \ 97 do { \ 98 backtrace(__func__); \ 99 (void)console_flush(); \ 100 do_panic(); \ 101 } while (false) 102 103 /* Function called when stack protection check code detects a corrupted stack */ 104 void __dead2 __stack_chk_fail(void); 105 106 void tf_log(const char *fmt, ...) __printflike(1, 2); 107 void tf_log_set_max_level(unsigned int log_level); 108 109 #endif /* __ASSEMBLY__ */ 110 #endif /* DEBUG_H */ 111