make kernel-groveling crash(8) work on aarch64

This commit is contained in:
jakllsch 2018-09-15 19:47:48 +00:00
parent 2a4070a502
commit bb72cd05aa
8 changed files with 53 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $ */
/* $NetBSD: db_disasm.c,v 1.4 2018/09/15 19:47:48 jakllsch Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.4 2018/09/15 19:47:48 jakllsch Exp $");
#include <sys/param.h>
#include <machine/db_machdep.h>
@ -35,6 +35,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.3 2018/07/17 10:07:49 ryo Exp $");
#include <ddb/db_sym.h>
#include <ddb/db_output.h>
#include <ddb/db_access.h>
#include <ddb/db_user.h>
#include <arch/aarch64/aarch64/disasm.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_machdep.c,v 1.7 2018/08/14 05:51:54 ryo Exp $ */
/* $NetBSD: db_machdep.c,v 1.8 2018/09/15 19:47:48 jakllsch Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.7 2018/08/14 05:51:54 ryo Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.8 2018/09/15 19:47:48 jakllsch Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.7 2018/08/14 05:51:54 ryo Exp $");
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <ddb/db_interface.h>
#include <ddb/db_user.h>
#include <dev/cons.h>
@ -78,6 +79,7 @@ const struct db_command db_machine_command_table[] = {
NULL, NULL)
},
#endif
#if defined(_KERNEL)
{
DDB_ADD_CMD(
"cpuinfo", db_md_cpuinfo_cmd, 0,
@ -124,6 +126,7 @@ const struct db_command db_machine_command_table[] = {
"<param>",
"\tparam: <address> | <#>")
},
#endif
{
DDB_ADD_CMD(NULL, NULL, 0,
NULL,
@ -215,6 +218,7 @@ dump_trapframe(struct trapframe *tf, void (*pr)(const char *, ...))
tf->tf_reg[30], tf->tf_sp);
}
#if defined(_KERNEL)
void
db_md_cpuinfo_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
const char *modif)
@ -715,6 +719,7 @@ db_md_watch_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
show_watchpoints();
}
#endif
#ifdef MULTIPROCESSOR
volatile struct cpu_info *db_trigger;
@ -755,6 +760,7 @@ db_md_switch_cpu_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
#endif /* _KERNEL */
#endif /* MULTIPROCESSOR */
#ifdef DDB
int
kdb_trap(int type, struct trapframe *tf)
{
@ -846,3 +852,4 @@ kdb_trap(int type, struct trapframe *tf)
return 1;
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_trace.c,v 1.5 2018/09/15 19:16:58 jakllsch Exp $ */
/* $NetBSD: db_trace.c,v 1.6 2018/09/15 19:47:48 jakllsch Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.5 2018/09/15 19:16:58 jakllsch Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.6 2018/09/15 19:47:48 jakllsch Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -53,8 +53,9 @@ __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.5 2018/09/15 19:16:58 jakllsch Exp $"
#define MAXBACKTRACE 128 /* against infinite loop */
__CTASSERT(VM_MIN_ADDRESS == 0);
#define IN_USER_VM_ADDRESS(addr) \
((VM_MIN_ADDRESS <= (addr)) && ((addr) < VM_MAX_ADDRESS))
((addr) < VM_MAX_ADDRESS)
#define IN_KERNEL_VM_ADDRESS(addr) \
((VM_MIN_KERNEL_ADDRESS <= (addr)) && ((addr) < VM_MAX_KERNEL_ADDRESS))
@ -74,6 +75,7 @@ is_lwp(void *p)
static const char *
getlwpnamebysp(uint64_t sp)
{
#if defined(_KERNEL)
lwp_t *lwp;
for (lwp = db_lwp_first(); lwp != NULL; lwp = db_lwp_next(lwp)) {
@ -82,6 +84,7 @@ getlwpnamebysp(uint64_t sp)
return lwp->l_name;
}
}
#endif
return "unknown";
}
@ -157,6 +160,7 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
}
}
#if defined(_KERNEL)
if (!have_addr) {
if (trace_lwp) {
addr = (db_expr_t)curlwp;
@ -166,6 +170,7 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
tf = DDB_REGS;
}
}
#endif
if (trace_thread) {
proc_t *pp, p;
@ -193,12 +198,15 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
db_read_bytes(addr, sizeof(l), (char *)&l);
db_read_bytes((db_addr_t)l.l_proc, sizeof(p), (char *)&p);
if (addr == (db_addr_t)curlwp) {
#if defined(_KERNEL)
if (addr == (db_expr_t)curlwp) {
fp = (uint64_t)&DDB_REGS->tf_reg[29]; /* &reg[29]={fp,lr} */
tf = DDB_REGS;
(*pr)("trace: pid %d lid %d (curlwp) at tf %p\n",
p.p_pid, l.l_lid, tf);
} else {
} else
#endif
{
tf = l.l_md.md_ktf;
db_read_bytes((db_addr_t)&tf->tf_reg[29], sizeof(fp), (char *)&fp);
(*pr)("trace: pid %d lid %d at tf %p\n",
@ -215,12 +223,14 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
count = MAXBACKTRACE;
if (tf != NULL) {
#if defined(_KERNEL)
(*pr)("---- trapframe %p (%zu bytes) ----\n",
tf, sizeof(*tf));
dump_trapframe(tf, pr);
(*pr)("------------------------"
"------------------------\n");
#endif
lastfp = lastlr = lr = fp = 0;
db_read_bytes((db_addr_t)&tf->tf_pc, sizeof(lr), (char *)&lr);
db_read_bytes((db_addr_t)&tf->tf_reg[29], sizeof(fp), (char *)&fp);
@ -243,6 +253,7 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
if (!trace_user && IN_USER_VM_ADDRESS(lr))
break;
#if defined(_KERNEL)
extern char el1_trap[]; /* XXX */
extern char el0_trap[]; /* XXX */
if (((char *)(lr - 4) == (char *)el0_trap) ||
@ -281,7 +292,9 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
pr_traceaddr("fp", fp, lr, flags, pr);
} else {
} else
#endif
{
pr_traceaddr("fp", fp, lr - 4, flags, pr);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: disasm.c,v 1.4 2018/07/28 09:54:32 ryo Exp $ */
/* $NetBSD: disasm.c,v 1.5 2018/09/15 19:47:48 jakllsch Exp $ */
/*
* Copyright (c) 2018 Ryo Shimizu <ryo@nerv.org>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: disasm.c,v 1.4 2018/07/28 09:54:32 ryo Exp $");
__KERNEL_RCSID(0, "$NetBSD: disasm.c,v 1.5 2018/09/15 19:47:48 jakllsch Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -35,6 +35,10 @@ __KERNEL_RCSID(0, "$NetBSD: disasm.c,v 1.4 2018/07/28 09:54:32 ryo Exp $");
#include <arch/aarch64/aarch64/disasm.h>
#ifndef _KERNEL
#include <stdio.h>
#include <stdbool.h>
#endif
#define PRINTF di->di_printf
#define PRINTADDR di->di_printaddr

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_machdep.h,v 1.6 2018/07/17 10:07:49 ryo Exp $ */
/* $NetBSD: db_machdep.h,v 1.7 2018/09/15 19:47:48 jakllsch Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -68,6 +68,7 @@
#include <sys/types.h>
#include <aarch64/frame.h>
#include <ddb/db_user.h>
typedef long long int db_expr_t;
#define DDB_EXPR_FMT "ll"
@ -214,6 +215,7 @@ void aarch64_watchpoint_set(int, vaddr_t, int, int);
#define WATCHPOINT_ACCESS_LOADSTORE 0x03
#define WATCHPOINT_ACCESS_MASK 0x03
#define DB_ELF_SYMBOLS
#elif defined(__arm__)

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.h,v 1.4 2018/08/05 06:48:50 skrll Exp $ */
/* $NetBSD: machdep.h,v 1.5 2018/09/15 19:47:48 jakllsch Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
@ -36,6 +36,7 @@
// initarm_common
#include <machine/bootconfig.h>
struct boot_physmem;
static inline paddr_t
aarch64_kern_vtophys(vaddr_t va)
@ -108,6 +109,7 @@ void ucas_ras_check(struct trapframe *);
int cpu_set_onfault(struct faultbuf *) __returns_twice;
void cpu_jump_onfault(struct trapframe *, const struct faultbuf *, int);
#if defined(_KERNEL)
static inline void
cpu_unset_onfault(void)
{
@ -128,6 +130,7 @@ cpu_disable_onfault(void)
curlwp->l_md.md_onfault = NULL;
return fb;
}
#endif
/* fpu.c */
void fpu_attach(struct cpu_info *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.h,v 1.9 2018/09/10 15:14:50 maxv Exp $ */
/* $NetBSD: pmap.h,v 1.10 2018/09/15 19:47:48 jakllsch Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -34,6 +34,7 @@
#ifdef __aarch64__
#ifdef _KERNEL
#include <sys/types.h>
#include <sys/pool.h>
#include <sys/queue.h>
@ -216,6 +217,8 @@ bool pmap_extract_coherency(pmap_t, vaddr_t, paddr_t *, bool *);
#define PMAP_MAPSIZE1 L2_SIZE
#endif /* _KERNEL */
#elif defined(__arm__)
#include <arm/pmap.h>

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.40 2018/05/20 03:09:02 christos Exp $
# $NetBSD: Makefile,v 1.41 2018/09/15 19:47:48 jakllsch Exp $
PROG= crash
MAN= crash.8
@ -19,6 +19,7 @@ DPADD+= ${LIBUTIL} ${LIBKVM} ${LIBEDIT} ${LIBTERMINFO}
|| ${MACHINE} == "sparc" \
|| ${MACHINE} == "sparc64" \
|| ${MACHINE_CPU} == "arm" \
|| ${MACHINE_CPU} == "aarch64" \
|| ${MACHINE_ARCH} == "m68k"
SRCS+= db_trace.c
.if ${MACHINE_ARCH} != "m68k"
@ -68,6 +69,9 @@ MACHINE_FAMILY = ${MACHINE_CPU}
.PATH: ${S}/arch/arm/arm32
SRCS+=disassem.c cpufunc_asm.S
.endif
.if ${MACHINE_CPU} == "aarch64"
SRCS+=disasm.c
.endif
.PATH: ${S}/arch/${MACHINE_FAMILY}/${MACHINE_FAMILY}