Source-Changes-HG archive

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

[src/trunk]: src make savecore for arm64 basically work.



details:   https://anonhg.NetBSD.org/src/rev/a46657997078
branches:  trunk
changeset: 446975:a46657997078
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Dec 27 09:55:27 2018 +0000

description:
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.

diffstat:

 external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c |  51 ++++++++++++++++++++++++++-
 sys/arch/aarch64/aarch64/aarch64_machdep.c    |  10 +++--
 sys/arch/aarch64/aarch64/cpuswitch.S          |  32 +++++-----------
 sys/arch/aarch64/aarch64/db_machdep.c         |  12 +++--
 sys/arch/aarch64/aarch64/db_trace.c           |   8 ++-
 sys/arch/aarch64/aarch64/genassym.cf          |   5 +-
 sys/arch/aarch64/aarch64/vm_machdep.c         |   6 +-
 sys/arch/aarch64/include/pcb.h                |   3 +-
 sys/arch/aarch64/include/proc.h               |   3 +-
 9 files changed, 87 insertions(+), 43 deletions(-)

diffs (truncated from 347 to 300 lines):

diff -r 7643a5d49d7d -r a46657997078 external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c
--- a/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c     Thu Dec 27 08:13:50 2018 +0000
+++ b/external/gpl3/gdb/dist/gdb/aarch64-nbsd-nat.c     Thu Dec 27 09:55:27 2018 +0000
@@ -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 @@
     }
 }
 
+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 @@
   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);
 }
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Thu Dec 27 09:55:27 2018 +0000
@@ -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 @@
        extern char _end[];
        extern char lwp0uspace[];
 
+       struct pcb *pcb;
        struct trapframe *tf;
        psize_t memsize_total;
        vaddr_t kernstart, kernend;
@@ -374,12 +375,13 @@
         */
        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;
 }
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/cpuswitch.S
--- a/sys/arch/aarch64/aarch64/cpuswitch.S      Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/cpuswitch.S      Thu Dec 27 09:55:27 2018 +0000
@@ -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 @@
         */
        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 @@
        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 @@
        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 */
 
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/db_machdep.c
--- a/sys/arch/aarch64/aarch64/db_machdep.c     Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/db_machdep.c     Thu Dec 27 09:55:27 2018 +0000
@@ -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 @@
     const char *modif)
 {
        lwp_t *l;
+       struct pcb *pcb;
 
        if (!have_addr) {
                db_printf("lwp: <address>\n");
@@ -319,9 +320,10 @@
        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);
 
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/db_trace.c
--- a/sys/arch/aarch64/aarch64/db_trace.c       Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/db_trace.c       Thu Dec 27 09:55:27 2018 +0000
@@ -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 <ryo%nerv.org@localhost>
@@ -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 @@
                } 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);
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/genassym.cf
--- a/sys/arch/aarch64/aarch64/genassym.cf      Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/genassym.cf      Thu Dec 27 09:55:27 2018 +0000
@@ -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_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 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])
diff -r 7643a5d49d7d -r a46657997078 sys/arch/aarch64/aarch64/vm_machdep.c
--- a/sys/arch/aarch64/aarch64/vm_machdep.c     Thu Dec 27 08:13:50 2018 +0000
+++ b/sys/arch/aarch64/aarch64/vm_machdep.c     Thu Dec 27 09:55:27 2018 +0000
@@ -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 $");



Home | Main Index | Thread Index | Old Index