Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc/ibm4xx copy{in, out}str: sync style with booke.



details:   https://anonhg.NetBSD.org/src/rev/0bf993087767
branches:  trunk
changeset: 849528:0bf993087767
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Mar 05 00:54:13 2020 +0000

description:
copy{in,out}str: sync style with booke.

- early return in case of len == 0
- *done = 0 on fault

diffstat:

 sys/arch/powerpc/ibm4xx/copyinstr.c  |  61 ++++++++++++++++++----------------
 sys/arch/powerpc/ibm4xx/copyoutstr.c |  62 +++++++++++++++++++----------------
 2 files changed, 65 insertions(+), 58 deletions(-)

diffs (191 lines):

diff -r 6e12b71cf1d8 -r 0bf993087767 sys/arch/powerpc/ibm4xx/copyinstr.c
--- a/sys/arch/powerpc/ibm4xx/copyinstr.c       Thu Mar 05 00:33:56 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyinstr.c       Thu Mar 05 00:54:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyinstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $        */
+/*     $NetBSD: copyinstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -49,11 +49,16 @@
        int rv, msr, pid, tmp, ctx;
        struct faultbuf env;
 
+       if (__predict_false(len == 0)) {
+               if (done)
+                       *done = 0;
+               return 0;
+       }
+
        if ((rv = setfault(&env))) {
                curpcb->pcb_onfault = NULL;
-               /* XXXX -- len may be lost on a fault */
                if (done)
-                       *done = len;
+                       *done = 0;
                return rv;
        }
 
@@ -63,34 +68,32 @@
                ctx = pm->pm_ctx;
        }
 
-       if (len) {
-               __asm volatile("mtctr %3;"              /* Set up counter */
-                       "mfmsr %0;"                     /* Save MSR */
-                       "li %1,0x20; "
-                       "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
-                       "mfpid %1;"                     /* Save old PID */
-                       "sync; isync;"
+       __asm volatile(
+               "mtctr %3;"                     /* Set up counter */
+               "mfmsr %0;"                     /* Save MSR */
+               "li %1,0x20;"
+               "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
+               "mfpid %1;"                     /* Save old PID */
+               "sync; isync;"
 
-                       "li %3,0;"                      /* Clear len */
+               "li %3,0;"                      /* Clear len */
 
-                       "1: "
-                       "mtpid %4; sync;"               /* Load user ctx */
-                       "lbz %2,0(%5); addi %5,%5,1;"   /* Load byte */
-                       "sync; isync;"
-                       "mtpid %1;sync;"
-                       "stb %2,0(%6);  dcbf 0,%6; addi %6,%6,1;"       /* Store kernel byte */
-                       "sync; isync;"
-                       "addi %3,%3,1;"                 /* Inc len */
-                       "or. %2,%2,%2;"
-                       "bdnzf 2,1b;"                   /*
-                                                        * while(ctr-- && !zero)
-                                                        */
+               "1: "
+               "mtpid %4; sync;"               /* Load user ctx */
+               "lbz %2,0(%5); addi %5,%5,1;"   /* Load byte */
+               "sync; isync;"
+               "mtpid %1;sync;"
+               "stb %2,0(%6); dcbf 0,%6; addi %6,%6,1;"
+                                               /* Store kernel byte */
+               "sync; isync;"
+               "addi %3,%3,1;"                 /* Inc len */
+               "or. %2,%2,%2;"
+               "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
+               "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
+               "sync; isync;"
+               : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
+               : "r" (ctx), "b" (udaddr), "b" (kaddr));
 
-                       "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
-                       "sync; isync;"
-                       : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
-                       : "r" (ctx), "b" (udaddr), "b" (kaddr));
-       }
        curpcb->pcb_onfault = NULL;
        if (done)
                *done = len;
diff -r 6e12b71cf1d8 -r 0bf993087767 sys/arch/powerpc/ibm4xx/copyoutstr.c
--- a/sys/arch/powerpc/ibm4xx/copyoutstr.c      Thu Mar 05 00:33:56 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyoutstr.c      Thu Mar 05 00:54:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyoutstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $       */
+/*     $NetBSD: copyoutstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -49,11 +49,16 @@
        int rv, msr, pid, tmp, ctx;
        struct faultbuf env;
 
+       if (__predict_false(len == 0)) {
+               if (done)
+                       *done = 0;
+               return 0;
+       }
+
        if ((rv = setfault(&env))) {
                curpcb->pcb_onfault = NULL;
-               /* XXXX -- len may be lost on a fault */
                if (done)
-                       *done = len;
+                       *done = 0;
                return rv;
        }
 
@@ -63,34 +68,33 @@
                ctx = pm->pm_ctx;
        }
 
-       if (len) {
-               __asm volatile("mtctr %3;"              /* Set up counter */
-                       "mfmsr %0;"                     /* Save MSR */
-                       "li %1,0x20; "
-                       "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
-                       "mfpid %1;"                     /* Save old PID */
-                       "sync; isync;"
+       __asm volatile(
+               "mtctr %3;"                     /* Set up counter */
+               "mfmsr %0;"                     /* Save MSR */
+               "li %1,0x20;"
+               "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
+               "mfpid %1;"                     /* Save old PID */
+               "sync; isync;"
 
-                       "li %3,0;"                      /* Clear len */
+               "li %3,0;"                      /* Clear len */
 
-                       "1:"
-                       "mtpid %1;sync;"
-                       "lbz %2,0(%6); addi %6,%6,1;"   /* Store kernel byte */
-                       "sync; isync;"
-                       "mtpid %4; sync;"               /* Load user ctx */
-                       "stb %2,0(%5);  dcbf 0,%5; addi %5,%5,1;"       /* Load byte */
-                       "sync; isync;"
-                       "addi %3,%3,1;"                 /* Inc len */
-                       "or. %2,%2,%2;"
-                       "bdnzf 2,1b;"                   /*
-                                                        * while(ctr-- && !zero)
-                                                        */
+               "1:"
+               "mtpid %1;sync;"
+               "lbz %2,0(%6); addi %6,%6,1;"   /* Store kernel byte */
+               "sync; isync;"
+               "mtpid %4; sync;"               /* Load user ctx */
+               "stb %2,0(%5); dcbf 0,%5; addi %5,%5,1;"
+                                               /* Load byte */
+               "sync; isync;"
+               "addi %3,%3,1;"                 /* Inc len */
+               "or. %2,%2,%2;"
+               "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
 
-                       "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
-                       "sync; isync;"
-                       : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
-                       : "r" (ctx), "b" (udaddr), "b" (kaddr));
-       }
+               "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
+               "sync; isync;"
+               : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
+               : "r" (ctx), "b" (udaddr), "b" (kaddr));
+
        curpcb->pcb_onfault = NULL;
        if (done)
                *done = len;



Home | Main Index | Thread Index | Old Index