blob: 9b2d8421657e0a69706a3b9d5faceb9cfddb0f69 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2014-2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __DEBUG_H__
8#define __DEBUG_H__
9
10#include <stdio.h>
11
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012/*
13 * Print a formatted string on the UART.
14 *
15 * Does the same thing as the standard libc's printf() function but in a MP-safe
16 * manner, i.e. it can be called from several CPUs simultaneously without
17 * getting interleaved messages.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018 */
19__attribute__((format(printf, 1, 2)))
20void mp_printf(const char *fmt, ...);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021
22/*
23 * The log output macros print output to the console. These macros produce
24 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
25 * make command line) is greater or equal than the level required for that
26 * type of log output.
27 * The format expected is similar to printf(). For example:
Sandrine Bailleux750b7cc2018-11-08 14:10:18 +010028 * INFO("Info %s.\n", "message") -> INFO: Info message.
29 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030 */
31#define LOG_LEVEL_NONE 0
32#define LOG_LEVEL_ERROR 10
33#define LOG_LEVEL_NOTICE 20
34#define LOG_LEVEL_WARNING 30
35#define LOG_LEVEL_INFO 40
36#define LOG_LEVEL_VERBOSE 50
37
38#if LOG_LEVEL >= LOG_LEVEL_NOTICE
39# define NOTICE(...) mp_printf("NOTICE: " __VA_ARGS__)
40#else
41# define NOTICE(...)
42#endif
43
44#if LOG_LEVEL >= LOG_LEVEL_ERROR
45# define ERROR(...) mp_printf("ERROR: " __VA_ARGS__)
46#else
47# define ERROR(...)
48#endif
49
50#if LOG_LEVEL >= LOG_LEVEL_WARNING
51# define WARN(...) mp_printf("WARNING: " __VA_ARGS__)
52#else
53# define WARN(...)
54#endif
55
56#if LOG_LEVEL >= LOG_LEVEL_INFO
57# define INFO(...) mp_printf("INFO: " __VA_ARGS__)
58#else
59# define INFO(...)
60#endif
61
62#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
63# define VERBOSE(...) mp_printf("VERBOSE: " __VA_ARGS__)
64#else
65# define VERBOSE(...)
66#endif
67
Ambroise Vincent602b7f52019-02-11 14:13:43 +000068#if ENABLE_BACKTRACE
69void backtrace(const char *cookie);
70#else
71#define backtrace(x)
72#endif
73
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020074/*
Sandrine Bailleuxa2d516f2019-01-15 16:34:19 +010075 * For the moment this panic function is very basic: report an error and
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020076 * spin. This can be expanded in the future to provide more information.
77 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020078void __attribute__((__noreturn__)) do_panic(const char *file, int line);
79#define panic() do_panic(__FILE__, __LINE__)
80
81void __attribute__((__noreturn__)) do_bug_unreachable(const char *file, int line);
82#define bug_unreachable() do_bug_unreachable(__FILE__, __LINE__)
83
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084#endif /* __DEBUG_H__ */