Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Detangle some of the PowerPC CPU configurat...



details:   https://anonhg.NetBSD.org/src/rev/4733274909df
branches:  trunk
changeset: 998086:4733274909df
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Apr 07 05:25:55 2019 +0000

description:
Detangle some of the PowerPC CPU configuration spaghetti.

diffstat:

 sys/arch/powerpc/booke/booke_machdep.c  |  10 +++-
 sys/arch/powerpc/booke/copyin.c         |  55 ++++++++++++++++++++++----
 sys/arch/powerpc/booke/copyout.c        |  67 ++++++++++++++++++++++++++++++--
 sys/arch/powerpc/ibm4xx/trap.c          |  33 +++++++++++++++-
 sys/arch/powerpc/include/booke/cpuvar.h |   4 +-
 sys/arch/powerpc/include/types.h        |   4 +-
 sys/arch/powerpc/powerpc/trap.c         |   6 +-
 7 files changed, 153 insertions(+), 26 deletions(-)

diffs (truncated from 371 to 300 lines):

diff -r c3232f3717a0 -r 4733274909df sys/arch/powerpc/booke/booke_machdep.c
--- a/sys/arch/powerpc/booke/booke_machdep.c    Sun Apr 07 04:11:56 2019 +0000
+++ b/sys/arch/powerpc/booke/booke_machdep.c    Sun Apr 07 05:25:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: booke_machdep.c,v 1.25 2016/12/06 07:34:22 rin Exp $   */
+/*     $NetBSD: booke_machdep.c,v 1.26 2019/04/07 05:25:55 thorpej Exp $       */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -38,7 +38,7 @@
 #define        _POWERPC_BUS_DMA_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: booke_machdep.c,v 1.25 2016/12/06 07:34:22 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: booke_machdep.c,v 1.26 2019/04/07 05:25:55 thorpej Exp $");
 
 #include "opt_modular.h"
 
@@ -566,8 +566,12 @@
 void
 booke_sstep(struct trapframe *tf)
 {
+       uint32_t insn;
+
        KASSERT(tf->tf_srr1 & PSL_DE);
-       const uint32_t insn = ufetch_32((const void *)tf->tf_srr0);
+       if (ufetch_32((const void *)tf->tf_srr0, &insn) != 0)
+               return;
+
        register_t dbcr0 = DBCR0_IAC1 | DBCR0_IDM;
        register_t dbcr1 = DBCR1_IAC1US_USER | DBCR1_IAC1ER_DS1;
        if ((insn >> 28) == 4) {
diff -r c3232f3717a0 -r 4733274909df sys/arch/powerpc/booke/copyin.c
--- a/sys/arch/powerpc/booke/copyin.c   Sun Apr 07 04:11:56 2019 +0000
+++ b/sys/arch/powerpc/booke/copyin.c   Sun Apr 07 05:25:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyin.c,v 1.6 2014/07/24 23:27:25 joerg Exp $ */
+/*     $NetBSD: copyin.c,v 1.7 2019/04/07 05:25:55 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -36,10 +36,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyin.c,v 1.6 2014/07/24 23:27:25 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyin.c,v 1.7 2019/04/07 05:25:55 thorpej Exp $");
+
+#define        __UFETCHSTORE_PRIVATE
 
 #include <sys/param.h>
 #include <sys/lwp.h>
+#include <sys/systm.h>
 
 #include <powerpc/pcb.h>
 
@@ -60,7 +63,6 @@
        return data;
 }
 
-#if 0
 static inline uint16_t
 copyin_halfword(const uint16_t * const usaddr16, register_t ds_msr)
 {
@@ -75,7 +77,6 @@
            : [ds_msr] "r" (ds_msr), [usaddr16] "b" (usaddr16));
        return data;
 }
-#endif
 
 static inline uint32_t
 copyin_word(const uint32_t * const usaddr32, register_t ds_msr)
@@ -199,22 +200,58 @@
        }
 }
 
-uint32_t
-ufetch_32(const void *vusaddr)
+int
+_ufetch_8(const uint8_t *vusaddr, uint8_t *valp)
+{
+       struct pcb * const pcb = lwp_getpcb(curlwp);
+       struct faultbuf env;
+
+       if (setfault(&env) != 0) {
+               pcb->pcb_onfault = NULL;
+               return EFAULT;
+       }
+
+       *valp = copyin_byte(vusaddr, mfmsr() | PSL_DS);
+
+       pcb->pcb_onfault = NULL;
+
+       return 0;
+}
+
+int
+_ufetch_16(const uint16_t *vusaddr, uint16_t *valp)
 {
        struct pcb * const pcb = lwp_getpcb(curlwp);
        struct faultbuf env;
 
        if (setfault(&env) != 0) {
                pcb->pcb_onfault = NULL;
-               return -1;
+               return EFAULT;
        }
 
-       uint32_t rv = copyin_word(vusaddr, mfmsr() | PSL_DS);
+       *valp = copyin_halfword(vusaddr, mfmsr() | PSL_DS);
 
        pcb->pcb_onfault = NULL;
 
-       return rv;
+       return 0;
+}
+
+int
+_ufetch_32(const uint32_t *vusaddr, uint32_t *valp)
+{
+       struct pcb * const pcb = lwp_getpcb(curlwp);
+       struct faultbuf env;
+
+       if (setfault(&env) != 0) {
+               pcb->pcb_onfault = NULL;
+               return EFAULT;
+       }
+
+       *valp = copyin_word(vusaddr, mfmsr() | PSL_DS);
+
+       pcb->pcb_onfault = NULL;
+
+       return 0;
 }
 
 int
diff -r c3232f3717a0 -r 4733274909df sys/arch/powerpc/booke/copyout.c
--- a/sys/arch/powerpc/booke/copyout.c  Sun Apr 07 04:11:56 2019 +0000
+++ b/sys/arch/powerpc/booke/copyout.c  Sun Apr 07 05:25:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyout.c,v 1.4 2014/07/24 23:29:02 joerg Exp $        */
+/*     $NetBSD: copyout.c,v 1.5 2019/04/07 05:25:55 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -36,10 +36,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyout.c,v 1.4 2014/07/24 23:29:02 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyout.c,v 1.5 2019/04/07 05:25:55 thorpej Exp $");
+
+#define        __UFETCHSTORE_PRIVATE
 
 #include <sys/param.h>
 #include <sys/lwp.h>
+#include <sys/systm.h>
 
 #include <powerpc/pcb.h>
 
@@ -58,20 +61,18 @@
            : [ds_msr] "r" (ds_msr), [data] "r" (data), [udaddr] "b" (udaddr));
 }
 
-#if 0
 static inline void
-copyout_uint16(uint8_t *udaddr, uint8_t data, register_t ds_msr)
+copyout_uint16(uint16_t *udaddr, uint8_t data, register_t ds_msr)
 {
        register_t msr;
        __asm volatile(
                "mfmsr  %[msr]"                         /* Save MSR */
        "\n\t"  "mtmsr  %[ds_msr]; sync; isync"         /* DS on */
-       "\n\t"  "stb    %[data],0(%[udaddr])"           /* store user byte */
+       "\n\t"  "sth    %[data],0(%[udaddr])"           /* store user half */
        "\n\t"  "mtmsr  %[msr]; sync; isync"            /* DS off */
            : [msr] "=&r" (msr)
            : [ds_msr] "r" (ds_msr), [data] "r" (data), [udaddr] "b" (udaddr));
 }
-#endif
 
 static inline void
 copyout_uint32(uint32_t * const udaddr, uint32_t data, register_t ds_msr)
@@ -298,6 +299,60 @@
 }
 
 int
+_ustore_8(uint8_t *vusaddr, uint8_t val)
+{
+       struct pcb * const pcb = lwp_getpcb(curlwp);
+       struct faultbuf env;
+
+       if (setfault(&env) != 0) {
+               pcb->pcb_onfault = NULL;
+               return EFAULT;
+       }
+
+       copyout_uint8(vusaddr, val, mfmsr() | PSL_DS);
+
+       pcb->pcb_onfault = NULL;
+
+       return 0;
+}
+
+int
+_ustore_16(uint16_t *vusaddr, uint16_t val)
+{
+       struct pcb * const pcb = lwp_getpcb(curlwp);
+       struct faultbuf env;
+
+       if (setfault(&env) != 0) {
+               pcb->pcb_onfault = NULL;
+               return EFAULT;
+       }
+
+       copyout_uint16(vusaddr, val, mfmsr() | PSL_DS);
+
+       pcb->pcb_onfault = NULL;
+
+       return 0;
+}
+
+int
+_ustore_32(uint32_t *vusaddr, uint32_t val)
+{
+       struct pcb * const pcb = lwp_getpcb(curlwp);
+       struct faultbuf env;
+
+       if (setfault(&env) != 0) {
+               pcb->pcb_onfault = NULL;
+               return EFAULT;
+       }
+
+       copyout_uint32(vusaddr, val, mfmsr() | PSL_DS);
+
+       pcb->pcb_onfault = NULL;
+
+       return 0;
+}
+
+int
 copyout(const void *vksaddr, void *vudaddr, size_t len)
 {
        struct pcb * const pcb = lwp_getpcb(curlwp);
diff -r c3232f3717a0 -r 4733274909df sys/arch/powerpc/ibm4xx/trap.c
--- a/sys/arch/powerpc/ibm4xx/trap.c    Sun Apr 07 04:11:56 2019 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap.c    Sun Apr 07 05:25:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.69 2016/12/26 21:54:00 rin Exp $    */
+/*     $NetBSD: trap.c,v 1.70 2019/04/07 05:25:55 thorpej Exp $        */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,12 +67,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69 2016/12/26 21:54:00 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.70 2019/04/07 05:25:55 thorpej Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 
+#define        __UFETCHSTORE_PRIVATE
+
 #include <sys/param.h>
 #include <sys/proc.h>
 #include <sys/reboot.h>
@@ -677,3 +679,30 @@
 
        return -1;
 }
+
+/*
+ * XXX Extremely lame implementations of _ufetch_* / _ustore_*.  IBM 4xx
+ * experts should make versions that are good.
+ */
+
+#define UFETCH(sz)                                                     \
+int                                                                    \
+_ufetch_ ## sz(const uint ## sz ## _t *uaddr, uint ## sz ## _t *valp)  \
+{                                                                      \
+       return copyin(uaddr, valp, sizeof(*valp));                      \
+}
+
+UFETCH(8)
+UFETCH(16)
+UFETCH(32)
+
+#define USTORE(sz)                                                     \
+int                                                                    \
+_ustore_ ## sz(uint ## sz ## _t *uaddr, uint ## sz ## _t val)          \
+{                                                                      \
+       return copyout(&val, uaddr, sizeof(val));                       \
+}
+
+USTORE(8)
+USTORE(16)
+USTORE(32)



Home | Main Index | Thread Index | Old Index