1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2018 Intel Corporation. All rights reserved.
4  *
5  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6  */
7 
8 #ifndef __SOF_DEBUG_PANIC_H__
9 #define __SOF_DEBUG_PANIC_H__
10 
11 #include <arch/debug/panic.h>
12 #include <ipc/trace.h>
13 #include <stdint.h>
14 
15 #ifdef __clang_analyzer__
16 #define SOF_NORETURN __attribute__((analyzer_noreturn))
17 #elif __GNUC__
18 #define SOF_NORETURN __attribute__((noreturn))
19 #else
20 #define SOF_NORETURN
21 #endif
22 
23 #ifndef RELATIVE_FILE
24 #error "This file requires RELATIVE_FILE to be defined. " \
25 	"Add it to CMake's target with sof_append_relative_path_definitions."
26 #endif
27 
28 void dump_panicinfo(void *addr, struct sof_ipc_panic_info *panic_info);
29 void panic_dump(uint32_t p, struct sof_ipc_panic_info *panic_info,
30 		uintptr_t *data)
31 	SOF_NORETURN;
32 
33 #ifdef __ZEPHYR__
34 #include <kernel.h>
35 #define panic(x) k_panic()
36 
37 #define assert(x) \
38 	do {			\
39 		if (!(x))	\
40 			k_oops();\
41 	} while (0)
42 #else
43 
44 void __panic(uint32_t p, char *filename, uint32_t linenum) SOF_NORETURN;
45 
46 /** panic dump filename and linenumber of the call
47  *
48  * \param x panic code defined in ipc/trace.h
49  */
50 #define panic(x) __panic((x), (RELATIVE_FILE), (__LINE__))
51 
52 /* runtime assertion */
53 #define assert(cond) (void)((cond) || (panic(SOF_IPC_PANIC_ASSERT), 0))
54 
55 #endif
56 
57 #endif /* __SOF_DEBUG_PANIC_H__ */
58