From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: gdb-patches@sourceware.org
Cc: Jovan Dmitrovic <jovan.dmitrovic@htecgroup.com>,
Djordje Todorovic <Djordje.Todorovic@htecgroup.com>,
Milica Matic <milica.matic@htecgroup.com>,
"Maciej W. Rozycki" <macro@globalfoundries.com>
Subject: [PATCH v2 10/12] MIPS: Correct segment calculation for MIPS16 JAL/X
Date: Mon, 17 Aug 2026 17:54:08 +0100 (BST) [thread overview]
Message-ID: <alpine.DEB.2.21.2608162342380.14132@angie.orcam.me.uk> (raw)
In-Reply-To: <alpine.DEB.2.21.2608161728490.14132@angie.orcam.me.uk>
From: Maciej W. Rozycki <macro@globalfoundries.com>
Fix an off-by-two segment calculation bug in determining the target PC
for MIPS16 JAL and JALX instructions in `extended_mips16_next_pc'. The
segment to use is determined by the address right after the instruction.
However unlike with extended instructions while JAL and JALX are being
decoded by said function `pc' points at the start of the instruction
rather than beyond the EXTEND prefix. Therefore the correct adjustment
for `pc' is 4 rather than 2.
This bug was originally present in `add_offset_16' and not eliminated
with the rewrite in commit 484933d11fca ("MIPS: Rewrite `add_offset_16'
to match its name").
No testcase added as that would require 256MiB+ of target memory and a
correspondingly large executable to be built, which seems not worth it
for such a corner-case bug.
Approved-By: Maciej W. Rozycki <macro@orcam.me.uk>
---
New change in v2.
---
gdb/mips-tdep.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
gdb-mips16-next-pc-jal.diff
Index: binutils-gdb/gdb/mips-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/mips-tdep.c
+++ binutils-gdb/gdb/mips-tdep.c
@@ -2297,7 +2297,7 @@ extended_mips16_next_pc (regcache *regca
{
struct upk_mips16 upk;
unpack_mips16 (gdbarch, pc, extension, insn, jalxtype, &upk);
- pc = ((pc + 2) & (~(CORE_ADDR) 0x0fffffff)) | (upk.offset << 2);
+ pc = ((pc + 4) & (~(CORE_ADDR) 0x0fffffff)) | (upk.offset << 2);
if ((insn >> 10) & 0x01) /* Exchange mode */
pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode. */
else
next prev parent reply other threads:[~2026-08-17 16:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 16:53 [PATCH v2 00/12] MIPS+testsuite: BLEZL stepping fix and associated test infrastructure Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 01/12] testsuite: Factor out target feature test template Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 02/12] PowerPC/testsuite: Reduce feature tests in terms of `allow_target_tests' Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 03/12] MIPS/testsuite: Verify MIPS I CPU branch stepping Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 04/12] MIPS: Correct BLEZL single-stepping Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 05/12] MIPS/testsuite: Verify MIPS II CPU branch stepping Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 06/12] MIPS/testsuite: Verify MIPS DSP ASE " Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 07/12] MIPS/testsuite: Verify MIPS16 " Maciej W. Rozycki
2026-08-17 16:53 ` [PATCH v2 08/12] MIPS/testsuite: Verify microMIPS " Maciej W. Rozycki
2026-08-17 16:54 ` [PATCH v2 09/12] MIPS: Reorder a reference to "BGTZ, BGTZL" in `mips32_next_pc' Maciej W. Rozycki
2026-08-17 16:54 ` Maciej W. Rozycki [this message]
2026-08-17 16:54 ` [PATCH v2 11/12] MIPS: Return correct size from `mips_insn_size' for MIPS16 JAL/X Maciej W. Rozycki
2026-08-17 16:54 ` [PATCH v2 12/12] MIPS: Fix stepping through instructions branching to own delay slot Maciej W. Rozycki
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=alpine.DEB.2.21.2608162342380.14132@angie.orcam.me.uk \
--to=macro@orcam.me.uk \
--cc=Djordje.Todorovic@htecgroup.com \
--cc=gdb-patches@sourceware.org \
--cc=jovan.dmitrovic@htecgroup.com \
--cc=macro@globalfoundries.com \
--cc=milica.matic@htecgroup.com \
/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