1 /*
2  * Copyright (c) 2010-2014 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Private kernel definitions (IA-32)
10  *
11  * This file contains private kernel structures definitions and various
12  * other definitions for the Intel Architecture 32 bit (IA-32) processor
13  * architecture.
14  * The header include/zephyr/kernel.h contains the public kernel interface
15  * definitions, with include/zephyr/arch/x86/ia32/arch.h supplying the
16  * IA-32 specific portions of the public kernel interface.
17  *
18  * This file is also included by assembly language files which must #define
19  * _ASMLANGUAGE before including this header file.  Note that kernel
20  * assembly source files obtains structure offset values via "absolute symbols"
21  * in the offsets.o module.
22  */
23 
24 /* this file is only meant to be included by kernel_structs.h */
25 
26 #ifndef ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_DATA_H_
27 #define ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_DATA_H_
28 
29 #include <zephyr/toolchain.h>
30 #include <zephyr/linker/sections.h>
31 #include <ia32/exception.h>
32 #include <zephyr/sys/util.h>
33 #include <zephyr/arch/x86/cet.h>
34 
35 #ifndef _ASMLANGUAGE
36 #include <zephyr/kernel.h>
37 #include <zephyr/types.h>
38 #include <zephyr/sys/dlist.h>
39 #endif
40 
41 /* Some configurations require that the stack/registers be adjusted before
42  * z_thread_entry. See discussion in swap.S for z_x86_thread_entry_wrapper()
43  */
44 #if defined(CONFIG_X86_DEBUG_INFO)
45 #define _THREAD_WRAPPER_REQUIRED
46 #endif
47 
48 #if defined(CONFIG_LAZY_FPU_SHARING) && defined(CONFIG_X86_SSE)
49 #define _FP_USER_MASK (K_FP_REGS | K_SSE_REGS)
50 #elif defined(CONFIG_LAZY_FPU_SHARING)
51 #define _FP_USER_MASK (K_FP_REGS)
52 #endif
53 
54 #ifndef _ASMLANGUAGE
55 
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #ifdef _THREAD_WRAPPER_REQUIRED
62 extern void z_x86_thread_entry_wrapper(k_thread_entry_t entry,
63 				      void *p1, void *p2, void *p3);
64 #endif /* _THREAD_WRAPPER_REQUIRED */
65 
66 #ifdef CONFIG_THREAD_LOCAL_STORAGE
67 extern void z_x86_tls_update_gdt(struct k_thread *thread);
68 #endif
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* _ASMLANGUAGE */
75 
76 #define X86_IRQ_SHADOW_STACK_DEFINE(name, size)							\
77 	arch_thread_hw_shadow_stack_t Z_GENERIC_SECTION(.x86shadowstack)			\
78 	__aligned(CONFIG_X86_CET_SHADOW_STACK_ALIGNMENT)					\
79 	name[size / sizeof(arch_thread_hw_shadow_stack_t)] =					\
80 		{ [size / sizeof(arch_thread_hw_shadow_stack_t) - 4] =				\
81 			(uintptr_t)name + size - 2 * sizeof(arch_thread_hw_shadow_stack_t),	\
82 		  [size / sizeof(arch_thread_hw_shadow_stack_t) - 3] = 0,			\
83 		  [size / sizeof(arch_thread_hw_shadow_stack_t) - 2] = 0,			\
84 		}
85 
86 #endif /* ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_DATA_H_ */
87