Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm Rework VFP support to use PCU.



details:   https://anonhg.NetBSD.org/src/rev/0585e89ab563
branches:  trunk
changeset: 780929:0585e89ab563
user:      matt <matt%NetBSD.org@localhost>
date:      Sun Aug 12 05:05:47 2012 +0000

description:
Rework VFP support to use PCU.
Add emulation of instruction which save/restore the VFP FPSCR.
Add a sysarch hook to VFP FPSCR manipulation.

[The emulation will be used by libc to store/fetch exception modes and
rounding mode on a per-thread basis.]

diffstat:

 sys/arch/arm/arm/arm_machdep.c   |   14 +-
 sys/arch/arm/arm/undefined.c     |   11 +-
 sys/arch/arm/arm32/cpu.c         |   10 +-
 sys/arch/arm/arm32/cpuswitch.S   |   17 +-
 sys/arch/arm/arm32/sys_machdep.c |   39 +++-
 sys/arch/arm/arm32/vm_machdep.c  |   25 +--
 sys/arch/arm/conf/files.arm      |    4 +-
 sys/arch/arm/include/cpu.h       |   13 +-
 sys/arch/arm/include/pcb.h       |    1 -
 sys/arch/arm/include/proc.h      |    4 +-
 sys/arch/arm/include/sysarch.h   |    8 +-
 sys/arch/arm/include/types.h     |    7 +-
 sys/arch/arm/include/vfpvar.h    |   48 ----
 sys/arch/arm/vfp/vfp_init.c      |  405 ++++++++++++++++++++++----------------
 14 files changed, 317 insertions(+), 289 deletions(-)

diffs (truncated from 1036 to 300 lines):

diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm/arm_machdep.c
--- a/sys/arch/arm/arm/arm_machdep.c    Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm/arm_machdep.c    Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm_machdep.c,v 1.31 2012/02/19 21:06:04 rmind Exp $   */
+/*     $NetBSD: arm_machdep.c,v 1.32 2012/08/12 05:05:47 matt Exp $    */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -78,7 +78,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.31 2012/02/19 21:06:04 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.32 2012/08/12 05:05:47 matt Exp $");
 
 #include <sys/exec.h>
 #include <sys/proc.h>
@@ -109,6 +109,12 @@
 #endif
 };
 
+const pcu_ops_t * const pcu_ops_md_defs[PCU_UNIT_COUNT] = {
+#if defined(FPU_VFP)
+       [PCU_FPU] = &arm_vfp_ops,
+#endif
+};
+
 /*
  * The ARM architecture places the vector page at address 0.
  * Later ARM architecture versions, however, allow it to be
@@ -174,9 +180,7 @@
 #endif
        pcb->pcb_flags = 0;
 #ifdef FPU_VFP
-       l->l_md.md_flags &= ~MDP_VFPUSED;
-       if (pcb->pcb_vfpcpu != NULL)
-               vfp_saveregs_lwp(l, 0);
+       vfp_discardcontext();
 #endif
 }
 
diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm/undefined.c
--- a/sys/arch/arm/arm/undefined.c      Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm/undefined.c      Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: undefined.c,v 1.45 2012/08/11 07:05:57 matt Exp $      */
+/*     $NetBSD: undefined.c,v 1.46 2012/08/12 05:05:47 matt Exp $      */
 
 /*
  * Copyright (c) 2001 Ben Harris.
@@ -54,9 +54,9 @@
 #include <sys/kgdb.h>
 #endif
 
-__KERNEL_RCSID(0, "$NetBSD: undefined.c,v 1.45 2012/08/11 07:05:57 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: undefined.c,v 1.46 2012/08/12 05:05:47 matt Exp $");
 
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/queue.h>
 #include <sys/signal.h>
 #include <sys/systm.h>
@@ -99,8 +99,7 @@
        KASSERT(coproc >= 0 && coproc < NUM_UNKNOWN_HANDLERS);
        KASSERT(handler != NULL); /* Used to be legal. */
 
-       /* XXX: M_TEMP??? */
-       uh = malloc(sizeof(*uh), M_TEMP, M_WAITOK);
+       uh = kmem_alloc(sizeof(*uh), KM_SLEEP);
        uh->uh_handler = handler;
        install_coproc_handler_static(coproc, uh);
        return uh;
@@ -119,7 +118,7 @@
        struct undefined_handler *uh = cookie;
 
        LIST_REMOVE(uh, uh_link);
-       free(uh, M_TEMP);
+       kmem_free(uh, sizeof(*uh));
 }
 
 static struct evcnt cp15_ev =
diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm32/cpu.c
--- a/sys/arch/arm/arm32/cpu.c  Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm32/cpu.c  Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.82 2012/07/14 07:55:28 matt Exp $    */
+/*     $NetBSD: cpu.c,v 1.83 2012/08/12 05:05:47 matt Exp $    */
 
 /*
  * Copyright (c) 1995 Mark Brinicombe.
@@ -46,7 +46,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.82 2012/07/14 07:55:28 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.83 2012/08/12 05:05:47 matt Exp $");
 
 #include <sys/systm.h>
 #include <sys/malloc.h>
@@ -64,10 +64,6 @@
 #include <arm/fpe-arm/armfpe.h>
 #endif
 
-#ifdef FPU_VFP
-#include <arm/vfpvar.h>
-#endif
-
 char cpu_model[256];
 
 /* Prototypes */
@@ -161,9 +157,7 @@
                initialise_arm_fpe();
 #endif
 
-#ifdef FPU_VFP
        vfp_attach();
-#endif
 }
 
 enum cpu_class {
diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm32/cpuswitch.S
--- a/sys/arch/arm/arm32/cpuswitch.S    Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm32/cpuswitch.S    Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpuswitch.S,v 1.63 2011/04/07 10:03:47 matt Exp $      */
+/*     $NetBSD: cpuswitch.S,v 1.64 2012/08/12 05:05:47 matt Exp $      */
 
 /*
  * Copyright 2003 Wasabi Systems, Inc.
@@ -89,7 +89,7 @@
 #include <machine/asm.h>
 #include <machine/cpu.h>
 
-       RCSID("$NetBSD: cpuswitch.S,v 1.63 2011/04/07 10:03:47 matt Exp $")
+       RCSID("$NetBSD: cpuswitch.S,v 1.64 2012/08/12 05:05:47 matt Exp $")
 
 /* LINTSTUB: include <sys/param.h> */
        
@@ -235,15 +235,6 @@
        /* rem: r7 = new pcb */
        /* rem: interrupts are enabled */
 
-#ifdef FPU_VFP
-       /*
-        * Now's a good time to 'save' the VFP context.  Note that we
-        * don't really force a save here, which can save time if we
-        * end up restarting the same context.
-        */
-       bl      _C_LABEL(vfp_savecontext)
-#endif
-
        /* Restore saved context */
 
 .Ldo_switch:
@@ -290,10 +281,6 @@
        /* rem: r6 = new lwp */
        /* rem: r7 = new pcb */
 
-#ifdef FPU_VFP
-       mov     r0, r6
-       bl      _C_LABEL(vfp_loadcontext)
-#endif
 #ifdef ARMFPE
        add     r0, r7, #(PCB_SIZE) & 0x00ff
        add     r0, r0, #(PCB_SIZE) & 0xff00 
diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm32/sys_machdep.c
--- a/sys/arch/arm/arm32/sys_machdep.c  Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm32/sys_machdep.c  Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_machdep.c,v 1.14 2011/11/17 15:02:22 joerg Exp $   */
+/*     $NetBSD: sys_machdep.c,v 1.15 2012/08/12 05:05:47 matt Exp $    */
 
 /*
  * Copyright (c) 1995-1997 Mark Brinicombe.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.14 2011/11/17 15:02:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.15 2012/08/12 05:05:47 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,10 +54,13 @@
 #include <sys/syscallargs.h>
 
 #include <machine/sysarch.h>
+#include <machine/pcb.h>
+#include <arm/vfpreg.h>
 
 /* Prototypes */
 static int arm32_sync_icache(struct lwp *, const void *, register_t *);
 static int arm32_drain_writebuf(struct lwp *, const void *, register_t *);
+static int arm32_vfp_fpscr(struct lwp *, const void *, register_t *);
 
 static int
 arm32_sync_icache(struct lwp *l, const void *args, register_t *retval)
@@ -86,6 +89,34 @@
        return(0);
 }
 
+static int
+arm32_vfp_fpscr(struct lwp *l, const void *uap, register_t *retval)
+{
+       struct pcb * const pcb = lwp_getpcb(l);
+
+#ifdef FPU_VFP
+       /*
+        * Save the current VFP state (to make sure the FPSCR copy is
+        * up to date).
+        */
+       vfp_savecontext();
+#endif
+
+       retval[0] = pcb->pcb_vfp.vfp_fpscr;
+       if (uap) {
+               struct arm_vfp_fpscr_args ua;
+               int error;
+               if ((error = copyin(uap, &ua, sizeof(ua))) != 0)
+                       return (error);
+               if (((ua.fpscr_clear|ua.fpscr_set) & ~VFP_FPSCR_RMODE) != 0)
+                       return EINVAL;
+               pcb->pcb_vfp.vfp_fpscr &= ~ua.fpscr_clear;
+               pcb->pcb_vfp.vfp_fpscr |= ua.fpscr_set;
+       }
+
+       return 0;
+}
+
 int
 sys_sysarch(struct lwp *l, const struct sys_sysarch_args *uap, register_t *retval)
 {
@@ -104,6 +135,10 @@
                error = arm32_drain_writebuf(l, SCARG(uap, parms), retval);
                break;
 
+       case ARM_VFP_FPSCR :
+               error = arm32_vfp_fpscr(l, SCARG(uap, parms), retval);
+               break;
+
        default:
                error = EINVAL;
                break;
diff -r 47a2cb980e76 -r 0585e89ab563 sys/arch/arm/arm32/vm_machdep.c
--- a/sys/arch/arm/arm32/vm_machdep.c   Sun Aug 12 03:35:13 2012 +0000
+++ b/sys/arch/arm/arm32/vm_machdep.c   Sun Aug 12 05:05:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep.c,v 1.57 2012/08/03 07:59:22 matt Exp $     */
+/*     $NetBSD: vm_machdep.c,v 1.58 2012/08/12 05:05:47 matt Exp $     */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.57 2012/08/03 07:59:22 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.58 2012/08/12 05:05:47 matt Exp $");
 
 #include "opt_armfpe.h"
 #include "opt_pmap_debug.h"
@@ -137,16 +137,7 @@
        }
 #endif
 
-       l2->l_md.md_flags = l1->l_md.md_flags & MDP_VFPUSED;
-
-#ifdef FPU_VFP
-       /*
-        * Copy the floating point state from the VFP to the PCB
-        * if this process has state stored there.
-        */
-       if (pcb1->pcb_vfpcpu != NULL)
-               vfp_saveregs_lwp(l1, 1);
-#endif
+       l2->l_md.md_flags = l1->l_md.md_flags & MDLWP_VFPUSED;
 
        /* Copy the pcb */
        *pcb2 = *pcb1;
@@ -209,22 +200,12 @@
 void
 cpu_lwp_free(struct lwp *l, int proc)
 {
-#ifdef FPU_VFP
-       struct pcb *pcb;
-#endif
-
 #ifdef ARMFPE
        /* Abort any active FP operation and deactivate the context */
        arm_fpe_core_abort(FP_CONTEXT(l), NULL, NULL);
        arm_fpe_core_changecontext(0);
 #endif /* ARMFPE */
 
-#ifdef FPU_VFP
-       pcb = lwp_getpcb(l);
-       if (pcb->pcb_vfpcpu != NULL)
-               vfp_saveregs_lwp(l, 0);
-#endif
-



Home | Main Index | Thread Index | Old Index