1 /* SPDX-License-Identifier: GPL-2.0 */
9 * The legacy x87 FPU state format, as saved by FSAVE and
10 * restored by the FRSTOR instructions:
13 u32 cwd; /* FPU Control Word */
14 u32 swd; /* FPU Status Word */
15 u32 twd; /* FPU Tag Word */
16 u32 fip; /* FPU IP Offset */
17 u32 fcs; /* FPU IP Selector */
18 u32 foo; /* FPU Operand Pointer Offset */
19 u32 fos; /* FPU Operand Pointer Selector */
21 /* 8*10 bytes for each FP-reg = 80 bytes: */
24 /* Software status information [not touched by FSAVE]: */
29 * The legacy fx SSE/MMX FPU state format, as saved by FXSAVE and
30 * restored by the FXRSTOR instructions. It's similar to the FSAVE
31 * format, but differs in some areas, plus has extensions at
32 * the end for the XMM registers.
35 u16 cwd; /* Control Word */
36 u16 swd; /* Status Word */
37 u16 twd; /* Tag Word */
38 u16 fop; /* Last Instruction Opcode */
41 u64 rip; /* Instruction Pointer */
42 u64 rdp; /* Data Pointer */
45 u32 fip; /* FPU IP Offset */
46 u32 fcs; /* FPU IP Selector */
47 u32 foo; /* FPU Operand Offset */
48 u32 fos; /* FPU Operand Selector */
51 u32 mxcsr; /* MXCSR Register State */
52 u32 mxcsr_mask; /* MXCSR Mask */
54 /* 8*16 bytes for each FP-reg = 128 bytes: */
57 /* 16*16 bytes for each XMM-reg = 256 bytes: */
67 } __attribute__((aligned(16)));
69 /* Default value for fxregs_state.mxcsr: */
70 #define MXCSR_DEFAULT 0x1f80
72 /* Copy both mxcsr & mxcsr_flags with a single u64 memcpy: */
73 #define MXCSR_AND_FLAGS_SIZE sizeof(u64)
76 * Software based FPU emulation state. This is arbitrary really,
77 * it matches the x87 format to make it easier to understand:
87 /* 8*10 bytes for each FP-reg = 80 bytes: */
95 struct math_emu_info *info;
100 * List of XSAVE features Linux knows about:
106 * Values above here are "legacy states".
107 * Those below are "extended states".
115 XFEATURE_PT_UNIMPLEMENTED_SO_FAR,
117 XFEATURE_RSRVD_COMP_10,
118 XFEATURE_RSRVD_COMP_11,
119 XFEATURE_RSRVD_COMP_12,
120 XFEATURE_RSRVD_COMP_13,
121 XFEATURE_RSRVD_COMP_14,
127 #define XFEATURE_MASK_FP (1 << XFEATURE_FP)
128 #define XFEATURE_MASK_SSE (1 << XFEATURE_SSE)
129 #define XFEATURE_MASK_YMM (1 << XFEATURE_YMM)
130 #define XFEATURE_MASK_BNDREGS (1 << XFEATURE_BNDREGS)
131 #define XFEATURE_MASK_BNDCSR (1 << XFEATURE_BNDCSR)
132 #define XFEATURE_MASK_OPMASK (1 << XFEATURE_OPMASK)
133 #define XFEATURE_MASK_ZMM_Hi256 (1 << XFEATURE_ZMM_Hi256)
134 #define XFEATURE_MASK_Hi16_ZMM (1 << XFEATURE_Hi16_ZMM)
135 #define XFEATURE_MASK_PT (1 << XFEATURE_PT_UNIMPLEMENTED_SO_FAR)
136 #define XFEATURE_MASK_PKRU (1 << XFEATURE_PKRU)
137 #define XFEATURE_MASK_LBR (1 << XFEATURE_LBR)
139 #define XFEATURE_MASK_FPSSE (XFEATURE_MASK_FP | XFEATURE_MASK_SSE)
140 #define XFEATURE_MASK_AVX512 (XFEATURE_MASK_OPMASK \
141 | XFEATURE_MASK_ZMM_Hi256 \
142 | XFEATURE_MASK_Hi16_ZMM)
144 #define FIRST_EXTENDED_XFEATURE XFEATURE_YMM
159 * There are 16x 256-bit AVX registers named YMM0-YMM15.
160 * The low 128 bits are aliased to the 16 SSE registers (XMM0-XMM15)
161 * and are stored in 'struct fxregs_state::xmm_space[]' in the
164 * The high 128 bits are stored here.
167 struct reg_128_bit hi_ymm[16];
170 /* Intel MPX support: */
177 * State component 3 is used for the 4 128-bit bounds registers
179 struct mpx_bndreg_state {
180 struct mpx_bndreg bndreg[4];
184 * State component 4 is used for the 64-bit user-mode MPX
185 * configuration register BNDCFGU and the 64-bit MPX status
186 * register BNDSTATUS. We call the pair "BNDCSR".
194 * The BNDCSR state is padded out to be 64-bytes in size.
196 struct mpx_bndcsr_state {
198 struct mpx_bndcsr bndcsr;
199 u8 pad_to_64_bytes[64];
203 /* AVX-512 Components: */
206 * State component 5 is used for the 8 64-bit opmask registers
207 * k0-k7 (opmask state).
209 struct avx_512_opmask_state {
214 * State component 6 is used for the upper 256 bits of the
215 * registers ZMM0-ZMM15. These 16 256-bit values are denoted
216 * ZMM0_H-ZMM15_H (ZMM_Hi256 state).
218 struct avx_512_zmm_uppers_state {
219 struct reg_256_bit zmm_upper[16];
223 * State component 7 is used for the 16 512-bit registers
224 * ZMM16-ZMM31 (Hi16_ZMM state).
226 struct avx_512_hi16_state {
227 struct reg_512_bit hi16_zmm[16];
231 * State component 9: 32-bit PKRU register. The state is
232 * 8 bytes long but only 4 bytes is used currently.
240 * State component 15: Architectural LBR configuration state.
241 * The size of Arch LBR state depends on the number of LBRs (lbr_depth).
250 struct arch_lbr_state {
256 struct lbr_entry entries[];
259 struct xstate_header {
263 } __attribute__((packed));
266 * xstate_header.xcomp_bv[63] indicates that the extended_state_area
267 * is in compacted format.
269 #define XCOMP_BV_COMPACTED_FORMAT ((u64)1 << 63)
272 * This is our most modern FPU state format, as saved by the XSAVE
273 * and restored by the XRSTOR instructions.
275 * It consists of a legacy fxregs portion, an xstate header and
276 * subsequent areas as defined by the xstate header. Not all CPUs
277 * support all the extensions, so the size of the extended area
278 * can vary quite a bit between CPUs.
281 struct fxregs_state i387;
282 struct xstate_header header;
283 u8 extended_state_area[0];
284 } __attribute__ ((packed, aligned (64)));
287 * This is a union of all the possible FPU state formats
288 * put together, so that we can pick the right one runtime.
290 * The size of the structure is determined by the largest
291 * member - which is the xsave area. The padding is there
292 * to ensure that statically-allocated task_structs (just
293 * the init_task today) have enough space.
296 struct fregs_state fsave;
297 struct fxregs_state fxsave;
298 struct swregs_state soft;
299 struct xregs_state xsave;
300 u8 __padding[PAGE_SIZE];
304 * Highest level per task FPU state data structure that
305 * contains the FPU register state plus various FPU
312 * Records the last CPU on which this context was loaded into
313 * FPU registers. (In the lazy-restore case we might be
314 * able to reuse FPU registers across multiple context switches
315 * this way, if no intermediate task used the FPU.)
317 * A value of -1 is used to indicate that the FPU state in context
318 * memory is newer than the FPU state in registers, and that the
319 * FPU state should be reloaded next time the task is run.
321 unsigned int last_cpu;
326 * Records the timestamp of AVX512 use during last context switch.
328 unsigned long avx512_timestamp;
333 * In-memory copy of all FPU registers that we save/restore
334 * over context switches. If the task is using the FPU then
335 * the registers in the FPU are more recent than this state
336 * copy. If the task context-switches away then they get
337 * saved here and represent the FPU state.
339 union fpregs_state state;
341 * WARNING: 'state' is dynamically-sized. Do not put
342 * anything after it here.
346 #endif /* _ASM_X86_FPU_H */