public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] m68k: Support for jump visualization in disassembly
@ 2024-06-18 15:02 Andreas Schwab
  0 siblings, 0 replies; only message in thread
From: Andreas Schwab @ 2024-06-18 15:02 UTC (permalink / raw)
  To: binutils

opcodes/
	* m68k-dis.c (m68k_opcode_to_insn_type): Define.
	(match_insn_m68k): Call it to set insn_type.
	(print_insn_arg) [case 'B']: Set branch target address.
	(print_insn_m68k): Set insn_info_valid.
---
 opcodes/m68k-dis.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/opcodes/m68k-dis.c b/opcodes/m68k-dis.c
index bc2f82031c8..7e9b087951e 100644
--- a/opcodes/m68k-dis.c
+++ b/opcodes/m68k-dis.c
@@ -991,6 +991,8 @@ print_insn_arg (const char *d,
       else
 	return PRINT_INSN_ARG_INVALID_OP_TABLE;
 
+      info->target = addr + disp;
+
       (*info->print_address_func) (addr + disp, info);
       break;
 
@@ -1442,6 +1444,27 @@ print_insn_arg (const char *d,
   return p - p0;
 }
 
+/* Return the insn type determined from the opcode information.  */
+
+static enum dis_insn_type
+m68k_opcode_to_insn_type (const struct m68k_opcode *opc)
+{
+  /* All branches have an operand in 'B' format (the 'B' place only comes
+     with the 'B' format).  */
+  if (strchr (opc->args, 'B') == NULL)
+    return dis_nonbranch;
+
+  /* Most branches are conditional branches, detect the ones that aren't
+     from the opcode name.  */
+  if (strncmp (opc->name, "bra", 3) == 0)
+    return dis_branch;
+
+  if (strncmp (opc->name, "bsr", 3) == 0)
+    return dis_jsr;
+
+  return dis_condbranch;
+}
+
 /* Try to match the current instruction to best and if so, return the
    number of bytes consumed from the instruction stream, else zero.
    Return -1 on memory error.  */
@@ -1573,6 +1596,7 @@ match_insn_m68k (bfd_vma memaddr,
   p = save_p;
   info->fprintf_styled_func = save_printer;
   info->print_address_func = save_print_address;
+  info->insn_type = m68k_opcode_to_insn_type (best);
 
   d = args;
 
@@ -1730,6 +1754,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
 
   bfd_byte *buffer = priv.the_buffer;
 
+  info->insn_info_valid = 1;
   info->private_data = & priv;
   /* Tell objdump to use two bytes per chunk
      and six bytes per line for displaying raw data.  */
@@ -1761,6 +1786,8 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
       info->fprintf_styled_func (info->stream, dis_style_text, " ");
       info->fprintf_styled_func (info->stream, dis_style_immediate,
 				 "0x%04x", (buffer[0] << 8) + buffer[1]);
+
+      info->insn_type = dis_noninsn;
     }
 
   return val ? val : 2;
-- 
2.45.2


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

only message in thread, other threads:[~2024-06-18 15:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-18 15:02 [PATCH] m68k: Support for jump visualization in disassembly Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).