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