Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
18
19#ifndef ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_
20#define ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_
21
29#if defined(CONFIG_EAGER_FPU_SHARING) || defined(CONFIG_LAZY_FPU_SHARING)
30#ifdef CONFIG_X86_SSE
31#define FP_REG_SET_ALIGN 16
32#else
33#define FP_REG_SET_ALIGN 4
34#endif
35#else
36/* Unused, no special alignment requirements, use default alignment for
37 * char buffers on this arch
38 */
39#define FP_REG_SET_ALIGN 1
40#endif /* CONFIG_*_FP_SHARING */
41
42/*
43 * Bits for _thread_arch.flags, see their use in intstub.S et al.
44 */
45
46#define X86_THREAD_FLAG_INT 0x01
47#define X86_THREAD_FLAG_EXC 0x02
48#define X86_THREAD_FLAG_ALL (X86_THREAD_FLAG_INT | X86_THREAD_FLAG_EXC)
49
50#ifndef _ASMLANGUAGE
51#include <stdint.h>
53
54/*
55 * The following structure defines the set of 'non-volatile' integer registers.
56 * These registers must be preserved by a called C function. These are the
57 * only registers that need to be saved/restored when a cooperative context
58 * switch occurs.
59 */
60
61struct _callee_saved {
62 unsigned long esp;
63
64 /*
65 * The EBP, EBX, ESI and EDI registers are also considered
66 * non-volatile, i.e. callee-save, but their values are pushed onto
67 * the stack rather than stored in the TCS structure.
68 */
69
70};
71
72typedef struct _callee_saved _callee_saved_t;
73
74/*
75 * The macros CONFIG_{LAZY|EAGER}_FPU_SHARING shall be set to indicate that the
76 * saving/restoring of the traditional x87 floating point (and MMX) registers
77 * are supported by the kernel's context swapping code. The macro
78 * CONFIG_X86_SSE shall _also_ be set if saving/restoring of the XMM
79 * registers is also supported in the kernel's context swapping code.
80 */
81
82#if defined(CONFIG_EAGER_FPU_SHARING) || defined(CONFIG_LAZY_FPU_SHARING)
83
84/* definition of a single x87 (floating point / MMX) register */
85
86typedef struct s_FpReg {
87 unsigned char reg[10]; /* 80 bits: ST[0-7] */
88} tFpReg;
89
90/*
91 * The following is the "normal" floating point register save area, or
92 * more accurately the save area required by the 'fnsave' and 'frstor'
93 * instructions. The structure matches the layout described in the
94 * "Intel(r) 64 and IA-32 Architectures Software Developer's Manual
95 * Volume 1: Basic Architecture": Protected Mode x87 FPU State Image in
96 * Memory, 32-Bit Format.
97 */
98
99typedef struct s_FpRegSet { /* # of bytes: name of register */
100 unsigned short fcw; /* 2 : x87 FPU control word */
101 unsigned short pad1; /* 2 : N/A */
102 unsigned short fsw; /* 2 : x87 FPU status word */
103 unsigned short pad2; /* 2 : N/A */
104 unsigned short ftw; /* 2 : x87 FPU tag word */
105 unsigned short pad3; /* 2 : N/A */
106 unsigned int fpuip; /* 4 : x87 FPU instruction pointer offset */
107 unsigned short cs; /* 2 : x87 FPU instruction pointer selector */
108 unsigned short fop : 11; /* 2 : x87 FPU opcode */
109 unsigned short pad4 : 5; /* : 5 bits = 00000 */
110 unsigned int fpudp; /* 4 : x87 FPU instr operand ptr offset */
111 unsigned short ds; /* 2 : x87 FPU instr operand ptr selector */
112 unsigned short pad5; /* 2 : N/A */
113 tFpReg fpReg[8]; /* 80 : ST0 -> ST7 */
114} tFpRegSet __aligned(FP_REG_SET_ALIGN);
115
116#ifdef CONFIG_X86_SSE
117
118/* definition of a single x87 (floating point / MMX) register */
119
120typedef struct s_FpRegEx {
121 unsigned char reg[10]; /* 80 bits: ST[0-7] or MM[0-7] */
122 unsigned char rsrvd[6]; /* 48 bits: reserved */
123} tFpRegEx;
124
125/* definition of a single XMM register */
126
127typedef struct s_XmmReg {
128 unsigned char reg[16]; /* 128 bits: XMM[0-7] */
129} tXmmReg;
130
131/*
132 * The following is the "extended" floating point register save area, or
133 * more accurately the save area required by the 'fxsave' and 'fxrstor'
134 * instructions. The structure matches the layout described in the
135 * "Intel 64 and IA-32 Architectures Software Developer's Manual
136 * Volume 2A: Instruction Set Reference, A-M", except for the bytes from offset
137 * 464 to 511 since these "are available to software use. The processor does
138 * not write to bytes 464:511 of an FXSAVE area".
139 *
140 * This structure must be aligned on a 16 byte boundary when the instructions
141 * fxsave/fxrstor are used to write/read the data to/from the structure.
142 */
143
144typedef struct s_FpRegSetEx /* # of bytes: name of register */
145{
146 unsigned short fcw; /* 2 : x87 FPU control word */
147 unsigned short fsw; /* 2 : x87 FPU status word */
148 unsigned char ftw; /* 1 : x87 FPU abridged tag word */
149 unsigned char rsrvd0; /* 1 : reserved */
150 unsigned short fop; /* 2 : x87 FPU opcode */
151 unsigned int fpuip; /* 4 : x87 FPU instruction pointer offset */
152 unsigned short cs; /* 2 : x87 FPU instruction pointer selector */
153 unsigned short rsrvd1; /* 2 : reserved */
154 unsigned int fpudp; /* 4 : x87 FPU instr operand ptr offset */
155 unsigned short ds; /* 2 : x87 FPU instr operand ptr selector */
156 unsigned short rsrvd2; /* 2 : reserved */
157 unsigned int mxcsr; /* 4 : MXCSR register state */
158 unsigned int mxcsrMask; /* 4 : MXCSR register mask */
159 tFpRegEx fpReg[8]; /* 128 : x87 FPU/MMX registers */
160 tXmmReg xmmReg[8]; /* 128 : XMM registers */
161 unsigned char rsrvd3[176]; /* 176 : reserved */
162} tFpRegSetEx __aligned(FP_REG_SET_ALIGN);
163
164#else /* CONFIG_X86_SSE == 0 */
165
166typedef struct s_FpRegSetEx {
168
169#endif /* CONFIG_X86_SSE == 0 */
170
171#else /* !CONFIG_LAZY_FPU_SHARING && !CONFIG_EAGER_FPU_SHARING */
172
173/* empty floating point register definition */
174
175typedef struct s_FpRegSet {
177
178typedef struct s_FpRegSetEx {
180
181#endif /* CONFIG_LAZY_FPU_SHARING || CONFIG_EAGER_FPU_SHARING */
182
183/*
184 * The following structure defines the set of 'volatile' x87 FPU/MMX/SSE
185 * registers. These registers need not be preserved by a called C function.
186 * Given that they are not preserved across function calls, they must be
187 * save/restored (along with s_coopFloatReg) when a preemptive context
188 * switch occurs.
189 */
190
191typedef struct s_preempFloatReg {
192 union {
193 /* threads with K_FP_REGS utilize this format */
195 /* threads with K_SSE_REGS utilize this format */
199
200/*
201 * The thread control structure definition. It contains the
202 * various fields to manage a _single_ thread. The TCS will be aligned
203 * to the appropriate architecture specific boundary via the
204 * arch_new_thread() call.
205 */
206
207struct _thread_arch {
208 uint8_t flags;
209
210#ifdef CONFIG_USERSPACE
211#ifndef CONFIG_X86_COMMON_PAGE_TABLE
212 /* Physical address of the page tables used by this thread */
213 uintptr_t ptables;
214#endif /* CONFIG_X86_COMMON_PAGE_TABLE */
215
216 /* Initial privilege mode stack pointer when doing a system call.
217 * Un-set for supervisor threads.
218 */
219 char *psp;
220#endif
221
222#if defined(CONFIG_LAZY_FPU_SHARING)
223 /*
224 * Nested exception count to maintain setting of EXC_ACTIVE flag across
225 * outermost exception. EXC_ACTIVE is used by z_swap() lazy FP
226 * save/restore and by debug tools.
227 */
228 unsigned excNestCount; /* nested exception count */
229#endif /* CONFIG_LAZY_FPU_SHARING */
230
231 tPreempFloatReg preempFloatReg; /* volatile float register storage */
232
233#ifdef CONFIG_HW_SHADOW_STACK
234 long *shstk_addr;
235 long *shstk_base;
236 size_t shstk_size;
237#endif
238};
239
240typedef struct _thread_arch _thread_arch_t;
241
242#endif /* _ASMLANGUAGE */
243
244#endif /* ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_ */
struct s_preempFloatReg tPreempFloatReg
struct s_FpRegSetEx tFpRegSetEx
struct s_FpRegSet tFpRegSet
#define FP_REG_SET_ALIGN
Floating point register set alignment.
Definition thread.h:39
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Definition thread.h:178
Definition thread.h:175
Definition thread.h:191
tFpRegSetEx fpRegsEx
Definition thread.h:196
tFpRegSet fpRegs
Definition thread.h:194
union s_preempFloatReg::@323266213337235055365216304163117335152077101163 floatRegsUnion