shithub: riscv

Download patch

ref: 262d5c101bae721f5e4428510448f6c7a247fde4
parent: a203d904744fd0207ed48c8cb7fcde2775899f74
parent: 5a059477f8066f25ece1ba2b8c49ab8ea24d19de
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Dec 21 10:06:04 EST 2020

merge

--- a/sys/src/9/pc/fns.h
+++ b/sys/src/9/pc/fns.h
@@ -17,6 +17,10 @@
 void	(*coherence)(void);
 void	cpuid(int, int, ulong regs[]);
 void	fpuinit(void);
+void	fpuprocsetup(Proc*);
+void	fpuprocfork(Proc*);
+void	fpuprocsave(Proc*);
+void	fpuprocrestore(Proc*);
 int	cpuidentify(void);
 void	cpuidprint(void);
 void	(*cycles)(uvlong*);
--- a/sys/src/9/pc/fpu.c
+++ b/sys/src/9/pc/fpu.c
@@ -307,3 +307,54 @@
 		fprestore = fpx87restore;
 	}
 }
+
+void
+fpuprocsetup(Proc *p)
+{
+	p->fpstate = FPinit;
+	fpoff();
+}
+
+void
+fpuprocfork(Proc *p)
+{
+	int s;
+
+	s = splhi();
+	switch(up->fpstate & ~FPillegal){
+	case FPactive:
+		fpsave(up->fpsave);
+		up->fpstate = FPinactive;
+	case FPinactive:
+		while(p->fpsave == nil)
+			p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
+		memmove(p->fpsave, up->fpsave, sizeof(FPsave));
+		p->fpstate = FPinactive;
+	}
+	splx(s);
+}
+
+void
+fpuprocsave(Proc *p)
+{
+	if(p->fpstate == FPactive){
+		if(p->state == Moribund)
+			fpclear();
+		else{
+			/*
+			 * Fpsave() stores without handling pending
+			 * unmasked exeptions. Postnote() can't be called
+			 * so the handling of pending exceptions is delayed
+			 * until the process runs again and generates an
+			 * emulation fault to activate the FPU.
+			 */
+			fpsave(p->fpsave);
+		}
+		p->fpstate = FPinactive;
+	}
+}
+
+void
+fpuprocrestore(Proc*)
+{
+}
--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -233,14 +233,10 @@
 	}
 }
 
-/*
- *  set up floating point for a new process
- */
 void
 procsetup(Proc *p)
 {
-	p->fpstate = FPinit;
-	fpoff();
+	fpuprocsetup(p);
 
 	memset(p->gdt, 0, sizeof(p->gdt));
 	p->nldt = 0;
@@ -256,8 +252,6 @@
 void
 procfork(Proc *p)
 {
-	int s;
-
 	/* inherit user descriptors */
 	memmove(p->gdt, up->gdt, sizeof(p->gdt));
 
@@ -268,19 +262,7 @@
 		p->nldt = up->nldt;
 	}
 
-	/* save floating point state */
-	s = splhi();
-	switch(up->fpstate & ~FPillegal){
-	case FPactive:
-		fpsave(up->fpsave);
-		up->fpstate = FPinactive;
-	case FPinactive:
-		while(p->fpsave == nil)
-			p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
-		memmove(p->fpsave, up->fpsave, sizeof(FPsave));
-		p->fpstate = FPinactive;
-	}
-	splx(s);
+	fpuprocfork(p);
 }
 
 void
@@ -293,6 +275,8 @@
 	
 	if(p->vmx != nil)
 		vmxprocrestore(p);
+
+	fpuprocrestore(p);
 }
 
 /*
@@ -309,21 +293,7 @@
 	if(p->state == Moribund)
 		p->dr[7] = 0;
 
-	if(p->fpstate == FPactive){
-		if(p->state == Moribund)
-			fpclear();
-		else{
-			/*
-			 * Fpsave() stores without handling pending
-			 * unmasked exeptions. Postnote() can't be called
-			 * so the handling of pending exceptions is delayed
-			 * until the process runs again and generates an
-			 * emulation fault to activate the FPU.
-			 */
-			fpsave(p->fpsave);
-		}
-		p->fpstate = FPinactive;
-	}
+	fpuprocsave(p);
 
 	/*
 	 * While this processor is in the scheduler, the process could run
--- a/sys/src/9/xen/fns.h
+++ b/sys/src/9/xen/fns.h
@@ -11,6 +11,10 @@
 void	(*coherence)(void);
 void	cpuid(int, int, ulong regs[]);
 void	fpuinit(void);
+void	fpuprocsetup(Proc*);
+void	fpuprocfork(Proc*);
+void	fpuprocsave(Proc*);
+void	fpuprocrestore(Proc*);
 int		cpuidentify(void);
 void	cpuidprint(void);
 void	(*cycles)(uvlong*);
--- a/sys/src/9/xen/main.c
+++ b/sys/src/9/xen/main.c
@@ -322,39 +322,22 @@
 	}
 }
 
-/*
- *  set up floating point for a new process
- */
 void
-procsetup(Proc*p)
+procsetup(Proc *p)
 {
-	p->fpstate = FPinit;
-	fpoff();
+	fpuprocsetup(p);
 }
 
 void
 procfork(Proc *p)
 {
-	int s;
-
-	/* save floating point state */
-	s = splhi();
-	switch(up->fpstate & ~FPillegal){
-	case FPactive:
-		fpsave(up->fpsave);
-		up->fpstate = FPinactive;
-	case FPinactive:
-		while(p->fpsave == nil)
-			p->fpsave = mallocalign(sizeof(FPsave), FPalign, 0, 0);
-		memmove(p->fpsave, up->fpsave, sizeof(FPsave));
-		p->fpstate = FPinactive;
-	}
-	splx(s);
+	fpuprocfork(p);
 }
 
 void
 procrestore(Proc *p)
 {
+	fpuprocrestore(p);
 }
 
 /*
@@ -363,21 +346,7 @@
 void
 procsave(Proc *p)
 {
-	if(p->fpstate == FPactive){
-		if(p->state == Moribund)
-			fpclear();
-		else{
-			/*
-			 * Fpsave() stores without handling pending
-			 * unmasked exeptions. Postnote() can't be called
-			 * so the handling of pending exceptions is delayed
-			 * until the process runs again and generates an
-			 * emulation fault to activate the FPU.
-			 */
-			fpsave(p->fpsave);
-		}
-		p->fpstate = FPinactive;
-	}
+	fpuprocsave(p);
 
 	/*
 	 * While this processor is in the scheduler, the process could run