public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] backends: add ARM compatible mode to AARCH64
@ 2014-03-28 14:13 Jean Pihet
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Pihet @ 2014-03-28 14:13 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 2053 bytes --]

Add the initial register setup for AARCH64 running ARM code (so
called the compat mode).
This makes 'eu-stack -p' happy on ARM binaries.

Based on the latest mjw/aarch64-unwind branch.

Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
---
 backends/arm_initreg.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/backends/arm_initreg.c b/backends/arm_initreg.c
index c03146e..5837383 100644
--- a/backends/arm_initreg.c
+++ b/backends/arm_initreg.c
@@ -36,6 +36,12 @@
 # include <sys/ptrace.h>
 #endif
 
+#ifdef __aarch64__
+# include <linux/uio.h>
+# include <sys/user.h>
+# include <sys/ptrace.h>
+#endif
+
 #define BACKEND arm_
 #include "libebl_CPU.h"
 
@@ -44,15 +50,39 @@ arm_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
 			  ebl_tid_registers_t *setfunc __attribute__ ((unused)),
 			       void *arg __attribute__ ((unused)))
 {
-#if ! defined __arm__
+#if !defined __arm__ && !defined __aarch64__
   return false;
-#else
+#else	/* __arm__ || __aarch64__ */
+#if defined __arm__
   struct user_regs user_regs;
   if (ptrace (PTRACE_GETREGS, tid, NULL, &user_regs) != 0)
     return false;
+
   Dwarf_Word dwarf_regs[16];
+  /* R0..R12 SP LR PC */
   for (int i = 0; i < 16; i++)
     dwarf_regs[i] = user_regs.uregs[i];
+
   return setfunc (0, 16, dwarf_regs, arg);
+#elif defined __aarch64__
+  /* Compat mode: arm compatible code running on aarch64 */
+  int i;
+  struct user_pt_regs gregs;
+  struct iovec iovec;
+  iovec.iov_base = &gregs;
+  iovec.iov_len = sizeof (gregs);
+  if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0)
+    return false;
+
+  Dwarf_Word dwarf_regs[16];
+  /* R0..R12 SP LR PC, encoded as 32 bit quantities */
+  uint32_t *u32_ptr = (uint32_t *) &gregs.regs[0];
+  for (i = 0; i < 16; i++)
+    dwarf_regs[i] = u32_ptr[i];
+
+  return setfunc (0, 16, dwarf_regs, arg);
+#else
+# error "source file error, it cannot happen"
+#endif
 #endif
 }
-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] backends: add ARM compatible mode to AARCH64
@ 2014-03-30 11:08 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2014-03-30 11:08 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 591 bytes --]

On Fri, Mar 28, 2014 at 03:13:10PM +0100, Jean Pihet wrote:
> Add the initial register setup for AARCH64 running ARM code (so
> called the compat mode).
> This makes 'eu-stack -p' happy on ARM binaries.
> 
> Based on the latest mjw/aarch64-unwind branch.

Thanks, looks good.
I added a ChangeLog entry and pushed it to master since it doesn't
really depend on the aarch64 backend, but is just part of the arm
backend (although it is of course less useful without the aarch64
backend, I'll try to get a clean system setup and push it after
some more testing).

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-03-30 11:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-28 14:13 [PATCH] backends: add ARM compatible mode to AARCH64 Jean Pihet
2014-03-30 11:08 Mark Wielaard

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).