Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/powerpc - In vec_restore_from_mcontext() and vec_sa...



details:   https://anonhg.NetBSD.org/src/rev/ffbb327a63ac
branches:  trunk
changeset: 990592:ffbb327a63ac
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Oct 30 19:44:56 2021 +0000

description:
- In vec_restore_from_mcontext() and vec_save_to_mcontext(), allows the
  mcontext argument to be NULL.
- In sendsig_sigcontext(), don't set PSL_VEC in the saved MSR; we can't
  actually round-trip the AltiVec registers.  At least get them saved
  into the PCB by calling vec_save_to_mcontext() (with a NULL mcontext
  argument).
- In compat_16_sys___sigreturn14(), call vec_restore_from_mcontext()
  with a NULL mcontext argument, which will force any subsequent use
  of AltiVec to re-load the AltiVec registers from the PCB.

This isn't ideal, but it's the best we can do with the limited capability
of sigcontext.

Fixes PR port-powerpc/56471.

diffstat:

 sys/arch/powerpc/oea/altivec.c               |  28 +++++++++++++++++-----------
 sys/arch/powerpc/powerpc/compat_16_machdep.c |  20 +++++++++++++++++---
 2 files changed, 34 insertions(+), 14 deletions(-)

diffs (104 lines):

diff -r 32400f64479c -r ffbb327a63ac sys/arch/powerpc/oea/altivec.c
--- a/sys/arch/powerpc/oea/altivec.c    Sat Oct 30 19:28:40 2021 +0000
+++ b/sys/arch/powerpc/oea/altivec.c    Sat Oct 30 19:44:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: altivec.c,v 1.33 2020/07/06 10:52:12 rin Exp $ */
+/*     $NetBSD: altivec.c,v 1.34 2021/10/30 19:44:56 thorpej Exp $     */
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altivec.c,v 1.33 2020/07/06 10:52:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altivec.c,v 1.34 2021/10/30 19:44:56 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -166,10 +166,13 @@
        /* we don't need to save the state, just drop it */
        pcu_discard(&vec_ops, l, true);
 
-       memcpy(pcb->pcb_vr.vreg, &mcp->__vrf.__vrs, sizeof (pcb->pcb_vr.vreg));
-       pcb->pcb_vr.vscr = mcp->__vrf.__vscr;
-       pcb->pcb_vr.vrsave = mcp->__vrf.__vrsave;
-       l->l_md.md_utf->tf_vrsave = pcb->pcb_vr.vrsave;
+       if (mcp != NULL) {      /* XXX see compat_16_sys___sigreturn14() */
+               memcpy(pcb->pcb_vr.vreg, &mcp->__vrf.__vrs,
+                   sizeof (pcb->pcb_vr.vreg));
+               pcb->pcb_vr.vscr = mcp->__vrf.__vscr;
+               pcb->pcb_vr.vrsave = mcp->__vrf.__vrsave;
+               l->l_md.md_utf->tf_vrsave = pcb->pcb_vr.vrsave;
+       }
 }
 
 bool
@@ -188,11 +191,14 @@
         */
        pcu_save(&vec_ops, l);
 
-       mcp->__gregs[_REG_MSR] |= PSL_VEC;
-       mcp->__vrf.__vscr = pcb->pcb_vr.vscr;
-       mcp->__vrf.__vrsave = l->l_md.md_utf->tf_vrsave;
-       memcpy(mcp->__vrf.__vrs, pcb->pcb_vr.vreg, sizeof (mcp->__vrf.__vrs));
-       *flagp |= _UC_POWERPC_VEC;
+       if (mcp != NULL) {      /* XXX see sendsig_sigcontext() */
+               mcp->__gregs[_REG_MSR] |= PSL_VEC;
+               mcp->__vrf.__vscr = pcb->pcb_vr.vscr;
+               mcp->__vrf.__vrsave = l->l_md.md_utf->tf_vrsave;
+               memcpy(mcp->__vrf.__vrs, pcb->pcb_vr.vreg,
+                   sizeof (mcp->__vrf.__vrs));
+               *flagp |= _UC_POWERPC_VEC;
+       }
        return true;
 }
 
diff -r 32400f64479c -r ffbb327a63ac sys/arch/powerpc/powerpc/compat_16_machdep.c
--- a/sys/arch/powerpc/powerpc/compat_16_machdep.c      Sat Oct 30 19:28:40 2021 +0000
+++ b/sys/arch/powerpc/powerpc/compat_16_machdep.c      Sat Oct 30 19:44:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_16_machdep.c,v 1.21 2021/10/27 04:15:00 thorpej Exp $   */
+/*     $NetBSD: compat_16_machdep.c,v 1.22 2021/10/30 19:44:56 thorpej Exp $   */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.21 2021/10/27 04:15:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.22 2021/10/30 19:44:56 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -104,7 +104,12 @@
        utf->srr1 |= pcb->pcb_flags & (PCB_FE0|PCB_FE1);
 #endif
 #if defined(ALTIVEC) || defined(PPC_HAVE_SPE)
-       utf->srr1 |= vec_used_p(l) ? PSL_VEC : 0;
+       /*
+        * We can't round-trip the vector unit registers with a
+        * sigcontext, so at least get them saved into the PCB.
+        * XXX vec_save_to_mcontext() has a special hack for this.
+        */
+       vec_save_to_mcontext(l, NULL, NULL);
 #endif
 #ifdef PPC_OEA
        utf->vrsave = tf->tf_vrsave;
@@ -221,6 +226,15 @@
        pcb->pcb_flags &= ~(PCB_FE0|PCB_FE1);
        pcb->pcb_flags |= utf->srr1 & (PCB_FE0|PCB_FE1);
 #endif
+#if defined(ALTIVEC) || defined(PPC_HAVE_SPE)
+       /*
+        * We can't round-trip the vector unit registers with a
+        * sigcontext, so at least force them to get reloaded from
+        * the PCB (we saved them into the PCB in sendsig_sigcontext()).
+        * XXX vec_restore_from_mcontext() has a special hack for this.
+        */
+       vec_restore_from_mcontext(l, NULL);
+#endif
 #ifdef PPC_OEA
        tf->tf_vrsave = utf->vrsave;
        tf->tf_mq = utf->mq;



Home | Main Index | Thread Index | Old Index