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