Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mips move stacktrace_subr() from trap.c into new mi...



details:   https://anonhg.NetBSD.org/src/rev/c1dd83e48e8b
branches:  trunk
changeset: 937295:c1dd83e48e8b
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Aug 15 07:42:07 2020 +0000

description:
move stacktrace_subr() from trap.c into new mips_stacktrace.c so
it can be shared between ddb, other mips kernel components (see
locore), and an upcoming crash(8) port.

remove second copy of kdbpeek() (hidden by old DDB_TRACE
option, but they're functionally equivalent.)

tested on octeon.

ok simonb@

diffstat:

 sys/arch/mips/conf/files.mips        |    3 +-
 sys/arch/mips/include/locore.h       |    3 +-
 sys/arch/mips/include/stacktrace.h   |   40 ++
 sys/arch/mips/mips/db_interface.c    |   16 +-
 sys/arch/mips/mips/db_trace.c        |   11 +-
 sys/arch/mips/mips/mips_stacktrace.c |  503 +++++++++++++++++++++++++++++++++++
 sys/arch/mips/mips/trap.c            |  450 +-------------------------------
 7 files changed, 554 insertions(+), 472 deletions(-)

diffs (truncated from 1131 to 300 lines):

diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/conf/files.mips
--- a/sys/arch/mips/conf/files.mips     Sat Aug 15 07:24:09 2020 +0000
+++ b/sys/arch/mips/conf/files.mips     Sat Aug 15 07:42:07 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.mips,v 1.78 2020/08/09 08:49:00 skrll Exp $
+#      $NetBSD: files.mips,v 1.79 2020/08/15 07:42:07 mrg Exp $
 #
 
 defflag        opt_cputype.h           NOFPU FPEMUL
@@ -46,6 +46,7 @@
 file   arch/mips/mips/ipifuncs.c               multiprocessor
 file   arch/mips/mips/kgdb_machdep.c           kgdb
 file   arch/mips/mips/pmap_machdep.c
+file   arch/mips/mips/mips_stacktrace.c
 file   uvm/pmap/pmap.c
 file   uvm/pmap/pmap_segtab.c
 file   uvm/pmap/pmap_synci.c
diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/include/locore.h
--- a/sys/arch/mips/include/locore.h    Sat Aug 15 07:24:09 2020 +0000
+++ b/sys/arch/mips/include/locore.h    Sat Aug 15 07:42:07 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.h,v 1.113 2020/07/31 08:54:09 simonb Exp $ */
+/* $NetBSD: locore.h,v 1.114 2020/08/15 07:42:07 mrg Exp $ */
 
 /*
  * This file should not be included by MI code!!!
@@ -667,7 +667,6 @@
 
 /* trap.c */
 void   netintr(void);
-bool   kdbpeek(vaddr_t, int *);
 
 /* mips_dsp.c */
 void   dsp_init(void);
diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/include/stacktrace.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mips/include/stacktrace.h        Sat Aug 15 07:42:07 2020 +0000
@@ -0,0 +1,40 @@
+/*     $NetBSD: stacktrace.h,v 1.1 2020/08/15 07:42:07 mrg Exp $       */
+
+/*
+ * Copyright (c) 2020 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _MIPS_STACKTRACE_H_
+#define _MIPS_STACKTRACE_H_
+
+#include <sys/types.h>
+
+void   stacktrace_subr(mips_reg_t, mips_reg_t, mips_reg_t, mips_reg_t,
+           vaddr_t, vaddr_t, vaddr_t, vaddr_t,
+           void (*)(const char*, ...));
+
+#endif /* _MIPS_STACKTRACE_H_ */
diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/mips/db_interface.c
--- a/sys/arch/mips/mips/db_interface.c Sat Aug 15 07:24:09 2020 +0000
+++ b/sys/arch/mips/mips/db_interface.c Sat Aug 15 07:42:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_interface.c,v 1.88 2020/08/12 07:37:39 skrll Exp $  */
+/*     $NetBSD: db_interface.c,v 1.89 2020/08/15 07:42:07 mrg Exp $    */
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.88 2020/08/12 07:37:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.89 2020/08/15 07:42:07 mrg Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_cputype.h"       /* which mips CPUs do we support? */
@@ -94,18 +94,6 @@
 
 CTASSERT(sizeof(ddb_regs) == sizeof(struct reg));
 
-#ifdef DDB_TRACE
-bool
-kdbpeek(vaddr_t addr, int *valp)
-{
-
-       if (addr == 0 || (addr & 3))
-               return false;
-       *valp = *(int *)addr;
-       return true;
-}
-#endif
-
 #ifndef KGDB
 int
 kdb_trap(int type, struct reg *regs)
diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/mips/db_trace.c
--- a/sys/arch/mips/mips/db_trace.c     Sat Aug 15 07:24:09 2020 +0000
+++ b/sys/arch/mips/mips/db_trace.c     Sat Aug 15 07:42:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_trace.c,v 1.43 2015/06/06 22:19:07 matt Exp $       */
+/*     $NetBSD: db_trace.c,v 1.44 2020/08/15 07:42:07 mrg Exp $        */
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.43 2015/06/06 22:19:07 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.44 2020/08/15 07:42:07 mrg Exp $");
 
 #include "opt_ddb.h"
 
@@ -38,8 +38,10 @@
 #include <sys/cpu.h>
 
 #include <mips/mips_opcode.h>
+#include <mips/stacktrace.h>
 
 #include <machine/db_machdep.h>
+#include <machine/locore.h>
 
 #include <ddb/db_interface.h>
 #include <ddb/db_output.h>
@@ -69,11 +71,6 @@
  */
 struct mips_saved_state *db_cur_exc_frame = 0;
 
-/*XXX*/
-void   stacktrace_subr(mips_reg_t, mips_reg_t, mips_reg_t, mips_reg_t,
-           vaddr_t, vaddr_t, vaddr_t, vaddr_t,
-           void (*)(const char*, ...));
-
 /*
  * Stack trace helper.
  */
diff -r 8b96e00dae4e -r c1dd83e48e8b sys/arch/mips/mips/mips_stacktrace.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mips/mips/mips_stacktrace.c      Sat Aug 15 07:42:07 2020 +0000
@@ -0,0 +1,503 @@
+/*     $NetBSD: mips_stacktrace.c,v 1.1 2020/08/15 07:42:07 mrg Exp $  */
+
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department and Ralph Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: NetBSD: trap.c,v 1.255 2020/07/13 09:00:40 simonb Exp
+ * from: Utah Hdr: trap.c 1.32 91/04/06
+ *
+ *     @(#)trap.c      8.5 (Berkeley) 1/11/94
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.1 2020/08/15 07:42:07 mrg Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_ddb.h"
+#include "opt_kgdb.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include <mips/locore.h>
+#include <mips/mips_opcode.h>
+#include <mips/stacktrace.h>
+
+#ifdef DDB
+#include <machine/db_machdep.h>
+#include <ddb/db_sym.h>
+#endif
+
+#ifdef KGDB
+#include <sys/kgdb.h>
+#endif
+
+#ifndef DDB_TRACE
+
+#if defined(DEBUG) || defined(DDB) || defined(KGDB) || defined(geo)
+
+extern char start[], edata[], verylocore[];
+#ifdef MIPS1
+extern char mips1_kern_gen_exception[];
+extern char mips1_user_gen_exception[];
+extern char mips1_kern_intr[];
+extern char mips1_user_intr[];
+extern char mips1_systemcall[];
+#endif
+#ifdef MIPS3
+extern char mips3_kern_gen_exception[];
+extern char mips3_user_gen_exception[];
+extern char mips3_kern_intr[];
+extern char mips3_user_intr[];
+extern char mips3_systemcall[];
+#endif
+#ifdef MIPS32
+extern char mips32_kern_gen_exception[];
+extern char mips32_user_gen_exception[];
+extern char mips32_kern_intr[];
+extern char mips32_user_intr[];
+extern char mips32_systemcall[];
+#endif
+#ifdef MIPS32R2
+extern char mips32r2_kern_gen_exception[];
+extern char mips32r2_user_gen_exception[];
+extern char mips32r2_kern_intr[];
+extern char mips32r2_user_intr[];
+extern char mips32r2_systemcall[];
+#endif
+#ifdef MIPS64
+extern char mips64_kern_gen_exception[];
+extern char mips64_user_gen_exception[];
+extern char mips64_kern_intr[];
+extern char mips64_user_intr[];
+extern char mips64_systemcall[];
+#endif
+#ifdef MIPS64R2
+extern char mips64r2_kern_gen_exception[];
+extern char mips64r2_user_gen_exception[];
+extern char mips64r2_kern_intr[];
+extern char mips64r2_user_intr[];
+extern char mips64r2_systemcall[];
+#endif
+
+#define        MIPS_JR_RA      0x03e00008      /* instruction code for jr ra */
+#define        MIPS_JR_K0      0x03400008      /* instruction code for jr k0 */
+#define        MIPS_ERET       0x42000018      /* instruction code for eret */
+
+int main(void *);      /* XXX */
+
+/*
+ * Functions ``special'' enough to print by name
+ */
+#define Name(_fn)  { (void*)_fn, # _fn }
+const static struct { void *addr; const char *name;} names[] = {
+       Name(stacktrace),
+       Name(stacktrace_subr),
+       Name(main),
+       Name(trap),
+
+#ifdef MIPS1   /*  r2000 family  (mips-I CPU) */
+       Name(mips1_kern_gen_exception),
+       Name(mips1_user_gen_exception),
+       Name(mips1_systemcall),
+       Name(mips1_kern_intr),
+       Name(mips1_user_intr),
+#endif /* MIPS1 */
+
+#if defined(MIPS3)                     /* r4000 family (mips-III CPU) */
+       Name(mips3_kern_gen_exception),



Home | Main Index | Thread Index | Old Index