1 /*
2  * Copyright (c) 2025 Renesas Electronics Corporation
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  * RX CPUs.
13  */
14 
15 #include <zephyr/kernel.h>
16 #include <zephyr/arch/cpu.h>
17 #include <kernel_arch_data.h>
18 #include <zephyr/logging/log.h>
19 #include <zephyr/irq.h>
20 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
21 
22 #ifdef CONFIG_EXCEPTION_DEBUG
dump_rx_esf(const struct arch_esf * esf)23 static void dump_rx_esf(const struct arch_esf *esf)
24 {
25 	EXCEPTION_DUMP(" ACC_L: 0x%08x  ACC_H:  0x%08x", esf->acc_l, esf->acc_h);
26 	EXCEPTION_DUMP(" r1:    0x%08x  r2:     0x%08x  r3:     0x%08x",
27 			esf->r1, esf->r2, esf->r3);
28 	EXCEPTION_DUMP(" r4:    0x%08x  r5:     0x%08x  r6:     0x%08x",
29 			esf->r4, esf->r5, esf->r6);
30 	EXCEPTION_DUMP(" r7:    0x%08x  r8:     0x%08x  r9:     0x%08x",
31 			esf->r7, esf->r8, esf->r9);
32 	EXCEPTION_DUMP(" r10:   0x%08x  r11:    0x%08x  r12:    0x%08x",
33 			esf->r10, esf->r11, esf->r12);
34 	EXCEPTION_DUMP(" r13:   0x%08x  r14:    0x%08x  r15:    0x%08x",
35 			esf->r13, esf->r14, esf->r15);
36 	EXCEPTION_DUMP(" PC:    0x%08x  PSW:    0x%08x", esf->entry_point, esf->psw);
37 }
38 #endif
39 
z_rx_fatal_error(unsigned int reason,const struct arch_esf * esf)40 void z_rx_fatal_error(unsigned int reason, const struct arch_esf *esf)
41 {
42 #ifdef CONFIG_EXCEPTION_DEBUG
43 	if (esf != NULL) {
44 		dump_rx_esf(esf);
45 	}
46 #endif /* CONFIG_EXCEPTION_DEBUG */
47 
48 	z_fatal_error(reason, esf);
49 }
arch_system_halt(unsigned int reason)50 FUNC_NORETURN void arch_system_halt(unsigned int reason)
51 {
52 	ARG_UNUSED(reason);
53 
54 	__asm__("brk");
55 
56 	CODE_UNREACHABLE;
57 }
58