shithub: riscv

Download patch

ref: e969575d2e55eec89d3a2765b974e023123d8fa5
parent: b4bcc761bce6e818e554d8726ea8fe81bed37396
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jul 8 13:45:10 EDT 2023

pc, pc64: clear osxsave flag in cr4 when not used

--- a/sys/src/9/pc/fpu.c
+++ b/sys/src/9/pc/fpu.c
@@ -9,6 +9,7 @@
 enum {
 	CR4Osfxsr  = 1 << 9,
 	CR4Oxmmex  = 1 << 10,
+	CR4Oxsave  = 1 << 18,
 };
 
 /* from l.s */
@@ -297,15 +298,23 @@
 {
 	uintptr cr4;
 
+	m->xcr0 = 0;
+	cr4 = getcr4();
+	cr4 &= ~CR4Oxsave;
 	if((m->cpuiddx & (Sse|Fxsr)) == (Sse|Fxsr)){ /* have sse fp? */
+		cr4 |= CR4Osfxsr|CR4Oxmmex;
+		putcr4(cr4);
+
 		fpsave = fpssesave;
 		fprestore = fpsserestore;
-		cr4 = getcr4() | CR4Osfxsr|CR4Oxmmex;
-		putcr4(cr4);
 	} else {
+		cr4 &= ~(CR4Osfxsr|CR4Oxmmex);
+		putcr4(cr4);
+
 		fpsave = fpx87save;
 		fprestore = fpx87restore;
 	}
+	fpoff();
 }
 
 void
--- a/sys/src/9/pc64/fpu.c
+++ b/sys/src/9/pc64/fpu.c
@@ -210,12 +210,15 @@
 	u64int cr4;
 	ulong regs[4];
 
+	m->xcr0 = 0;
 	cr4 = getcr4() | CR4Osfxsr|CR4Oxmmex;
 	if((m->cpuidcx & (Xsave|Avx)) == (Xsave|Avx) && getconf("*noavx") == nil){
 		cr4 |= CR4Oxsave;
 		putcr4(cr4);
-		m->xcr0 = 7; /* x87, sse, avx */
+
+		m->xcr0 = 7;	/* x87, sse, avx */
 		putxcr0(m->xcr0);
+
 		cpuid(0xd, 1, regs);
 		if(regs[0] & Xsaves){
 			fpsave = fpxsaves;
@@ -228,7 +231,9 @@
 			fprestore = fpxrestore;
 		}
 	} else {
+		cr4 &= ~CR4Oxsave;
 		putcr4(cr4);
+
 		fpsave = fpssesave;
 		fprestore = fpsserestore;
 	}