1 /*
2  * Copyright (c) 2013-2014 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief NMI handler infrastructure
10  *
11  * Provides a boot time handler that simply hangs in a sleep loop, and a run
12  * time handler that resets the CPU. Also provides a mechanism for hooking a
13  * custom run time handler.
14  */
15 
16 #include <zephyr/kernel.h>
17 #include <zephyr/arch/cpu.h>
18 #include <zephyr/sys/printk.h>
19 #include <zephyr/sys/reboot.h>
20 #include <zephyr/toolchain.h>
21 #include <zephyr/linker/sections.h>
22 
23 extern void z_SysNmiOnReset(void);
24 #if !defined(CONFIG_RUNTIME_NMI)
25 #define handler z_SysNmiOnReset
26 #endif
27 
28 #ifdef CONFIG_RUNTIME_NMI
29 typedef void (*_NmiHandler_t)(void);
30 static _NmiHandler_t handler = z_SysNmiOnReset;
31 
32 /**
33  *
34  * @brief Install a custom runtime NMI handler
35  *
36  * Meant to be called by platform code if they want to install a custom NMI
37  * handler that reboots. It should be installed after the console is
38  * initialized if it is meant to output to the console.
39  *
40  */
41 
z_arm_nmi_set_handler(void (* pHandler)(void))42 void z_arm_nmi_set_handler(void (*pHandler)(void))
43 {
44 	handler = pHandler;
45 }
46 #endif /* CONFIG_RUNTIME_NMI */
47 
48 /**
49  *
50  * @brief Handler installed in the vector table
51  *
52  * Simply call what is installed in 'static void(*handler)(void)'.
53  *
54  */
55 
z_arm_nmi(void)56 void z_arm_nmi(void)
57 {
58 	handler();
59 	z_arm_int_exit();
60 }
61