Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Refactor the 68040 writeback() from each m68k port'...



details:   https://anonhg.NetBSD.org/src/rev/cd43da20f438
branches:  trunk
changeset: 449000:cd43da20f438
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Feb 18 01:12:22 2019 +0000

description:
Refactor the 68040 writeback() from each m68k port's trap handler into a
shared copy: m68040_writeback().  It is essentially a copy of the Atari
version, with some minor cosmetic tweaks and one small performance optimization
from the mvme68k port.

Tested by rjs@ on a Quadra 950.  (Thanks!)

diffstat:

 sys/arch/atari/atari/trap.c         |  314 +---------------------------
 sys/arch/atari/conf/files.atari     |    3 +-
 sys/arch/atari/include/cpu.h        |    3 +-
 sys/arch/cesfic/cesfic/trap.c       |  310 +---------------------------
 sys/arch/cesfic/conf/files.cesfic   |    3 +-
 sys/arch/cesfic/include/cpu.h       |    3 +-
 sys/arch/hp300/conf/files.hp300     |    3 +-
 sys/arch/hp300/hp300/trap.c         |  313 +---------------------------
 sys/arch/hp300/include/cpu.h        |    3 +-
 sys/arch/luna68k/conf/files.luna68k |    3 +-
 sys/arch/luna68k/include/cpu.h      |    3 +-
 sys/arch/luna68k/luna68k/trap.c     |  310 +---------------------------
 sys/arch/m68k/include/frame.h       |    6 +-
 sys/arch/m68k/m68k/m68k_trap.c      |  400 ++++++++++++++++++++++++++++++++++++
 sys/arch/mac68k/conf/files.mac68k   |    3 +-
 sys/arch/mac68k/include/cpu.h       |    3 +-
 sys/arch/mac68k/mac68k/trap.c       |  317 +----------------------------
 sys/arch/mvme68k/conf/files.mvme68k |    3 +-
 sys/arch/mvme68k/mvme68k/trap.c     |  326 +----------------------------
 sys/arch/news68k/conf/files.news68k |    3 +-
 sys/arch/news68k/include/cpu.h      |    3 +-
 sys/arch/news68k/news68k/trap.c     |  313 +---------------------------
 sys/arch/next68k/conf/files.next68k |    3 +-
 sys/arch/next68k/include/cpu.h      |    3 +-
 sys/arch/next68k/next68k/trap.c     |  309 +---------------------------
 sys/arch/x68k/conf/files.x68k       |    3 +-
 sys/arch/x68k/include/cpu.h         |    3 +-
 sys/arch/x68k/x68k/trap.c           |  310 +---------------------------
 28 files changed, 467 insertions(+), 2812 deletions(-)

diffs (truncated from 3891 to 300 lines):

diff -r d06dcca604ea -r cd43da20f438 sys/arch/atari/atari/trap.c
--- a/sys/arch/atari/atari/trap.c       Mon Feb 18 00:42:54 2019 +0000
+++ b/sys/arch/atari/atari/trap.c       Mon Feb 18 01:12:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.113 2015/03/04 20:29:59 martin Exp $        */
+/*     $NetBSD: trap.c,v 1.114 2019/02/18 01:12:22 thorpej Exp $       */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.113 2015/03/04 20:29:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.114 2019/02/18 01:12:22 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_execfmt.h"
@@ -93,9 +93,6 @@
 static void panictrap(int, u_int, u_int, struct frame *);
 static void trapcpfault(struct lwp *, struct frame *, int);
 static void userret(struct lwp *, struct frame *fp, u_quad_t, u_int, int);
-#ifdef M68040
-static int  writeback(struct frame *, int);
-#endif /* M68040 */
 
 const char *trap_type[] = {
        "Bus error",
@@ -220,7 +217,7 @@
                "pid %d(%s): writeback aborted in sigreturn, pc=%x\n",
                                    p->p_pid, p->p_comm, fp->f_pc, faultaddr);
 #endif
-               } else if ((sig = writeback(fp, fromtrap))) {
+               } else if ((sig = m68040_writeback(fp, fromtrap))) {
                        ksiginfo_t ksi;
                        beenhere = 1;
                        oticks = p->p_sticks;
@@ -633,7 +630,7 @@
                                }
 #ifdef M68040
                                if (cputype == CPU_68040)
-                                       (void) writeback(fp, 1);
+                                       (void) m68040_writeback(fp, 1);
 #endif
                                return;
                        }
@@ -688,306 +685,3 @@
 out:
        userret(l, fp, sticks, v, 1); 
 }
-
-#ifdef M68040
-#ifdef DEBUG
-struct writebackstats {
-       int calls;
-       int cpushes;
-       int move16s;
-       int wb1s, wb2s, wb3s;
-       int wbsize[4];
-} wbstats;
-
-const char *f7sz[] = { "longword", "byte", "word", "line" };
-const char *f7tt[] = { "normal", "MOVE16", "AFC", "ACK" };
-const char *f7tm[] = { "d-push", "u-data", "u-code", "M-data",
-                "M-code", "k-data", "k-code", "RES" };
-const char wberrstr[] =
-    "WARNING: pid %d(%s) writeback [%s] failed, pc=%x fa=%x wba=%x wbd=%x\n";
-
-static void dumpwb(int, u_short, u_int, u_int);
-static void dumpssw(u_short);
-#endif /* DEBUG */
-
-static int
-writeback(struct frame *fp, int docachepush)
-{
-       struct fmt7 *f = &fp->f_fmt7;
-       struct lwp *l = curlwp;
-       struct proc *p = l->l_proc;
-       struct pcb *pcb = lwp_getpcb(l);
-       int     err = 0;
-       u_int   fa = 0;
-       void *oonfault = pcb->pcb_onfault;
-       paddr_t pa;
-
-#ifdef DEBUG
-       if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) {
-               printf(" pid=%d, fa=%x,", p->p_pid, f->f_fa);
-               dumpssw(f->f_ssw);
-       }
-       wbstats.calls++;
-#endif
-       /*
-        * Deal with special cases first.
-        */
-       if ((f->f_ssw & SSW4_TMMASK) == SSW4_TMDCP) {
-               /*
-                * Dcache push fault.
-                * Line-align the address and write out the push data to
-                * the indicated physical address.
-                */
-#ifdef DEBUG
-               if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid)) {
-                       printf(" pushing %s to PA %x, data %x",
-                              f7sz[(f->f_ssw & SSW4_SZMASK) >> 5],
-                              f->f_fa, f->f_pd0);
-                       if ((f->f_ssw & SSW4_SZMASK) == SSW4_SZLN)
-                               printf("/%x/%x/%x",
-                                      f->f_pd1, f->f_pd2, f->f_pd3);
-                       printf("\n");
-               }
-               if (f->f_wb1s & SSW4_WBSV)
-                       panic("writeback: cache push with WB1S valid");
-               wbstats.cpushes++;
-#endif
-               /*
-                * XXX there are security problems if we attempt to do a
-                * cache push after a signal handler has been called.
-                */
-               if (docachepush) {
-                       pmap_enter(pmap_kernel(), (vaddr_t)vmmap,
-                           trunc_page(f->f_fa), VM_PROT_WRITE,
-                           VM_PROT_WRITE|PMAP_WIRED);
-                       pmap_update(pmap_kernel());
-                       fa = (u_int)&vmmap[(f->f_fa & PGOFSET) & ~0xF];
-                       memcpy((void *)fa, (void *)&f->f_pd0, 16);
-                       (void) pmap_extract(pmap_kernel(), (vaddr_t)fa, &pa);
-                       DCFL(pa);
-                       pmap_remove(pmap_kernel(), (vaddr_t)vmmap,
-                                   (vaddr_t)&vmmap[PAGE_SIZE]);
-                       pmap_update(pmap_kernel());
-               } else
-                       printf("WARNING: pid %d(%s) uid %d: CPUSH not done\n",
-                              p->p_pid, p->p_comm, kauth_cred_geteuid(l->l_cred));
-       } else if ((f->f_ssw & (SSW4_RW|SSW4_TTMASK)) == SSW4_TTM16) {
-               /*
-                * MOVE16 fault.
-                * Line-align the address and write out the push data to
-                * the indicated virtual address.
-                */
-#ifdef DEBUG
-               if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
-                       printf(" MOVE16 to VA %x(%x), data %x/%x/%x/%x\n",
-                              f->f_fa, f->f_fa & ~0xF, f->f_pd0, f->f_pd1,
-                              f->f_pd2, f->f_pd3);
-               if (f->f_wb1s & SSW4_WBSV)
-                       panic("writeback: MOVE16 with WB1S valid");
-               wbstats.move16s++;
-#endif
-               if (KDFAULT(f->f_wb1s))
-                       memcpy((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0, 16);
-               else
-                       err = suline((void *)(f->f_fa & ~0xF), (void *)&f->f_pd0);
-               if (err) {
-                       fa = f->f_fa & ~0xF;
-#ifdef DEBUG
-                       if (mmudebug & MDB_WBFAILED)
-                               printf(wberrstr, p->p_pid, p->p_comm,
-                                      "MOVE16", fp->f_pc, f->f_fa,
-                                      f->f_fa & ~0xF, f->f_pd0);
-#endif
-               }
-       } else if (f->f_wb1s & SSW4_WBSV) {
-               /*
-                * Writeback #1.
-                * Position the "memory-aligned" data and write it out.
-                */
-               u_int wb1d = f->f_wb1d;
-               int off;
-
-#ifdef DEBUG
-               if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
-                       dumpwb(1, f->f_wb1s, f->f_wb1a, f->f_wb1d);
-               wbstats.wb1s++;
-               wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++;
-#endif
-               off = (f->f_wb1a & 3) * 8;
-               switch (f->f_wb1s & SSW4_SZMASK) {
-               case SSW4_SZLW:
-                       if (off)
-                               wb1d = (wb1d >> (32 - off)) | (wb1d << off);
-                       if (KDFAULT(f->f_wb1s))
-                               *(long *)f->f_wb1a = wb1d;
-                       else
-                               err = suword((void *)f->f_wb1a, wb1d);
-                       break;
-               case SSW4_SZB:
-                       off = 24 - off;
-                       if (off)
-                               wb1d >>= off;
-                       if (KDFAULT(f->f_wb1s))
-                               *(char *)f->f_wb1a = wb1d;
-                       else
-                               err = subyte((void *)f->f_wb1a, wb1d);
-                       break;
-               case SSW4_SZW:
-                       off = (off + 16) % 32;
-                       if (off)
-                               wb1d = (wb1d >> (32 - off)) | (wb1d << off);
-                       if (KDFAULT(f->f_wb1s))
-                               *(short *)f->f_wb1a = wb1d;
-                       else
-                               err = susword((void *)f->f_wb1a, wb1d);
-                       break;
-               }
-               if (err) {
-                       fa = f->f_wb1a;
-#ifdef DEBUG
-                       if (mmudebug & MDB_WBFAILED)
-                               printf(wberrstr, p->p_pid, p->p_comm,
-                                      "#1", fp->f_pc, f->f_fa,
-                                      f->f_wb1a, f->f_wb1d);
-#endif
-               }
-       }
-       /*
-        * Deal with the "normal" writebacks.
-        *
-        * XXX writeback2 is known to reflect a LINE size writeback after
-        * a MOVE16 was already dealt with above.  Ignore it.
-        */
-       if (err == 0 && (f->f_wb2s & SSW4_WBSV) &&
-           (f->f_wb2s & SSW4_SZMASK) != SSW4_SZLN) {
-#ifdef DEBUG
-               if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
-                       dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d);
-               wbstats.wb2s++;
-               wbstats.wbsize[(f->f_wb2s&SSW4_SZMASK)>>5]++;
-#endif
-               switch (f->f_wb2s & SSW4_SZMASK) {
-               case SSW4_SZLW:
-                       if (KDFAULT(f->f_wb2s))
-                               *(long *)f->f_wb2a = f->f_wb2d;
-                       else
-                               err = suword((void *)f->f_wb2a, f->f_wb2d);
-                       break;
-               case SSW4_SZB:
-                       if (KDFAULT(f->f_wb2s))
-                               *(char *)f->f_wb2a = f->f_wb2d;
-                       else
-                               err = subyte((void *)f->f_wb2a, f->f_wb2d);
-                       break;
-               case SSW4_SZW:
-                       if (KDFAULT(f->f_wb2s))
-                               *(short *)f->f_wb2a = f->f_wb2d;
-                       else
-                               err = susword((void *)f->f_wb2a, f->f_wb2d);
-                       break;
-               }
-               if (err) {
-                       fa = f->f_wb2a;
-#ifdef DEBUG
-                       if (mmudebug & MDB_WBFAILED) {
-                               printf(wberrstr, p->p_pid, p->p_comm,
-                                      "#2", fp->f_pc, f->f_fa,
-                                      f->f_wb2a, f->f_wb2d);
-                               dumpssw(f->f_ssw);
-                               dumpwb(2, f->f_wb2s, f->f_wb2a, f->f_wb2d);
-                       }
-#endif
-               }
-       }
-       if (err == 0 && (f->f_wb3s & SSW4_WBSV)) {
-#ifdef DEBUG
-               if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
-                       dumpwb(3, f->f_wb3s, f->f_wb3a, f->f_wb3d);
-               wbstats.wb3s++;
-               wbstats.wbsize[(f->f_wb3s&SSW4_SZMASK)>>5]++;
-#endif
-               switch (f->f_wb3s & SSW4_SZMASK) {
-               case SSW4_SZLW:
-                       if (KDFAULT(f->f_wb3s))
-                               *(long *)f->f_wb3a = f->f_wb3d;
-                       else
-                               err = suword((void *)f->f_wb3a, f->f_wb3d);
-                       break;
-               case SSW4_SZB:
-                       if (KDFAULT(f->f_wb3s))
-                               *(char *)f->f_wb3a = f->f_wb3d;
-                       else
-                               err = subyte((void *)f->f_wb3a, f->f_wb3d);
-                       break;
-               case SSW4_SZW:
-                       if (KDFAULT(f->f_wb3s))
-                               *(short *)f->f_wb3a = f->f_wb3d;
-                       else
-                               err = susword((void *)f->f_wb3a, f->f_wb3d);
-                       break;
-#ifdef DEBUG
-               case SSW4_SZLN:
-                       panic("writeback: wb3s indicates LINE write");
-#endif
-               }
-               if (err) {
-                       fa = f->f_wb3a;
-#ifdef DEBUG
-                       if (mmudebug & MDB_WBFAILED)
-                               printf(wberrstr, p->p_pid, p->p_comm,
-                                      "#3", fp->f_pc, f->f_fa,
-                                      f->f_wb3a, f->f_wb3d);
-#endif



Home | Main Index | Thread Index | Old Index