Re: [PATCH v1 01/10] Add LoongArch64 framework code support

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

 



Hi, Lianbo

Thanks for your review.

On 10/8/23 20:00, lijiang wrote:
> Hi, Ming
> So sorry for the late reply.
>
>
>      gdb_patch:
>             if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
>                     patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
>     +       if [ -f ${GDB}-loongarch.patch ] && [ -s ${GDB}-loongarch.patch ]; then \
>     +               patch -p0 < ${GDB}-loongarch.patch; cp ${GDB}-loongarch.patch ${GDB}; fi
>
>  
> This means we have to maintain a specific gdb patch for loongarch. Although a similar method still exists in the crash-7-branch, I would not suggest doing that in crash-8(unless this is the optimal solution).
>
> Ideally, you could backport the relevant patches based on the current gdb-10.2.patch, and remove redundant(or unnecessary) changes, which makes the gdb patches less changes.

This is really ugly, I'm trying to make gdb backport patch as simple as possible.  OK, I will  backport the relevant patches based on the current gdb-10.2.patch.

>     @@ -1670,6 +1690,7 @@ target_to_name(int target)
>             case MIPS64: return("MIPS64");
>             case SPARC64: return("SPARC64");
>             case RISCV64: return("RISCV64");
>     +       case LOONGARCH64: return("LOONGARCH64");
>             }
>
>  
> It doesn't support building the loongarch crash binary on an X86 64 host, right?

It is supported building the loongarch crash binary on an X86 64 host.I will fix this issue in v2 version.

>
>     @@ -2015,6 +2021,8 @@ struct offset_table {                    /* stash of commonly-used offsets */
>             long atomic_t_counter;
>             long percpu_counter_count;
>             long mm_struct_mm_count;
>     +       long task_struct_thread_reg01;
>     +       long task_struct_thread_reg03;
>
>
> They have to be appended to the end of the tables, see the writing patch section:
> https://github.com/crash-utility/crash/wiki
>  

Thanks, I will fix this in V2.

>     +
>     +/* from arch/loongarch/include/asm/ptrace.h */
>     +struct loongarch64_pt_regs {
>     +       /* Saved main processor registers. */
>     +       unsigned long regs[32];
>     +
>     +       /* Saved special registers. */
>     +       unsigned long csr_crmd;
>     +       unsigned long csr_prmd;
>     +       unsigned long csr_euen;
>     +       unsigned long csr_ecfg;
>     +       unsigned long csr_estat;
>     +       unsigned long csr_epc;
>     +       unsigned long csr_badvaddr;
>     +       unsigned long orig_a0;
>     +};
>     +
>     +struct loongarch64_unwind_frame {
>     +        unsigned long sp;
>     +        unsigned long pc;
>     +        unsigned long ra;
>     +};
>
>  
> If the above definitions are only used for the loongarch64.c, I would suggest moving them somewhere in the loongarch64.c.
>
OK. I will fix this in V2.
>
>     +
>     +#define KSYMS_START     (0x1)
>     +
>     +struct machine_specific {
>     +       ulong phys_base;
>     +       ulong vmalloc_start_addr;
>     +       ulong modules_vaddr;
>     +       ulong modules_end;
>     +
>     +       struct loongarch64_pt_regs *crash_task_regs;
>     +};
>     +
>     +/*
>     + * Basic page table format:
>     + *
>     + *   63  62 61       PALEN-1            12      10 9  8 7 6 5 4 3 2 1 0
>     + * +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+
>     + * |RPLV|NX|NR|      |  PA[PALEN-1:12]    |    |SP|PN|W|P|G|MAT|PLV|D|V|
>     + * +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+
>     + *
>     + *
>     + * Huge page table format:
>     + *
>     + *   63  62 61       PALEN-1            12      10 9  8 7 6 5 4 3 2 1 0
>     + * +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+
>     + * |RPLV|NX|NR|      |  PA[PALEN-1:12] | G|    |SP|PN|W|P|H|MAT|PLV|D|V|
>     + * +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+
>     + *
>     + */
>     +/* from arch/loongarch/include/asm/pgtable-bits.h */
>     +
>     +/* Page table bits */
>     +#define        _PAGE_VALID_SHIFT       0
>     +#define        _PAGE_ACCESSED_SHIFT    0  /* Reuse Valid for Accessed */
>     +#define        _PAGE_DIRTY_SHIFT       1
>     +#define        _PAGE_PLV_SHIFT         2  /* 2~3, two bits */
>     +#define        _CACHE_SHIFT            4  /* 4~5, two bits */
>     +#define        _PAGE_GLOBAL_SHIFT      6
>     +#define        _PAGE_HUGE_SHIFT        6  /* HUGE is a PMD bit */
>     +#define        _PAGE_PRESENT_SHIFT     7
>     +#define        _PAGE_WRITE_SHIFT       8
>     +#define        _PAGE_MODIFIED_SHIFT    9
>     +#define        _PAGE_PROTNONE_SHIFT    10
>     +#define        _PAGE_SPECIAL_SHIFT     11
>     +#define        _PAGE_HGLOBAL_SHIFT     12 /* HGlobal is a PMD bit */
>     +#define        _PAGE_PFN_SHIFT         12
>     +#define        _PAGE_SWP_EXCLUSIVE_SHIFT 23
>     +#define        _PAGE_PFN_END_SHIFT     48
>     +#define        _PAGE_PRESENT_INVALID_SHIFT 60
>     +#define        _PAGE_NO_READ_SHIFT     61
>     +#define        _PAGE_NO_EXEC_SHIFT     62
>     +#define        _PAGE_RPLV_SHIFT        63
>     +
>     +#ifndef _ULCAST_
>     +#define _ULCAST_ (unsigned long)
>     +#endif
>     +
>     +/* Used by software */
>     +#define _PAGE_PRESENT          (_ULCAST_(1) << _PAGE_PRESENT_SHIFT)
>     +#define _PAGE_PRESENT_INVALID  (_ULCAST_(1) << _PAGE_PRESENT_INVALID_SHIFT)
>     +#define _PAGE_WRITE            (_ULCAST_(1) << _PAGE_WRITE_SHIFT)
>     +#define _PAGE_ACCESSED         (_ULCAST_(1) << _PAGE_ACCESSED_SHIFT)
>     +#define _PAGE_MODIFIED         (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT)
>     +#define _PAGE_PROTNONE         (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT)
>     +#define _PAGE_SPECIAL          (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT)
>     +
>     +/* We borrow bit 23 to store the exclusive marker in swap PTEs. */
>     +#define _PAGE_SWP_EXCLUSIVE    (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT)
>     +
>     +/* Used by TLB hardware (placed in EntryLo*) */
>     +#define _PAGE_VALID            (_ULCAST_(1) << _PAGE_VALID_SHIFT)
>     +#define _PAGE_DIRTY            (_ULCAST_(1) << _PAGE_DIRTY_SHIFT)
>     +#define _PAGE_PLV              (_ULCAST_(3) << _PAGE_PLV_SHIFT)
>     +#define _PAGE_GLOBAL           (_ULCAST_(1) << _PAGE_GLOBAL_SHIFT)
>     +#define _PAGE_HUGE             (_ULCAST_(1) << _PAGE_HUGE_SHIFT)
>     +#define _PAGE_HGLOBAL          (_ULCAST_(1) << _PAGE_HGLOBAL_SHIFT)
>     +#define _PAGE_NO_READ          (_ULCAST_(1) << _PAGE_NO_READ_SHIFT)
>     +#define _PAGE_NO_EXEC          (_ULCAST_(1) << _PAGE_NO_EXEC_SHIFT)
>     +#define _PAGE_RPLV             (_ULCAST_(1) << _PAGE_RPLV_SHIFT)
>     +#define _CACHE_MASK            (_ULCAST_(3) << _CACHE_SHIFT)
>     +#define _PFN_SHIFT             (PAGESHIFT() - 12 + _PAGE_PFN_SHIFT)
>     +
>     +#define _PAGE_USER     (PLV_USER << _PAGE_PLV_SHIFT)
>     +#define _PAGE_KERN     (PLV_KERN << _PAGE_PLV_SHIFT)
>     +
>     +#define _PFN_MASK (~((_ULCAST_(1) << (_PFN_SHIFT)) - 1) & \
>     +                 ((_ULCAST_(1) << (_PAGE_PFN_END_SHIFT)) - 1))
>     +
>     +#endif /* LOONGARCH64 */
>     +
>      /*
>       *  netdump.c
>       */
>     diff --git a/diskdump.c b/diskdump.c
>     index 2c284ff..94b98b5 100644
>     --- a/diskdump.c
>     +++ b/diskdump.c
>     @@ -674,6 +674,9 @@ restart:
>             else if (STRNEQ(header->utsname.machine, "riscv64") &&
>                 machine_type_mismatch(file, "RISCV64", NULL, 0))
>                     goto err;
>     +       else if (STRNEQ(header->utsname.machine, "loongarch64") &&
>     +               machine_type_mismatch(file, "LOONGARCH64", NULL, 0))
>     +               goto err;
>
>             if (header->block_size != block_size) {
>                     block_size = header->block_size;
>     @@ -834,6 +837,8 @@ restart:
>                     dd->machine_type = EM_SPARCV9;
>             else if (machine_type("RISCV64"))
>                     dd->machine_type = EM_RISCV;
>     +       else if (machine_type("LOONGARCH64"))
>     +               dd->machine_type = EM_LOONGARCH;
>             else {
>                     error(INFO, "%s: unsupported machine type: %s\n",
>                             DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
>     @@ -1593,6 +1598,12 @@ get_diskdump_regs_riscv64(struct bt_info *bt, ulong *eip, ulong *esp)
>             machdep->get_stack_frame(bt, eip, esp);
>      }
>
>     +static void
>     +get_diskdump_regs_loongarch64(struct bt_info *bt, ulong *eip, ulong *esp)
>     +{
>     +       machdep->get_stack_frame(bt, eip, esp);
>     +}
>     +
>      static void
>      get_diskdump_regs_sparc64(struct bt_info *bt, ulong *eip, ulong *esp)
>      {
>     @@ -1676,6 +1687,10 @@ get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
>                     get_diskdump_regs_riscv64(bt, eip, esp);
>                     break;
>
>     +       case EM_LOONGARCH:
>     +               get_diskdump_regs_loongarch64(bt, eip, esp);
>     +               break;
>     +
>             default:
>                     error(FATAL, "%s: unsupported machine type: %s\n",
>                             DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
>     @@ -1823,7 +1838,7 @@ dump_note_offsets(FILE *fp)
>                             if (machine_type("X86_64") || machine_type("S390X") ||
>                                 machine_type("ARM64") || machine_type("PPC64") ||
>                                 machine_type("SPARC64") || machine_type("MIPS64") ||
>     -                           machine_type("RISCV64")) {
>     +                           machine_type("RISCV64") || machine_type("LOONGARCH64")) {
>                                     note64 = (void *)dd->notes_buf + tot;
>                                     len = sizeof(Elf64_Nhdr);
>                                     if (STRNEQ((char *)note64 + len, "QEMU"))
>     @@ -1934,6 +1949,8 @@ __diskdump_memory_dump(FILE *fp)
>                     fprintf(fp, "(EM_AARCH64)\n"); break;
>             case EM_SPARCV9:
>                     fprintf(fp, "(EM_SPARCV9)\n"); break;
>     +       case EM_LOONGARCH:
>     +               fprintf(fp, "(EM_LOONGARCH)\n"); break;
>             default:
>                     fprintf(fp, "(unknown)\n"); break;
>             }
>     diff --git a/gdb-10.2-loongarch.patch b/gdb-10.2-loongarch.patch
>     new file mode 100644
>     index 0000000..82c1640
>     --- /dev/null
>     +++ b/gdb-10.2-loongarch.patch
>     @@ -0,0 +1,15206 @@
>     +From 6a84c2ee3967892e476338f8f4b85617ced2c4bb Mon Sep 17 00:00:00 2001
>     +From: Ming Wang <wangming01@xxxxxxxxxxx>
>     +Date: Sat, 8 Jul 2023 15:07:21 +0800
>     +Subject: [PATCH] gdb: Add LoongArch support.
>     +
>     +Signed-off-by: Ming Wang <wangming01@xxxxxxxxxxx>
>     +---
>     + bfd/Makefile.am                          |   17 +-
>     + bfd/Makefile.in                          |   21 +-
>     + bfd/archures.c                           |    5 +
>     + bfd/bfd-in2.h                            |   85 +
>     + bfd/config.bfd                           |   15 +
>     + bfd/configure                            |    2 +
>     + bfd/configure.ac <https://mailgw.loongson.cn/linkserver?dest=http%3A%2F%2Fconfigure.ac&tid=_____8AxqOj_mSJlEwYwAA--.55953S2&rcpt=wangming01@xxxxxxxxxxx&ifnotice=1&rindex=0>                         |    2 +
>     + bfd/cpu-loongarch.c                      |   61 +
>     + bfd/elf-bfd.h                            |    9 +
>     + bfd/elf.c                                |  114 +-
>     + bfd/elfnn-loongarch.c                    | 4128 ++++++++++++++++++++++
>     + bfd/elfxx-loongarch.c                    | 1618 +++++++++
>     + bfd/elfxx-loongarch.h                    |   45 +
>     + bfd/libbfd.h                             |   80 +
>     + bfd/po/BLD-POTFILES.in                   |    2 +
>     + bfd/po/SRC-POTFILES.in                   |    1 +
>     + bfd/reloc.c                              |  171 +
>     + bfd/targets.c                            |    8 +
>     + config.guess                             |    3 +
>     + config.sub                               |    1 +
>     + gdb/Makefile.in                          |   13 +
>     + gdb/arch/loongarch-linux-nat.c           |   93 +
>     + gdb/arch/loongarch-linux-nat.h           |   35 +
>     + gdb/arch/loongarch.c                     |   75 +
>     + gdb/arch/loongarch.h                     |   35 +
>     + gdb/configure.host                       |    3 +
>     + gdb/configure.nat                        |    4 +
>     + gdb/configure.tgt                        |    8 +
>     + gdb/doc/gdb.texinfo                      |   10 +
>     + gdb/features/Makefile                    |   10 +
>     + gdb/features/loongarch/base32.c          |   48 +
>     + gdb/features/loongarch/base32.xml        |   46 +
>     + gdb/features/loongarch/base64.c          |   48 +
>     + gdb/features/loongarch/base64.xml        |   46 +
>     + gdb/features/loongarch/fpu32.c           |   54 +
>     + gdb/features/loongarch/fpu32.xml         |   53 +
>     + gdb/features/loongarch/fpu64.c           |   62 +
>     + gdb/features/loongarch/fpu64.xml         |   58 +
>     + gdb/features/loongarch/lasx.c            |   80 +
>     + gdb/features/loongarch/lasx.xml          |   59 +
>     + gdb/features/loongarch/lbt32.c           |   19 +
>     + gdb/features/loongarch/lbt32.xml         |   17 +
>     + gdb/features/loongarch/lbt64.c           |   19 +
>     + gdb/features/loongarch/lbt64.xml         |   17 +
>     + gdb/features/loongarch/lsx.c             |   80 +
>     + gdb/features/loongarch/lsx.xml           |   59 +
>     + gdb/loongarch-linux-nat.c                |  878 +++++
>     + gdb/loongarch-linux-tdep.c               |  709 ++++
>     + gdb/loongarch-linux-tdep.h               |   48 +
>     + gdb/loongarch-tdep.c                     | 1926 ++++++++++
>     + gdb/loongarch-tdep.h                     |   61 +
>     + gdb/nat/loongarch-linux-watch.c          |  330 ++
>     + gdb/nat/loongarch-linux-watch.h          |  132 +
>     + gdb/remote.c                             |   25 +
>     + gdb/target.h                             |    3 +
>     + gdb/testsuite/gdb.base/dump.exp          |    4 +
>     + gdb/testsuite/gdb.base/float.exp         |    2 +
>     + gdb/testsuite/gdb.trace/entry-values.exp |    2 +
>     + gdb/testsuite/gdb.xml/tdesc-regs.exp     |    5 +
>     + gdbserver/Makefile.in                    |    2 +
>     + gdbserver/configure.srv                  |    7 +
>     + gdbserver/linux-loongarch-low.cc         |  284 ++
>     + include/dis-asm.h                        |    1 +
>     + include/elf/common.h                     |   14 +
>     + include/elf/loongarch.h                  |  267 ++
>     + include/opcode/loongarch.h               |  239 ++
>     + opcodes/Makefile.am                      |    3 +
>     + opcodes/Makefile.in                      |    6 +
>     + opcodes/configure                        |    1 +
>     + opcodes/configure.ac <https://mailgw.loongson.cn/linkserver?dest=http%3A%2F%2Fconfigure.ac&tid=_____8AxqOj_mSJlEwYwAA--.55953S2&rcpt=wangming01@xxxxxxxxxxx&ifnotice=1&rindex=1>                     |    1 +
>     + opcodes/disassemble.c                    |    9 +
>     + opcodes/disassemble.h                    |    1 +
>     + opcodes/loongarch-coder.c                |  481 +++
>     + opcodes/loongarch-dis.c                  |  342 ++
>     + opcodes/loongarch-opc.c                  |  870 +++++
>     + opcodes/po/POTFILES.in                   |    3 +
>     + 76 files changed, 14091 insertions(+), 4 deletions(-)
>     + create mode 100644 bfd/cpu-loongarch.c
>     + create mode 100644 bfd/elfnn-loongarch.c
>     + create mode 100644 bfd/elfxx-loongarch.c
>     + create mode 100644 bfd/elfxx-loongarch.h
>     + create mode 100644 gdb/arch/loongarch-linux-nat.c
>     + create mode 100644 gdb/arch/loongarch-linux-nat.h
>     + create mode 100644 gdb/arch/loongarch.c
>     + create mode 100644 gdb/arch/loongarch.h
>     + create mode 100644 gdb/features/loongarch/base32.c
>     + create mode 100644 gdb/features/loongarch/base32.xml
>     + create mode 100644 gdb/features/loongarch/base64.c
>     + create mode 100644 gdb/features/loongarch/base64.xml
>     + create mode 100644 gdb/features/loongarch/fpu32.c
>     + create mode 100644 gdb/features/loongarch/fpu32.xml
>     + create mode 100644 gdb/features/loongarch/fpu64.c
>     + create mode 100644 gdb/features/loongarch/fpu64.xml
>     + create mode 100644 gdb/features/loongarch/lasx.c
>     + create mode 100644 gdb/features/loongarch/lasx.xml
>     + create mode 100644 gdb/features/loongarch/lbt32.c
>     + create mode 100644 gdb/features/loongarch/lbt32.xml
>     + create mode 100644 gdb/features/loongarch/lbt64.c
>     + create mode 100644 gdb/features/loongarch/lbt64.xml
>     + create mode 100644 gdb/features/loongarch/lsx.c
>     + create mode 100644 gdb/features/loongarch/lsx.xml
>     + create mode 100644 gdb/loongarch-linux-nat.c
>     + create mode 100644 gdb/loongarch-linux-tdep.c
>     + create mode 100644 gdb/loongarch-linux-tdep.h
>     + create mode 100644 gdb/loongarch-tdep.c
>     + create mode 100644 gdb/loongarch-tdep.h
>     + create mode 100644 gdb/nat/loongarch-linux-watch.c
>     + create mode 100644 gdb/nat/loongarch-linux-watch.h
>     + create mode 100644 gdbserver/linux-loongarch-low.cc
>     + create mode 100644 include/elf/loongarch.h
>     + create mode 100644 include/opcode/loongarch.h
>     + create mode 100644 opcodes/loongarch-coder.c
>     + create mode 100644 opcodes/loongarch-dis.c
>     + create mode 100644 opcodes/loongarch-opc.c
>     +
>
>
> The gdb patches have their own format(style), for more details, please refer to the current gdb-10.2.patch.
Thanks, Where can I get an introduction to the relevant format? Is it generated directly using the patch command?
>
> Could you please try to simplify the gdb patches? Or is it possible to drop unnecessary changes when backporting the related patches from upstream?

I'm trying to make gdb backport patch as simple as possible. This may take some time.


Thanks,

Ming




--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/crash-utility
Contribution Guidelines: https://github.com/crash-utility/crash/wiki




[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux