1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  */
5 
6 #ifndef KERNEL_PANIC_H
7 #define KERNEL_PANIC_H
8 
9 #include <compiler.h>
10 
11 /* debug disabled => __FILE__, ... and panic message are not built. */
12 #if defined(CFG_TEE_CORE_DEBUG)
13 #define __panic(str)	__do_panic(__FILE__, __LINE__, __func__, str)
14 #else
15 #define __panic(str)	__do_panic((void *)0, 0, (void *)0, str)
16 #endif
17 
18 void __do_panic(const char *file, const int line, const char *func,
19 		const char *msg) __noreturn;
20 
21 /*
22  * Suppress GCC warning on expansion of the panic() macro with no argument:
23  *  'ISO C99 requires at least one argument for the "..." in a variadic macro'
24  * Occurs when '-pedantic' is combined with '-std=gnu99'.
25  * Suppression applies only to this file and the expansion of macros defined in
26  * this file.
27  */
28 #pragma GCC system_header
29 
30 /* panic() can get a string or no argument */
31 #define _panic0()	__panic((void *)0)
32 #define _panic1(s)	__panic(s)
33 #define _panic_fn(a, b, name, ...) name
34 #define panic(...) _panic_fn("", ##__VA_ARGS__, _panic1, _panic0)(__VA_ARGS__)
35 
36 /*
37  * Weak function used in __do_panic() to put the current CPU on hold.
38  * If no arch-specific override is provided, defaults to a busy loop.
39  */
40 void cpu_idle(void);
41 
42 #endif /*KERNEL_PANIC_H*/
43