aboutsummaryrefslogtreecommitdiff
path: root/sys/i386
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2024-03-27 11:01:44 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2024-03-28 11:56:21 +0000
commit1c091d11261a3c8cc3728b92760e65242c0f5949 (patch)
tree64580dd7a865c4442bddc2cab9f2160489b6efbe /sys/i386
parentfb393d22c9fd1d53da559ecc6e67e1322fb08a38 (diff)
downloadsrc-1c091d11261a3c8cc3728b92760e65242c0f5949.tar.gz
src-1c091d11261a3c8cc3728b92760e65242c0f5949.zip
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/i386/npx.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c
index 16ad7a96ab35..0334aedd740b 100644
--- a/sys/i386/i386/npx.c
+++ b/sys/i386/i386/npx.c
@@ -975,8 +975,11 @@ npxgetregs(struct thread *td)
struct pcb *pcb;
uint64_t *xstate_bv, bit;
char *sa;
+ union savefpu *s;
+ uint32_t mxcsr, mxcsr_mask;
int max_ext_n, i;
int owned;
+ bool do_mxcsr;
if (!hw_float)
return (_MC_FPOWNED_NONE);
@@ -1019,10 +1022,28 @@ npxgetregs(struct thread *td)
bit = 1ULL << i;
if ((xsave_mask & bit) == 0 || (*xstate_bv & bit) != 0)
continue;
+ do_mxcsr = false;
+ if (i == 0 && (*xstate_bv & (XFEATURE_ENABLED_SSE |
+ XFEATURE_ENABLED_AVX)) != 0) {
+ /*
+ * x87 area was not saved by XSAVEOPT,
+ * but one of XMM or AVX was. Then we need
+ * to preserve MXCSR from being overwritten
+ * with the default value.
+ */
+ s = (union savefpu *)sa;
+ mxcsr = s->sv_xmm.sv_env.en_mxcsr;
+ mxcsr_mask = s->sv_xmm.sv_env.en_mxcsr_mask;
+ do_mxcsr = true;
+ }
bcopy((char *)npx_initialstate +
xsave_area_desc[i].offset,
sa + xsave_area_desc[i].offset,
xsave_area_desc[i].size);
+ if (do_mxcsr) {
+ s->sv_xmm.sv_env.en_mxcsr = mxcsr;
+ s->sv_xmm.sv_env.en_mxcsr_mask = mxcsr_mask;
+ }
*xstate_bv |= bit;
}
}