From: kenrou <kenrou60@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb/rl78: Fix register bank calculation from PSW
Date: Sat, 14 Nov 2026 06:32:49 +0900 [thread overview]
Message-ID: <CAP5piuQZ7BJ+kyoq+VnXoxhfBNDH=jZAphpdcnVRbqdShxOtLg@mail.gmail.com> (raw)
[-- 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
reply other threads:[~2026-11-13 21:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='CAP5piuQZ7BJ+kyoq+VnXoxhfBNDH=jZAphpdcnVRbqdShxOtLg@mail.gmail.com' \
--to=kenrou60@gmail.com \
--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