Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm Consistency around the user trapframe for all L...



details:   https://anonhg.NetBSD.org/src/rev/8098edda62db
branches:  trunk
changeset: 354875:8098edda62db
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun Jul 02 16:16:44 2017 +0000

description:
Consistency around the user trapframe for all LWPs and there's no need to
keep assigning it in kernel entry points.

diffstat:

 sys/arch/arm/arm/syscall.c         |   6 +++---
 sys/arch/arm/arm/undefined.c       |   7 ++++---
 sys/arch/arm/arm32/arm32_boot.c    |  27 ++++++++++++++++++++++++---
 sys/arch/arm/arm32/arm32_machdep.c |  26 +++++++++++++++++++++++---
 sys/arch/arm/arm32/fault.c         |  18 +++++++++---------
 5 files changed, 63 insertions(+), 21 deletions(-)

diffs (227 lines):

diff -r bd3c26fae4b8 -r 8098edda62db sys/arch/arm/arm/syscall.c
--- a/sys/arch/arm/arm/syscall.c        Sun Jul 02 16:06:42 2017 +0000
+++ b/sys/arch/arm/arm/syscall.c        Sun Jul 02 16:16:44 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.61 2017/07/02 16:06:42 skrll Exp $       */
+/*     $NetBSD: syscall.c,v 1.62 2017/07/02 16:16:44 skrll Exp $       */
 
 /*-
  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.61 2017/07/02 16:06:42 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.62 2017/07/02 16:16:44 skrll Exp $");
 
 #include <sys/cpu.h>
 #include <sys/device.h>
@@ -155,7 +155,7 @@
 #endif
        }
 
-       lwp_settrapframe(l, tf);
+       KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf, lwp_trapframe(l));
 
 #ifdef CPU_ARM7
        /*
diff -r bd3c26fae4b8 -r 8098edda62db sys/arch/arm/arm/undefined.c
--- a/sys/arch/arm/arm/undefined.c      Sun Jul 02 16:06:42 2017 +0000
+++ b/sys/arch/arm/arm/undefined.c      Sun Jul 02 16:16:44 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: undefined.c,v 1.59 2017/05/06 13:05:59 skrll Exp $     */
+/*     $NetBSD: undefined.c,v 1.60 2017/07/02 16:16:44 skrll Exp $     */
 
 /*
  * Copyright (c) 2001 Ben Harris.
@@ -55,7 +55,7 @@
 #include <sys/kgdb.h>
 #endif
 
-__KERNEL_RCSID(0, "$NetBSD: undefined.c,v 1.59 2017/05/06 13:05:59 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: undefined.c,v 1.60 2017/07/02 16:16:44 skrll Exp $");
 
 #include <sys/kmem.h>
 #include <sys/queue.h>
@@ -420,7 +420,8 @@
                 * time of fault.
                 */
                fault_code = FAULT_USER;
-               lwp_settrapframe(l, tf);
+               KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf,
+                   lwp_trapframe(l));
        } else
                fault_code = 0;
 
diff -r bd3c26fae4b8 -r 8098edda62db sys/arch/arm/arm32/arm32_boot.c
--- a/sys/arch/arm/arm32/arm32_boot.c   Sun Jul 02 16:06:42 2017 +0000
+++ b/sys/arch/arm/arm32/arm32_boot.c   Sun Jul 02 16:16:44 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_boot.c,v 1.18 2016/12/22 14:47:54 cherry Exp $   */
+/*     $NetBSD: arm32_boot.c,v 1.19 2017/07/02 16:16:44 skrll Exp $    */
 
 /*
  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
@@ -123,7 +123,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.18 2016/12/22 14:47:54 cherry Exp $");
+__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.19 2017/07/02 16:16:44 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -173,6 +173,27 @@
         */
        uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
 
+       struct lwp * const l = &lwp0;
+       struct pcb * const pcb = lwp_getpcb(l);
+
+       /* Zero out the PCB. */
+       memset(pcb, 0, sizeof(*pcb));
+
+       pcb->pcb_ksp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
+       pcb->pcb_ksp -= sizeof(struct trapframe);
+
+       struct trapframe * tf = (struct trapframe *)pcb->pcb_ksp;
+
+       /* Zero out the trapframe. */
+       memset(tf, 0, sizeof(*tf));
+       lwp_settrapframe(l, tf);
+
+#if defined(__ARMEB__)
+       tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
+#else
+       tf->tf_spsr = PSR_USR32_MODE;
+#endif
+
 #ifdef VERBOSE_INIT_ARM
        printf("bootstrap done.\n");
 #endif
@@ -313,7 +334,7 @@
 #endif
 
        /* We return the new stack pointer address */
-       return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
+       return pcb->pcb_ksp;
 }
 
 #ifdef MULTIPROCESSOR
diff -r bd3c26fae4b8 -r 8098edda62db sys/arch/arm/arm32/arm32_machdep.c
--- a/sys/arch/arm/arm32/arm32_machdep.c        Sun Jul 02 16:06:42 2017 +0000
+++ b/sys/arch/arm/arm32/arm32_machdep.c        Sun Jul 02 16:16:44 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_machdep.c,v 1.113 2017/07/02 16:06:42 skrll Exp $        */
+/*     $NetBSD: arm32_machdep.c,v 1.114 2017/07/02 16:16:44 skrll Exp $        */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.113 2017/07/02 16:06:42 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.114 2017/07/02 16:16:44 skrll Exp $");
 
 #include "opt_modular.h"
 #include "opt_md.h"
@@ -315,10 +315,30 @@
        format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
        printf("avail memory = %s\n", pbuf);
 
+       /*
+        * This is actually done by initarm_common, but not all ports use it
+        * yet so do it here to catch them as well
+        */
        struct lwp * const l = &lwp0;
        struct pcb * const pcb = lwp_getpcb(l);
+
+       /* Zero out the PCB. */
+       memset(pcb, 0, sizeof(*pcb));
+
        pcb->pcb_ksp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
-       lwp_settrapframe(l, (struct trapframe *)pcb->pcb_ksp - 1);
+       pcb->pcb_ksp -= sizeof(struct trapframe);
+
+       struct trapframe * tf = (struct trapframe *)pcb->pcb_ksp;
+
+       /* Zero out the trapframe. */
+       memset(tf, 0, sizeof(*tf));
+       lwp_settrapframe(l, tf);
+
+#if defined(__ARMEB__)
+       tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
+#else
+       tf->tf_spsr = PSR_USR32_MODE;
+#endif
 }
 
 /*
diff -r bd3c26fae4b8 -r 8098edda62db sys/arch/arm/arm32/fault.c
--- a/sys/arch/arm/arm32/fault.c        Sun Jul 02 16:06:42 2017 +0000
+++ b/sys/arch/arm/arm32/fault.c        Sun Jul 02 16:16:44 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fault.c,v 1.103 2015/03/02 13:36:36 martin Exp $       */
+/*     $NetBSD: fault.c,v 1.104 2017/07/02 16:16:44 skrll Exp $        */
 
 /*
  * Copyright 2003 Wasabi Systems, Inc.
@@ -81,7 +81,7 @@
 #include "opt_kgdb.h"
 
 #include <sys/types.h>
-__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.103 2015/03/02 13:36:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.104 2017/07/02 16:16:44 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -310,9 +310,8 @@
                return;
        }
 
-       if (user) {
-               lwp_settrapframe(l, tf);
-       }
+       KASSERTMSG(!user || tf == lwp_trapframe(l), "tf %p vs %p", tf,
+           lwp_trapframe(l));
 
        /*
         * Make sure the Program Counter is sane. We could fall foul of
@@ -624,7 +623,7 @@
        ksi->ksi_addr = (uint32_t *)(intptr_t)far;
        ksi->ksi_trap = fsr;
 
-       lwp_settrapframe(l, tf);
+       KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf, lwp_trapframe(l));
 
        return (1);
 }
@@ -731,7 +730,7 @@
        ksi->ksi_addr = (uint32_t *)(intptr_t)far;
        ksi->ksi_trap = fsr;
 
-       lwp_settrapframe(l, tf);
+       KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf, lwp_trapframe(l));
 
        return (1);
 }
@@ -834,7 +833,8 @@
                ksi.ksi_signo = SIGILL;
                ksi.ksi_code = ILL_ILLOPC;
                ksi.ksi_addr = (uint32_t *)(intptr_t) tf->tf_pc;
-               lwp_settrapframe(l, tf);
+               KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf,
+                   lwp_trapframe(l));
                goto do_trapsignal;
        default:
                break;
@@ -846,7 +846,7 @@
 
        /* Get fault address */
        fault_pc = tf->tf_pc;
-       lwp_settrapframe(l, tf);
+       KASSERTMSG(tf == lwp_trapframe(l), "tf %p vs %p", tf, lwp_trapframe(l));
        UVMHIST_LOG(maphist, " (pc=0x%x, l=0x%x, tf=0x%x)",
            fault_pc, l, tf, 0);
 



Home | Main Index | Thread Index | Old Index