1 /*
2  * Copyright (c) 2014 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Fatal fault handling
10  *
11  * This module implements the routines necessary for handling fatal faults on
12  * ARCv2 CPUs.
13  */
14 
15 #include <zephyr/kernel.h>
16 #include <offsets_short.h>
17 #include <zephyr/arch/cpu.h>
18 #include <zephyr/logging/log.h>
19 #include <kernel_arch_data.h>
20 #include <zephyr/arch/exception.h>
21 
22 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
23 
24 #ifdef CONFIG_EXCEPTION_DEBUG
dump_arc_esf(const struct arch_esf * esf)25 static void dump_arc_esf(const struct arch_esf *esf)
26 {
27 	EXCEPTION_DUMP(" r0: 0x%" PRIxPTR "  r1: 0x%" PRIxPTR "  r2: 0x%" PRIxPTR
28 		"  r3: 0x%" PRIxPTR "", esf->r0, esf->r1, esf->r2, esf->r3);
29 	EXCEPTION_DUMP(" r4: 0x%" PRIxPTR "  r5: 0x%" PRIxPTR "  r6: 0x%" PRIxPTR
30 		"  r7: 0x%" PRIxPTR "", esf->r4, esf->r5, esf->r6, esf->r7);
31 	EXCEPTION_DUMP(" r8: 0x%" PRIxPTR "  r9: 0x%" PRIxPTR " r10: 0x%" PRIxPTR
32 		" r11: 0x%" PRIxPTR "", esf->r8, esf->r9, esf->r10, esf->r11);
33 	EXCEPTION_DUMP("r12: 0x%" PRIxPTR " r13: 0x%" PRIxPTR "  pc: 0x%" PRIxPTR "",
34 		esf->r12, esf->r13, esf->pc);
35 	EXCEPTION_DUMP(" blink: 0x%" PRIxPTR " status32: 0x%" PRIxPTR "",
36 		esf->blink, esf->status32);
37 #ifdef CONFIG_ARC_HAS_ZOL
38 	EXCEPTION_DUMP("lp_end: 0x%" PRIxPTR " lp_start: 0x%" PRIxPTR
39 			" lp_count: 0x%" PRIxPTR "", esf->lp_end, esf->lp_start, esf->lp_count);
40 #endif /* CONFIG_ARC_HAS_ZOL */
41 }
42 #endif
43 
z_arc_fatal_error(unsigned int reason,const struct arch_esf * esf)44 void z_arc_fatal_error(unsigned int reason, const struct arch_esf *esf)
45 {
46 #ifdef CONFIG_EXCEPTION_DEBUG
47 	if (esf != NULL) {
48 		dump_arc_esf(esf);
49 	}
50 #endif /* CONFIG_EXCEPTION_DEBUG */
51 
52 	z_fatal_error(reason, esf);
53 }
54 
arch_syscall_oops(void * ssf_ptr)55 FUNC_NORETURN void arch_syscall_oops(void *ssf_ptr)
56 {
57 	/* TODO: convert ssf_ptr contents into an esf, they are not the same */
58 	ARG_UNUSED(ssf_ptr);
59 
60 	z_arc_fatal_error(K_ERR_KERNEL_OOPS, NULL);
61 	CODE_UNREACHABLE;
62 }
63 
arch_system_halt(unsigned int reason)64 FUNC_NORETURN void arch_system_halt(unsigned int reason)
65 {
66 	ARG_UNUSED(reason);
67 
68 	__asm__("brk");
69 
70 	CODE_UNREACHABLE;
71 }
72