Home | History | Annotate | Download | only in common
      1 /*
      2  * Copyright (c) 2013-2017, 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 /* The log output macros print output to the console. These macros produce
     11  * compiled log output only if the LOG_LEVEL defined in the makefile (or the
     12  * make command line) is greater or equal than the level required for that
     13  * type of log output.
     14  * The format expected is the same as for printf(). For example:
     15  * INFO("Info %s.\n", "message")    -> INFO:    Info message.
     16  * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
     17  */
     18 
     19 #define LOG_LEVEL_NONE			0
     20 #define LOG_LEVEL_ERROR			10
     21 #define LOG_LEVEL_NOTICE		20
     22 #define LOG_LEVEL_WARNING		30
     23 #define LOG_LEVEL_INFO			40
     24 #define LOG_LEVEL_VERBOSE		50
     25 
     26 #ifndef __ASSEMBLY__
     27 #include <stdarg.h>
     28 #include <stdio.h>
     29 
     30 /*
     31  * Define Log Markers corresponding to each log level which will
     32  * be embedded in the format string and is expected by tf_log() to determine
     33  * the log level.
     34  */
     35 #define LOG_MARKER_ERROR		"\xa"	/* 10 */
     36 #define LOG_MARKER_NOTICE		"\x14"	/* 20 */
     37 #define LOG_MARKER_WARNING		"\x1e"	/* 30 */
     38 #define LOG_MARKER_INFO			"\x28"	/* 40 */
     39 #define LOG_MARKER_VERBOSE		"\x32"	/* 50 */
     40 
     41 #if LOG_LEVEL >= LOG_LEVEL_NOTICE
     42 # define NOTICE(...)	tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
     43 #else
     44 # define NOTICE(...)
     45 #endif
     46 
     47 #if LOG_LEVEL >= LOG_LEVEL_ERROR
     48 # define ERROR(...)	tf_log(LOG_MARKER_ERROR __VA_ARGS__)
     49 #else
     50 # define ERROR(...)
     51 #endif
     52 
     53 #if LOG_LEVEL >= LOG_LEVEL_WARNING
     54 # define WARN(...)	tf_log(LOG_MARKER_WARNING __VA_ARGS__)
     55 #else
     56 # define WARN(...)
     57 #endif
     58 
     59 #if LOG_LEVEL >= LOG_LEVEL_INFO
     60 # define INFO(...)	tf_log(LOG_MARKER_INFO __VA_ARGS__)
     61 #else
     62 # define INFO(...)
     63 #endif
     64 
     65 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
     66 # define VERBOSE(...)	tf_log(LOG_MARKER_VERBOSE __VA_ARGS__)
     67 #else
     68 # define VERBOSE(...)
     69 #endif
     70 
     71 void __dead2 do_panic(void);
     72 #define panic()	do_panic()
     73 
     74 /* Function called when stack protection check code detects a corrupted stack */
     75 void __dead2 __stack_chk_fail(void);
     76 
     77 void tf_log(const char *fmt, ...) __printflike(1, 2);
     78 void tf_printf(const char *fmt, ...) __printflike(1, 2);
     79 int tf_snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
     80 void tf_vprintf(const char *fmt, va_list args);
     81 void tf_string_print(const char *str);
     82 void tf_log_set_max_level(unsigned int log_level);
     83 
     84 #endif /* __ASSEMBLY__ */
     85 #endif /* __DEBUG_H__ */
     86