Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kyle McMartin <kmcmarti@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] aarch64: extend decode_adrp to decode immediate offset
Date: Tue, 03 Jun 2014 05:02:00 -0000	[thread overview]
Message-ID: <20140603050153.GB15355@redacted.bos.redhat.com> (raw)
In-Reply-To: <20140603050011.GA15355@redacted.bos.redhat.com>

This is needed in order to figure out what an ADRP instruction is
attempting to calculate the address of, for use by a further
functionality.

gdb/
2014-06-03  Kyle McMartin  <kmcmarti@redhat.com>

	* aarch64-tdep.c (decode_adrp): Generalise function to handle
	ADR as well as ADRP, and decode the offset.
	(aarch64_analyze_prologue): Discard unneeded arguments to
	decode_adrp.
---
 gdb/aarch64-tdep.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 4abe36e..9550f42 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -255,7 +255,7 @@ decode_add_sub_imm (CORE_ADDR addr, uint32_t insn, unsigned *rd, unsigned *rn,
   return 0;
 }
 
-/* Decode an opcode if it represents an ADRP instruction.
+/* Decode an opcode if it represents an ADRP/ADR instruction.
 
    ADDR specifies the address of the opcode.
    INSN specifies the opcode to test.
@@ -264,16 +264,28 @@ decode_add_sub_imm (CORE_ADDR addr, uint32_t insn, unsigned *rd, unsigned *rn,
    Return 1 if the opcodes matches and is decoded, otherwise 0.  */
 
 static int
-decode_adrp (CORE_ADDR addr, uint32_t insn, unsigned *rd)
+decode_adrp (CORE_ADDR addr, uint32_t insn, int *page, unsigned *rd,
+	     int64_t *imm)
 {
-  if (decode_masked_match (insn, 0x9f000000, 0x90000000))
+  if (decode_masked_match (insn, 0x1f000000, 0x10000000))
     {
       *rd = (insn >> 0) & 0x1f;
+      *imm = (extract_signed_bitfield (insn, 19, 5) << 2)
+	      | ((insn >> 29) & 0x3);
+      *page = 0;
+
+      if (insn & 0x80000000)
+	{
+	  *page = 1;
+	  *imm <<= 12;
+	}
 
       if (aarch64_debug)
 	fprintf_unfiltered (gdb_stdlog,
-			    "decode: 0x%s 0x%x adrp x%u, #?\n",
-			    core_addr_to_string_nz (addr), insn, *rd);
+			    "decode: 0x%s 0x%x %s x%u, #0x%llx\n",
+			    core_addr_to_string_nz (addr), insn,
+			    *page ? "adrp" : "adr", *rd,
+			    (unsigned long long)*imm);
       return 1;
     }
   return 0;
@@ -681,8 +693,10 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       unsigned rt2;
       int op_is_sub;
       int32_t imm;
+      int64_t imm64;
       unsigned cond;
       int is64;
+      int page;
       unsigned is_link;
       unsigned op;
       unsigned bit;
@@ -692,7 +706,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
 
       if (decode_add_sub_imm (start, insn, &rd, &rn, &imm))
 	regs[rd] = pv_add_constant (regs[rn], imm);
-      else if (decode_adrp (start, insn, &rd))
+      else if (decode_adrp (start, insn, &page, &rd, &imm64))
 	regs[rd] = pv_unknown ();
       else if (decode_b (start, insn, &is_link, &offset))
 	{
-- 
1.9.3


  reply	other threads:[~2014-06-03  5:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03  5:00 [PATCH 0/2] aarch64: skip over stack protector setup in function prologues Kyle McMartin
2014-06-03  5:02 ` Kyle McMartin [this message]
2014-06-03  8:22   ` [PATCH 1/2] aarch64: extend decode_adrp to decode immediate offset Marcus Shawcroft
2014-06-03 14:50     ` Kyle McMartin
2014-06-03  5:03 ` [PATCH 2/2] aarch64: implement walking over the stack protector Kyle McMartin
2014-06-03  5:42   ` Andrew Pinski
2014-06-03 14:51     ` Kyle McMartin
2014-06-05 20:06       ` Kyle McMartin
2014-06-05 20:36         ` Andrew Pinski
2014-06-05 20:53           ` Kyle McMartin

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=20140603050153.GB15355@redacted.bos.redhat.com \
    --to=kmcmarti@redhat.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