Module Name: src
Committed By: mrg
Date: Thu Dec 27 09:55:27 UTC 2018
Modified Files:
src/external/gpl3/gdb/dist/gdb: aarch64-nbsd-nat.c
src/sys/arch/aarch64/aarch64: aarch64_machdep.c cpuswitch.S
db_machdep.c db_trace.c genassym.cf vm_machdep.c
src/sys/arch/aarch64/include: pcb.h proc.h
Log Message:
make savecore for arm64 basically work.
- move MD lwp "md_ktf" member into struct pcb. the pcb is used by
the gdb "bsd-kvm" target code to find the stack of each thread
and needs to be available in a well known location.
- implement aarch64_nbsd_supply_pcb() in GDB. makes basic gdb work
on a crash dump.
- remove '#if L_MD_KTF + 8 == L_MD_CPACR' conditional code, as there
is no more L_MD_KTF.
with this gdb has minimal working functionality with "target kvm",
and crash can at least "ps" on a crash dump.
ok skrll.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/aarch64/db_machdep.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/aarch64/aarch64/db_trace.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/genassym.cf
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/aarch64/vm_machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/aarch64/include/pcb.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/include/proc.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c:1.1 src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c:1.2
--- src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c:1.1 Mon May 21 02:10:47 2018
+++ src/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c Thu Dec 27 09:55:27 2018
@@ -22,7 +22,9 @@
#include <sys/types.h>
#include <sys/ptrace.h>
-#include <machine/reg.h>
+
+#include <machine/frame.h>
+#include <machine/pcb.h>
#include "nbsd-nat.h"
#include "aarch64-tdep.h"
@@ -124,6 +126,50 @@ aarch64_nbsd_store_inferior_registers (s
}
}
+static int
+aarch64_nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
+{
+ struct trapframe tf;
+ int i;
+
+ /* The following is true for NetBSD/arm64:
+
+ The pcb contains the frame pointer at the point of the context
+ switch in cpu_switchto(). At that point we have a stack frame as
+ described by `struct trapframe', which has the following layout:
+
+ x0..x30
+ sp
+ pc
+ spsr
+ tpidr
+
+ This accounts for all callee-saved registers specified by the psABI.
+ From this information we reconstruct the register state as it would
+ look when we just returned from cpu_switchto().
+
+ For kernel core dumps, dumpsys() builds a fake trapframe for us. */
+
+ /* The trapframe pointer shouldn't be zero. */
+ if (pcb->pcb_tf == 0)
+ return 0;
+
+ /* Read the stack frame, and check its validity. */
+ read_memory ((uintptr_t)pcb->pcb_tf, (gdb_byte *) &tf, sizeof tf);
+
+ for (i = 0; i <= 30; i++)
+ {
+ regcache_raw_supply (regcache, AARCH64_X0_REGNUM + i, &tf.tf_reg[i]);
+ }
+ regcache_raw_supply (regcache, AARCH64_SP_REGNUM, &tf.tf_sp);
+ regcache_raw_supply (regcache, AARCH64_PC_REGNUM, &tf.tf_pc);
+
+ regcache_raw_supply (regcache, AARCH64_FPCR_REGNUM, &pcb->pcb_fpregs.fpcr);
+ regcache_raw_supply (regcache, AARCH64_FPSR_REGNUM, &pcb->pcb_fpregs.fpsr);
+
+ return 1;
+}
+
void
_initialize_aarch64_nbsd_nat (void)
{
@@ -133,4 +179,7 @@ _initialize_aarch64_nbsd_nat (void)
t->to_fetch_registers = aarch64_nbsd_fetch_inferior_registers;
t->to_store_registers = aarch64_nbsd_store_inferior_registers;
nbsd_nat_add_target (t);
+
+ /* Support debugging kernel virtual memory images. */
+ bsd_kvm_add_target (aarch64_nbsd_supply_pcb);
}
Index: src/sys/arch/aarch64/aarch64/aarch64_machdep.c
diff -u src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.23 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.24
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.23 Wed Nov 28 09:16:19 2018
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.23 2018/11/28 09:16:19 ryo Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.24 2018/12/27 09:55:27 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.23 2018/11/28 09:16:19 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.24 2018/12/27 09:55:27 mrg Exp $");
#include "opt_arm_debug.h"
#include "opt_ddb.h"
@@ -199,6 +199,7 @@ initarm_common(vaddr_t kvm_base, vsize_t
extern char _end[];
extern char lwp0uspace[];
+ struct pcb *pcb;
struct trapframe *tf;
psize_t memsize_total;
vaddr_t kernstart, kernend;
@@ -374,12 +375,13 @@ initarm_common(vaddr_t kvm_base, vsize_t
*/
uvm_lwp_setuarea(&lwp0, (vaddr_t)lwp0uspace);
memset(&lwp0.l_md, 0, sizeof(lwp0.l_md));
- memset(lwp_getpcb(&lwp0), 0, sizeof(struct pcb));
+ pcb = lwp_getpcb(&lwp0);
+ memset(pcb, 0, sizeof(struct pcb));
tf = (struct trapframe *)(lwp0uspace + USPACE) - 1;
memset(tf, 0, sizeof(struct trapframe));
tf->tf_spsr = SPSR_M_EL0T;
- lwp0.l_md.md_utf = lwp0.l_md.md_ktf = tf;
+ lwp0.l_md.md_utf = pcb->pcb_tf = tf;
return (vaddr_t)tf;
}
Index: src/sys/arch/aarch64/aarch64/cpuswitch.S
diff -u src/sys/arch/aarch64/aarch64/cpuswitch.S:1.10 src/sys/arch/aarch64/aarch64/cpuswitch.S:1.11
--- src/sys/arch/aarch64/aarch64/cpuswitch.S:1.10 Thu Dec 13 10:44:25 2018
+++ src/sys/arch/aarch64/aarch64/cpuswitch.S Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuswitch.S,v 1.10 2018/12/13 10:44:25 ryo Exp $ */
+/* $NetBSD: cpuswitch.S,v 1.11 2018/12/27 09:55:27 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include "opt_ddb.h"
#include "opt_kasan.h"
-RCSID("$NetBSD: cpuswitch.S,v 1.10 2018/12/13 10:44:25 ryo Exp $")
+RCSID("$NetBSD: cpuswitch.S,v 1.11 2018/12/27 09:55:27 mrg Exp $")
/*
* At IPL_SCHED:
@@ -66,23 +66,17 @@ ENTRY_NP(cpu_switchto)
*/
mov x4, sp
mrs x5, cpacr_el1
-#if L_MD_KTF + 8 == L_MD_CPACR
- stp x4, x5, [x0, #L_MD_KTF]
-#else
- str x4, [x0, #L_MD_KTF]
str x5, [x0, #L_MD_CPACR]
-#endif
+ ldr x6, [x0, #L_PCB] /* x6 = lwp_getpcb(oldlwp) */
+ str x4, [x6, #PCB_TF]
/* We are done with the old lwp */
.Lrestore_lwp:
DISABLE_INTERRUPT
-#if L_MD_KTF + 8 == L_MD_CPACR
- ldp x4, x5, [x1, #L_MD_KTF] /* get trapframe ptr and cpacr_el1 */
-#else
- ldr x4, [x1, #L_MD_KTF] /* get trapframe ptr (aka SP) */
+ ldr x6, [x1, #L_PCB] /* x6 = lwp_getpcb(newlwp) */
+ ldr x4, [x6, #PCB_TF] /* get trapframe ptr (aka SP) */
ldr x5, [x1, #L_MD_CPACR] /* get cpacr_el1 */
-#endif
mov sp, x4 /* restore stack pointer */
msr cpacr_el1, x5 /* restore cpacr_el1 */
@@ -136,12 +130,9 @@ ENTRY_NP(cpu_switchto_softint)
ldr x19, [x3, #CI_CURLWP] /* x19 := curcpu()->ci_curlwp */
mov x4, sp
mrs x5, cpacr_el1
-#if L_MD_KTF + 8 == L_MD_CPACR
- stp x4, x5, [x19, #L_MD_KTF]
-#else
- str x4, [x19, #L_MD_KTF]
+ ldr x6, [x19, #L_PCB] /* x6 = lwp_getpcb(curlwp) */
+ str x4, [x6, #PCB_TF]
str x5, [x19, #L_MD_CPACR]
-#endif
str x0, [x3, #CI_CURLWP] /* curcpu()->ci_curlwp = softlwp; */
#ifdef KASAN
@@ -165,12 +156,9 @@ ENTRY_NP(cpu_switchto_softint)
mrs x3, tpidr_el1
DISABLE_INTERRUPT
str x19, [x3, #CI_CURLWP] /* curcpu()->ci_curlwp := x19 */
-#if L_MD_KTF + 8 == L_MD_CPACR
- ldp x4, x5, [x19, #L_MD_KTF]
-#else
- ldr x4, [x19, #L_MD_KTF] /* x4 := pinned_lwp->l_md_ktf */
+ ldr x6, [x19, #L_PCB] /* x6 = lwp_getpcb(curlwp) */
+ ldr x4, [x6, #PCB_TF] /* x4 := pinned_lwp->l_addr->pcb_tf */
ldr x5, [x19, #L_MD_CPACR] /* x5 := pinned_lwp->l_md_cpacr */
-#endif
mov sp, x4 /* restore pinned_lwp sp */
msr cpacr_el1, x5 /* restore pinned_lwp cpacr */
Index: src/sys/arch/aarch64/aarch64/db_machdep.c
diff -u src/sys/arch/aarch64/aarch64/db_machdep.c:1.12 src/sys/arch/aarch64/aarch64/db_machdep.c:1.13
--- src/sys/arch/aarch64/aarch64/db_machdep.c:1.12 Thu Dec 13 10:44:25 2018
+++ src/sys/arch/aarch64/aarch64/db_machdep.c Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.c,v 1.12 2018/12/13 10:44:25 ryo Exp $ */
+/* $NetBSD: db_machdep.c,v 1.13 2018/12/27 09:55:27 mrg 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.12 2018/12/13 10:44:25 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.13 2018/12/27 09:55:27 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd32.h"
@@ -303,6 +303,7 @@ db_md_lwp_cmd(db_expr_t addr, bool have_
const char *modif)
{
lwp_t *l;
+ struct pcb *pcb;
if (!have_addr) {
db_printf("lwp: <address>\n");
@@ -319,9 +320,10 @@ db_md_lwp_cmd(db_expr_t addr, bool have_
db_printf("\tl->l_md.md_onfault=%p\n", l->l_md.md_onfault);
db_printf("\tl->l_md.md_utf =%p\n", l->l_md.md_utf);
dump_trapframe(l->l_md.md_utf, db_printf);
- db_printf("\tl->l_md.md_ktf =%p\n", l->l_md.md_ktf);
- if (l->l_md.md_ktf != l->l_md.md_utf)
- dump_trapframe(l->l_md.md_ktf, db_printf);
+ pcb = l->l_addr;
+ db_printf("\tl->l_addr.pcb_tf =%p\n", pcb->pcb_tf);
+ if (pcb->pcb_tf != l->l_md.md_utf)
+ dump_trapframe(pcb->pcb_tf, db_printf);
db_printf("\tl->l_md.md_cpacr =%016" PRIx64 "\n", l->l_md.md_cpacr);
db_printf("\tl->l_md.md_flags =%08x\n", l->l_md.md_flags);
Index: src/sys/arch/aarch64/aarch64/db_trace.c
diff -u src/sys/arch/aarch64/aarch64/db_trace.c:1.6 src/sys/arch/aarch64/aarch64/db_trace.c:1.7
--- src/sys/arch/aarch64/aarch64/db_trace.c:1.6 Sat Sep 15 19:47:48 2018
+++ src/sys/arch/aarch64/aarch64/db_trace.c Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.6 2018/09/15 19:47:48 jakllsch Exp $ */
+/* $NetBSD: db_trace.c,v 1.7 2018/12/27 09:55:27 mrg Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <[email protected]>
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.6 2018/09/15 19:47:48 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.7 2018/12/27 09:55:27 mrg Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -207,7 +207,9 @@ db_stack_trace_print(db_expr_t addr, boo
} else
#endif
{
- tf = l.l_md.md_ktf;
+ struct pcb *pcb = lwp_getpcb(&l);
+
+ tf = pcb->pcb_tf;
db_read_bytes((db_addr_t)&tf->tf_reg[29], sizeof(fp), (char *)&fp);
(*pr)("trace: pid %d lid %d at tf %p\n",
p.p_pid, l.l_lid, tf);
Index: src/sys/arch/aarch64/aarch64/genassym.cf
diff -u src/sys/arch/aarch64/aarch64/genassym.cf:1.11 src/sys/arch/aarch64/aarch64/genassym.cf:1.12
--- src/sys/arch/aarch64/aarch64/genassym.cf:1.11 Thu Dec 13 10:44:25 2018
+++ src/sys/arch/aarch64/aarch64/genassym.cf Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.11 2018/12/13 10:44:25 ryo Exp $
+# $NetBSD: genassym.cf,v 1.12 2018/12/27 09:55:27 mrg Exp $
#-
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -180,7 +180,6 @@ define L_CTXSWTCH offsetof(struct lwp,
define L_PRIVATE offsetof(struct lwp, l_private)
define L_MD_FLAGS offsetof(struct lwp, l_md.md_flags)
define L_MD_UTF offsetof(struct lwp, l_md.md_utf)
-define L_MD_KTF offsetof(struct lwp, l_md.md_ktf)
define L_MD_CPACR offsetof(struct lwp, l_md.md_cpacr)
define L_MD_ONFAULT offsetof(struct lwp, l_md.md_onfault)
@@ -229,6 +228,8 @@ define VM_PMAP offsetof(struct vmspace
define SIGTRAP SIGTRAP
define SIGEMT SIGEMT
+define PCB_TF offsetof(struct pcb, pcb_tf)
+
define TF_X0 offsetof(struct trapframe, tf_reg[0])
define TF_X1 offsetof(struct trapframe, tf_reg[1])
define TF_X2 offsetof(struct trapframe, tf_reg[2])
Index: src/sys/arch/aarch64/aarch64/vm_machdep.c
diff -u src/sys/arch/aarch64/aarch64/vm_machdep.c:1.4 src/sys/arch/aarch64/aarch64/vm_machdep.c:1.5
--- src/sys/arch/aarch64/aarch64/vm_machdep.c:1.4 Tue Jul 17 00:36:30 2018
+++ src/sys/arch/aarch64/aarch64/vm_machdep.c Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.4 2018/07/17 00:36:30 christos Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.5 2018/12/27 09:55:27 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.4 2018/07/17 00:36:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.5 2018/12/27 09:55:27 mrg Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -130,7 +130,7 @@ cpu_lwp_fork(struct lwp *l1, struct lwp
KASSERT(reg_daif_read() == 0);
ktf->tf_lr = (uintptr_t)lwp_trampoline;
- l2->l_md.md_ktf = ktf;
+ pcb2->pcb_tf = ktf;
}
/*
Index: src/sys/arch/aarch64/include/pcb.h
diff -u src/sys/arch/aarch64/include/pcb.h:1.1 src/sys/arch/aarch64/include/pcb.h:1.2
--- src/sys/arch/aarch64/include/pcb.h:1.1 Sun Aug 10 05:47:38 2014
+++ src/sys/arch/aarch64/include/pcb.h Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pcb.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
+/* $NetBSD: pcb.h,v 1.2 2018/12/27 09:55:27 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
struct pcb {
struct fpreg pcb_fpregs;
+ struct trapframe *pcb_tf;
};
struct md_coredump {
Index: src/sys/arch/aarch64/include/proc.h
diff -u src/sys/arch/aarch64/include/proc.h:1.2 src/sys/arch/aarch64/include/proc.h:1.3
--- src/sys/arch/aarch64/include/proc.h:1.2 Sun Apr 1 04:35:03 2018
+++ src/sys/arch/aarch64/include/proc.h Thu Dec 27 09:55:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.2 2018/04/01 04:35:03 ryo Exp $ */
+/* $NetBSD: proc.h,v 1.3 2018/12/27 09:55:27 mrg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -37,7 +37,6 @@
struct mdlwp {
void *md_onfault;
struct trapframe *md_utf;
- struct trapframe *md_ktf;
uint64_t md_cpacr;
uint32_t md_flags;
};