From d274473e209837684b16d8bfcbcd3e77f41bda93 Mon Sep 17 00:00:00 2001 From: Kenrou 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