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/arc/v2/exception.h>
21 #include <err_dump_handling.h>
22
23 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
24
25 #ifdef CONFIG_EXCEPTION_DEBUG
dump_arc_esf(const struct arch_esf * esf)26 static void dump_arc_esf(const struct arch_esf *esf)
27 {
28 ARC_EXCEPTION_DUMP(" r0: 0x%" PRIxPTR " r1: 0x%" PRIxPTR " r2: 0x%" PRIxPTR
29 " r3: 0x%" PRIxPTR "", esf->r0, esf->r1, esf->r2, esf->r3);
30 ARC_EXCEPTION_DUMP(" r4: 0x%" PRIxPTR " r5: 0x%" PRIxPTR " r6: 0x%" PRIxPTR
31 " r7: 0x%" PRIxPTR "", esf->r4, esf->r5, esf->r6, esf->r7);
32 ARC_EXCEPTION_DUMP(" r8: 0x%" PRIxPTR " r9: 0x%" PRIxPTR " r10: 0x%" PRIxPTR
33 " r11: 0x%" PRIxPTR "", esf->r8, esf->r9, esf->r10, esf->r11);
34 ARC_EXCEPTION_DUMP("r12: 0x%" PRIxPTR " r13: 0x%" PRIxPTR " pc: 0x%" PRIxPTR "",
35 esf->r12, esf->r13, esf->pc);
36 ARC_EXCEPTION_DUMP(" blink: 0x%" PRIxPTR " status32: 0x%" PRIxPTR "",
37 esf->blink, esf->status32);
38 #ifdef CONFIG_ARC_HAS_ZOL
39 ARC_EXCEPTION_DUMP("lp_end: 0x%" PRIxPTR " lp_start: 0x%" PRIxPTR
40 " lp_count: 0x%" PRIxPTR "", esf->lp_end, esf->lp_start, esf->lp_count);
41 #endif /* CONFIG_ARC_HAS_ZOL */
42 }
43 #endif
44
z_arc_fatal_error(unsigned int reason,const struct arch_esf * esf)45 void z_arc_fatal_error(unsigned int reason, const struct arch_esf *esf)
46 {
47 #ifdef CONFIG_EXCEPTION_DEBUG
48 if (esf != NULL) {
49 dump_arc_esf(esf);
50 }
51 #endif /* CONFIG_EXCEPTION_DEBUG */
52
53 z_fatal_error(reason, esf);
54 }
55
arch_syscall_oops(void * ssf_ptr)56 FUNC_NORETURN void arch_syscall_oops(void *ssf_ptr)
57 {
58 /* TODO: convert ssf_ptr contents into an esf, they are not the same */
59 ARG_UNUSED(ssf_ptr);
60
61 z_arc_fatal_error(K_ERR_KERNEL_OOPS, NULL);
62 CODE_UNREACHABLE;
63 }
64
arch_system_halt(unsigned int reason)65 FUNC_NORETURN void arch_system_halt(unsigned int reason)
66 {
67 ARG_UNUSED(reason);
68
69 __asm__("brk");
70
71 CODE_UNREACHABLE;
72 }
73