Module Name:    src
Committed By:   mrg
Date:           Mon Aug 17 03:19:35 UTC 2020

Modified Files:
        src/sys/arch/mips/include: cpu.h db_machdep.h locore.h mips3_pte.h
            pcb.h pmap.h types.h
        src/sys/arch/mips/mips: db_interface.c mips_stacktrace.c

Log Message:
port crash(8) to mips.  (most of the kernel side.)

- expose parts of _KERNEL to _KMEMUSER as well
- hide more things for _KERNEL
- avoid DB_MACHINE_COMMANDS in crash(8)
- XXX add mips_label_t for !_KERNEL and use it in the pcb to
  avoid conflicting with the ddb/crash one
- enable dumppcb

some changes to make stack trace fail instead of SEGV and
the userland changes to crash itself not part of this change.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/arch/mips/include/cpu.h
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/mips/include/db_machdep.h
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/mips/include/locore.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/mips/include/mips3_pte.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/mips/include/pcb.h
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/mips/include/pmap.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/mips/include/types.h
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/mips/mips/db_interface.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/mips/mips/mips_stacktrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/include/cpu.h
diff -u src/sys/arch/mips/include/cpu.h:1.130 src/sys/arch/mips/include/cpu.h:1.131
--- src/sys/arch/mips/include/cpu.h:1.130	Sun Aug  9 06:26:49 2020
+++ src/sys/arch/mips/include/cpu.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.130 2020/08/09 06:26:49 skrll Exp $	*/
+/*	$NetBSD: cpu.h,v 1.131 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #error Use assym.h to get definitions from <mips/cpu.h>
 #endif
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_KMEMUSER)
 
 #if defined(_KERNEL_OPT)
 #include "opt_cputype.h"
@@ -57,6 +57,7 @@
 #include <sys/device_if.h>
 #include <sys/evcnt.h>
 #include <sys/kcpuset.h>
+#include <sys/intr.h>
 
 typedef struct cpu_watchpoint {
 	register_t	cw_addr;
@@ -158,6 +159,9 @@ struct cpu_info {
 #endif
 
 };
+#endif /* _KERNEL || _KMEMUSER */
+
+#ifdef _KERNEL
 
 #ifdef MULTIPROCESSOR
 #define	CPU_INFO_ITERATOR		int

Index: src/sys/arch/mips/include/db_machdep.h
diff -u src/sys/arch/mips/include/db_machdep.h:1.32 src/sys/arch/mips/include/db_machdep.h:1.33
--- src/sys/arch/mips/include/db_machdep.h:1.32	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/db_machdep.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.32 2020/07/26 08:08:41 simonb Exp $ */
+/* $NetBSD: db_machdep.h,v 1.33 2020/08/17 03:19:35 mrg Exp $ */
 
 /*
  * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
@@ -34,7 +34,11 @@
 #ifndef	_MIPS_DB_MACHDEP_H_
 #define	_MIPS_DB_MACHDEP_H_
 
+#include <sys/types.h>
+#include <sys/stdbool.h>
+
 #include <uvm/uvm_param.h>		/* XXX  boolean_t */
+
 #include <mips/trap.h>			/* T_BREAK */
 #include <mips/reg.h>			/* register state */
 #include <mips/regnum.h>		/* symbolic register indices */
@@ -126,9 +130,11 @@ void db_resume_others(void);
 
 extern void (*cpu_reset_address)(void);
 
+#ifdef _KERNEL
 /*
  * We have machine-dependent commands.
  */
 #define	DB_MACHINE_COMMANDS
+#endif
 
 #endif	/* _MIPS_DB_MACHDEP_H_ */

Index: src/sys/arch/mips/include/locore.h
diff -u src/sys/arch/mips/include/locore.h:1.114 src/sys/arch/mips/include/locore.h:1.115
--- src/sys/arch/mips/include/locore.h:1.114	Sat Aug 15 07:42:07 2020
+++ src/sys/arch/mips/include/locore.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.h,v 1.114 2020/08/15 07:42:07 mrg Exp $ */
+/* $NetBSD: locore.h,v 1.115 2020/08/17 03:19:35 mrg Exp $ */
 
 /*
  * This file should not be included by MI code!!!
@@ -95,6 +95,7 @@ typedef uint32_t pt_entry_t;
 
 /* XXX some .S files look for MIPS3_PLUS */
 #ifndef __ASSEMBLER__
+#ifdef _KERNEL
 
 /* XXX simonb
  * Should the following be in a cpu_info type structure?
@@ -753,7 +754,6 @@ void	mips_page_physload(vaddr_t, vaddr_t
 #define	    MIPS_PRID_CID_INGENIC	0xe1
 #define	MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
 
-#ifdef _KERNEL
 /*
  * Global variables used to communicate CPU type, and parameters
  * such as cache size, from locore to higher-level code (e.g., pmap).
@@ -917,7 +917,7 @@ struct pridtab {
 # define MIPS_CIDFL_RMI_L2SZ(cidfl)					\
 		((256*1024) << (((cidfl) & MIPS_CIDFL_RMI_L2SZ_MASK)	\
 			>> MIPS_CIDFL_RMI_L2SZ_SHIFT))
-#endif /* !__ASSEMBLER__ */
 #endif	/* _KERNEL */
+#endif /* !__ASSEMBLER__ */
 
 #endif	/* _MIPS_LOCORE_H */

Index: src/sys/arch/mips/include/mips3_pte.h
diff -u src/sys/arch/mips/include/mips3_pte.h:1.30 src/sys/arch/mips/include/mips3_pte.h:1.31
--- src/sys/arch/mips/include/mips3_pte.h:1.30	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/mips3_pte.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips3_pte.h,v 1.30 2020/07/26 08:08:41 simonb Exp $	*/
+/*	$NetBSD: mips3_pte.h,v 1.31 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -174,6 +174,7 @@ unsigned int 	pg_g:1,			/* HW: ignore as
 #define	MIPS3_PG_SIZE_64M	0x07ffe000
 #define	MIPS3_PG_SIZE_256M	0x1fffe000
 
+#ifdef _KERNEL
 #define	MIPS3_PG_SIZE_MASK_TO_SIZE(pg_mask)	\
     ((((pg_mask) | 0x00001fff) + 1) / 2)
 
@@ -182,6 +183,7 @@ unsigned int 	pg_g:1,			/* HW: ignore as
 
 CTASSERT(MIPS3_PG_SIZE_TO_MASK(4096) == MIPS3_PG_SIZE_4K);
 CTASSERT(MIPS3_PG_SIZE_TO_MASK(8192) == MIPS3_PG_SIZE_4K);
+#endif
 
 /* NEC Vr41xx uses different pagemask values. */
 #define	MIPS4100_PG_SIZE_1K	0x00000000

Index: src/sys/arch/mips/include/pcb.h
diff -u src/sys/arch/mips/include/pcb.h:1.24 src/sys/arch/mips/include/pcb.h:1.25
--- src/sys/arch/mips/include/pcb.h:1.24	Tue Aug 16 06:58:15 2011
+++ src/sys/arch/mips/include/pcb.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcb.h,v 1.24 2011/08/16 06:58:15 matt Exp $	*/
+/*	$NetBSD: pcb.h,v 1.25 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -56,7 +56,7 @@ struct pcb_faultinfo {
  * MIPS process control block
  */
 struct pcb {
-	label_t pcb_context;		/* kernel context for resume */
+	mips_label_t pcb_context;	/* kernel context for resume */
 	void *	pcb_onfault;		/* for copyin/copyout faults */
 	uint32_t pcb_ppl;		/* previous priority level */
 	struct fpreg pcb_fpregs;	/* saved floating point registers */

Index: src/sys/arch/mips/include/pmap.h
diff -u src/sys/arch/mips/include/pmap.h:1.73 src/sys/arch/mips/include/pmap.h:1.74
--- src/sys/arch/mips/include/pmap.h:1.73	Fri Aug  7 07:19:45 2020
+++ src/sys/arch/mips/include/pmap.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.73 2020/08/07 07:19:45 skrll Exp $	*/
+/*	$NetBSD: pmap.h,v 1.74 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -175,6 +175,7 @@ struct tlbmask {
 #define	PMAP_SEGTABSIZE		(1 << (31 - SEGSHIFT))
 #endif
 
+#include <uvm/uvm_pmap.h>
 #include <uvm/pmap/vmpagemd.h>
 #include <uvm/pmap/pmap.h>
 #include <uvm/pmap/pmap_tlb.h>

Index: src/sys/arch/mips/include/types.h
diff -u src/sys/arch/mips/include/types.h:1.71 src/sys/arch/mips/include/types.h:1.72
--- src/sys/arch/mips/include/types.h:1.71	Thu Jul 30 06:54:07 2020
+++ src/sys/arch/mips/include/types.h	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: types.h,v 1.71 2020/07/30 06:54:07 skrll Exp $	*/
+/*	$NetBSD: types.h,v 1.72 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -115,9 +115,17 @@ typedef __uint64_t	uregister32_t;
 #define	PRIxUREGISTER	PRIx64
 #endif /* __mips_o32 */
 
+#if defined(_KMEMUSER)
+typedef struct mips_label_t {
+	register_t val[14];
+} mips_label_t;
+#else
 typedef struct label_t {
 	register_t val[14];
 } label_t;
+typedef label_t mips_label_t;
+#endif
+
 #define	_L_S0		0
 #define	_L_S1		1
 #define	_L_S2		2

Index: src/sys/arch/mips/mips/db_interface.c
diff -u src/sys/arch/mips/mips/db_interface.c:1.89 src/sys/arch/mips/mips/db_interface.c:1.90
--- src/sys/arch/mips/mips/db_interface.c:1.89	Sat Aug 15 07:42:07 2020
+++ src/sys/arch/mips/mips/db_interface.c	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.89 2020/08/15 07:42:07 mrg Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.90 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*
  * Mach Operating System
@@ -27,12 +27,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.89 2020/08/15 07:42:07 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.90 2020/08/17 03:19:35 mrg Exp $");
 
+#ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
 #include "opt_cputype.h"	/* which mips CPUs do we support? */
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
+#endif
 
 #define __PMAP_PRIVATE
 
@@ -57,6 +59,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_interface
 #include <machine/int_fmtio.h>
 #include <machine/db_machdep.h>
 #include <ddb/db_access.h>
+#include <ddb/db_user.h>
 #ifndef KGDB
 #include <ddb/db_command.h>
 #include <ddb/db_output.h>
@@ -92,6 +95,7 @@ void db_mtcr_cmd(db_expr_t, bool, db_exp
 
 paddr_t kvtophys(vaddr_t);
 
+#ifdef _KERNEL
 CTASSERT(sizeof(ddb_regs) == sizeof(struct reg));
 
 #ifndef KGDB
@@ -1041,3 +1045,5 @@ db_mach_cpu_cmd(db_expr_t addr, bool hav
 	}
 }
 #endif	/* MULTIPROCESSOR */
+
+#endif	/* _KERNEL */

Index: src/sys/arch/mips/mips/mips_stacktrace.c
diff -u src/sys/arch/mips/mips/mips_stacktrace.c:1.1 src/sys/arch/mips/mips/mips_stacktrace.c:1.2
--- src/sys/arch/mips/mips/mips_stacktrace.c:1.1	Sat Aug 15 07:42:07 2020
+++ src/sys/arch/mips/mips/mips_stacktrace.c	Mon Aug 17 03:19:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_stacktrace.c,v 1.1 2020/08/15 07:42:07 mrg Exp $	*/
+/*	$NetBSD: mips_stacktrace.c,v 1.2 2020/08/17 03:19:35 mrg Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.1 2020/08/15 07:42:07 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_stacktrace.c,v 1.2 2020/08/17 03:19:35 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -59,6 +59,7 @@ __KERNEL_RCSID(0, "$NetBSD: mips_stacktr
 #include <machine/db_machdep.h>
 #include <ddb/db_sym.h>
 #endif
+#include <ddb/db_user.h>
 
 #ifdef KGDB
 #include <sys/kgdb.h>
@@ -122,7 +123,8 @@ 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[] = {
+static const struct { void *addr; const char *name;} names[] = {
+#ifdef _KERNEL
 	Name(stacktrace),
 	Name(stacktrace_subr),
 	Name(main),
@@ -178,12 +180,13 @@ const static struct { void *addr; const 
 
 	Name(cpu_idle),
 	Name(cpu_switchto),
+#endif /* _KERNEL */
 	{0, 0}
 };
 
 
-bool
-static kdbpeek(vaddr_t addr, int *valp)
+static bool
+kdbpeek(vaddr_t addr, unsigned *valp)
 {
 	if (addr & 3) {
 		printf("kdbpeek: unaligned address %#"PRIxVADDR"\n", addr);
@@ -193,7 +196,7 @@ static kdbpeek(vaddr_t addr, int *valp)
 		printf("kdbpeek: NULL\n");
 		return false;
 	} else {
-		*valp = *(int *)addr;
+		*valp = *(unsigned *)addr;
 		return true;
 	}
 }
@@ -312,7 +315,7 @@ loop:
 	sym = db_search_symbol(pc, DB_STGY_ANY, &diff);
 	if (sym != DB_SYM_NULL && diff == 0) {
 		/* check func(foo) __attribute__((__noreturn__)) case */
-		if (!kdbpeek(pc - 2 * sizeof(int), &instr))
+		if (!kdbpeek(pc - 2 * sizeof(unsigned), &instr))
 			return;
 		i.word = instr;
 		if (i.JType.op == OP_JAL) {
@@ -494,8 +497,12 @@ done:
 		}
 	} else {
 finish:
+#ifdef _KERNEL
 		(*printfn)("User-level: pid %d.%d\n",
 		    curlwp->l_proc->p_pid, curlwp->l_lid);
+#else
+		(*printfn)("User-level: FIXME\n");
+#endif
 	}
 }
 

Reply via email to