blob: 4b30175d926a2e14e616a38d1046e01699ad696a [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
Antonio Nino Diazf2218e72019-03-19 10:59:11 +000012#ifdef IMAGE_CACTUS_MM
13/* Remove dependency on spinlocks for Cactus-MM */
14#define mp_printf printf
15#else
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020016/*
17 * Print a formatted string on the UART.
18 *
19 * Does the same thing as the standard libc's printf() function but in a MP-safe
20 * manner, i.e. it can be called from several CPUs simultaneously without
21 * getting interleaved messages.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020022 */
23__attribute__((format(printf, 1, 2)))
24void mp_printf(const char *fmt, ...);
Antonio Nino Diazf2218e72019-03-19 10:59:11 +000025#endif /* IMAGE_CACTUS_MM */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020026
27/*
28 * The log output macros print output to the console. These macros produce
29 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
30 * make command line) is greater or equal than the level required for that
31 * type of log output.
32 * The format expected is similar to printf(). For example:
Sandrine Bailleux750b7cc2018-11-08 14:10:18 +010033 * INFO("Info %s.\n", "message") -> INFO: Info message.
34 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035 */
36#define LOG_LEVEL_NONE 0
37#define LOG_LEVEL_ERROR 10
38#define LOG_LEVEL_NOTICE 20
39#define LOG_LEVEL_WARNING 30
40#define LOG_LEVEL_INFO 40
41#define LOG_LEVEL_VERBOSE 50
42
43#if LOG_LEVEL >= LOG_LEVEL_NOTICE
44# define NOTICE(...) mp_printf("NOTICE: " __VA_ARGS__)
45#else
46# define NOTICE(...)
47#endif
48
49#if LOG_LEVEL >= LOG_LEVEL_ERROR
50# define ERROR(...) mp_printf("ERROR: " __VA_ARGS__)
51#else
52# define ERROR(...)
53#endif
54
55#if LOG_LEVEL >= LOG_LEVEL_WARNING
56# define WARN(...) mp_printf("WARNING: " __VA_ARGS__)
57#else
58# define WARN(...)
59#endif
60
61#if LOG_LEVEL >= LOG_LEVEL_INFO
62# define INFO(...) mp_printf("INFO: " __VA_ARGS__)
63#else
64# define INFO(...)
65#endif
66
67#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
68# define VERBOSE(...) mp_printf("VERBOSE: " __VA_ARGS__)
69#else
70# define VERBOSE(...)
71#endif
72
Ambroise Vincent602b7f52019-02-11 14:13:43 +000073#if ENABLE_BACKTRACE
74void backtrace(const char *cookie);
75#else
76#define backtrace(x)
77#endif
78
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020079/*
Sandrine Bailleuxa2d516f2019-01-15 16:34:19 +010080 * For the moment this panic function is very basic: report an error and
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020081 * spin. This can be expanded in the future to provide more information.
82 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020083void __attribute__((__noreturn__)) do_panic(const char *file, int line);
84#define panic() do_panic(__FILE__, __LINE__)
85
86void __attribute__((__noreturn__)) do_bug_unreachable(const char *file, int line);
87#define bug_unreachable() do_bug_unreachable(__FILE__, __LINE__)
88
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020089#endif /* __DEBUG_H__ */