1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  * Copyright (c) 2014, STMicroelectronics International N.V.
5  */
6 
7 #include <kernel/panic.h>
8 #include <kernel/thread.h>
9 #include <kernel/unwind.h>
10 #include <trace.h>
11 
__do_panic(const char * file __maybe_unused,const int line __maybe_unused,const char * func __maybe_unused,const char * msg __maybe_unused)12 void __do_panic(const char *file __maybe_unused,
13 		const int line __maybe_unused,
14 		const char *func __maybe_unused,
15 		const char *msg __maybe_unused)
16 {
17 	/* disable prehemption */
18 	(void)thread_mask_exceptions(THREAD_EXCP_ALL);
19 
20 	/* TODO: notify other cores */
21 
22 	/* trace: Panic ['panic-string-message' ]at FILE:LINE [<FUNCTION>]" */
23 	if (!file && !func && !msg)
24 		EMSG_RAW("Panic");
25 	else
26 		EMSG_RAW("Panic %s%s%sat %s:%d %s%s%s",
27 			 msg ? "'" : "", msg ? msg : "", msg ? "' " : "",
28 			 file ? file : "?", file ? line : 0,
29 			 func ? "<" : "", func ? func : "", func ? ">" : "");
30 
31 	print_kernel_stack();
32 	/* abort current execution */
33 	while (1)
34 		cpu_idle();
35 }
36 
cpu_idle(void)37 void __weak cpu_idle(void)
38 {
39 }
40