blob: 6025590b495190819f37946fbb583c95c41eefab [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
nabkah01002e5692022-10-10 12:36:46 +01002 * Copyright (c) 2014-2022, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
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
nabkah01002e5692022-10-10 12:36:46 +010027#ifdef IMAGE_REALM
28void realm_printf(const char *fmt, ...);
29#define mp_printf realm_printf
30#endif
31
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020032/*
33 * The log output macros print output to the console. These macros produce
34 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
35 * make command line) is greater or equal than the level required for that
36 * type of log output.
37 * The format expected is similar to printf(). For example:
Sandrine Bailleux750b7cc2018-11-08 14:10:18 +010038 * INFO("Info %s.\n", "message") -> INFO: Info message.
39 * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020040 */
41#define LOG_LEVEL_NONE 0
42#define LOG_LEVEL_ERROR 10
43#define LOG_LEVEL_NOTICE 20
44#define LOG_LEVEL_WARNING 30
45#define LOG_LEVEL_INFO 40
46#define LOG_LEVEL_VERBOSE 50
47
48#if LOG_LEVEL >= LOG_LEVEL_NOTICE
49# define NOTICE(...) mp_printf("NOTICE: " __VA_ARGS__)
50#else
51# define NOTICE(...)
52#endif
53
54#if LOG_LEVEL >= LOG_LEVEL_ERROR
55# define ERROR(...) mp_printf("ERROR: " __VA_ARGS__)
56#else
57# define ERROR(...)
58#endif
59
60#if LOG_LEVEL >= LOG_LEVEL_WARNING
61# define WARN(...) mp_printf("WARNING: " __VA_ARGS__)
62#else
63# define WARN(...)
64#endif
65
66#if LOG_LEVEL >= LOG_LEVEL_INFO
67# define INFO(...) mp_printf("INFO: " __VA_ARGS__)
68#else
69# define INFO(...)
70#endif
71
72#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
73# define VERBOSE(...) mp_printf("VERBOSE: " __VA_ARGS__)
74#else
75# define VERBOSE(...)
76#endif
77
Ambroise Vincent602b7f52019-02-11 14:13:43 +000078#if ENABLE_BACKTRACE
79void backtrace(const char *cookie);
80#else
81#define backtrace(x)
82#endif
83
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084/*
Sandrine Bailleuxa2d516f2019-01-15 16:34:19 +010085 * For the moment this panic function is very basic: report an error and
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020086 * spin. This can be expanded in the future to provide more information.
87 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020088void __attribute__((__noreturn__)) do_panic(const char *file, int line);
89#define panic() do_panic(__FILE__, __LINE__)
90
91void __attribute__((__noreturn__)) do_bug_unreachable(const char *file, int line);
92#define bug_unreachable() do_bug_unreachable(__FILE__, __LINE__)
93
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020094#endif /* __DEBUG_H__ */