Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Milica Matic <milicamatic05@gmail.com>
To: gdb-patches@sourceware.org
Cc: milica.matic@htecgroup.com, simark@simark.ca, cfu@wavecomp.com,
	aburgess@redhat.com, kevinb@redhat.com, macro@orcam.me.uk,
	djordje.todorovic@htecgroup.com,
	Robert Suchanek <Robert.Suchanek@imgtec.com>,
	Faraz Shahbazker <fshahbazker@wavecomp.com>
Subject: [PATCH 04/21] Instruction mapping support (pre-R6 to R6).
Date: Fri, 13 Dec 2024 16:53:11 +0100	[thread overview]
Message-ID: <20241213155328.406003-6-milica.matic@htecgroup.com> (raw)
In-Reply-To: <20241213155328.406003-1-milica.matic@htecgroup.com>

From: Robert Suchanek <Robert.Suchanek@imgtec.com>

Enhancing MIPS R6 support in the assembler by providing reliable
mapping between pre-R6 and R6 instructions, along with mechanisms
for detecting and addressing potential issues in optimizations.
Add function is_isa_r6.

Cherry-picked 6ebc24a
from https://github.com/MIPS/binutils-gdb

Signed-off-by: Robert Suchanek <Robert.Suchanek@imgtec.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Milica Matic <milica.matic@htecgroup.com>

Conflicts:
	gas/config/tc-mips.c
	include/opcode/mips.h
	opcodes/mips-dis.c
---
 gas/config/tc-mips.c  | 34 +++++++++++++++++++++++++++++++++-
 include/opcode/mips.h |  2 ++
 opcodes/mips-dis.c    | 19 +++++++++++++++----
 3 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index f135745be4d..ddaa0bd5efc 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -7743,6 +7743,37 @@ append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
 			address_expr->X_add_number);
       *reloc_type = BFD_RELOC_UNUSED;
     }
+  else if (mips_opts.micromips
+	   && ISA_IS_R6 (mips_opts.isa)
+	   /* microMIPS pre-R6 to R6 branch/jump instruction mapping in
+	      noreorder block is restricted to have only a nop in the delay
+	      slot.  */
+	   && compact_branch_p (&history[0])
+	   && (history[0].insn_mo->pinfo2 & INSN2_CONVERTED_TO_COMPACT)
+	   && history[0].noreorder_p
+	   && strcmp (ip->insn_mo->name, "nop") != 0)
+    {
+      as_bad (_("unable to convert `%s' to its compact form because it has a non NOP "
+		"instruction (`%s') in its delay slot.  Please move the delay slot "
+		"instruction before the branch and disable noreorder."),
+	      history[0].insn_mo->name, ip->insn_mo->name);
+      add_fixed_insn (ip);
+    }
+  else if (mips_opts.micromips
+	   && ISA_IS_R6 (mips_opts.isa)
+	   && history[0].noreorder_p
+	   && (strcmp (history[0].insn_mo->name, "bal") == 0
+	       || strcmp (history[0].insn_mo->name, "jal") == 0
+	       || strcmp (history[0].insn_mo->name, "jalr") == 0
+	       || strcmp (history[0].insn_mo->name, "bgezal") == 0
+	       || strcmp (history[0].insn_mo->name, "bltzal") == 0))
+    {
+      as_bad (_("unable to convert `%s' to its compact form because the link register "
+		"would have a different value.  Please move the delay slot instruction "
+		"before the branch and disable noreorder."),
+	      history[0].insn_mo->name);
+      add_fixed_insn (ip);
+    }
   else if (mips_opts.micromips
 	   && address_expr
 	   && ((relax32 && *reloc_type == BFD_RELOC_16_PCREL_S2)
@@ -8076,8 +8107,9 @@ append_insn (struct mips_cl_insn *ip, expressionS *address_expr,
     }
 
   /* If we have just completed an unconditional branch, clear the history.  */
-  if ((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
+  if (((delayed_branch_p (&history[1]) && uncond_branch_p (&history[1]))
       || (compact_branch_p (&history[0]) && uncond_branch_p (&history[0])))
+      && !(history[0].insn_mo->pinfo2 & INSN2_CONVERTED_TO_COMPACT))
     {
       unsigned int i;
 
diff --git a/include/opcode/mips.h b/include/opcode/mips.h
index 4a5d3638c87..bd247ffd0f0 100644
--- a/include/opcode/mips.h
+++ b/include/opcode/mips.h
@@ -887,6 +887,8 @@ mips_opcode_32bit_p (const struct mips_opcode *mo)
    encoding is needed or otherwise the final EXTEND entry will apply,
    for the disassembly of the prefix only.  */
 #define INSN2_SHORT_ONLY	    0x00010000
+/* This indicates pre-R6 instructions mapped to R6 ones.  */
+#define INSN2_CONVERTED_TO_COMPACT  0x00020000
 
 /* Masks used to mark instructions to indicate which MIPS ISA level
    they were introduced in.  INSN_ISA_MASK masks an enumeration that
diff --git a/opcodes/mips-dis.c b/opcodes/mips-dis.c
index ad5ec8ab9b2..4861150d0dd 100644
--- a/opcodes/mips-dis.c
+++ b/opcodes/mips-dis.c
@@ -818,6 +818,17 @@ is_micromips (Elf_Internal_Ehdr *header)
   return 0;
 }
 
+/* Check if ISA is R6.  */
+
+static inline int
+is_isa_r6 (unsigned long isa)
+{
+  if ((isa & INSN_ISA_MASK) == ISA_MIPS32R6
+      || ((isa & INSN_ISA_MASK) == ISA_MIPS64R6))
+    return 1;
+  return 0;
+}
+
 /* Convert ASE flags from .MIPS.abiflags to internal values.  */
 
 static unsigned long
@@ -2041,10 +2052,10 @@ print_insn_mips (bfd_vma memaddr,
 	      && (word & op->mask) == op->match)
 	    {
 	      /* We always disassemble the jalx instruction, except for MIPS r6.  */
-	      if (!opcode_is_member (op, mips_isa, mips_ase, mips_processor)
-		 && (strcmp (op->name, "jalx")
-		     || (mips_isa & INSN_ISA_MASK) == ISA_MIPS32R6
-		     || (mips_isa & INSN_ISA_MASK) == ISA_MIPS64R6))
+	      if ((!opcode_is_member (op, mips_isa, mips_ase, mips_processor)
+		  && (strcmp (op->name, "jalx") || is_isa_r6 (mips_isa)))
+		  || (is_isa_r6 (op->membership)
+		      && (op->pinfo2 & INSN2_CONVERTED_TO_COMPACT)))
 		continue;
 
 	      /* Figure out instruction type and branch delay information.  */
-- 
2.34.1


  parent reply	other threads:[~2024-12-13 15:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13 15:53 [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Milica Matic
2024-12-13 15:53 ` [PATCH 00/21] " Milica Matic
2024-12-13 15:53 ` [PATCH 01/21] Don't adjust microMIPS HI/LO rel section-relative Milica Matic
2024-12-13 15:53 ` [PATCH 02/21] Add new relocations for microMIPSR6 Milica Matic
2024-12-13 15:53 ` [PATCH 03/21] Improve WARN for $0 constraint on MIPSR6 branches Milica Matic
2024-12-13 15:53 ` Milica Matic [this message]
2024-12-13 15:53 ` [PATCH 05/21] Add microMIPSR6 support Milica Matic
2024-12-13 15:53 ` [PATCH 06/21] Update branch relaxation Milica Matic
2024-12-13 15:53 ` [PATCH 07/21] Add --user-defined-sdata-sections Milica Matic
2024-12-13 15:53 ` [PATCH 08/21] Disassembler fix Milica Matic
2024-12-13 15:53 ` [PATCH 09/21] MIPS: Add CRYPTO ASE support Milica Matic
2024-12-13 15:53 ` [PATCH 10/21] Add the m6201 architecture Milica Matic
2024-12-13 15:53 ` [PATCH 11/21] Add GINV(+VIRT) ASE for MIPSr6/microMIPS6 Milica Matic
2024-12-13 15:53 ` [PATCH 12/21] Implement the XBurst MXU extensions Milica Matic
2024-12-13 15:53 ` [PATCH 13/21] MIPS: Update encoding of d16mule MXU instruction Milica Matic
2024-12-13 15:53 ` [PATCH 14/21] Re-arrange MXU code blocks and add comments Milica Matic
2024-12-13 15:53 ` [PATCH 15/21] Accept MCU mapped string operands as constants Milica Matic
2024-12-13 15:53 ` [PATCH 16/21] Fix addr2line mapping - garbage collected modules Milica Matic
2024-12-13 15:53 ` [PATCH 17/21] Extend trap macros to handle immediate zero Milica Matic
2024-12-13 15:53 ` [PATCH 18/21] Fix failing test cases for linux and 64-bit target Milica Matic
2024-12-13 15:53 ` [PATCH 19/21] Remove exec permission tc-mips.c Milica Matic
2024-12-13 15:53 ` [PATCH 20/21] Workaround for line info in compressed MIPS func Milica Matic
2024-12-13 15:53 ` [PATCH 21/21] Fix gold linker build issues for mingw Milica Matic
2025-01-07 21:18 ` [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Kevin Buettner
2025-01-09  1:11   ` [EXTERNAL]Re: " Chao-ying Fu
2025-01-07 21:31 ` Kevin Buettner

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=20241213155328.406003-6-milica.matic@htecgroup.com \
    --to=milicamatic05@gmail.com \
    --cc=Robert.Suchanek@imgtec.com \
    --cc=aburgess@redhat.com \
    --cc=cfu@wavecomp.com \
    --cc=djordje.todorovic@htecgroup.com \
    --cc=fshahbazker@wavecomp.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    --cc=macro@orcam.me.uk \
    --cc=milica.matic@htecgroup.com \
    --cc=simark@simark.ca \
    /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