1 /*
2  * Copyright (c) 2019 Intel Corporation
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/kernel.h>
7 #include <ksched.h>
8 #include <zephyr/kernel_structs.h>
9 #include <kernel_internal.h>
10 #include <zephyr/logging/log.h>
11 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
12 
13 /* NMI handlers should override weak implementation
14  * return true if NMI is handled, false otherwise
15  */
z_x86_do_kernel_nmi(const struct arch_esf * esf)16 __weak bool z_x86_do_kernel_nmi(const struct arch_esf *esf)
17 {
18 	ARG_UNUSED(esf);
19 
20 	return false;
21 }
22 
z_x86_exception(struct arch_esf * esf)23 void z_x86_exception(struct arch_esf *esf)
24 {
25 	switch (esf->vector) {
26 	case Z_X86_OOPS_VECTOR:
27 		z_x86_do_kernel_oops(esf);
28 		break;
29 	case IV_PAGE_FAULT:
30 		z_x86_page_fault_handler(esf);
31 		break;
32 	case IV_NON_MASKABLE_INTERRUPT:
33 		if (!z_x86_do_kernel_nmi(esf)) {
34 			z_x86_unhandled_cpu_exception(esf->vector, esf);
35 			CODE_UNREACHABLE;
36 		}
37 		break;
38 	default:
39 		z_x86_unhandled_cpu_exception(esf->vector, esf);
40 		CODE_UNREACHABLE;
41 	}
42 }
43 
44 #ifdef CONFIG_USERSPACE
arch_syscall_oops(void * ssf_ptr)45 void arch_syscall_oops(void *ssf_ptr)
46 {
47 	struct x86_ssf *ssf = ssf_ptr;
48 
49 	LOG_ERR("Bad system call from RIP 0x%lx", ssf->rip);
50 
51 	z_x86_fatal_error(K_ERR_KERNEL_OOPS, NULL);
52 }
53 #endif /* CONFIG_USERSPACE */
54