blob: 216c53d9b47638bb3c0859e75966a8eb6a70f540 [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
68/*
69 * For the moment this Panic function is very basic, Report an error and
70 * spin. This can be expanded in the future to provide more information.
71 */
72#if DEBUG
73void __attribute__((__noreturn__)) do_panic(const char *file, int line);
74#define panic() do_panic(__FILE__, __LINE__)
75
76void __attribute__((__noreturn__)) do_bug_unreachable(const char *file, int line);
77#define bug_unreachable() do_bug_unreachable(__FILE__, __LINE__)
78
79#else
80void __attribute__((__noreturn__)) do_panic(void);
81#define panic() do_panic()
82
83void __attribute__((__noreturn__)) do_bug_unreachable(void);
84#define bug_unreachable() do_bug_unreachable()
85
86#endif
87
88#endif /* __DEBUG_H__ */