public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdbserver: LoongArch: Simplify code with register number macros
@ 2022-07-10 9:31 Tiezhu Yang
0 siblings, 0 replies; only message in thread
From: Tiezhu Yang @ 2022-07-10 9:31 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3eba483364436567fd1b6ac4b5d82e23bb223a54
commit 3eba483364436567fd1b6ac4b5d82e23bb223a54
Author: Youling Tang <tangyouling@loongson.cn>
Date: Sun Jul 10 10:22:33 2022 +0800
gdbserver: LoongArch: Simplify code with register number macros
Move "enum loongarch_regnum" to gdb/arch/loongarch.h so that the
macro definitions can be used in gdbserver/linux-loongarch-low.cc
to simplify the code.
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Diff:
---
gdb/arch/loongarch.h | 16 ++++++++++++++++
gdb/loongarch-tdep.h | 16 ----------------
gdbserver/linux-loongarch-low.cc | 24 +++++++++---------------
3 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/gdb/arch/loongarch.h b/gdb/arch/loongarch.h
index 8194ea66c0a..5cf5498079a 100644
--- a/gdb/arch/loongarch.h
+++ b/gdb/arch/loongarch.h
@@ -22,6 +22,22 @@
#include "gdbsupport/tdesc.h"
+/* Register numbers of various important registers. */
+enum
+{
+ LOONGARCH_RA_REGNUM = 1, /* Return Address. */
+ LOONGARCH_SP_REGNUM = 3, /* Stack Pointer. */
+ LOONGARCH_A0_REGNUM = 4, /* First Argument/Return Value. */
+ LOONGARCH_A7_REGNUM = 11, /* Seventh Argument/Syscall Number. */
+ LOONGARCH_FP_REGNUM = 22, /* Frame Pointer. */
+ LOONGARCH_ORIG_A0_REGNUM = 32, /* Syscall's original arg0. */
+ LOONGARCH_PC_REGNUM = 33, /* Program Counter. */
+ LOONGARCH_BADV_REGNUM = 34, /* Bad Vaddr for Addressing Exception. */
+ LOONGARCH_LINUX_NUM_GREGSET = 45, /* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10. */
+ LOONGARCH_ARG_REGNUM = 8, /* r4-r11: general-purpose argument registers.
+ f0-f7: floating-point argument registers. */
+};
+
/* The set of LoongArch architectural features that we track that impact how
we configure the actual gdbarch instance. We hold one of these in the
gdbarch_tdep structure, and use it to distinguish between different
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index 672bc2b80de..b68a7892f2b 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -27,22 +27,6 @@
#include "elf/loongarch.h"
#include "opcode/loongarch.h"
-/* Register numbers of various important registers. */
-enum
-{
- LOONGARCH_RA_REGNUM = 1, /* Return Address. */
- LOONGARCH_SP_REGNUM = 3, /* Stack Pointer. */
- LOONGARCH_A0_REGNUM = 4, /* First Argument/Return Value. */
- LOONGARCH_A7_REGNUM = 11, /* Seventh Argument/Syscall Number. */
- LOONGARCH_FP_REGNUM = 22, /* Frame Pointer. */
- LOONGARCH_ORIG_A0_REGNUM = 32, /* Syscall's original arg0. */
- LOONGARCH_PC_REGNUM = 33, /* Program Counter. */
- LOONGARCH_BADV_REGNUM = 34, /* Bad Vaddr for Addressing Exception. */
- LOONGARCH_LINUX_NUM_GREGSET = 45, /* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10. */
- LOONGARCH_ARG_REGNUM = 8, /* r4-r11: general-purpose argument registers.
- f0-f7: floating-point argument registers. */
-};
-
/* Register set definitions. */
extern const struct regset loongarch_gregset;
diff --git a/gdbserver/linux-loongarch-low.cc b/gdbserver/linux-loongarch-low.cc
index 5d3739354e6..7b81e4b786a 100644
--- a/gdbserver/linux-loongarch-low.cc
+++ b/gdbserver/linux-loongarch-low.cc
@@ -94,15 +94,13 @@ loongarch_target::low_arch_setup ()
static void
loongarch_fill_gregset (struct regcache *regcache, void *buf)
{
- const struct target_desc *tdesc = regcache->tdesc;
elf_gregset_t *regset = (elf_gregset_t *) buf;
- int regno = find_regno (tdesc, "r0");
int i;
for (i = 1; i < 32; i++)
- collect_register (regcache, regno + i, *regset + i);
- collect_register_by_name (regcache, "pc", *regset + 32);
- collect_register_by_name (regcache, "badv", *regset + 33);
+ collect_register (regcache, i, *regset + i);
+ collect_register (regcache, LOONGARCH_PC_REGNUM, *regset + LOONGARCH_PC_REGNUM);
+ collect_register (regcache, LOONGARCH_BADV_REGNUM, *regset + LOONGARCH_BADV_REGNUM);
}
/* Supply GPRs from BUF into REGCACHE. */
@@ -110,16 +108,14 @@ loongarch_fill_gregset (struct regcache *regcache, void *buf)
static void
loongarch_store_gregset (struct regcache *regcache, const void *buf)
{
- const struct target_desc *tdesc = regcache->tdesc;
const elf_gregset_t *regset = (const elf_gregset_t *) buf;
- int regno = find_regno (tdesc, "r0");
int i;
- supply_register_zeroed (regcache, regno);
+ supply_register_zeroed (regcache, 0);
for (i = 1; i < 32; i++)
- supply_register (regcache, regno + i, *regset + i);
- supply_register_by_name (regcache, "pc", *regset + 32);
- supply_register_by_name (regcache, "badv", *regset + 33);
+ supply_register (regcache, i, *regset + i);
+ supply_register (regcache, LOONGARCH_PC_REGNUM, *regset + LOONGARCH_PC_REGNUM);
+ supply_register (regcache, LOONGARCH_BADV_REGNUM, *regset + LOONGARCH_BADV_REGNUM);
}
/* LoongArch/Linux regsets. */
@@ -158,11 +154,9 @@ loongarch_target::get_regs_info ()
bool
loongarch_target::low_fetch_register (regcache *regcache, int regno)
{
- const struct target_desc *tdesc = regcache->tdesc;
-
- if (regno != find_regno (tdesc, "r0"))
+ if (regno != 0)
return false;
- supply_register_zeroed (regcache, regno);
+ supply_register_zeroed (regcache, 0);
return true;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-10 9:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-10 9:31 [binutils-gdb] gdbserver: LoongArch: Simplify code with register number macros Tiezhu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).