Source-Changes-HG archive

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

[src/trunk]: src/sys/arch small rototill.



details:   https://anonhg.NetBSD.org/src/rev/882b655f6f7d
branches:  trunk
changeset: 781059:882b655f6f7d
user:      matt <matt%NetBSD.org@localhost>
date:      Thu Aug 16 17:35:01 2012 +0000

description:
small rototill.
pcb_flags is dead.  PCB_NOALIGNFLT is now in stored l_md.md_flags as
MDLWP_NOALIGNFLT.  This avoids a few loads of the PCB in exception handling.
pcb_tf has been moved to l_md.md_tf.  Again this avoids a lot of pcb
references just to access or set this.  It also means that pcb doesn't
need to accessed by MI code.
Move pcb_onfault to after the pcb union.
Add pcb_sp macro to make code prettier.
Add lwp_settrapframe(l, tf) to set the l_md.md_tf field.
Use lwp_trapframe to access it (was process_frame but that name was changed
in a previous commit).
Kill off curpcb in acorn26.
Kill the checks for curlwp being NULL.
Move TRAP_USERMODE from arm32/fault.c to frame.h and a __PROG26 version.
Replace tests for usermode with that macro.

diffstat:

 sys/arch/acorn26/acorn26/cpuswitch.c  |  10 +---
 sys/arch/acorn26/acorn26/except.c     |  73 ++++++++++++----------------------
 sys/arch/acorn26/acorn26/machdep.c    |   6 +-
 sys/arch/acorn26/acorn26/vm_machdep.c |  13 +++--
 sys/arch/arm/arm/arm_machdep.c        |  16 ++-----
 sys/arch/arm/arm/ast.c                |  19 +-------
 sys/arch/arm/arm/compat_13_machdep.c  |  11 +---
 sys/arch/arm/arm/compat_16_machdep.c  |   5 +-
 sys/arch/arm/arm/syscall.c            |  16 ++----
 sys/arch/arm/arm/undefined.c          |  13 +++--
 sys/arch/arm/arm32/arm32_machdep.c    |  18 +++++---
 sys/arch/arm/arm32/cpuswitch.S        |  10 ++--
 sys/arch/arm/arm32/fault.c            |  51 ++++++++++-------------
 sys/arch/arm/arm32/genassym.cf        |  10 ++-
 sys/arch/arm/arm32/vm_machdep.c       |  18 ++++----
 sys/arch/arm/include/arm32/frame.h    |  20 ++++++---
 sys/arch/arm/include/cpu.h            |   5 +-
 sys/arch/arm/include/frame.h          |  11 ++++-
 sys/arch/arm/include/pcb.h            |  14 +++---
 sys/arch/arm/include/proc.h           |   6 +-
 20 files changed, 155 insertions(+), 190 deletions(-)

diffs (truncated from 1165 to 300 lines):

diff -r 874e3ca693fd -r 882b655f6f7d sys/arch/acorn26/acorn26/cpuswitch.c
--- a/sys/arch/acorn26/acorn26/cpuswitch.c      Thu Aug 16 17:25:36 2012 +0000
+++ b/sys/arch/acorn26/acorn26/cpuswitch.c      Thu Aug 16 17:35:01 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpuswitch.c,v 1.17 2009/11/21 20:32:17 rmind Exp $     */
+/*     $NetBSD: cpuswitch.c,v 1.18 2012/08/16 17:35:01 matt Exp $      */
 
 /*
  * Copyright (c) 2000 Ben Harris.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpuswitch.c,v 1.17 2009/11/21 20:32:17 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpuswitch.c,v 1.18 2012/08/16 17:35:01 matt Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -60,8 +60,6 @@
 lwp_t *
 cpu_switchto(lwp_t *old, lwp_t *new, bool returning)
 {
-       struct cpu_info * const ci = curcpu();
-       struct pcb *pcb;
        struct proc *p2;
 
        /*
@@ -73,14 +71,12 @@
 #endif
 
        curlwp = new;
-       pcb = lwp_getpcb(curlwp);
-       ci->ci_curpcb = pcb;
 
        if ((new->l_flag & LW_SYSTEM) == 0) {
                /* Check for Restartable Atomic Sequences. */
                p2 = new->l_proc;
                if (p2->p_raslist != NULL) {
-                       struct trapframe *tf = pcb->pcb_tf;
+                       struct trapframe * const tf = lwp_trapframe(curlwp);
                        void *pc;
 
                        pc = ras_lookup(p2, (void *)(tf->tf_r15 & R15_PC));
diff -r 874e3ca693fd -r 882b655f6f7d sys/arch/acorn26/acorn26/except.c
--- a/sys/arch/acorn26/acorn26/except.c Thu Aug 16 17:25:36 2012 +0000
+++ b/sys/arch/acorn26/acorn26/except.c Thu Aug 16 17:35:01 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: except.c,v 1.28 2012/05/11 15:39:17 skrll Exp $ */
+/* $NetBSD: except.c,v 1.29 2012/08/16 17:35:01 matt Exp $ */
 /*-
  * Copyright (c) 1998, 1999, 2000 Ben Harris
  * All rights reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: except.c,v 1.28 2012/05/11 15:39:17 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: except.c,v 1.29 2012/08/16 17:35:01 matt Exp $");
 
 #include "opt_ddb.h"
 
@@ -93,9 +93,8 @@
 void
 prefetch_abort_handler(struct trapframe *tf)
 {
-       vaddr_t pc;
-       struct proc *p;
-       struct lwp *l;
+       struct lwp * const l = curlwp;
+       struct proc * const p = l->l_proc;
 
        /* Enable interrupts if they were enabled before the trap. */
        if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0)
@@ -109,18 +108,11 @@
         */
 
        curcpu()->ci_data.cpu_ntrap++;
-       l = curlwp;
-       if (l == NULL)
-               l = &lwp0;
-       p = l->l_proc;
 
-       if ((tf->tf_r15 & R15_MODE) == R15_MODE_USR) {
-               struct pcb *pcb = lwp_getpcb(l);
-               pcb->pcb_tf = tf;
+       if (TRAP_USERMODE(tf)) {
+               lwp_settrapframe(l, tf);
                LWP_CACHE_CREDS(l, p);
-       }
-
-       if ((tf->tf_r15 & R15_MODE) != R15_MODE_USR) {
+       } else {
 #ifdef DDB
                db_printf("Prefetch abort in kernel mode\n");
                kdb_trap(T_FAULT, tf);
@@ -134,7 +126,7 @@
        }
 
        /* User-mode prefetch abort */
-       pc = tf->tf_r15 & R15_PC;
+       vaddr_t pc = tf->tf_r15 & R15_PC;
 
        do_fault(tf, l, &p->p_vmspace->vm_map, pc, VM_PROT_EXECUTE);
 
@@ -144,13 +136,13 @@
 void
 data_abort_handler(struct trapframe *tf)
 {
-       vaddr_t pc, va;
-       vsize_t asize;
-       struct proc *p;
-       struct lwp *l;
+       struct lwp * const l = curlwp;
+       struct proc * const p = l->l_proc;
        vm_prot_t atype;
        bool usrmode, twopages;
        struct vm_map *map;
+       vaddr_t pc, va;
+       vsize_t asize;
 
        /*
         * Data aborts in kernel mode are possible (copyout etc), so
@@ -167,13 +159,8 @@
        if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0)
                int_on();
        curcpu()->ci_data.cpu_ntrap++;
-       l = curlwp;
-       if (l == NULL)
-               l = &lwp0;
-       p = l->l_proc;
        if ((tf->tf_r15 & R15_MODE) == R15_MODE_USR) {
-               struct pcb *pcb = lwp_getpcb(l);
-               pcb->pcb_tf = tf;
+               lwp_settrapframe(l, tf);
                LWP_CACHE_CREDS(l, p);
        }
        pc = tf->tf_r15 & R15_PC;
@@ -190,7 +177,7 @@
        if (twopages)
                do_fault(tf, l, map, va + asize - 4, atype);
 
-       if ((tf->tf_r15 & R15_MODE) == R15_MODE_USR)
+       if (TRAP_USERMODE(tf))
                userret(l);
 }
 
@@ -202,16 +189,13 @@
     struct vm_map *map, vaddr_t va, vm_prot_t atype)
 {
        int error;
-       struct pcb *pcb;
-       void *onfault;
-       bool user;
 
        if (pmap_fault(map->pmap, va, atype))
                return;
 
-       pcb = lwp_getpcb(l);
-       onfault = pcb->pcb_onfault;
-       user = (tf->tf_r15 & R15_MODE) == R15_MODE_USR;
+       struct pcb * const pcb = lwp_getpcb(l);
+       void * const onfault = pcb->pcb_onfault;
+       const bool user = TRAP_USERMODE(tf);
 
        if (cpu_intr_p()) {
                KASSERT(!user);
@@ -459,7 +443,7 @@
 {
        register_t insn;
 
-       if ((tf->tf_r15 & R15_MODE) == R15_MODE_USR)
+       if (TRAP_USERMODE(tf))
                return true;
        insn = *(register_t *)(tf->tf_r15 & R15_PC);
        if ((insn & 0x0d200000) == 0x04200000)
@@ -471,33 +455,30 @@
 void
 address_exception_handler(struct trapframe *tf)
 {
-       struct lwp *l;
-       vaddr_t pc;
+       struct lwp * const l = curlwp;
+       struct pcb * const pcb = lwp_getpcb(l);
        ksiginfo_t ksi;
 
        /* Enable interrupts if they were enabled before the trap. */
        if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0)
                int_on();
+
        curcpu()->ci_data.cpu_ntrap++;
-       l = curlwp;
-       if (l == NULL)
-               l = &lwp0;
-       if ((tf->tf_r15 & R15_MODE) == R15_MODE_USR) {
-               struct pcb *pcb = lwp_getpcb(l);
-               pcb->pcb_tf = tf;
+       if (TRAP_USERMODE(tf)) {
+               lwp_settrapframe(l, tf);
                LWP_CACHE_CREDS(l, l->l_proc);
        }
 
-       if (curpcb->pcb_onfault != NULL) {
+       if (pcb->pcb_onfault != NULL) {
                tf->tf_r0 = EFAULT;
                tf->tf_r15 = (tf->tf_r15 & ~R15_PC) |
-                   (register_t)curpcb->pcb_onfault;
+                   (uintptr_t)pcb->pcb_onfault;
                return;
        }
 
-       pc = tf->tf_r15 & R15_PC;
+       vaddr_t pc = tf->tf_r15 & R15_PC;
 
-       if ((tf->tf_r15 & R15_MODE) != R15_MODE_USR) {
+       if (!TRAP_USERMODE(tf)) {
 #ifdef DDB
                db_printf("Address exception in kernel mode\n");
                kdb_trap(T_FAULT, tf);
diff -r 874e3ca693fd -r 882b655f6f7d sys/arch/acorn26/acorn26/machdep.c
--- a/sys/arch/acorn26/acorn26/machdep.c        Thu Aug 16 17:25:36 2012 +0000
+++ b/sys/arch/acorn26/acorn26/machdep.c        Thu Aug 16 17:35:01 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.36 2012/05/11 15:39:17 skrll Exp $ */
+/* $NetBSD: machdep.c,v 1.37 2012/08/16 17:35:01 matt Exp $ */
 
 /*-
  * Copyright (c) 1998 Ben Harris
@@ -32,7 +32,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.36 2012/05/11 15:39:17 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.37 2012/08/16 17:35:01 matt Exp $");
 
 #include <sys/buf.h>
 #include <sys/kernel.h>
@@ -169,8 +169,6 @@
        format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
        printf("avail memory = %s\n", pbuf);
 
-       curpcb = lwp_getpcb(&lwp0);
-
 #if 0
        /* Test exception handlers */
        __asm(".word 0x06000010"); /* undefined instruction */
diff -r 874e3ca693fd -r 882b655f6f7d sys/arch/acorn26/acorn26/vm_machdep.c
--- a/sys/arch/acorn26/acorn26/vm_machdep.c     Thu Aug 16 17:25:36 2012 +0000
+++ b/sys/arch/acorn26/acorn26/vm_machdep.c     Thu Aug 16 17:35:01 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.28 2012/02/19 21:05:58 rmind Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.29 2012/08/16 17:35:01 matt Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 Ben Harris
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.28 2012/02/19 21:05:58 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.29 2012/08/16 17:35:01 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -80,6 +80,7 @@
 #include <machine/frame.h>
 #include <machine/intr.h>
 #include <machine/machdep.h>
+#include <machine/pcb.h>
 
 /*
  * Finish a fork operation, with thread l2 nearly set up.
@@ -122,21 +123,21 @@
        tf = (struct trapframe *)(uvm_lwp_getuarea(l2) + USPACE) - 1;
        sf = (struct switchframe *)tf - 1;
        /* Duplicate old process's trapframe (if it had one) */
-       if (pcb1->pcb_tf == NULL)
+       if (lwp_trapframe(l1) == NULL)
                memset(tf, 0, sizeof(*tf));
        else
-               *tf = *pcb1->pcb_tf;
+               *tf = *lwp_trapframe(l1);
        /* If specified, give the child a different stack. */
        if (stack != NULL)
                tf->tf_usr_sp = (u_int)stack + stacksize;
-       pcb2->pcb_tf = tf;
+       lwp_settrapframe(l2, tf);
        /* Fabricate a new switchframe */
        memset(sf, 0, sizeof(*sf));
 
        sf->sf_r13 = (register_t)tf; /* Initial stack pointer */
        sf->sf_pc  = (register_t)lwp_trampoline | R15_MODE_SVC;
 
-       pcb2->pcb_tf = tf;
+       lwp_settrapframe(l2, tf);
        pcb2->pcb_sf = sf;
        pcb2->pcb_onfault = NULL;
        sf->sf_r4 = (register_t)func;
diff -r 874e3ca693fd -r 882b655f6f7d sys/arch/arm/arm/arm_machdep.c
--- a/sys/arch/arm/arm/arm_machdep.c    Thu Aug 16 17:25:36 2012 +0000
+++ b/sys/arch/arm/arm/arm_machdep.c    Thu Aug 16 17:35:01 2012 +0000



Home | Main Index | Thread Index | Old Index