Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb: LoongArch: Emulate floating-point branch instructions
Date: Wed, 30 Apr 2025 15:10:15 +0800	[thread overview]
Message-ID: <20250430071015.23552-1-yangtiezhu@loongson.cn> (raw)

Add bceqz and bcnez cases in loongarch_insn_is_cond_branch() and
loongarch_next_pc() to emulate floating-point branch instructions.

Here are the references:

https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_bceqz_bcnez
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#table-table-of-instruction-encoding

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 gdb/loongarch-tdep.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 092127dd810..d79ec686e6a 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -74,7 +74,9 @@ loongarch_insn_is_cond_branch (insn_t insn)
       || (insn & 0xfc000000) == 0x68000000	/* bltu  */
       || (insn & 0xfc000000) == 0x6c000000	/* bgeu  */
       || (insn & 0xfc000000) == 0x40000000	/* beqz  */
-      || (insn & 0xfc000000) == 0x44000000)	/* bnez  */
+      || (insn & 0xfc000000) == 0x44000000	/* bnez  */
+      || (insn & 0xfc000300) == 0x48000000	/* bceqz  */
+      || (insn & 0xfc000300) == 0x48000100)	/* bcnez  */
     return true;
   return false;
 }
@@ -314,6 +316,20 @@ loongarch_next_pc (struct regcache *regcache, CORE_ADDR cur_pc)
       if (rj != 0)
 	next_pc = cur_pc + loongarch_decode_imm ("0:5|10:16<<2", insn, 1);
     }
+  else if ((insn & 0xfc000300) == 0x48000000)		/* bceqz cj, offs21  */
+    {
+      LONGEST cj = regcache_raw_get_signed (regcache,
+		     loongarch_decode_imm ("5:3", insn, 0) + LOONGARCH_FIRST_FCC_REGNUM);
+      if (cj == 0)
+	next_pc = cur_pc + loongarch_decode_imm ("0:5|10:16<<2", insn, 1);
+    }
+  else if ((insn & 0xfc000300) == 0x48000100)		/* bcnez cj, offs21  */
+    {
+      LONGEST cj = regcache_raw_get_signed (regcache,
+		     loongarch_decode_imm ("5:3", insn, 0) + LOONGARCH_FIRST_FCC_REGNUM);
+      if (cj != 0)
+	next_pc = cur_pc + loongarch_decode_imm ("0:5|10:16<<2", insn, 1);
+    }
   else if ((insn & 0xffff8000) == 0x002b0000)		/* syscall  */
     {
       if (tdep->syscall_next_pc != nullptr)
-- 
2.42.0


             reply	other threads:[~2025-04-30  7:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30  7:10 Tiezhu Yang [this message]
2025-05-07  4:30 ` Kevin Buettner
2025-05-10 13:29   ` 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=20250430071015.23552-1-yangtiezhu@loongson.cn \
    --to=yangtiezhu@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