Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/8] Make aarch64_decode_adrp handle both ADR and ADRP instructions
Date: Fri, 18 Sep 2015 12:43:00 -0000	[thread overview]
Message-ID: <1442580184-22562-3-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1442580184-22562-1-git-send-email-yao.qi@linaro.org>

From: Pierre Langlois <pierre.langlois@arm.com>

We will need to decode both ADR and ADRP instructions in GDBserver.
This patch makes common code handle both cases, even if GDB only needs
to decode the ADRP instruction.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_analyze_prologue): New is_adrp
	variable.  Call aarch64_decode_adr instead of
	aarch64_decode_adrp.
	* arch/aarch64-insn.h (aarch64_decode_adrp): Delete.
	(aarch64_decode_adr): New function declaration.
	* arch/aarch64-insn.c (aarch64_decode_adrp): Delete.
	(aarch64_decode_adr): New function, factored out from
	aarch64_decode_adrp to decode both adr and adrp instructions.
---
 gdb/aarch64-tdep.c      |  4 +++-
 gdb/arch/aarch64-insn.c | 29 ++++++++++++++++++++++++-----
 gdb/arch/aarch64-insn.h |  3 ++-
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 92e2404..da61e54 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -551,13 +551,15 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       int is_cbnz;
       int is_tbnz;
       unsigned bit;
+      int is_adrp;
       int32_t offset;
 
       insn = read_memory_unsigned_integer (start, 4, byte_order_for_code);
 
       if (aarch64_decode_add_sub_imm (start, insn, &rd, &rn, &imm))
 	regs[rd] = pv_add_constant (regs[rn], imm);
-      else if (aarch64_decode_adrp (start, insn, &rd))
+      else if (aarch64_decode_adr (start, insn, &is_adrp, &rd, &offset)
+	       && is_adrp)
 	regs[rd] = pv_unknown ();
       else if (aarch64_decode_b (start, insn, &is_link, &offset))
 	{
diff --git a/gdb/arch/aarch64-insn.c b/gdb/arch/aarch64-insn.c
index 3a289a2..13d0013 100644
--- a/gdb/arch/aarch64-insn.c
+++ b/gdb/arch/aarch64-insn.c
@@ -55,25 +55,44 @@ decode_masked_match (uint32_t insn, uint32_t mask, uint32_t pattern)
   return (insn & mask) == pattern;
 }
 
-/* Decode an opcode if it represents an ADRP instruction.
+/* Decode an opcode if it represents an ADR or ADRP instruction.
 
    ADDR specifies the address of the opcode.
    INSN specifies the opcode to test.
+   IS_ADRP receives the 'op' field from the decoded instruction.
    RD receives the 'rd' field from the decoded instruction.
+   OFFSET receives the 'immhi:immlo' field from the decoded instruction.
 
    Return 1 if the opcodes matches and is decoded, otherwise 0.  */
 
 int
-aarch64_decode_adrp (CORE_ADDR addr, uint32_t insn, unsigned *rd)
+aarch64_decode_adr (CORE_ADDR addr, uint32_t insn, int *is_adrp,
+		    unsigned *rd, int32_t *offset)
 {
-  if (decode_masked_match (insn, 0x9f000000, 0x90000000))
+  /* adr  0ii1 0000 iiii iiii iiii iiii iiir rrrr */
+  /* adrp 1ii1 0000 iiii iiii iiii iiii iiir rrrr */
+  if (decode_masked_match (insn, 0x1f000000, 0x10000000))
     {
+      uint32_t immlo = (insn >> 29) & 0x3;
+      int32_t immhi = extract_signed_bitfield (insn, 19, 5) << 2;
+
+      *is_adrp = (insn >> 31) & 0x1;
       *rd = (insn >> 0) & 0x1f;
 
+      if (*is_adrp)
+	{
+	  /* The ADRP instruction has an offset with a -/+ 4GB range,
+	     encoded as (immhi:immlo * 4096).  */
+	  *offset = (immhi | immlo) * 4096;
+	}
+      else
+	*offset = (immhi | immlo);
+
       if (aarch64_debug)
 	{
-	  debug_printf ("decode: 0x%s 0x%x adrp x%u, #?\n",
-			core_addr_to_string_nz (addr), insn, *rd);
+	  debug_printf ("decode: 0x%s 0x%x %s x%u, #?\n",
+			core_addr_to_string_nz (addr), insn,
+			*is_adrp ?  "adrp" : "adr", *rd);
 	}
       return 1;
     }
diff --git a/gdb/arch/aarch64-insn.h b/gdb/arch/aarch64-insn.h
index 7775a34..2facb44 100644
--- a/gdb/arch/aarch64-insn.h
+++ b/gdb/arch/aarch64-insn.h
@@ -21,7 +21,8 @@
 
 extern int aarch64_debug;
 
-int aarch64_decode_adrp (CORE_ADDR addr, uint32_t insn, unsigned *rd);
+int aarch64_decode_adr (CORE_ADDR addr, uint32_t insn, int *is_adrp,
+			unsigned *rd, int32_t *offset);
 
 int aarch64_decode_b (CORE_ADDR addr, uint32_t insn, int *is_bl,
 		      int32_t *offset);
-- 
1.9.1


  reply	other threads:[~2015-09-18 12:43 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 11:31 [PATCH 0/8] [AArch64] Support fast tracepoints Pierre Langlois
2015-09-14 11:31 ` [PATCH 1/8] [AArch64] Use debug_printf instead of fprintf_unfiltered Pierre Langlois
2015-09-15 10:06   ` Yao Qi
2015-09-15 11:07     ` Pierre Langlois
2015-09-15 11:19       ` Yao Qi
2015-09-15 11:43         ` [PATCH 2/8 v2] " Pierre Langlois
2015-09-15 17:40           ` Pierre Langlois
2015-09-14 11:31 ` [PATCH 3/8] [AArch64] Make aarch64_decode_adrp handle both ADR and ADRP instructions Pierre Langlois
2015-09-15 10:12   ` Yao Qi
2015-09-15 12:05     ` [PATCH 3/8 v2] " Pierre Langlois
2015-09-14 11:32 ` [PATCH 7/8] [testsuite] Add a gdb.trace test for instruction relocation Pierre Langlois
2015-09-15 11:27   ` Yao Qi
2015-09-14 11:32 ` [PATCH 6/8] [testsuite][AArch64] Enable fast tracepoint tests Pierre Langlois
2015-09-15 10:18   ` Yao Qi
2015-09-14 11:32 ` [PATCH 5/8] [GDBserver][AArch64] Implement target_emit_ops Pierre Langlois
2015-09-14 11:33 ` [PATCH 4/8] [GDBserver][AArch64] Add support for fast tracepoints Pierre Langlois
2015-09-15 13:01   ` Yao Qi
2015-09-14 11:38 ` [PATCH 2/8] [AArch64] Move instruction decoding into new arch/ directory Pierre Langlois
2015-09-15 10:10   ` Yao Qi
2015-09-15 12:02     ` [PATCH 2/8 v2] " Pierre Langlois
2015-09-14 11:38 ` [PATCH 8/8] [testsuite] Add a test case for fast tracepoints' locking mechanism Pierre Langlois
2015-09-14 16:45 ` [PATCH] Add NEWS entry for fast tracepoint support on aarch64-linux Pierre Langlois
2015-09-18 12:43 ` [PATCH 0/8 V2] [AArch64] Support fast tracepoints Yao Qi
2015-09-18 12:43   ` Yao Qi [this message]
2015-09-18 12:43   ` [PATCH 5/8] Enable fast tracepoint tests Yao Qi
2015-09-18 12:43   ` [PATCH 7/8] Add a test case for fast tracepoints' locking mechanism Yao Qi
2015-09-18 12:43   ` [PATCH 1/8] Move instruction decoding into new arch/ directory Yao Qi
2015-09-18 12:43   ` [PATCH 4/8] Implement target_emit_ops Yao Qi
2015-09-18 12:57     ` Pierre Langlois
2016-02-05 20:09     ` Antoine Tremblay
2016-02-08 17:30       ` Yao Qi
2016-02-08 17:59         ` Antoine Tremblay
2015-09-18 12:43   ` [PATCH 8/8] Add NEWS entry for fast tracepoint support on aarch64-linux Yao Qi
2015-09-18 14:07     ` Eli Zaretskii
2015-09-18 12:44   ` [PATCH 3/8] Add support for fast tracepoints Yao Qi
2015-09-18 12:44   ` [PATCH 6/8] Add a gdb.trace test for instruction relocation Yao Qi
2015-09-21 14:06   ` [PATCH 0/8 V2] [AArch64] Support fast tracepoints Yao Qi

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=1442580184-22562-3-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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