Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/rl78: Fix register bank calculation from PSW
@ 2026-11-13 21:32 kenrou
  0 siblings, 0 replies; only message in thread
From: kenrou @ 2026-11-13 21:32 UTC (permalink / raw)
  To: gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 191 bytes --]

Thank you for the feedback.

This patch fixes the RL78 register bank calculation to use
RL78_PSW_RBS0 and RL78_PSW_RBS1, matching the logic used by
the RL78 simulator.

Tested with rl78-elf.

[-- Attachment #1.2: Type: text/html, Size: 370 bytes --]

[-- Attachment #2: 0001-gdb-rl78-Fix-register-bank-calculation-from-PSW.patch --]
[-- Type: application/octet-stream, Size: 1822 bytes --]

From d274473e209837684b16d8bfcbcd3e77f41bda93 Mon Sep 17 00:00:00 2001
From: Kenrou <kenrou60@gmail.com>
Date: Sat, 14 Nov 2026 06:06:41 +0900
Subject: [PATCH] gdb/rl78: Fix register bank calculation from PSW

RBS0 and RBS1 are located at bits 3 and 5 of the RL78 PSW.

rl78_pseudo_register_read incorrectly used bit 4 (AC)
instead of bit 5 when calculating the active register
bank. As a result, GDB could read registers from the
wrong bank when AC was set.

Use RL78_PSW_RBS0 and RL78_PSW_RBS1 to determine the
active register bank, matching the logic used by the
RL78 simulator.
---
 gdb/rl78-tdep.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 4204ce5c8cb..ca284e4f2f4 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -693,7 +693,9 @@ rl78_pseudo_register_read (struct gdbarch *gdbarch,
       if (status == REG_VALID)
 	{
 	  /* RSB0 is at bit 3; RSBS1 is at bit 5.  */
-	  int bank = ((psw >> 3) & 1) | ((psw >> 4) & 1);
+          int rb0 = (psw & RL78_PSW_RBS0) ? 1 : 0;
+          int rb1 = (psw & RL78_PSW_RBS1) ? 2 : 0;
+          int bank = rb0 | rb1;
 	  int raw_regnum = RL78_RAW_BANK0_R0_REGNUM + bank * RL78_REGS_PER_BANK
 			   + (reg - RL78_X_REGNUM);
 	  status = regcache->raw_read (raw_regnum, buffer);
@@ -707,7 +709,9 @@ rl78_pseudo_register_read (struct gdbarch *gdbarch,
       if (status == REG_VALID)
 	{
 	  /* RSB0 is at bit 3; RSBS1 is at bit 5.  */
-	  int bank = ((psw >> 3) & 1) | ((psw >> 4) & 1);
+          int rb0 = (psw & RL78_PSW_RBS0) ? 1 : 0;
+          int rb1 = (psw & RL78_PSW_RBS1) ? 2 : 0;
+          int bank = rb0 | rb1;
 	  int raw_regnum = RL78_RAW_BANK0_R0_REGNUM + bank * RL78_REGS_PER_BANK
 			   + 2 * (reg - RL78_AX_REGNUM);
 	  status = regcache->raw_read (raw_regnum, buffer);
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-13 21:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 21:32 [PATCH] gdb/rl78: Fix register bank calculation from PSW kenrou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox