Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Antoine Tremblay <antoine.tremblay@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH v2 06/17] arm-tdep.c: Use relocation visitor in Thumb 16-bits instruction decoding
Date: Thu, 09 Jun 2016 12:56:00 -0000	[thread overview]
Message-ID: <1465476975-25062-7-git-send-email-antoine.tremblay@ericsson.com> (raw)
In-Reply-To: <1465476975-25062-1-git-send-email-antoine.tremblay@ericsson.com>

From: Simon Marchi <simon.marchi@ericsson.com>

This is the same as the previous patch, but for the 16-bits Thumb
instructions.

gdb/ChangeLog:

	* arm-tdep.c (thumb_16bit_insn_reloc_visitor): New.
	(thumb_decode_pc_relative_16bit): Add visitor parameter and use
	it.
	(thumb_16bit_relocate_insn): Add and use visitor parameter.
	(thumb_16bit_insn_reloc_visitor): New.
	(arm_process_displaced_insn): Pass
	thumb_16it_insn_reloc_visitor to thumb_16bit_relocate_insn.
---
 gdb/arm-tdep.c | 81 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 24 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 6a9d110..0f35eb3 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -4529,6 +4529,21 @@ struct thumb_32bit_insn_reloc_visitor
 		       struct arm_insn_reloc_data *data);
 };
 
+struct thumb_16bit_insn_reloc_visitor
+{
+  int (*alu_reg) (uint16_t insn, struct arm_insn_reloc_data *data);
+  int (*b) (uint16_t insn, struct arm_insn_reloc_data *data);
+  int (*bx_blx_reg) (uint16_t insn, struct arm_insn_reloc_data *data);
+  int (*cbnz_cbz) (uint16_t insn1, struct arm_insn_reloc_data *data);
+  int (*load_literal) (uint16_t insn1, struct arm_insn_reloc_data *data);
+  int (*others) (uint16_t insn, const char *iname,
+		 struct arm_insn_reloc_data *data);
+  int (*pc_relative_16bit) (uint16_t insn, struct arm_insn_reloc_data *data,
+			    int rd, unsigned int imm);
+  int (*pop_pc_16bit) (uint16_t insn, struct arm_insn_reloc_data *data);
+  int (*svc) (uint16_t insn, struct arm_insn_reloc_data *data);
+};
+
 /* Helper for register reads for displaced stepping.  In particular, this
    returns the PC as it would be seen by the instruction at its original
    location.  */
@@ -7050,12 +7065,14 @@ thumb_copy_pc_relative_16bit (uint16_t insn, struct arm_insn_reloc_data *data,
 }
 
 static int
-thumb_decode_pc_relative_16bit (uint16_t insn, struct arm_insn_reloc_data *data)
+thumb_decode_pc_relative_16bit (uint16_t insn,
+				struct thumb_16bit_insn_reloc_visitor *visitor,
+				struct arm_insn_reloc_data *data)
 {
   unsigned int rd = bits (insn, 8, 10);
   unsigned int imm8 = bits (insn, 0, 7);
 
-  return thumb_copy_pc_relative_16bit (insn, data, rd, imm8);
+  return visitor->pc_relative_16bit (insn, data, rd, imm8);
 }
 
 static int
@@ -7320,7 +7337,9 @@ thumb_copy_pop_pc_16bit (uint16_t insn1, struct arm_insn_reloc_data *data)
 }
 
 static int
-thumb_16bit_relocate_insn (uint16_t insn1, struct arm_insn_reloc_data *data)
+thumb_16bit_relocate_insn (uint16_t insn1,
+			   struct thumb_16bit_insn_reloc_visitor *visitor,
+			   struct arm_insn_reloc_data *data)
 {
   unsigned short op_bit_12_15 = bits (insn1, 12, 15);
   unsigned short op_bit_10_11 = bits (insn1, 10, 11);
@@ -7331,79 +7350,79 @@ thumb_16bit_relocate_insn (uint16_t insn1, struct arm_insn_reloc_data *data)
     {
       /* Shift (imme), add, subtract, move and compare.  */
     case 0: case 1: case 2: case 3:
-      err = thumb_copy_unmodified_16bit (insn1, "shift/add/sub/mov/cmp", data);
+      err = visitor->others (insn1, "shift/add/sub/mov/cmp", data);
       break;
     case 4:
       switch (op_bit_10_11)
 	{
 	case 0: /* Data-processing */
-	  err = thumb_copy_unmodified_16bit (insn1, "data-processing", data);
+	  err = visitor->others (insn1, "data-processing", data);
 	  break;
 	case 1: /* Special data instructions and branch and exchange.  */
 	  {
 	    unsigned short op = bits (insn1, 7, 9);
 	    if (op == 6 || op == 7) /* BX or BLX */
-	      err = thumb_copy_bx_blx_reg (insn1, data);
+	      err = visitor->bx_blx_reg (insn1, data);
 	    else if (bits (insn1, 6, 7) != 0) /* ADD/MOV/CMP high registers.  */
-	      err = thumb_copy_alu_reg (insn1, data);
+	      err = visitor->alu_reg (insn1, data);
 	    else
-	      err = thumb_copy_unmodified_16bit (insn1, "special data", data);
+	      err = visitor->others (insn1, "special data", data);
 	  }
 	  break;
 	default: /* LDR (literal) */
-	  err = thumb_copy_16bit_ldr_literal (insn1, data);
+	  err = visitor->load_literal (insn1, data);
 	}
       break;
     case 5: case 6: case 7: case 8: case 9: /* Load/Store single data item */
-      err = thumb_copy_unmodified_16bit (insn1, "ldr/str", data);
+      err = visitor->others (insn1, "ldr/str", data);
       break;
     case 10:
       if (op_bit_10_11 < 2) /* Generate PC-relative address */
-	err = thumb_decode_pc_relative_16bit (insn1, data);
+	err = thumb_decode_pc_relative_16bit (insn1, visitor, data);
       else /* Generate SP-relative address */
-	err = thumb_copy_unmodified_16bit (insn1, "sp-relative", data);
+	err = visitor->others (insn1, "sp-relative", data);
       break;
     case 11: /* Misc 16-bit instructions */
       {
 	switch (bits (insn1, 8, 11))
 	  {
 	  case 1: case 3:  case 9: case 11: /* CBNZ, CBZ */
-	    err = thumb_copy_cbnz_cbz (insn1, data);
+	    err = visitor->cbnz_cbz (insn1, data);
 	    break;
 	  case 12: case 13: /* POP */
 	    if (bit (insn1, 8)) /* PC is in register list.  */
-	      err = thumb_copy_pop_pc_16bit (insn1, data);
+	      err = visitor->pop_pc_16bit (insn1, data);
 	    else
-	      err = thumb_copy_unmodified_16bit (insn1, "pop", data);
+	      err = visitor->others (insn1, "pop", data);
 	    break;
 	  case 15: /* If-Then, and hints */
 	    if (bits (insn1, 0, 3))
 	      /* If-Then makes up to four following instructions conditional.
 		 IT instruction itself is not conditional, so handle it as a
 		 common unmodified instruction.  */
-	      err = thumb_copy_unmodified_16bit (insn1, "If-Then", data);
+	      err = visitor->others (insn1, "If-Then", data);
 	    else
-	      err = thumb_copy_unmodified_16bit (insn1, "hints", data);
+	      err = visitor->others (insn1, "hints", data);
 	    break;
 	  default:
-	    err = thumb_copy_unmodified_16bit (insn1, "misc", data);
+	    err = visitor->others (insn1, "misc", data);
 	  }
       }
       break;
     case 12:
       if (op_bit_10_11 < 2) /* Store multiple registers */
-	err = thumb_copy_unmodified_16bit (insn1, "stm", data);
+	err = visitor->others (insn1, "stm", data);
       else /* Load multiple registers */
-	err = thumb_copy_unmodified_16bit (insn1, "ldm", data);
+	err = visitor->others (insn1, "ldm", data);
       break;
     case 13: /* Conditional branch and supervisor call */
       if (bits (insn1, 9, 11) != 7) /* conditional branch */
-	err = thumb_copy_b (insn1, data);
+	err = visitor->b (insn1, data);
       else
-	err = thumb_copy_svc (insn1, data);
+	err = visitor->svc (insn1, data);
       break;
     case 14: /* Unconditional branch */
-      err = thumb_copy_b (insn1, data);
+      err = visitor->b (insn1, data);
       break;
     default:
       err = 1;
@@ -7663,6 +7682,19 @@ static struct thumb_32bit_insn_reloc_visitor thumb_32bit_insn_reloc_visitor =
   thumb_32bit_copy_undef,
 };
 
+static struct thumb_16bit_insn_reloc_visitor thumb_16bit_insn_reloc_visitor =
+{
+  thumb_copy_alu_reg,
+  thumb_copy_b,
+  thumb_copy_bx_blx_reg,
+  thumb_copy_cbnz_cbz,
+  thumb_copy_16bit_ldr_literal,
+  thumb_copy_unmodified_16bit,
+  thumb_copy_pc_relative_16bit,
+  thumb_copy_pop_pc_16bit,
+  thumb_copy_svc,
+};
+
 void
 arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to, struct regcache *regs,
@@ -7722,7 +7754,8 @@ arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from,
 					   &reloc_data);
 	}
       else
-        err = thumb_16bit_relocate_insn (insn1, &reloc_data);
+	err = thumb_16bit_relocate_insn (insn1, &thumb_16bit_insn_reloc_visitor,
+					 &reloc_data);
     }
 
   if (err)
-- 
2.8.1


  parent reply	other threads:[~2016-06-09 12:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-09 12:56 [PATCH v2 00/17] Fast tracepoint support for ARMv7 Antoine Tremblay
2016-06-09 12:56 ` [PATCH v2 07/17] Move ARM instruction decode functions to arch/arm-insn-reloc.c Antoine Tremblay
2016-06-09 12:56 ` [PATCH v2 08/17] Move Thumb 32 bits " Antoine Tremblay
2016-06-09 12:56 ` [PATCH v2 11/17] Use software single step to step out of a fast tracepoint jump pad Antoine Tremblay
2016-06-09 12:56 ` Antoine Tremblay [this message]
2016-06-09 12:57 ` [PATCH v2 17/17] arm fast tracepoints: Relocation of Thumb 32-bits instructions Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 04/17] arm-tdep.c: Use relocation visitor in ARM instruction decoding Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 09/17] Move Thumb 16 bits instruction decode functions to arch/arm-insn-reloc.c Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 03/17] arm-tdep.c: Move debug printout from decode to copy function Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 16/17] arm fast tracepoints: Relocation of ARM instructions Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 12/17] Add ARM/Thumb instruction assembler for fast tracepoints Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 02/17] arm-tdep.c: Refactor displaced stepping relocation functions Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 01/17] arm-tdep.c: Replace arguments to decode function by a structure Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 13/17] Fast tracepoint support for ARM on Linux Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 10/17] gdbserver: pass pointer to struct tracepoint to install_fast_tracepoint_jump_pad Antoine Tremblay
2016-06-15 14:59   ` Marcin Kościelnicki
2016-06-15 15:42     ` Antoine Tremblay
2016-06-16 17:14     ` [PATCH v3] " Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 05/17] arm-tdep.c: Use relocation visitor in Thumb 32-bits instruction decoding Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 14/17] JIT conditions support for ARM tracepoints Antoine Tremblay
2016-06-09 12:57 ` [PATCH v2 15/17] arm: Move insn_references_pc to common code Antoine Tremblay
2016-06-29 13:55 ` [PATCH v2 00/17] Fast tracepoint support for ARMv7 Antoine Tremblay
2016-06-29 16:59   ` Pedro Alves
2016-06-29 19:15     ` Antoine Tremblay
2016-06-29 20:10       ` Pedro Alves
2016-06-30 11:46         ` Antoine Tremblay

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=1465476975-25062-7-git-send-email-antoine.tremblay@ericsson.com \
    --to=antoine.tremblay@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.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