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