public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Youling Tang <tangyouling@loongson.cn>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] gdbserver: LoongArch: Simplify code with register number macros
Date: Thu,  7 Jul 2022 11:16:30 +0800	[thread overview]
Message-ID: <1657163790-24891-1-git-send-email-tangyouling@loongson.cn> (raw)

Commit 0757a50396e3 ("gdb: LoongArch: Define register numbers and clean up
code") defines register number related macros, which are used in gebserver
to simplify related code.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 gdb/arch/loongarch.h             | 15 +++++++++++++++
 gdb/loongarch-linux-tdep.c       |  6 +++---
 gdb/loongarch-tdep.h             | 14 --------------
 gdbserver/linux-loongarch-low.cc | 24 +++++++++---------------
 4 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/gdb/arch/loongarch.h b/gdb/arch/loongarch.h
index 8194ea66c0a..a52e72cd459 100644
--- a/gdb/arch/loongarch.h
+++ b/gdb/arch/loongarch.h
@@ -60,6 +60,21 @@ struct loongarch_gdbarch_features
   }
 };
 
+/* Register numbers of various important registers.  */
+enum loongarch_regnum
+{
+  LOONGARCH_ZERO_REGNUM = 0,		/* First Integer Register/Constant Zero.  */
+  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.  */
+};
+
 #ifdef GDBSERVER
 
 /* Create and return a target description that is compatible with FEATURES.
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 1076e935997..4ecf1000308 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -40,7 +40,7 @@ loongarch_supply_gregset (const struct regset *regset,
 
   if (regnum == -1)
     {
-      regcache->raw_supply_zeroed (0);
+      regcache->raw_supply_zeroed (LOONGARCH_ZERO_REGNUM);
 
       for (int i = 1; i < 32; i++)
 	{
@@ -57,8 +57,8 @@ loongarch_supply_gregset (const struct regset *regset,
       buf = (const gdb_byte*) gprs + regsize * LOONGARCH_BADV_REGNUM;
       regcache->raw_supply (LOONGARCH_BADV_REGNUM, (const void *) buf);
     }
-  else if (regnum == 0)
-    regcache->raw_supply_zeroed (0);
+  else if (regnum == LOONGARCH_ZERO_REGNUM)
+    regcache->raw_supply_zeroed (LOONGARCH_ZERO_REGNUM);
   else if ((regnum > 0 && regnum < 32)
 	   || regnum == LOONGARCH_ORIG_A0_REGNUM
 	   || regnum == LOONGARCH_PC_REGNUM
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index acf0191fd65..b68a7892f2b 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -27,20 +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.  */
-};
-
 /* 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..9e2ada1f578 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, LOONGARCH_ZERO_REGNUM + 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, LOONGARCH_ZERO_REGNUM);
   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, LOONGARCH_ZERO_REGNUM + 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 != LOONGARCH_ZERO_REGNUM)
     return false;
-  supply_register_zeroed (regcache, regno);
+  supply_register_zeroed (regcache, LOONGARCH_ZERO_REGNUM);
   return true;
 }
 
-- 
2.20.1


             reply	other threads:[~2022-07-07  3:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  3:16 Youling Tang [this message]
2022-07-10  9:38 ` Tiezhu Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1657163790-24891-1-git-send-email-tangyouling@loongson.cn \
    --to=tangyouling@loongson.cn \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).