]> git.ipfire.org Git - ipfire-3.x.git/blame - libunwind/patches/libunwind-aarch64.patch
kernel: Enable /dev/mem
[ipfire-3.x.git] / libunwind / patches / libunwind-aarch64.patch
CommitLineData
add5a956
MT
1diff --git a/Makefile.am b/Makefile.am
2index d7278df..e24fe1e 100644
3--- a/Makefile.am
4+++ b/Makefile.am
5@@ -2,6 +2,9 @@ include_HEADERS = include/libunwind-dynamic.h \
6 include/libunwind-ptrace.h \
7 include/libunwind-coredump.h
8
9+if ARCH_AARCH64
10+include_HEADERS += include/libunwind-aarch64.h
11+endif
12 if ARCH_ARM
13 include_HEADERS += include/libunwind-arm.h
14 endif
15@@ -41,6 +44,9 @@ SUBDIRS = src tests doc
16 noinst_HEADERS = include/dwarf.h include/dwarf_i.h include/dwarf-eh.h \
17 include/compiler.h include/libunwind_i.h include/mempool.h \
18 include/remote.h \
19+ include/tdep-aarch64/dwarf-config.h \
20+ include/tdep-aarch64/jmpbuf.h \
21+ include/tdep-aarch64/libunwind_i.h \
22 include/tdep-arm/dwarf-config.h include/tdep-arm/ex_tables.h \
23 include/tdep-arm/jmpbuf.h include/tdep-arm/libunwind_i.h \
24 include/tdep-ia64/jmpbuf.h include/tdep-ia64/rse.h \
25diff --git a/README b/README
26index 71a631f..511fb0c 100644
27--- a/README
28+++ b/README
29@@ -9,6 +9,7 @@ several architecture/operating-system combinations:
30 Linux/IA-64: Fully tested and supported.
31 Linux/PARISC: Works well, but C library missing unwind-info.
32 HP-UX/IA-64: Mostly works but known to have some serious limitations.
33+ Linux/AArch64: Newly added.
34 Linux/PPC64: Newly added.
35 Linux/SuperH: Newly added.
36 FreeBSD/i386: Newly added.
37diff --git a/configure.ac b/configure.ac
38index cffe19b..096ca7b 100644
39--- a/configure.ac
40+++ b/configure.ac
41@@ -104,7 +104,7 @@ SET_ARCH([$target_cpu],[target_arch])
42
43 AC_ARG_ENABLE(coredump,
44 AS_HELP_STRING([--enable-coredump],[building libunwind-coredump library]),,
45- [AS_CASE([$host_arch], [arm*|mips*|sh*|x86*], [enable_coredump=yes], [enable_coredump=no])]
46+ [AS_CASE([$host_arch], [aarch64*|arm*|mips*|sh*|x86*], [enable_coredump=yes], [enable_coredump=no])]
47 )
48
49 AC_MSG_CHECKING([if we should build libunwind-coredump])
50@@ -121,6 +121,7 @@ AC_MSG_RESULT([$target_os])
51
52 AM_CONDITIONAL(BUILD_COREDUMP, test x$enable_coredump = xyes)
53 AM_CONDITIONAL(REMOTE_ONLY, test x$target_arch != x$host_arch)
54+AM_CONDITIONAL(ARCH_AARCH64, test x$target_arch = xaarch64)
55 AM_CONDITIONAL(ARCH_ARM, test x$target_arch = xarm)
56 AM_CONDITIONAL(ARCH_IA64, test x$target_arch = xia64)
57 AM_CONDITIONAL(ARCH_HPPA, test x$target_arch = xhppa)
58@@ -137,7 +138,7 @@ AM_CONDITIONAL(OS_FREEBSD, expr x$target_os : xfreebsd >/dev/null)
59 AC_MSG_CHECKING([for ELF helper width])
60 case "${target_arch}" in
61 (arm|hppa|ppc32|x86|sh) use_elf32=yes; AC_MSG_RESULT([32]);;
62-(ia64|ppc64|x86_64) use_elf64=yes; AC_MSG_RESULT([64]);;
63+(aarch64|ia64|ppc64|x86_64) use_elf64=yes; AC_MSG_RESULT([64]);;
64 (mips) use_elfxx=yes; AC_MSG_RESULT([xx]);;
65 *) AC_MSG_ERROR([Unknown ELF target: ${target_arch}])
66 esac
67@@ -186,6 +187,7 @@ AS_HELP_STRING([--enable-cxx-exceptions],[use libunwind to handle C++ exceptions
68 # C++ exception handling doesn't work too well on x86
69 case $target_arch in
70 x86*) enable_cxx_exceptions=no;;
71+ aarch64*) enable_cxx_exceptions=no;;
72 arm*) enable_cxx_exceptions=no;;
73 mips*) enable_cxx_exceptions=no;;
74 *) enable_cxx_exceptions=yes;;
75diff --git a/include/libunwind-aarch64.h b/include/libunwind-aarch64.h
76new file mode 100644
77index 0000000..d50da8f
78--- /dev/null
79+++ b/include/libunwind-aarch64.h
80@@ -0,0 +1,187 @@
81+/* libunwind - a platform-independent unwind library
82+ Copyright (C) 2001-2004 Hewlett-Packard Co
83+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
84+ Copyright (C) 2013 Linaro Limited
85+
86+This file is part of libunwind.
87+
88+Permission is hereby granted, free of charge, to any person obtaining
89+a copy of this software and associated documentation files (the
90+"Software"), to deal in the Software without restriction, including
91+without limitation the rights to use, copy, modify, merge, publish,
92+distribute, sublicense, and/or sell copies of the Software, and to
93+permit persons to whom the Software is furnished to do so, subject to
94+the following conditions:
95+
96+The above copyright notice and this permission notice shall be
97+included in all copies or substantial portions of the Software.
98+
99+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
100+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
101+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
102+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
103+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
104+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
105+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
106+
107+#ifndef LIBUNWIND_H
108+#define LIBUNWIND_H
109+
110+#if defined(__cplusplus) || defined(c_plusplus)
111+extern "C" {
112+#endif
113+
114+#include <inttypes.h>
115+#include <stddef.h>
116+#include <ucontext.h>
117+
118+#define UNW_TARGET aarch64
119+#define UNW_TARGET_AARCH64 1
120+
121+#define _U_TDEP_QP_TRUE 0 /* see libunwind-dynamic.h */
122+
123+/* This needs to be big enough to accommodate "struct cursor", while
124+ leaving some slack for future expansion. Changing this value will
125+ require recompiling all users of this library. Stack allocation is
126+ relatively cheap and unwind-state copying is relatively rare, so we
127+ want to err on making it rather too big than too small. */
128+
129+#define UNW_TDEP_CURSOR_LEN 4096
130+
131+typedef uint64_t unw_word_t;
132+typedef int64_t unw_sword_t;
133+
134+typedef long double unw_tdep_fpreg_t;
135+
136+typedef struct
137+ {
138+ /* no aarch64-specific auxiliary proc-info */
139+ }
140+unw_tdep_proc_info_t;
141+
142+typedef enum
143+ {
144+ /* 64-bit general registers. */
145+ UNW_AARCH64_X0,
146+ UNW_AARCH64_X1,
147+ UNW_AARCH64_X2,
148+ UNW_AARCH64_X3,
149+ UNW_AARCH64_X4,
150+ UNW_AARCH64_X5,
151+ UNW_AARCH64_X6,
152+ UNW_AARCH64_X7,
153+ UNW_AARCH64_X8,
154+
155+ /* Temporary registers. */
156+ UNW_AARCH64_X9,
157+ UNW_AARCH64_X10,
158+ UNW_AARCH64_X11,
159+ UNW_AARCH64_X12,
160+ UNW_AARCH64_X13,
161+ UNW_AARCH64_X14,
162+ UNW_AARCH64_X15,
163+
164+ /* Intra-procedure-call temporary registers. */
165+ UNW_AARCH64_X16,
166+ UNW_AARCH64_X17,
167+
168+ /* Callee-saved registers. */
169+ UNW_AARCH64_X18,
170+ UNW_AARCH64_X19,
171+ UNW_AARCH64_X20,
172+ UNW_AARCH64_X21,
173+ UNW_AARCH64_X22,
174+ UNW_AARCH64_X23,
175+ UNW_AARCH64_X24,
176+ UNW_AARCH64_X25,
177+ UNW_AARCH64_X26,
178+ UNW_AARCH64_X27,
179+ UNW_AARCH64_X28,
180+
181+ /* 64-bit frame pointer. */
182+ UNW_AARCH64_X29,
183+
184+ /* 64-bit link register. */
185+ UNW_AARCH64_X30,
186+
187+ /* 64-bit stack pointer. */
188+ UNW_AARCH64_SP = 31,
189+ UNW_AARCH64_PC,
190+ UNW_AARCH64_PSTATE,
191+
192+ /* 128-bit FP/Advanced SIMD registers. */
193+ UNW_AARCH64_V0 = 64,
194+ UNW_AARCH64_V1,
195+ UNW_AARCH64_V2,
196+ UNW_AARCH64_V3,
197+ UNW_AARCH64_V4,
198+ UNW_AARCH64_V5,
199+ UNW_AARCH64_V6,
200+ UNW_AARCH64_V7,
201+ UNW_AARCH64_V8,
202+ UNW_AARCH64_V9,
203+ UNW_AARCH64_V10,
204+ UNW_AARCH64_V11,
205+ UNW_AARCH64_V12,
206+ UNW_AARCH64_V13,
207+ UNW_AARCH64_V14,
208+ UNW_AARCH64_V15,
209+ UNW_AARCH64_V16,
210+ UNW_AARCH64_V17,
211+ UNW_AARCH64_V18,
212+ UNW_AARCH64_V19,
213+ UNW_AARCH64_V20,
214+ UNW_AARCH64_V21,
215+ UNW_AARCH64_V22,
216+ UNW_AARCH64_V23,
217+ UNW_AARCH64_V24,
218+ UNW_AARCH64_V25,
219+ UNW_AARCH64_V26,
220+ UNW_AARCH64_V27,
221+ UNW_AARCH64_V28,
222+ UNW_AARCH64_V29,
223+ UNW_AARCH64_V30,
224+ UNW_AARCH64_V31,
225+
226+ UNW_AARCH64_FPSR,
227+ UNW_AARCH64_FPCR,
228+
229+ /* For AArch64, the CFA is the value of SP (x31) at the call site of the
230+ previous frame. */
231+ UNW_AARCH64_CFA = UNW_AARCH64_SP,
232+
233+ UNW_TDEP_LAST_REG = UNW_AARCH64_FPCR,
234+
235+ UNW_TDEP_IP = UNW_AARCH64_X30,
236+ UNW_TDEP_SP = UNW_AARCH64_SP,
237+ UNW_TDEP_EH = UNW_AARCH64_X0,
238+
239+ }
240+aarch64_regnum_t;
241+
242+/* Use R0 through R3 to pass exception handling information. */
243+#define UNW_TDEP_NUM_EH_REGS 4
244+
245+typedef struct unw_tdep_save_loc
246+ {
247+ /* Additional target-dependent info on a save location. */
248+ }
249+unw_tdep_save_loc_t;
250+
251+
252+/* On AArch64, we can directly use ucontext_t as the unwind context. */
253+typedef ucontext_t unw_tdep_context_t;
254+
255+#include "libunwind-common.h"
256+#include "libunwind-dynamic.h"
257+
258+#define unw_tdep_getcontext(uc) (getcontext (uc), 0)
259+#define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg)
260+
261+extern int unw_tdep_is_fpreg (int);
262+
263+#if defined(__cplusplus) || defined(c_plusplus)
264+}
265+#endif
266+
267+#endif /* LIBUNWIND_H */
268diff --git a/include/libunwind.h.in b/include/libunwind.h.in
269index 25c4e3b..64b1457 100644
270--- a/include/libunwind.h.in
271+++ b/include/libunwind.h.in
272@@ -3,7 +3,9 @@
273
274 #ifndef UNW_REMOTE_ONLY
275
276-#if defined __arm__
277+#if defined __aarch64__
278+#include "libunwind-aarch64.h"
279+#elif defined __arm__
280 # include "libunwind-arm.h"
281 #elif defined __hppa__
282 # include "libunwind-hppa.h"
283diff --git a/include/tdep-aarch64/dwarf-config.h b/include/tdep-aarch64/dwarf-config.h
284new file mode 100644
285index 0000000..c3bbed5
286--- /dev/null
287+++ b/include/tdep-aarch64/dwarf-config.h
288@@ -0,0 +1,52 @@
289+/* libunwind - a platform-independent unwind library
290+ Copyright (C) 2008 CodeSourcery
291+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
292+ Copyright (C) 2013 Linaro Limited
293+
294+This file is part of libunwind.
295+
296+Permission is hereby granted, free of charge, to any person obtaining
297+a copy of this software and associated documentation files (the
298+"Software"), to deal in the Software without restriction, including
299+without limitation the rights to use, copy, modify, merge, publish,
300+distribute, sublicense, and/or sell copies of the Software, and to
301+permit persons to whom the Software is furnished to do so, subject to
302+the following conditions:
303+
304+The above copyright notice and this permission notice shall be
305+included in all copies or substantial portions of the Software.
306+
307+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
308+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
309+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
310+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
311+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
312+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
313+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
314+
315+#ifndef dwarf_config_h
316+#define dwarf_config_h
317+
318+/* This matches the value udes by GCC (see
319+ gcc/config/aarch64/aarch64.h:DWARF_FRAME_REGISTERS. */
320+#define DWARF_NUM_PRESERVED_REGS 97
321+
322+/* Return TRUE if the ADDR_SPACE uses big-endian byte-order. */
323+#define dwarf_is_big_endian(addr_space) 0
324+
325+#define dwarf_to_unw_regnum(reg) (((reg) <= UNW_AARCH64_V31) ? (reg) : 0)
326+
327+/* Convert a pointer to a dwarf_cursor structure to a pointer to
328+ unw_cursor_t. */
329+#define dwarf_to_cursor(c) ((unw_cursor_t *) (c))
330+
331+typedef struct dwarf_loc
332+ {
333+ unw_word_t val;
334+#ifndef UNW_LOCAL_ONLY
335+ unw_word_t type; /* see DWARF_LOC_TYPE_* macros. */
336+#endif
337+ }
338+dwarf_loc_t;
339+
340+#endif /* dwarf_config_h */
341diff --git a/include/tdep-aarch64/jmpbuf.h b/include/tdep-aarch64/jmpbuf.h
342new file mode 100644
343index 0000000..2eb53a7
344--- /dev/null
345+++ b/include/tdep-aarch64/jmpbuf.h
346@@ -0,0 +1,33 @@
347+/* libunwind - a platform-independent unwind library
348+ Copyright (C) 2008 CodeSourcery
349+ Copyright (C) 2013 Linaro Limited
350+
351+This file is part of libunwind.
352+
353+Permission is hereby granted, free of charge, to any person obtaining
354+a copy of this software and associated documentation files (the
355+"Software"), to deal in the Software without restriction, including
356+without limitation the rights to use, copy, modify, merge, publish,
357+distribute, sublicense, and/or sell copies of the Software, and to
358+permit persons to whom the Software is furnished to do so, subject to
359+the following conditions:
360+
361+The above copyright notice and this permission notice shall be
362+included in all copies or substantial portions of the Software.
363+
364+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
365+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
366+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
367+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
368+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
369+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
370+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
371+
372+/* Use glibc's jump-buffer indices; NPTL peeks at SP: */
373+
374+/* FIXME for AArch64 */
375+
376+#define JB_SP 13
377+#define JB_RP 14
378+#define JB_MASK_SAVED 15
379+#define JB_MASK 16
380diff --git a/include/tdep-aarch64/libunwind_i.h b/include/tdep-aarch64/libunwind_i.h
381new file mode 100644
382index 0000000..28943db
383--- /dev/null
384+++ b/include/tdep-aarch64/libunwind_i.h
385@@ -0,0 +1,294 @@
386+/* libunwind - a platform-independent unwind library
387+ Copyright (C) 2001-2005 Hewlett-Packard Co
388+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
389+ Copyright (C) 2013 Linaro Limited
390+
391+This file is part of libunwind.
392+
393+Permission is hereby granted, free of charge, to any person obtaining
394+a copy of this software and associated documentation files (the
395+"Software"), to deal in the Software without restriction, including
396+without limitation the rights to use, copy, modify, merge, publish,
397+distribute, sublicense, and/or sell copies of the Software, and to
398+permit persons to whom the Software is furnished to do so, subject to
399+the following conditions:
400+
401+The above copyright notice and this permission notice shall be
402+included in all copies or substantial portions of the Software.
403+
404+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
405+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
406+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
407+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
408+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
409+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
410+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
411+
412+#ifndef AARCH64_LIBUNWIND_I_H
413+#define AARCH64_LIBUNWIND_I_H
414+
415+/* Target-dependent definitions that are internal to libunwind but need
416+ to be shared with target-independent code. */
417+
418+#include <stdlib.h>
419+#include <libunwind.h>
420+
421+#include "elf64.h"
422+#include "mempool.h"
423+#include "dwarf.h"
424+
425+typedef struct
426+ {
427+ /* no aarch64-specific fast trace */
428+ }
429+unw_tdep_frame_t;
430+
431+#ifdef UNW_LOCAL_ONLY
432+
433+typedef unw_word_t aarch64_loc_t;
434+
435+#else /* !UNW_LOCAL_ONLY */
436+
437+typedef struct aarch64_loc
438+ {
439+ unw_word_t w0, w1;
440+ }
441+aarch64_loc_t;
442+
443+#endif /* !UNW_LOCAL_ONLY */
444+
445+struct unw_addr_space
446+ {
447+ struct unw_accessors acc;
448+ int big_endian;
449+ unw_caching_policy_t caching_policy;
450+#ifdef HAVE_ATOMIC_OPS_H
451+ AO_t cache_generation;
452+#else
453+ uint32_t cache_generation;
454+#endif
455+ unw_word_t dyn_generation; /* see dyn-common.h */
456+ unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
457+ struct dwarf_rs_cache global_cache;
458+ struct unw_debug_frame_list *debug_frames;
459+ };
460+
461+struct cursor
462+ {
463+ struct dwarf_cursor dwarf; /* must be first */
464+ enum
465+ {
466+ AARCH64_SCF_NONE,
467+ AARCH64_SCF_LINUX_RT_SIGFRAME,
468+ }
469+ sigcontext_format;
470+ unw_word_t sigcontext_addr;
471+ unw_word_t sigcontext_sp;
472+ unw_word_t sigcontext_pc;
473+ };
474+
475+#define DWARF_GET_LOC(l) ((l).val)
476+
477+#ifdef UNW_LOCAL_ONLY
478+# define DWARF_NULL_LOC DWARF_LOC (0, 0)
479+# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
480+# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
481+# define DWARF_IS_REG_LOC(l) 0
482+# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
483+ tdep_uc_addr((c)->as_arg, (r)), 0))
484+# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
485+# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
486+ tdep_uc_addr((c)->as_arg, (r)), 0))
487+
488+static inline int
489+dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
490+{
491+ if (!DWARF_GET_LOC (loc))
492+ return -1;
493+ *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
494+ return 0;
495+}
496+
497+static inline int
498+dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
499+{
500+ if (!DWARF_GET_LOC (loc))
501+ return -1;
502+ *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
503+ return 0;
504+}
505+
506+static inline int
507+dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
508+{
509+ if (!DWARF_GET_LOC (loc))
510+ return -1;
511+ *val = *(unw_word_t *) DWARF_GET_LOC (loc);
512+ return 0;
513+}
514+
515+static inline int
516+dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
517+{
518+ if (!DWARF_GET_LOC (loc))
519+ return -1;
520+ *(unw_word_t *) DWARF_GET_LOC (loc) = val;
521+ return 0;
522+}
523+
524+#else /* !UNW_LOCAL_ONLY */
525+# define DWARF_LOC_TYPE_FP (1 << 0)
526+# define DWARF_LOC_TYPE_REG (1 << 1)
527+# define DWARF_NULL_LOC DWARF_LOC (0, 0)
528+# define DWARF_IS_NULL_LOC(l) \
529+ ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
530+# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
531+# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
532+# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
533+# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
534+# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
535+# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
536+ | DWARF_LOC_TYPE_FP))
537+
538+static inline int
539+dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
540+{
541+ char *valp = (char *) &val;
542+ unw_word_t addr;
543+ int ret;
544+
545+ if (DWARF_IS_NULL_LOC (loc))
546+ return -UNW_EBADREG;
547+
548+ if (DWARF_IS_REG_LOC (loc))
549+ return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
550+ val, 0, c->as_arg);
551+
552+ addr = DWARF_GET_LOC (loc);
553+ if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
554+ 0, c->as_arg)) < 0)
555+ return ret;
556+
557+ return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0,
558+ c->as_arg);
559+}
560+
561+static inline int
562+dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
563+{
564+ char *valp = (char *) &val;
565+ unw_word_t addr;
566+ int ret;
567+
568+ if (DWARF_IS_NULL_LOC (loc))
569+ return -UNW_EBADREG;
570+
571+ if (DWARF_IS_REG_LOC (loc))
572+ return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
573+ &val, 1, c->as_arg);
574+
575+ addr = DWARF_GET_LOC (loc);
576+ if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
577+ 1, c->as_arg)) < 0)
578+ return ret;
579+
580+ return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1,
581+ 1, c->as_arg);
582+}
583+
584+static inline int
585+dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
586+{
587+ if (DWARF_IS_NULL_LOC (loc))
588+ return -UNW_EBADREG;
589+
590+ /* If a code-generator were to save a value of type unw_word_t in a
591+ floating-point register, we would have to support this case. I
592+ suppose it could happen with MMX registers, but does it really
593+ happen? */
594+ assert (!DWARF_IS_FP_LOC (loc));
595+
596+ if (DWARF_IS_REG_LOC (loc))
597+ return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
598+ 0, c->as_arg);
599+ else
600+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
601+ 0, c->as_arg);
602+}
603+
604+static inline int
605+dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
606+{
607+ if (DWARF_IS_NULL_LOC (loc))
608+ return -UNW_EBADREG;
609+
610+ /* If a code-generator were to save a value of type unw_word_t in a
611+ floating-point register, we would have to support this case. I
612+ suppose it could happen with MMX registers, but does it really
613+ happen? */
614+ assert (!DWARF_IS_FP_LOC (loc));
615+
616+ if (DWARF_IS_REG_LOC (loc))
617+ return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
618+ 1, c->as_arg);
619+ else
620+ return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
621+ 1, c->as_arg);
622+}
623+
624+#endif /* !UNW_LOCAL_ONLY */
625+
626+
627+
628+#define tdep_getcontext_trace unw_getcontext
629+#define tdep_init_done UNW_OBJ(init_done)
630+#define tdep_init UNW_OBJ(init)
631+/* Platforms that support UNW_INFO_FORMAT_TABLE need to define
632+ tdep_search_unwind_table. */
633+#define tdep_search_unwind_table dwarf_search_unwind_table
634+#define tdep_find_unwind_table dwarf_find_unwind_table
635+#define tdep_uc_addr UNW_OBJ(uc_addr)
636+#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
637+#define tdep_access_reg UNW_OBJ(access_reg)
638+#define tdep_access_fpreg UNW_OBJ(access_fpreg)
639+#define tdep_fetch_frame(c,ip,n) do {} while(0)
640+#define tdep_cache_frame(c,rs) do {} while(0)
641+#define tdep_reuse_frame(c,rs) do {} while(0)
642+#define tdep_stash_frame(c,rs) do {} while(0)
643+#define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
644+
645+#ifdef UNW_LOCAL_ONLY
646+# define tdep_find_proc_info(c,ip,n) \
647+ dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
648+ (c)->as_arg)
649+# define tdep_put_unwind_info(as,pi,arg) \
650+ dwarf_put_unwind_info((as), (pi), (arg))
651+#else
652+# define tdep_find_proc_info(c,ip,n) \
653+ (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
654+ (c)->as_arg)
655+# define tdep_put_unwind_info(as,pi,arg) \
656+ (*(as)->acc.put_unwind_info)((as), (pi), (arg))
657+#endif
658+
659+#define tdep_get_as(c) ((c)->dwarf.as)
660+#define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
661+#define tdep_get_ip(c) ((c)->dwarf.ip)
662+#define tdep_big_endian(as) ((as)->big_endian)
663+
664+extern int tdep_init_done;
665+
666+extern void tdep_init (void);
667+extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
668+ unw_dyn_info_t *di, unw_proc_info_t *pi,
669+ int need_unwind_info, void *arg);
670+extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
671+extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
672+ unsigned long *segbase, unsigned long *mapoff,
673+ char *path, size_t pathlen);
674+extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
675+ unw_word_t *valp, int write);
676+extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
677+ unw_fpreg_t *valp, int write);
678+
679+#endif /* AARCH64_LIBUNWIND_I_H */
680diff --git a/include/tdep/dwarf-config.h b/include/tdep/dwarf-config.h
681index 1da268b..5b09fc1 100644
682--- a/include/tdep/dwarf-config.h
683+++ b/include/tdep/dwarf-config.h
684@@ -1,7 +1,9 @@
685 /* Provide a real file - not a symlink - as it would cause multiarch conflicts
686 when multiple different arch releases are installed simultaneously. */
687
688-#if defined __arm__
689+#if defined __aarch64__
690+# include "tdep-aarch64/dwarf-config.h"
691+#elif defined __arm__
692 # include "tdep-arm/dwarf-config.h"
693 #elif defined __hppa__
694 # include "tdep-hppa/dwarf-config.h"
695diff --git a/include/tdep/jmpbuf.h b/include/tdep/jmpbuf.h
696index 7d04a42..684d0d9 100644
697--- a/include/tdep/jmpbuf.h
698+++ b/include/tdep/jmpbuf.h
699@@ -3,6 +3,8 @@
700
701 #ifndef UNW_REMOTE_ONLY
702
703+#if defined __aarch64__
704+# include "tdep-aarch64/jmpbuf.h"
705 #if defined __arm__
706 # include "tdep-arm/jmpbuf.h"
707 #elif defined __hppa__
708diff --git a/include/tdep/libunwind_i.h.in b/include/tdep/libunwind_i.h.in
709index 2ad6269..475f828 100644
710--- a/include/tdep/libunwind_i.h.in
711+++ b/include/tdep/libunwind_i.h.in
712@@ -3,7 +3,9 @@
713
714 #ifndef UNW_REMOTE_ONLY
715
716-#if defined __arm__
717+#if defined __aarch64__
718+# include "tdep-aarch64/libunwind_i.h"
719+#elif defined __arm__
720 # include "tdep-arm/libunwind_i.h"
721 #elif defined __hppa__
722 # include "tdep-hppa/libunwind_i.h"
723diff --git a/src/Makefile.am b/src/Makefile.am
724index 08d2870..f104214 100644
725--- a/src/Makefile.am
726+++ b/src/Makefile.am
727@@ -170,6 +170,28 @@ libunwind_elfxx_la_SOURCES = elfxx.c
728 noinst_LTLIBRARIES += $(LIBUNWIND_ELF)
729 libunwind_la_LIBADD += $(LIBUNWIND_ELF)
730
731+# The list of files that go into libunwind and libunwind-aarch64:
732+noinst_HEADERS += aarch64/init.h aarch64/offsets.h aarch64/unwind_i.h
733+libunwind_la_SOURCES_aarch64_common = $(libunwind_la_SOURCES_common) \
734+ aarch64/is_fpreg.c aarch64/regname.c
735+
736+# The list of files that go into libunwind:
737+libunwind_la_SOURCES_aarch64 = $(libunwind_la_SOURCES_aarch64_common) \
738+ $(libunwind_la_SOURCES_local) \
739+ aarch64/Lcreate_addr_space.c aarch64/Lget_proc_info.c \
740+ aarch64/Lget_save_loc.c aarch64/Lglobal.c aarch64/Linit.c \
741+ aarch64/Linit_local.c aarch64/Linit_remote.c \
742+ aarch64/Lis_signal_frame.c aarch64/Lregs.c aarch64/Lresume.c \
743+ aarch64/Lstep.c
744+
745+libunwind_aarch64_la_SOURCES_aarch64 = $(libunwind_la_SOURCES_aarch64_common) \
746+ $(libunwind_la_SOURCES_generic) \
747+ aarch64/Gcreate_addr_space.c aarch64/Gget_proc_info.c \
748+ aarch64/Gget_save_loc.c aarch64/Gglobal.c aarch64/Ginit.c \
749+ aarch64/Ginit_local.c aarch64/Ginit_remote.c \
750+ aarch64/Gis_signal_frame.c aarch64/Gregs.c aarch64/Gresume.c \
751+ aarch64/Gstep.c
752+
753 # The list of files that go into libunwind and libunwind-arm:
754 noinst_HEADERS += arm/init.h arm/offsets.h arm/unwind_i.h
755 libunwind_la_SOURCES_arm_common = $(libunwind_la_SOURCES_common) \
756@@ -418,6 +440,18 @@ if OS_FREEBSD
757 libunwind_coredump_la_SOURCES += coredump/_UCD_access_reg_freebsd.c
758 endif
759
760+if ARCH_AARCH64
761+ lib_LTLIBRARIES += libunwind-aarch64.la
762+ libunwind_la_SOURCES = $(libunwind_la_SOURCES_aarch64)
763+ libunwind_aarch64_la_SOURCES = $(libunwind_aarch64_la_SOURCES_aarch64)
764+ libunwind_aarch64_la_LDFLAGS = $(COMMON_SO_LDFLAGS) -version-info $(SOVERSION)
765+ libunwind_aarch64_la_LIBADD = libunwind-dwarf-generic.la
766+ libunwind_aarch64_la_LIBADD += libunwind-elf64.la
767+if !REMOTE_ONLY
768+ libunwind_aarch64_la_LIBADD += libunwind.la -lc
769+endif
770+# libunwind_setjmp_la_SOURCES += aarch64/siglongjmp.S
771+else
772 if ARCH_ARM
773 lib_LTLIBRARIES += libunwind-arm.la
774 libunwind_la_SOURCES = $(libunwind_la_SOURCES_arm)
775@@ -545,6 +579,7 @@ endif # ARCH_MIPS
776 endif # ARCH_HPPA
777 endif # ARCH_IA64
778 endif # ARCH_ARM
779+endif # ARCH_AARCH64
780
781 # libunwind-setjmp depends on libunwind-$(arch). Therefore must be added
782 # at the end.
783@@ -567,7 +602,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/tdep-$(arch) -I.
784 AM_CCASFLAGS = $(AM_CPPFLAGS)
785 noinst_HEADERS += unwind/unwind-internal.h
786
787-EXTRA_DIST = $(libunwind_la_SOURCES_arm) \
788+EXTRA_DIST = $(libunwind_la_SOURCES_aarch64) \
789+ $(libunwind_la_SOURCES_arm) \
790 $(libunwind_la_SOURCES_hppa) \
791 $(libunwind_la_SOURCES_ia64) \
792 $(libunwind_la_SOURCES_mips) \
793@@ -579,6 +615,7 @@ EXTRA_DIST = $(libunwind_la_SOURCES_arm) \
794 $(libunwind_la_SOURCES_common) \
795 $(libunwind_la_SOURCES_local) \
796 $(libunwind_la_SOURCES_generic) \
797+ $(libunwind_aarch64_la_SOURCES_aarch64) \
798 $(libunwind_arm_la_SOURCES_arm) \
799 $(libunwind_hppa_la_SOURCES_hppa) \
800 $(libunwind_ia64_la_SOURCES_ia64) \
801diff --git a/src/aarch64/Gcreate_addr_space.c b/src/aarch64/Gcreate_addr_space.c
802new file mode 100644
803index 0000000..b0f2b04
804--- /dev/null
805+++ b/src/aarch64/Gcreate_addr_space.c
806@@ -0,0 +1,60 @@
807+/* libunwind - a platform-independent unwind library
808+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
809+ Copyright (C) 2013 Linaro Limited
810+
811+This file is part of libunwind.
812+
813+Permission is hereby granted, free of charge, to any person obtaining
814+a copy of this software and associated documentation files (the
815+"Software"), to deal in the Software without restriction, including
816+without limitation the rights to use, copy, modify, merge, publish,
817+distribute, sublicense, and/or sell copies of the Software, and to
818+permit persons to whom the Software is furnished to do so, subject to
819+the following conditions:
820+
821+The above copyright notice and this permission notice shall be
822+included in all copies or substantial portions of the Software.
823+
824+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
825+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
826+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
827+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
828+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
829+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
830+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
831+
832+#include <string.h>
833+#include <stdlib.h>
834+
835+#include "unwind_i.h"
836+
837+PROTECTED unw_addr_space_t
838+unw_create_addr_space (unw_accessors_t *a, int byte_order)
839+{
840+#ifdef UNW_LOCAL_ONLY
841+ return NULL;
842+#else
843+ unw_addr_space_t as;
844+
845+ /* AArch64 supports little-endian and big-endian. */
846+ if (byte_order != 0 && byte_order != __LITTLE_ENDIAN
847+ && byte_order != __BIG_ENDIAN)
848+ return NULL;
849+
850+ as = malloc (sizeof (*as));
851+ if (!as)
852+ return NULL;
853+
854+ memset (as, 0, sizeof (*as));
855+
856+ as->acc = *a;
857+
858+ /* Default to little-endian for AArch64. */
859+ if (byte_order == 0 || byte_order == __LITTLE_ENDIAN)
860+ as->big_endian = 0;
861+ else
862+ as->big_endian = 1;
863+
864+ return as;
865+#endif
866+}
867diff --git a/src/aarch64/Gget_proc_info.c b/src/aarch64/Gget_proc_info.c
868new file mode 100644
869index 0000000..de9199f
870--- /dev/null
871+++ b/src/aarch64/Gget_proc_info.c
872@@ -0,0 +1,39 @@
873+/* libunwind - a platform-independent unwind library
874+ Copyright (C) 2008 CodeSourcery
875+
876+This file is part of libunwind.
877+
878+Permission is hereby granted, free of charge, to any person obtaining
879+a copy of this software and associated documentation files (the
880+"Software"), to deal in the Software without restriction, including
881+without limitation the rights to use, copy, modify, merge, publish,
882+distribute, sublicense, and/or sell copies of the Software, and to
883+permit persons to whom the Software is furnished to do so, subject to
884+the following conditions:
885+
886+The above copyright notice and this permission notice shall be
887+included in all copies or substantial portions of the Software.
888+
889+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
890+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
891+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
892+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
893+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
894+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
895+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
896+
897+#include "unwind_i.h"
898+
899+PROTECTED int
900+unw_get_proc_info (unw_cursor_t *cursor, unw_proc_info_t *pi)
901+{
902+ struct cursor *c = (struct cursor *) cursor;
903+ int ret;
904+
905+ ret = dwarf_make_proc_info (&c->dwarf);
906+ if (ret < 0)
907+ return ret;
908+
909+ *pi = c->dwarf.pi;
910+ return 0;
911+}
912diff --git a/src/aarch64/Gget_save_loc.c b/src/aarch64/Gget_save_loc.c
913new file mode 100644
914index 0000000..c76eb9c
915--- /dev/null
916+++ b/src/aarch64/Gget_save_loc.c
917@@ -0,0 +1,100 @@
918+/* libunwind - a platform-independent unwind library
919+ Copyright (C) 2008 CodeSourcery
920+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
921+ Copyright (C) 2013 Linaro Limited
922+
923+This file is part of libunwind.
924+
925+Permission is hereby granted, free of charge, to any person obtaining
926+a copy of this software and associated documentation files (the
927+"Software"), to deal in the Software without restriction, including
928+without limitation the rights to use, copy, modify, merge, publish,
929+distribute, sublicense, and/or sell copies of the Software, and to
930+permit persons to whom the Software is furnished to do so, subject to
931+the following conditions:
932+
933+The above copyright notice and this permission notice shall be
934+included in all copies or substantial portions of the Software.
935+
936+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
937+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
938+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
939+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
940+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
941+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
942+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
943+
944+#include "unwind_i.h"
945+
946+PROTECTED int
947+unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc)
948+{
949+ struct cursor *c = (struct cursor *) cursor;
950+ dwarf_loc_t loc;
951+
952+ switch (reg)
953+ {
954+ case UNW_AARCH64_X0:
955+ case UNW_AARCH64_X1:
956+ case UNW_AARCH64_X2:
957+ case UNW_AARCH64_X3:
958+ case UNW_AARCH64_X4:
959+ case UNW_AARCH64_X5:
960+ case UNW_AARCH64_X6:
961+ case UNW_AARCH64_X7:
962+ case UNW_AARCH64_X8:
963+ case UNW_AARCH64_X9:
964+ case UNW_AARCH64_X10:
965+ case UNW_AARCH64_X11:
966+ case UNW_AARCH64_X12:
967+ case UNW_AARCH64_X13:
968+ case UNW_AARCH64_X14:
969+ case UNW_AARCH64_X15:
970+ case UNW_AARCH64_X16:
971+ case UNW_AARCH64_X17:
972+ case UNW_AARCH64_X18:
973+ case UNW_AARCH64_X19:
974+ case UNW_AARCH64_X20:
975+ case UNW_AARCH64_X21:
976+ case UNW_AARCH64_X22:
977+ case UNW_AARCH64_X23:
978+ case UNW_AARCH64_X24:
979+ case UNW_AARCH64_X25:
980+ case UNW_AARCH64_X26:
981+ case UNW_AARCH64_X27:
982+ case UNW_AARCH64_X28:
983+ case UNW_AARCH64_X29:
984+ case UNW_AARCH64_X30:
985+ case UNW_AARCH64_SP:
986+ case UNW_AARCH64_PC:
987+ case UNW_AARCH64_PSTATE:
988+ loc = c->dwarf.loc[reg];
989+ break;
990+
991+ default:
992+ loc = DWARF_NULL_LOC; /* default to "not saved" */
993+ break;
994+ }
995+
996+ memset (sloc, 0, sizeof (*sloc));
997+
998+ if (DWARF_IS_NULL_LOC (loc))
999+ {
1000+ sloc->type = UNW_SLT_NONE;
1001+ return 0;
1002+ }
1003+
1004+#if !defined(UNW_LOCAL_ONLY)
1005+ if (DWARF_IS_REG_LOC (loc))
1006+ {
1007+ sloc->type = UNW_SLT_REG;
1008+ sloc->u.regnum = DWARF_GET_LOC (loc);
1009+ }
1010+ else
1011+#endif
1012+ {
1013+ sloc->type = UNW_SLT_MEMORY;
1014+ sloc->u.addr = DWARF_GET_LOC (loc);
1015+ }
1016+ return 0;
1017+}
1018diff --git a/src/aarch64/Gglobal.c b/src/aarch64/Gglobal.c
1019new file mode 100644
1020index 0000000..b0a7e26
1021--- /dev/null
1022+++ b/src/aarch64/Gglobal.c
1023@@ -0,0 +1,57 @@
1024+/* libunwind - a platform-independent unwind library
1025+ Copyright (C) 2008 CodeSourcery
1026+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1027+ Copyright (C) 2013 Linaro Limited
1028+
1029+This file is part of libunwind.
1030+
1031+Permission is hereby granted, free of charge, to any person obtaining
1032+a copy of this software and associated documentation files (the
1033+"Software"), to deal in the Software without restriction, including
1034+without limitation the rights to use, copy, modify, merge, publish,
1035+distribute, sublicense, and/or sell copies of the Software, and to
1036+permit persons to whom the Software is furnished to do so, subject to
1037+the following conditions:
1038+
1039+The above copyright notice and this permission notice shall be
1040+included in all copies or substantial portions of the Software.
1041+
1042+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1043+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1044+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1045+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1046+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1047+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1048+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1049+
1050+#include "unwind_i.h"
1051+#include "dwarf_i.h"
1052+
1053+HIDDEN define_lock (aarch64_lock);
1054+HIDDEN int tdep_init_done;
1055+
1056+HIDDEN void
1057+tdep_init (void)
1058+{
1059+ intrmask_t saved_mask;
1060+
1061+ sigfillset (&unwi_full_mask);
1062+
1063+ lock_acquire (&aarch64_lock, saved_mask);
1064+ {
1065+ if (tdep_init_done)
1066+ /* another thread else beat us to it... */
1067+ goto out;
1068+
1069+ mi_init ();
1070+
1071+ dwarf_init ();
1072+
1073+#ifndef UNW_REMOTE_ONLY
1074+ aarch64_local_addr_space_init ();
1075+#endif
1076+ tdep_init_done = 1; /* signal that we're initialized... */
1077+ }
1078+ out:
1079+ lock_release (&aarch64_lock, saved_mask);
1080+}
1081diff --git a/src/aarch64/Ginit.c b/src/aarch64/Ginit.c
1082new file mode 100644
1083index 0000000..449b417
1084--- /dev/null
1085+++ b/src/aarch64/Ginit.c
1086@@ -0,0 +1,187 @@
1087+/* libunwind - a platform-independent unwind library
1088+ Copyright (C) 2008 CodeSourcery
1089+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1090+ Copyright (C) 2013 Linaro Limited
1091+
1092+This file is part of libunwind.
1093+
1094+Permission is hereby granted, free of charge, to any person obtaining
1095+a copy of this software and associated documentation files (the
1096+"Software"), to deal in the Software without restriction, including
1097+without limitation the rights to use, copy, modify, merge, publish,
1098+distribute, sublicense, and/or sell copies of the Software, and to
1099+permit persons to whom the Software is furnished to do so, subject to
1100+the following conditions:
1101+
1102+The above copyright notice and this permission notice shall be
1103+included in all copies or substantial portions of the Software.
1104+
1105+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1106+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1107+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1108+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1109+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1110+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1111+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1112+
1113+#include <stdlib.h>
1114+#include <string.h>
1115+
1116+#include "unwind_i.h"
1117+
1118+#ifdef UNW_REMOTE_ONLY
1119+
1120+/* unw_local_addr_space is a NULL pointer in this case. */
1121+PROTECTED unw_addr_space_t unw_local_addr_space;
1122+
1123+#else /* !UNW_REMOTE_ONLY */
1124+
1125+static struct unw_addr_space local_addr_space;
1126+
1127+PROTECTED unw_addr_space_t unw_local_addr_space = &local_addr_space;
1128+
1129+static inline void *
1130+uc_addr (ucontext_t *uc, int reg)
1131+{
1132+ if (reg >= UNW_AARCH64_X0 && reg <= UNW_AARCH64_V31)
1133+ return &uc->uc_mcontext.regs[reg];
1134+ else
1135+ return NULL;
1136+}
1137+
1138+# ifdef UNW_LOCAL_ONLY
1139+
1140+HIDDEN void *
1141+tdep_uc_addr (ucontext_t *uc, int reg)
1142+{
1143+ return uc_addr (uc, reg);
1144+}
1145+
1146+# endif /* UNW_LOCAL_ONLY */
1147+
1148+HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
1149+
1150+/* XXX fix me: there is currently no way to locate the dyn-info list
1151+ by a remote unwinder. On ia64, this is done via a special
1152+ unwind-table entry. Perhaps something similar can be done with
1153+ DWARF2 unwind info. */
1154+
1155+static void
1156+put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
1157+{
1158+ /* it's a no-op */
1159+}
1160+
1161+static int
1162+get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
1163+ void *arg)
1164+{
1165+ *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
1166+ return 0;
1167+}
1168+
1169+static int
1170+access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write,
1171+ void *arg)
1172+{
1173+ if (write)
1174+ {
1175+ Debug (16, "mem[%x] <- %x\n", addr, *val);
1176+ *(unw_word_t *) addr = *val;
1177+ }
1178+ else
1179+ {
1180+ *val = *(unw_word_t *) addr;
1181+ Debug (16, "mem[%x] -> %x\n", addr, *val);
1182+ }
1183+ return 0;
1184+}
1185+
1186+static int
1187+access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, int write,
1188+ void *arg)
1189+{
1190+ unw_word_t *addr;
1191+ ucontext_t *uc = arg;
1192+
1193+ if (unw_is_fpreg (reg))
1194+ goto badreg;
1195+
1196+ if (!(addr = uc_addr (uc, reg)))
1197+ goto badreg;
1198+
1199+ if (write)
1200+ {
1201+ *(unw_word_t *) addr = *val;
1202+ Debug (12, "%s <- %x\n", unw_regname (reg), *val);
1203+ }
1204+ else
1205+ {
1206+ *val = *(unw_word_t *) addr;
1207+ Debug (12, "%s -> %x\n", unw_regname (reg), *val);
1208+ }
1209+ return 0;
1210+
1211+ badreg:
1212+ Debug (1, "bad register number %u\n", reg);
1213+ return -UNW_EBADREG;
1214+}
1215+
1216+static int
1217+access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
1218+ int write, void *arg)
1219+{
1220+ ucontext_t *uc = arg;
1221+ unw_fpreg_t *addr;
1222+
1223+ if (!unw_is_fpreg (reg))
1224+ goto badreg;
1225+
1226+ if (!(addr = uc_addr (uc, reg)))
1227+ goto badreg;
1228+
1229+ if (write)
1230+ {
1231+ Debug (12, "%s <- %08lx.%08lx.%08lx\n", unw_regname (reg),
1232+ ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
1233+ *(unw_fpreg_t *) addr = *val;
1234+ }
1235+ else
1236+ {
1237+ *val = *(unw_fpreg_t *) addr;
1238+ Debug (12, "%s -> %08lx.%08lx.%08lx\n", unw_regname (reg),
1239+ ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
1240+ }
1241+ return 0;
1242+
1243+ badreg:
1244+ Debug (1, "bad register number %u\n", reg);
1245+ /* attempt to access a non-preserved register */
1246+ return -UNW_EBADREG;
1247+}
1248+
1249+static int
1250+get_static_proc_name (unw_addr_space_t as, unw_word_t ip,
1251+ char *buf, size_t buf_len, unw_word_t *offp,
1252+ void *arg)
1253+{
1254+ return _Uelf64_get_proc_name (as, getpid (), ip, buf, buf_len, offp);
1255+}
1256+
1257+HIDDEN void
1258+aarch64_local_addr_space_init (void)
1259+{
1260+ memset (&local_addr_space, 0, sizeof (local_addr_space));
1261+ local_addr_space.caching_policy = UNW_CACHE_GLOBAL;
1262+ local_addr_space.acc.find_proc_info = dwarf_find_proc_info;
1263+ local_addr_space.acc.put_unwind_info = put_unwind_info;
1264+ local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
1265+ local_addr_space.acc.access_mem = access_mem;
1266+ local_addr_space.acc.access_reg = access_reg;
1267+ local_addr_space.acc.access_fpreg = access_fpreg;
1268+ local_addr_space.acc.resume = aarch64_local_resume;
1269+ local_addr_space.acc.get_proc_name = get_static_proc_name;
1270+ unw_flush_cache (&local_addr_space, 0, 0);
1271+}
1272+
1273+#endif /* !UNW_REMOTE_ONLY */
1274diff --git a/src/aarch64/Ginit_local.c b/src/aarch64/Ginit_local.c
1275new file mode 100644
1276index 0000000..dee6fd3
1277--- /dev/null
1278+++ b/src/aarch64/Ginit_local.c
1279@@ -0,0 +1,55 @@
1280+/* libunwind - a platform-independent unwind library
1281+ Copyright (C) 2008 CodeSourcery
1282+ Copyright (C) 2011-2013 Linaro Limited
1283+
1284+This file is part of libunwind.
1285+
1286+Permission is hereby granted, free of charge, to any person obtaining
1287+a copy of this software and associated documentation files (the
1288+"Software"), to deal in the Software without restriction, including
1289+without limitation the rights to use, copy, modify, merge, publish,
1290+distribute, sublicense, and/or sell copies of the Software, and to
1291+permit persons to whom the Software is furnished to do so, subject to
1292+the following conditions:
1293+
1294+The above copyright notice and this permission notice shall be
1295+included in all copies or substantial portions of the Software.
1296+
1297+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1298+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1299+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1300+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1301+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1302+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1303+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1304+
1305+#include "unwind_i.h"
1306+#include "init.h"
1307+
1308+#ifdef UNW_REMOTE_ONLY
1309+
1310+PROTECTED int
1311+unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
1312+{
1313+ return -UNW_EINVAL;
1314+}
1315+
1316+#else /* !UNW_REMOTE_ONLY */
1317+
1318+PROTECTED int
1319+unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
1320+{
1321+ struct cursor *c = (struct cursor *) cursor;
1322+
1323+ if (!tdep_init_done)
1324+ tdep_init ();
1325+
1326+ Debug (1, "(cursor=%p)\n", c);
1327+
1328+ c->dwarf.as = unw_local_addr_space;
1329+ c->dwarf.as_arg = uc;
1330+
1331+ return common_init (c, 1);
1332+}
1333+
1334+#endif /* !UNW_REMOTE_ONLY */
1335diff --git a/src/aarch64/Ginit_remote.c b/src/aarch64/Ginit_remote.c
1336new file mode 100644
1337index 0000000..f284e99
1338--- /dev/null
1339+++ b/src/aarch64/Ginit_remote.c
1340@@ -0,0 +1,45 @@
1341+/* libunwind - a platform-independent unwind library
1342+ Copyright (C) 2008 CodeSourcery
1343+
1344+This file is part of libunwind.
1345+
1346+Permission is hereby granted, free of charge, to any person obtaining
1347+a copy of this software and associated documentation files (the
1348+"Software"), to deal in the Software without restriction, including
1349+without limitation the rights to use, copy, modify, merge, publish,
1350+distribute, sublicense, and/or sell copies of the Software, and to
1351+permit persons to whom the Software is furnished to do so, subject to
1352+the following conditions:
1353+
1354+The above copyright notice and this permission notice shall be
1355+included in all copies or substantial portions of the Software.
1356+
1357+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1358+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1359+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1360+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1361+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1362+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1363+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1364+
1365+#include "init.h"
1366+#include "unwind_i.h"
1367+
1368+PROTECTED int
1369+unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
1370+{
1371+#ifdef UNW_LOCAL_ONLY
1372+ return -UNW_EINVAL;
1373+#else /* !UNW_LOCAL_ONLY */
1374+ struct cursor *c = (struct cursor *) cursor;
1375+
1376+ if (!tdep_init_done)
1377+ tdep_init ();
1378+
1379+ Debug (1, "(cursor=%p)\n", c);
1380+
1381+ c->dwarf.as = as;
1382+ c->dwarf.as_arg = as_arg;
1383+ return common_init (c, 0);
1384+#endif /* !UNW_LOCAL_ONLY */
1385+}
1386diff --git a/src/aarch64/Gis_signal_frame.c b/src/aarch64/Gis_signal_frame.c
1387new file mode 100644
1388index 0000000..53e32de
1389--- /dev/null
1390+++ b/src/aarch64/Gis_signal_frame.c
1391@@ -0,0 +1,64 @@
1392+/* libunwind - a platform-independent unwind library
1393+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1394+ Copyright (C) 2013 Linaro Limited
1395+
1396+This file is part of libunwind.
1397+
1398+Permission is hereby granted, free of charge, to any person obtaining
1399+a copy of this software and associated documentation files (the
1400+"Software"), to deal in the Software without restriction, including
1401+without limitation the rights to use, copy, modify, merge, publish,
1402+distribute, sublicense, and/or sell copies of the Software, and to
1403+permit persons to whom the Software is furnished to do so, subject to
1404+the following conditions:
1405+
1406+The above copyright notice and this permission notice shall be
1407+included in all copies or substantial portions of the Software.
1408+
1409+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1410+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1411+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1412+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1413+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1414+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1415+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1416+
1417+#include "unwind_i.h"
1418+
1419+/* The restorer stub will always have the form:
1420+
1421+ d2801168 movz x8, #0x8b
1422+ d4000001 svc #0x0
1423+*/
1424+
1425+PROTECTED int
1426+unw_is_signal_frame (unw_cursor_t *cursor)
1427+{
1428+#ifdef __linux__
1429+ struct cursor *c = (struct cursor *) cursor;
1430+ unw_word_t w0, ip;
1431+ unw_addr_space_t as;
1432+ unw_accessors_t *a;
1433+ void *arg;
1434+ int ret;
1435+
1436+ as = c->dwarf.as;
1437+ a = unw_get_accessors (as);
1438+ arg = c->dwarf.as_arg;
1439+
1440+ ip = c->dwarf.ip;
1441+
1442+ ret = (*a->access_mem) (as, ip, &w0, 0, arg);
1443+ if (ret < 0)
1444+ return ret;
1445+
1446+ /* FIXME: distinguish 32bit insn vs 64bit registers. */
1447+ if (w0 != 0xd4000001d2801168)
1448+ return 0;
1449+
1450+ return 1;
1451+
1452+#else
1453+ return -UNW_ENOINFO;
1454+#endif
1455+}
1456diff --git a/src/aarch64/Gregs.c b/src/aarch64/Gregs.c
1457new file mode 100644
1458index 0000000..0f6b9c6
1459--- /dev/null
1460+++ b/src/aarch64/Gregs.c
1461@@ -0,0 +1,113 @@
1462+/* libunwind - a platform-independent unwind library
1463+ Copyright (C) 2008 CodeSourcery
1464+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1465+ Copyright (C) 2013 Linaro Limited
1466+
1467+This file is part of libunwind.
1468+
1469+Permission is hereby granted, free of charge, to any person obtaining
1470+a copy of this software and associated documentation files (the
1471+"Software"), to deal in the Software without restriction, including
1472+without limitation the rights to use, copy, modify, merge, publish,
1473+distribute, sublicense, and/or sell copies of the Software, and to
1474+permit persons to whom the Software is furnished to do so, subject to
1475+the following conditions:
1476+
1477+The above copyright notice and this permission notice shall be
1478+included in all copies or substantial portions of the Software.
1479+
1480+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1481+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1482+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1483+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1484+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1485+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1486+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1487+
1488+#include "unwind_i.h"
1489+
1490+HIDDEN int
1491+tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
1492+ int write)
1493+{
1494+ dwarf_loc_t loc = DWARF_NULL_LOC;
1495+ unsigned int mask;
1496+
1497+ switch (reg)
1498+ {
1499+ case UNW_AARCH64_X0:
1500+ case UNW_AARCH64_X1:
1501+ case UNW_AARCH64_X2:
1502+ case UNW_AARCH64_X3:
1503+ mask = 1 << reg;
1504+ if (write)
1505+ {
1506+ c->dwarf.eh_args[reg] = *valp;
1507+ c->dwarf.eh_valid_mask |= mask;
1508+ return 0;
1509+ }
1510+ else if ((c->dwarf.eh_valid_mask & mask) != 0)
1511+ {
1512+ *valp = c->dwarf.eh_args[reg];
1513+ return 0;
1514+ }
1515+ else
1516+ loc = c->dwarf.loc[reg];
1517+ break;
1518+
1519+ case UNW_AARCH64_X4:
1520+ case UNW_AARCH64_X5:
1521+ case UNW_AARCH64_X6:
1522+ case UNW_AARCH64_X7:
1523+ case UNW_AARCH64_X8:
1524+ case UNW_AARCH64_X9:
1525+ case UNW_AARCH64_X10:
1526+ case UNW_AARCH64_X11:
1527+ case UNW_AARCH64_X12:
1528+ case UNW_AARCH64_X13:
1529+ case UNW_AARCH64_X14:
1530+ case UNW_AARCH64_X15:
1531+ case UNW_AARCH64_X16:
1532+ case UNW_AARCH64_X17:
1533+ case UNW_AARCH64_X18:
1534+ case UNW_AARCH64_X19:
1535+ case UNW_AARCH64_X20:
1536+ case UNW_AARCH64_X21:
1537+ case UNW_AARCH64_X22:
1538+ case UNW_AARCH64_X23:
1539+ case UNW_AARCH64_X24:
1540+ case UNW_AARCH64_X25:
1541+ case UNW_AARCH64_X26:
1542+ case UNW_AARCH64_X27:
1543+ case UNW_AARCH64_X28:
1544+ case UNW_AARCH64_X29:
1545+ case UNW_AARCH64_X30:
1546+ case UNW_AARCH64_PC:
1547+ case UNW_AARCH64_PSTATE:
1548+ loc = c->dwarf.loc[reg];
1549+ break;
1550+
1551+ case UNW_AARCH64_SP:
1552+ if (write)
1553+ return -UNW_EREADONLYREG;
1554+ *valp = c->dwarf.cfa;
1555+ return 0;
1556+
1557+ default:
1558+ Debug (1, "bad register number %u\n", reg);
1559+ return -UNW_EBADREG;
1560+ }
1561+
1562+ if (write)
1563+ return dwarf_put (&c->dwarf, loc, *valp);
1564+ else
1565+ return dwarf_get (&c->dwarf, loc, valp);
1566+}
1567+
1568+HIDDEN int
1569+tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
1570+ int write)
1571+{
1572+ Debug (1, "bad register number %u\n", reg);
1573+ return -UNW_EBADREG;
1574+}
1575diff --git a/src/aarch64/Gresume.c b/src/aarch64/Gresume.c
1576new file mode 100644
1577index 0000000..908646b
1578--- /dev/null
1579+++ b/src/aarch64/Gresume.c
1580@@ -0,0 +1,177 @@
1581+/* libunwind - a platform-independent unwind library
1582+ Copyright (C) 2008 CodeSourcery
1583+ Copyright (C) 2011-2013 Linaro Limited
1584+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1585+
1586+This file is part of libunwind.
1587+
1588+Permission is hereby granted, free of charge, to any person obtaining
1589+a copy of this software and associated documentation files (the
1590+"Software"), to deal in the Software without restriction, including
1591+without limitation the rights to use, copy, modify, merge, publish,
1592+distribute, sublicense, and/or sell copies of the Software, and to
1593+permit persons to whom the Software is furnished to do so, subject to
1594+the following conditions:
1595+
1596+The above copyright notice and this permission notice shall be
1597+included in all copies or substantial portions of the Software.
1598+
1599+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1600+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1601+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1602+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1603+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1604+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1605+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1606+
1607+#include "unwind_i.h"
1608+#include "offsets.h"
1609+
1610+#ifndef UNW_REMOTE_ONLY
1611+
1612+HIDDEN inline int
1613+aarch64_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
1614+{
1615+#ifdef __linux__
1616+ struct cursor *c = (struct cursor *) cursor;
1617+ unw_tdep_context_t *uc = c->dwarf.as_arg;
1618+
1619+ if (c->sigcontext_format == AARCH64_SCF_NONE)
1620+ {
1621+ /* Since there are no signals involved here we restore the non scratch
1622+ registers only. */
1623+ unsigned long regs[11];
1624+ regs[0] = uc->uc_mcontext.regs[19];
1625+ regs[1] = uc->uc_mcontext.regs[20];
1626+ regs[2] = uc->uc_mcontext.regs[21];
1627+ regs[3] = uc->uc_mcontext.regs[22];
1628+ regs[4] = uc->uc_mcontext.regs[23];
1629+ regs[5] = uc->uc_mcontext.regs[24];
1630+ regs[6] = uc->uc_mcontext.regs[25];
1631+ regs[7] = uc->uc_mcontext.regs[26];
1632+ regs[8] = uc->uc_mcontext.regs[27];
1633+ regs[9] = uc->uc_mcontext.regs[28];
1634+ regs[10] = uc->uc_mcontext.regs[30]; /* LR */
1635+ unsigned long sp = uc->uc_mcontext.sp;
1636+
1637+ struct regs_overlay {
1638+ char x[sizeof(regs)];
1639+ };
1640+
1641+ asm volatile (
1642+ "ldp x19, x20, [%0]\n"
1643+ "ldp x21, x22, [%0,16]\n"
1644+ "ldp x23, x24, [%0,32]\n"
1645+ "ldp x25, x26, [%0,48]\n"
1646+ "ldp x27, x28, [%0,64]\n"
1647+ "ldr x30, [%0,80]\n"
1648+ "mov sp, %1\n"
1649+ "ret \n"
1650+ :
1651+ : "r" (regs),
1652+ "r" (sp),
1653+ "m" (*(struct regs_overlay *)regs)
1654+ );
1655+ }
1656+ else
1657+ {
1658+ struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
1659+
1660+ if (c->dwarf.eh_valid_mask & 0x1) sc->regs[0] = c->dwarf.eh_args[0];
1661+ if (c->dwarf.eh_valid_mask & 0x2) sc->regs[1] = c->dwarf.eh_args[1];
1662+ if (c->dwarf.eh_valid_mask & 0x4) sc->regs[2] = c->dwarf.eh_args[2];
1663+ if (c->dwarf.eh_valid_mask & 0x8) sc->regs[3] = c->dwarf.eh_args[3];
1664+
1665+ sc->regs[4] = uc->uc_mcontext.regs[4];
1666+ sc->regs[5] = uc->uc_mcontext.regs[5];
1667+ sc->regs[6] = uc->uc_mcontext.regs[6];
1668+ sc->regs[7] = uc->uc_mcontext.regs[7];
1669+ sc->regs[8] = uc->uc_mcontext.regs[8];
1670+ sc->regs[9] = uc->uc_mcontext.regs[9];
1671+ sc->regs[10] = uc->uc_mcontext.regs[10];
1672+ sc->regs[11] = uc->uc_mcontext.regs[11];
1673+ sc->regs[12] = uc->uc_mcontext.regs[12];
1674+ sc->regs[13] = uc->uc_mcontext.regs[13];
1675+ sc->regs[14] = uc->uc_mcontext.regs[14];
1676+ sc->regs[15] = uc->uc_mcontext.regs[15];
1677+ sc->regs[16] = uc->uc_mcontext.regs[16];
1678+ sc->regs[17] = uc->uc_mcontext.regs[17];
1679+ sc->regs[18] = uc->uc_mcontext.regs[18];
1680+ sc->regs[19] = uc->uc_mcontext.regs[19];
1681+ sc->regs[20] = uc->uc_mcontext.regs[20];
1682+ sc->regs[21] = uc->uc_mcontext.regs[21];
1683+ sc->regs[22] = uc->uc_mcontext.regs[22];
1684+ sc->regs[23] = uc->uc_mcontext.regs[23];
1685+ sc->regs[24] = uc->uc_mcontext.regs[24];
1686+ sc->regs[25] = uc->uc_mcontext.regs[25];
1687+ sc->regs[26] = uc->uc_mcontext.regs[26];
1688+ sc->regs[27] = uc->uc_mcontext.regs[27];
1689+ sc->regs[28] = uc->uc_mcontext.regs[28];
1690+ sc->regs[29] = uc->uc_mcontext.regs[29];
1691+ sc->regs[30] = uc->uc_mcontext.regs[30];
1692+ sc->sp = uc->uc_mcontext.sp;
1693+ sc->pc = uc->uc_mcontext.pc;
1694+ sc->pstate = uc->uc_mcontext.pstate;
1695+
1696+ asm volatile (
1697+ "mov sp, %0\n"
1698+ "ret %1\n"
1699+ : : "r" (c->sigcontext_sp), "r" (c->sigcontext_pc)
1700+ );
1701+ }
1702+ __builtin_unreachable();
1703+#else
1704+ printf ("%s: implement me\n", __FUNCTION__);
1705+#endif
1706+ return -UNW_EINVAL;
1707+}
1708+
1709+#endif /* !UNW_REMOTE_ONLY */
1710+
1711+static inline void
1712+establish_machine_state (struct cursor *c)
1713+{
1714+ unw_addr_space_t as = c->dwarf.as;
1715+ void *arg = c->dwarf.as_arg;
1716+ unw_fpreg_t fpval;
1717+ unw_word_t val;
1718+ int reg;
1719+
1720+ Debug (8, "copying out cursor state\n");
1721+
1722+ for (reg = 0; reg <= UNW_AARCH64_PSTATE; ++reg)
1723+ {
1724+ Debug (16, "copying %s %d\n", unw_regname (reg), reg);
1725+ if (unw_is_fpreg (reg))
1726+ {
1727+ if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
1728+ as->acc.access_fpreg (as, reg, &fpval, 1, arg);
1729+ }
1730+ else
1731+ {
1732+ if (tdep_access_reg (c, reg, &val, 0) >= 0)
1733+ as->acc.access_reg (as, reg, &val, 1, arg);
1734+ }
1735+ }
1736+}
1737+
1738+PROTECTED int
1739+unw_resume (unw_cursor_t *cursor)
1740+{
1741+ struct cursor *c = (struct cursor *) cursor;
1742+
1743+ Debug (1, "(cursor=%p)\n", c);
1744+
1745+ if (!c->dwarf.ip)
1746+ {
1747+ /* This can happen easily when the frame-chain gets truncated
1748+ due to bad or missing unwind-info. */
1749+ Debug (1, "refusing to resume execution at address 0\n");
1750+ return -UNW_EINVAL;
1751+ }
1752+
1753+ establish_machine_state (c);
1754+
1755+ return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
1756+ c->dwarf.as_arg);
1757+}
1758diff --git a/src/aarch64/Gstep.c b/src/aarch64/Gstep.c
1759new file mode 100644
1760index 0000000..4aa15d1
1761--- /dev/null
1762+++ b/src/aarch64/Gstep.c
1763@@ -0,0 +1,129 @@
1764+/* libunwind - a platform-independent unwind library
1765+ Copyright (C) 2008 CodeSourcery
1766+ Copyright (C) 2011-2013 Linaro Limited
1767+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
1768+
1769+This file is part of libunwind.
1770+
1771+Permission is hereby granted, free of charge, to any person obtaining
1772+a copy of this software and associated documentation files (the
1773+"Software"), to deal in the Software without restriction, including
1774+without limitation the rights to use, copy, modify, merge, publish,
1775+distribute, sublicense, and/or sell copies of the Software, and to
1776+permit persons to whom the Software is furnished to do so, subject to
1777+the following conditions:
1778+
1779+The above copyright notice and this permission notice shall be
1780+included in all copies or substantial portions of the Software.
1781+
1782+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1783+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1784+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1785+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1786+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1787+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1788+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1789+
1790+#include "unwind_i.h"
1791+#include "offsets.h"
1792+
1793+PROTECTED int
1794+unw_handle_signal_frame (unw_cursor_t *cursor)
1795+{
1796+ struct cursor *c = (struct cursor *) cursor;
1797+ int ret;
1798+ unw_word_t sc_addr, sp, sp_addr = c->dwarf.cfa;
1799+ struct dwarf_loc sp_loc = DWARF_LOC (sp_addr, 0);
1800+
1801+ if ((ret = dwarf_get (&c->dwarf, sp_loc, &sp)) < 0)
1802+ return -UNW_EUNSPEC;
1803+
1804+ ret = unw_is_signal_frame (cursor);
1805+ Debug(1, "unw_is_signal_frame()=%d\n", ret);
1806+
1807+ /* Save the SP and PC to be able to return execution at this point
1808+ later in time (unw_resume). */
1809+ c->sigcontext_sp = c->dwarf.cfa;
1810+ c->sigcontext_pc = c->dwarf.ip;
1811+
1812+ if (ret)
1813+ {
1814+ c->sigcontext_format = AARCH64_SCF_LINUX_RT_SIGFRAME;
1815+ sc_addr = sp_addr + sizeof (siginfo_t) + LINUX_UC_MCONTEXT_OFF;
1816+ }
1817+ else
1818+ return -UNW_EUNSPEC;
1819+
1820+ c->sigcontext_addr = sc_addr;
1821+
1822+ /* Update the dwarf cursor.
1823+ Set the location of the registers to the corresponding addresses of the
1824+ uc_mcontext / sigcontext structure contents. */
1825+ c->dwarf.loc[UNW_AARCH64_X0] = DWARF_LOC (sc_addr + LINUX_SC_X0_OFF, 0);
1826+ c->dwarf.loc[UNW_AARCH64_X1] = DWARF_LOC (sc_addr + LINUX_SC_X1_OFF, 0);
1827+ c->dwarf.loc[UNW_AARCH64_X2] = DWARF_LOC (sc_addr + LINUX_SC_X2_OFF, 0);
1828+ c->dwarf.loc[UNW_AARCH64_X3] = DWARF_LOC (sc_addr + LINUX_SC_X3_OFF, 0);
1829+ c->dwarf.loc[UNW_AARCH64_X4] = DWARF_LOC (sc_addr + LINUX_SC_X4_OFF, 0);
1830+ c->dwarf.loc[UNW_AARCH64_X5] = DWARF_LOC (sc_addr + LINUX_SC_X5_OFF, 0);
1831+ c->dwarf.loc[UNW_AARCH64_X6] = DWARF_LOC (sc_addr + LINUX_SC_X6_OFF, 0);
1832+ c->dwarf.loc[UNW_AARCH64_X7] = DWARF_LOC (sc_addr + LINUX_SC_X7_OFF, 0);
1833+ c->dwarf.loc[UNW_AARCH64_X8] = DWARF_LOC (sc_addr + LINUX_SC_X8_OFF, 0);
1834+ c->dwarf.loc[UNW_AARCH64_X9] = DWARF_LOC (sc_addr + LINUX_SC_X9_OFF, 0);
1835+ c->dwarf.loc[UNW_AARCH64_X10] = DWARF_LOC (sc_addr + LINUX_SC_X10_OFF, 0);
1836+ c->dwarf.loc[UNW_AARCH64_X11] = DWARF_LOC (sc_addr + LINUX_SC_X11_OFF, 0);
1837+ c->dwarf.loc[UNW_AARCH64_X12] = DWARF_LOC (sc_addr + LINUX_SC_X12_OFF, 0);
1838+ c->dwarf.loc[UNW_AARCH64_X13] = DWARF_LOC (sc_addr + LINUX_SC_X13_OFF, 0);
1839+ c->dwarf.loc[UNW_AARCH64_X14] = DWARF_LOC (sc_addr + LINUX_SC_X14_OFF, 0);
1840+ c->dwarf.loc[UNW_AARCH64_X15] = DWARF_LOC (sc_addr + LINUX_SC_X15_OFF, 0);
1841+ c->dwarf.loc[UNW_AARCH64_X16] = DWARF_LOC (sc_addr + LINUX_SC_X16_OFF, 0);
1842+ c->dwarf.loc[UNW_AARCH64_X17] = DWARF_LOC (sc_addr + LINUX_SC_X17_OFF, 0);
1843+ c->dwarf.loc[UNW_AARCH64_X18] = DWARF_LOC (sc_addr + LINUX_SC_X18_OFF, 0);
1844+ c->dwarf.loc[UNW_AARCH64_X19] = DWARF_LOC (sc_addr + LINUX_SC_X19_OFF, 0);
1845+ c->dwarf.loc[UNW_AARCH64_X20] = DWARF_LOC (sc_addr + LINUX_SC_X20_OFF, 0);
1846+ c->dwarf.loc[UNW_AARCH64_X21] = DWARF_LOC (sc_addr + LINUX_SC_X21_OFF, 0);
1847+ c->dwarf.loc[UNW_AARCH64_X22] = DWARF_LOC (sc_addr + LINUX_SC_X22_OFF, 0);
1848+ c->dwarf.loc[UNW_AARCH64_X23] = DWARF_LOC (sc_addr + LINUX_SC_X23_OFF, 0);
1849+ c->dwarf.loc[UNW_AARCH64_X24] = DWARF_LOC (sc_addr + LINUX_SC_X24_OFF, 0);
1850+ c->dwarf.loc[UNW_AARCH64_X25] = DWARF_LOC (sc_addr + LINUX_SC_X25_OFF, 0);
1851+ c->dwarf.loc[UNW_AARCH64_X26] = DWARF_LOC (sc_addr + LINUX_SC_X26_OFF, 0);
1852+ c->dwarf.loc[UNW_AARCH64_X27] = DWARF_LOC (sc_addr + LINUX_SC_X27_OFF, 0);
1853+ c->dwarf.loc[UNW_AARCH64_X28] = DWARF_LOC (sc_addr + LINUX_SC_X28_OFF, 0);
1854+ c->dwarf.loc[UNW_AARCH64_X29] = DWARF_LOC (sc_addr + LINUX_SC_X29_OFF, 0);
1855+ c->dwarf.loc[UNW_AARCH64_X30] = DWARF_LOC (sc_addr + LINUX_SC_X30_OFF, 0);
1856+ c->dwarf.loc[UNW_AARCH64_SP] = DWARF_LOC (sc_addr + LINUX_SC_SP_OFF, 0);
1857+ c->dwarf.loc[UNW_AARCH64_PC] = DWARF_LOC (sc_addr + LINUX_SC_PC_OFF, 0);
1858+ c->dwarf.loc[UNW_AARCH64_PSTATE] = DWARF_LOC (sc_addr + LINUX_SC_PSTATE_OFF, 0);
1859+
1860+ /* Set SP/CFA and PC/IP. */
1861+ dwarf_get (&c->dwarf, c->dwarf.loc[UNW_AARCH64_SP], &c->dwarf.cfa);
1862+ dwarf_get (&c->dwarf, c->dwarf.loc[UNW_AARCH64_PC], &c->dwarf.ip);
1863+
1864+ c->dwarf.pi_valid = 0;
1865+
1866+ return 1;
1867+}
1868+
1869+PROTECTED int
1870+unw_step (unw_cursor_t *cursor)
1871+{
1872+ struct cursor *c = (struct cursor *) cursor;
1873+ int ret;
1874+
1875+ Debug (1, "(cursor=%p, ip=0x%016lx, cfa=0x%016lx))\n",
1876+ c, c->dwarf.ip, c->dwarf.cfa);
1877+
1878+ /* Check if this is a signal frame. */
1879+ if (unw_is_signal_frame (cursor))
1880+ return unw_handle_signal_frame (cursor);
1881+
1882+ ret = dwarf_step (&c->dwarf);
1883+ Debug(1, "dwarf_step()=%d\n", ret);
1884+
1885+ if (unlikely (ret == -UNW_ESTOPUNWIND))
1886+ return ret;
1887+
1888+ if (unlikely (ret < 0))
1889+ return 0;
1890+
1891+ return (c->dwarf.ip == 0) ? 0 : 1;
1892+}
1893diff --git a/src/aarch64/Lcreate_addr_space.c b/src/aarch64/Lcreate_addr_space.c
1894new file mode 100644
1895index 0000000..0f2dc6b
1896--- /dev/null
1897+++ b/src/aarch64/Lcreate_addr_space.c
1898@@ -0,0 +1,5 @@
1899+#define UNW_LOCAL_ONLY
1900+#include <libunwind.h>
1901+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1902+#include "Gcreate_addr_space.c"
1903+#endif
1904diff --git a/src/aarch64/Lget_proc_info.c b/src/aarch64/Lget_proc_info.c
1905new file mode 100644
1906index 0000000..69028b0
1907--- /dev/null
1908+++ b/src/aarch64/Lget_proc_info.c
1909@@ -0,0 +1,5 @@
1910+#define UNW_LOCAL_ONLY
1911+#include <libunwind.h>
1912+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1913+#include "Gget_proc_info.c"
1914+#endif
1915diff --git a/src/aarch64/Lget_save_loc.c b/src/aarch64/Lget_save_loc.c
1916new file mode 100644
1917index 0000000..9ea048a
1918--- /dev/null
1919+++ b/src/aarch64/Lget_save_loc.c
1920@@ -0,0 +1,5 @@
1921+#define UNW_LOCAL_ONLY
1922+#include <libunwind.h>
1923+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1924+#include "Gget_save_loc.c"
1925+#endif
1926diff --git a/src/aarch64/Lglobal.c b/src/aarch64/Lglobal.c
1927new file mode 100644
1928index 0000000..6d7b489
1929--- /dev/null
1930+++ b/src/aarch64/Lglobal.c
1931@@ -0,0 +1,5 @@
1932+#define UNW_LOCAL_ONLY
1933+#include <libunwind.h>
1934+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1935+#include "Gglobal.c"
1936+#endif
1937diff --git a/src/aarch64/Linit.c b/src/aarch64/Linit.c
1938new file mode 100644
1939index 0000000..e9abfdd
1940--- /dev/null
1941+++ b/src/aarch64/Linit.c
1942@@ -0,0 +1,5 @@
1943+#define UNW_LOCAL_ONLY
1944+#include <libunwind.h>
1945+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1946+#include "Ginit.c"
1947+#endif
1948diff --git a/src/aarch64/Linit_local.c b/src/aarch64/Linit_local.c
1949new file mode 100644
1950index 0000000..68a1687
1951--- /dev/null
1952+++ b/src/aarch64/Linit_local.c
1953@@ -0,0 +1,5 @@
1954+#define UNW_LOCAL_ONLY
1955+#include <libunwind.h>
1956+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1957+#include "Ginit_local.c"
1958+#endif
1959diff --git a/src/aarch64/Linit_remote.c b/src/aarch64/Linit_remote.c
1960new file mode 100644
1961index 0000000..58cb04a
1962--- /dev/null
1963+++ b/src/aarch64/Linit_remote.c
1964@@ -0,0 +1,5 @@
1965+#define UNW_LOCAL_ONLY
1966+#include <libunwind.h>
1967+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1968+#include "Ginit_remote.c"
1969+#endif
1970diff --git a/src/aarch64/Lis_signal_frame.c b/src/aarch64/Lis_signal_frame.c
1971new file mode 100644
1972index 0000000..b9a7c4f
1973--- /dev/null
1974+++ b/src/aarch64/Lis_signal_frame.c
1975@@ -0,0 +1,5 @@
1976+#define UNW_LOCAL_ONLY
1977+#include <libunwind.h>
1978+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1979+#include "Gis_signal_frame.c"
1980+#endif
1981diff --git a/src/aarch64/Lregs.c b/src/aarch64/Lregs.c
1982new file mode 100644
1983index 0000000..2c9c75c
1984--- /dev/null
1985+++ b/src/aarch64/Lregs.c
1986@@ -0,0 +1,5 @@
1987+#define UNW_LOCAL_ONLY
1988+#include <libunwind.h>
1989+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
1990+#include "Gregs.c"
1991+#endif
1992diff --git a/src/aarch64/Lresume.c b/src/aarch64/Lresume.c
1993new file mode 100644
1994index 0000000..41a8cf0
1995--- /dev/null
1996+++ b/src/aarch64/Lresume.c
1997@@ -0,0 +1,5 @@
1998+#define UNW_LOCAL_ONLY
1999+#include <libunwind.h>
2000+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
2001+#include "Gresume.c"
2002+#endif
2003diff --git a/src/aarch64/Lstep.c b/src/aarch64/Lstep.c
2004new file mode 100644
2005index 0000000..c1ac3c7
2006--- /dev/null
2007+++ b/src/aarch64/Lstep.c
2008@@ -0,0 +1,5 @@
2009+#define UNW_LOCAL_ONLY
2010+#include <libunwind.h>
2011+#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
2012+#include "Gstep.c"
2013+#endif
2014diff --git a/src/aarch64/gen-offsets.c b/src/aarch64/gen-offsets.c
2015new file mode 100644
2016index 0000000..eadc237
2017--- /dev/null
2018+++ b/src/aarch64/gen-offsets.c
2019@@ -0,0 +1,68 @@
2020+#include <stdio.h>
2021+#include <stddef.h>
2022+#include <ucontext.h>
2023+#include <asm/sigcontext.h>
2024+
2025+#define UC(N,X) \
2026+ printf ("#define LINUX_UC_" N "_OFF\t0x%X\n", offsetof (ucontext_t, X))
2027+
2028+#define SC(N,X) \
2029+ printf ("#define LINUX_SC_" N "_OFF\t0x%X\n", offsetof (struct sigcontext, X))
2030+
2031+int
2032+main (void)
2033+{
2034+ printf (
2035+"/* Linux-specific definitions: */\n\n"
2036+
2037+"/* Define various structure offsets to simplify cross-compilation. */\n\n"
2038+
2039+"/* Offsets for AArch64 Linux \"ucontext_t\": */\n\n");
2040+
2041+ UC ("FLAGS", uc_flags);
2042+ UC ("LINK", uc_link);
2043+ UC ("STACK", uc_stack);
2044+ UC ("MCONTEXT", uc_mcontext);
2045+ UC ("SIGMASK", uc_sigmask);
2046+
2047+ printf ("\n/* Offsets for AArch64 Linux \"struct sigcontext\": */\n\n");
2048+
2049+ SC ("R0", regs[0]);
2050+ SC ("R1", regs[1]);
2051+ SC ("R2", regs[2]);
2052+ SC ("R3", regs[3]);
2053+ SC ("R4", regs[4]);
2054+ SC ("R5", regs[5]);
2055+ SC ("R6", regs[6]);
2056+ SC ("R7", regs[7]);
2057+ SC ("R8", regs[8]);
2058+ SC ("R9", regs[9]);
2059+ SC ("R10", regs[10]);
2060+ SC ("R11", regs[11]);
2061+ SC ("R12", regs[12]);
2062+ SC ("R13", regs[13]);
2063+ SC ("R14", regs[14]);
2064+ SC ("R15", regs[15]);
2065+ SC ("R16", regs[16]);
2066+ SC ("R17", regs[17]);
2067+ SC ("R18", regs[18]);
2068+ SC ("R19", regs[19]);
2069+ SC ("R20", regs[20]);
2070+ SC ("R21", regs[21]);
2071+ SC ("R22", regs[22]);
2072+ SC ("R23", regs[23]);
2073+ SC ("R24", regs[24]);
2074+ SC ("R25", regs[25]);
2075+ SC ("R26", regs[26]);
2076+ SC ("R27", regs[27]);
2077+ SC ("R28", regs[28]);
2078+ SC ("R29", regs[29]);
2079+ SC ("R30", regs[30]);
2080+ SC ("R31", regs[31]);
2081+
2082+ SC ("PC", pc);
2083+ SC ("SP", sp);
2084+ SC ("Fault", fault_address);
2085+ SC ("state", pstate);
2086+ return 0;
2087+}
2088diff --git a/src/aarch64/init.h b/src/aarch64/init.h
2089new file mode 100644
2090index 0000000..0cedc1a
2091--- /dev/null
2092+++ b/src/aarch64/init.h
2093@@ -0,0 +1,127 @@
2094+/* libunwind - a platform-independent unwind library
2095+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
2096+ Copyright (C) 2013 Linaro Limited
2097+
2098+This file is part of libunwind.
2099+
2100+Permission is hereby granted, free of charge, to any person obtaining
2101+a copy of this software and associated documentation files (the
2102+"Software"), to deal in the Software without restriction, including
2103+without limitation the rights to use, copy, modify, merge, publish,
2104+distribute, sublicense, and/or sell copies of the Software, and to
2105+permit persons to whom the Software is furnished to do so, subject to
2106+the following conditions:
2107+
2108+The above copyright notice and this permission notice shall be
2109+included in all copies or substantial portions of the Software.
2110+
2111+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2112+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2113+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2114+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2115+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2116+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2117+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2118+
2119+#include "unwind_i.h"
2120+
2121+static inline int
2122+common_init (struct cursor *c, unsigned use_prev_instr)
2123+{
2124+ int ret, i;
2125+
2126+ c->dwarf.loc[UNW_AARCH64_X0] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X0);
2127+ c->dwarf.loc[UNW_AARCH64_X1] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X1);
2128+ c->dwarf.loc[UNW_AARCH64_X2] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X2);
2129+ c->dwarf.loc[UNW_AARCH64_X3] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X3);
2130+ c->dwarf.loc[UNW_AARCH64_X4] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X4);
2131+ c->dwarf.loc[UNW_AARCH64_X5] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X5);
2132+ c->dwarf.loc[UNW_AARCH64_X6] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X6);
2133+ c->dwarf.loc[UNW_AARCH64_X7] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X7);
2134+ c->dwarf.loc[UNW_AARCH64_X8] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X8);
2135+ c->dwarf.loc[UNW_AARCH64_X9] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X9);
2136+ c->dwarf.loc[UNW_AARCH64_X10] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X10);
2137+ c->dwarf.loc[UNW_AARCH64_X11] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X11);
2138+ c->dwarf.loc[UNW_AARCH64_X12] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X12);
2139+ c->dwarf.loc[UNW_AARCH64_X13] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X13);
2140+ c->dwarf.loc[UNW_AARCH64_X14] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X14);
2141+ c->dwarf.loc[UNW_AARCH64_X15] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X15);
2142+ c->dwarf.loc[UNW_AARCH64_X16] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X16);
2143+ c->dwarf.loc[UNW_AARCH64_X17] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X17);
2144+ c->dwarf.loc[UNW_AARCH64_X18] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X18);
2145+ c->dwarf.loc[UNW_AARCH64_X19] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X19);
2146+ c->dwarf.loc[UNW_AARCH64_X20] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X20);
2147+ c->dwarf.loc[UNW_AARCH64_X21] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X21);
2148+ c->dwarf.loc[UNW_AARCH64_X22] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X22);
2149+ c->dwarf.loc[UNW_AARCH64_X23] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X23);
2150+ c->dwarf.loc[UNW_AARCH64_X24] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X24);
2151+ c->dwarf.loc[UNW_AARCH64_X25] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X25);
2152+ c->dwarf.loc[UNW_AARCH64_X26] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X26);
2153+ c->dwarf.loc[UNW_AARCH64_X27] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X27);
2154+ c->dwarf.loc[UNW_AARCH64_X28] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X28);
2155+ c->dwarf.loc[UNW_AARCH64_X29] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X29);
2156+ c->dwarf.loc[UNW_AARCH64_X30] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_X30);
2157+ c->dwarf.loc[UNW_AARCH64_SP] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_SP);
2158+ c->dwarf.loc[UNW_AARCH64_PC] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_PC);
2159+ c->dwarf.loc[UNW_AARCH64_PSTATE] = DWARF_REG_LOC (&c->dwarf,
2160+ UNW_AARCH64_PSTATE);
2161+ c->dwarf.loc[UNW_AARCH64_V0] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V0);
2162+ c->dwarf.loc[UNW_AARCH64_V1] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V1);
2163+ c->dwarf.loc[UNW_AARCH64_V2] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V2);
2164+ c->dwarf.loc[UNW_AARCH64_V3] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V3);
2165+ c->dwarf.loc[UNW_AARCH64_V4] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V4);
2166+ c->dwarf.loc[UNW_AARCH64_V5] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V5);
2167+ c->dwarf.loc[UNW_AARCH64_V6] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V6);
2168+ c->dwarf.loc[UNW_AARCH64_V7] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V7);
2169+ c->dwarf.loc[UNW_AARCH64_V8] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V8);
2170+ c->dwarf.loc[UNW_AARCH64_V9] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V9);
2171+ c->dwarf.loc[UNW_AARCH64_V10] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V10);
2172+ c->dwarf.loc[UNW_AARCH64_V11] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V11);
2173+ c->dwarf.loc[UNW_AARCH64_V12] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V12);
2174+ c->dwarf.loc[UNW_AARCH64_V13] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V13);
2175+ c->dwarf.loc[UNW_AARCH64_V14] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V14);
2176+ c->dwarf.loc[UNW_AARCH64_V15] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V15);
2177+ c->dwarf.loc[UNW_AARCH64_V16] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V16);
2178+ c->dwarf.loc[UNW_AARCH64_V17] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V17);
2179+ c->dwarf.loc[UNW_AARCH64_V18] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V18);
2180+ c->dwarf.loc[UNW_AARCH64_V19] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V19);
2181+ c->dwarf.loc[UNW_AARCH64_V20] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V20);
2182+ c->dwarf.loc[UNW_AARCH64_V21] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V21);
2183+ c->dwarf.loc[UNW_AARCH64_V22] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V22);
2184+ c->dwarf.loc[UNW_AARCH64_V23] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V23);
2185+ c->dwarf.loc[UNW_AARCH64_V24] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V24);
2186+ c->dwarf.loc[UNW_AARCH64_V25] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V25);
2187+ c->dwarf.loc[UNW_AARCH64_V26] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V26);
2188+ c->dwarf.loc[UNW_AARCH64_V27] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V27);
2189+ c->dwarf.loc[UNW_AARCH64_V28] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V28);
2190+ c->dwarf.loc[UNW_AARCH64_V29] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V29);
2191+ c->dwarf.loc[UNW_AARCH64_V30] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V30);
2192+ c->dwarf.loc[UNW_AARCH64_V31] = DWARF_REG_LOC (&c->dwarf, UNW_AARCH64_V31);
2193+
2194+ for (i = UNW_AARCH64_PSTATE + 1; i < UNW_AARCH64_V0; ++i)
2195+ c->dwarf.loc[i] = DWARF_NULL_LOC;
2196+
2197+ ret = dwarf_get (&c->dwarf, c->dwarf.loc[UNW_AARCH64_PC], &c->dwarf.ip);
2198+ if (ret < 0)
2199+ return ret;
2200+
2201+ ret = dwarf_get (&c->dwarf, c->dwarf.loc[UNW_AARCH64_SP], &c->dwarf.cfa);
2202+ if (ret < 0)
2203+ return ret;
2204+
2205+ c->sigcontext_format = AARCH64_SCF_NONE;
2206+ c->sigcontext_addr = 0;
2207+ c->sigcontext_sp = 0;
2208+ c->sigcontext_pc = 0;
2209+
2210+ c->dwarf.args_size = 0;
2211+ c->dwarf.ret_addr_column = 0;
2212+ c->dwarf.stash_frames = 0;
2213+ c->dwarf.use_prev_instr = use_prev_instr;
2214+ c->dwarf.pi_valid = 0;
2215+ c->dwarf.pi_is_dynamic = 0;
2216+ c->dwarf.hint = 0;
2217+ c->dwarf.prev_rs = 0;
2218+
2219+ return 0;
2220+}
2221diff --git a/src/aarch64/is_fpreg.c b/src/aarch64/is_fpreg.c
2222new file mode 100644
2223index 0000000..7c32693
2224--- /dev/null
2225+++ b/src/aarch64/is_fpreg.c
2226@@ -0,0 +1,32 @@
2227+/* libunwind - a platform-independent unwind library
2228+ Copyright (C) 2008 CodeSourcery
2229+ Copyright (C) 2013 Linaro Limited
2230+
2231+This file is part of libunwind.
2232+
2233+Permission is hereby granted, free of charge, to any person obtaining
2234+a copy of this software and associated documentation files (the
2235+"Software"), to deal in the Software without restriction, including
2236+without limitation the rights to use, copy, modify, merge, publish,
2237+distribute, sublicense, and/or sell copies of the Software, and to
2238+permit persons to whom the Software is furnished to do so, subject to
2239+the following conditions:
2240+
2241+The above copyright notice and this permission notice shall be
2242+included in all copies or substantial portions of the Software.
2243+
2244+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2245+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2246+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2247+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2248+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2249+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2250+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2251+
2252+#include "libunwind_i.h"
2253+
2254+PROTECTED int
2255+unw_is_fpreg (int regnum)
2256+{
2257+ return (regnum >= UNW_AARCH64_V0 && regnum <= UNW_AARCH64_V31);
2258+}
2259diff --git a/src/aarch64/offsets.h b/src/aarch64/offsets.h
2260new file mode 100644
2261index 0000000..81aa74f
2262--- /dev/null
2263+++ b/src/aarch64/offsets.h
2264@@ -0,0 +1,49 @@
2265+/* Linux-specific definitions: */
2266+
2267+/* Define various structure offsets to simplify cross-compilation. */
2268+
2269+/* Offsets for AArch64 Linux "ucontext_t": */
2270+
2271+#define LINUX_UC_FLAGS_OFF 0x0
2272+#define LINUX_UC_LINK_OFF 0x8
2273+#define LINUX_UC_STACK_OFF 0x10
2274+#define LINUX_UC_SIGMASK_OFF 0x28
2275+#define LINUX_UC_MCONTEXT_OFF 0xb0
2276+
2277+/* Offsets for AArch64 Linux "struct sigcontext": */
2278+
2279+#define LINUX_SC_FAULTADDRESS_OFF 0x00
2280+#define LINUX_SC_X0_OFF 0x008
2281+#define LINUX_SC_X1_OFF 0x010
2282+#define LINUX_SC_X2_OFF 0x018
2283+#define LINUX_SC_X3_OFF 0x020
2284+#define LINUX_SC_X4_OFF 0x028
2285+#define LINUX_SC_X5_OFF 0x030
2286+#define LINUX_SC_X6_OFF 0x038
2287+#define LINUX_SC_X7_OFF 0x040
2288+#define LINUX_SC_X8_OFF 0x048
2289+#define LINUX_SC_X9_OFF 0x050
2290+#define LINUX_SC_X10_OFF 0x058
2291+#define LINUX_SC_X11_OFF 0x060
2292+#define LINUX_SC_X12_OFF 0x068
2293+#define LINUX_SC_X13_OFF 0x070
2294+#define LINUX_SC_X14_OFF 0x078
2295+#define LINUX_SC_X15_OFF 0x080
2296+#define LINUX_SC_X16_OFF 0x088
2297+#define LINUX_SC_X17_OFF 0x090
2298+#define LINUX_SC_X18_OFF 0x098
2299+#define LINUX_SC_X19_OFF 0x0a0
2300+#define LINUX_SC_X20_OFF 0x0a8
2301+#define LINUX_SC_X21_OFF 0x0b0
2302+#define LINUX_SC_X22_OFF 0x0b8
2303+#define LINUX_SC_X23_OFF 0x0c0
2304+#define LINUX_SC_X24_OFF 0x0c8
2305+#define LINUX_SC_X25_OFF 0x0d0
2306+#define LINUX_SC_X26_OFF 0x0d8
2307+#define LINUX_SC_X27_OFF 0x0e0
2308+#define LINUX_SC_X28_OFF 0x0e8
2309+#define LINUX_SC_X29_OFF 0x0f0
2310+#define LINUX_SC_X30_OFF 0x0f8
2311+#define LINUX_SC_SP_OFF 0x100
2312+#define LINUX_SC_PC_OFF 0x108
2313+#define LINUX_SC_PSTATE_OFF 0x110
2314diff --git a/src/aarch64/regname.c b/src/aarch64/regname.c
2315new file mode 100644
2316index 0000000..8c97342
2317--- /dev/null
2318+++ b/src/aarch64/regname.c
2319@@ -0,0 +1,106 @@
2320+/* libunwind - a platform-independent unwind library
2321+ Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
2322+ Copyright (C) 2013 Linaro Limited
2323+
2324+This file is part of libunwind.
2325+
2326+Permission is hereby granted, free of charge, to any person obtaining
2327+a copy of this software and associated documentation files (the
2328+"Software"), to deal in the Software without restriction, including
2329+without limitation the rights to use, copy, modify, merge, publish,
2330+distribute, sublicense, and/or sell copies of the Software, and to
2331+permit persons to whom the Software is furnished to do so, subject to
2332+the following conditions:
2333+
2334+The above copyright notice and this permission notice shall be
2335+included in all copies or substantial portions of the Software.
2336+
2337+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2338+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2339+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2340+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2341+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2342+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2343+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2344+
2345+#include "unwind_i.h"
2346+
2347+static const char *const regname[] =
2348+ {
2349+ [UNW_AARCH64_X0] = "x0",
2350+ [UNW_AARCH64_X1] = "x1",
2351+ [UNW_AARCH64_X2] = "x2",
2352+ [UNW_AARCH64_X3] = "x3",
2353+ [UNW_AARCH64_X4] = "x4",
2354+ [UNW_AARCH64_X5] = "x5",
2355+ [UNW_AARCH64_X6] = "x6",
2356+ [UNW_AARCH64_X7] = "x7",
2357+ [UNW_AARCH64_X8] = "x8",
2358+ [UNW_AARCH64_X9] = "x9",
2359+ [UNW_AARCH64_X10] = "x10",
2360+ [UNW_AARCH64_X11] = "x11",
2361+ [UNW_AARCH64_X12] = "x12",
2362+ [UNW_AARCH64_X13] = "x13",
2363+ [UNW_AARCH64_X14] = "x14",
2364+ [UNW_AARCH64_X15] = "x15",
2365+ [UNW_AARCH64_X16] = "ip0",
2366+ [UNW_AARCH64_X17] = "ip1",
2367+ [UNW_AARCH64_X18] = "x18",
2368+ [UNW_AARCH64_X19] = "x19",
2369+ [UNW_AARCH64_X20] = "x20",
2370+ [UNW_AARCH64_X21] = "x21",
2371+ [UNW_AARCH64_X22] = "x22",
2372+ [UNW_AARCH64_X23] = "x23",
2373+ [UNW_AARCH64_X24] = "x24",
2374+ [UNW_AARCH64_X25] = "x25",
2375+ [UNW_AARCH64_X26] = "x26",
2376+ [UNW_AARCH64_X27] = "x27",
2377+ [UNW_AARCH64_X28] = "x28",
2378+ [UNW_AARCH64_X29] = "fp",
2379+ [UNW_AARCH64_X30] = "lr",
2380+ [UNW_AARCH64_SP] = "sp",
2381+ [UNW_AARCH64_PC] = "pc",
2382+ [UNW_AARCH64_V0] = "v0",
2383+ [UNW_AARCH64_V1] = "v1",
2384+ [UNW_AARCH64_V2] = "v2",
2385+ [UNW_AARCH64_V3] = "v3",
2386+ [UNW_AARCH64_V4] = "v4",
2387+ [UNW_AARCH64_V5] = "v5",
2388+ [UNW_AARCH64_V6] = "v6",
2389+ [UNW_AARCH64_V7] = "v7",
2390+ [UNW_AARCH64_V8] = "v8",
2391+ [UNW_AARCH64_V9] = "v9",
2392+ [UNW_AARCH64_V10] = "v10",
2393+ [UNW_AARCH64_V11] = "v11",
2394+ [UNW_AARCH64_V12] = "v12",
2395+ [UNW_AARCH64_V13] = "v13",
2396+ [UNW_AARCH64_V14] = "v14",
2397+ [UNW_AARCH64_V15] = "v15",
2398+ [UNW_AARCH64_V16] = "v16",
2399+ [UNW_AARCH64_V17] = "v17",
2400+ [UNW_AARCH64_V18] = "v18",
2401+ [UNW_AARCH64_V19] = "v19",
2402+ [UNW_AARCH64_V20] = "v20",
2403+ [UNW_AARCH64_V21] = "v21",
2404+ [UNW_AARCH64_V22] = "v22",
2405+ [UNW_AARCH64_V23] = "v23",
2406+ [UNW_AARCH64_V24] = "v24",
2407+ [UNW_AARCH64_V25] = "v25",
2408+ [UNW_AARCH64_V26] = "v26",
2409+ [UNW_AARCH64_V27] = "v27",
2410+ [UNW_AARCH64_V28] = "v28",
2411+ [UNW_AARCH64_V29] = "v29",
2412+ [UNW_AARCH64_V30] = "v30",
2413+ [UNW_AARCH64_V31] = "v31",
2414+ [UNW_AARCH64_FPSR] = "fpsr",
2415+ [UNW_AARCH64_FPCR] = "fpcr",
2416+ };
2417+
2418+PROTECTED const char *
2419+unw_regname (unw_regnum_t reg)
2420+{
2421+ if (reg < (unw_regnum_t) ARRAY_SIZE (regname) && regname[reg] != NULL)
2422+ return regname[reg];
2423+ else
2424+ return "???";
2425+}
2426diff --git a/src/aarch64/siglongjmp.S b/src/aarch64/siglongjmp.S
2427new file mode 100644
2428index 0000000..9985c4b
2429--- /dev/null
2430+++ b/src/aarch64/siglongjmp.S
2431@@ -0,0 +1,12 @@
2432+ /* Dummy implementation for now. */
2433+
2434+ .global _UI_siglongjmp_cont
2435+ .global _UI_longjmp_cont
2436+
2437+_UI_siglongjmp_cont:
2438+_UI_longjmp_cont:
2439+ ret
2440+#ifdef __linux__
2441+ /* We do not need executable stack. */
2442+ .section .note.GNU-stack,"",%progbits
2443+#endif
2444diff --git a/src/aarch64/unwind_i.h b/src/aarch64/unwind_i.h
2445new file mode 100644
2446index 0000000..e4947a3
2447--- /dev/null
2448+++ b/src/aarch64/unwind_i.h
2449@@ -0,0 +1,43 @@
2450+/* libunwind - a platform-independent unwind library
2451+ Copyright (C) 2008 CodeSourcery
2452+ Copyright (C) 2013 Linaro Limited
2453+
2454+This file is part of libunwind.
2455+
2456+Permission is hereby granted, free of charge, to any person obtaining
2457+a copy of this software and associated documentation files (the
2458+"Software"), to deal in the Software without restriction, including
2459+without limitation the rights to use, copy, modify, merge, publish,
2460+distribute, sublicense, and/or sell copies of the Software, and to
2461+permit persons to whom the Software is furnished to do so, subject to
2462+the following conditions:
2463+
2464+The above copyright notice and this permission notice shall be
2465+included in all copies or substantial portions of the Software.
2466+
2467+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2468+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2469+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2470+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2471+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2472+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2473+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2474+
2475+#ifndef unwind_i_h
2476+#define unwind_i_h
2477+
2478+#include <stdint.h>
2479+
2480+#include <libunwind-aarch64.h>
2481+
2482+#include "libunwind_i.h"
2483+
2484+#define aarch64_lock UNW_OBJ(lock)
2485+#define aarch64_local_resume UNW_OBJ(local_resume)
2486+#define aarch64_local_addr_space_init UNW_OBJ(local_addr_space_init)
2487+
2488+extern void aarch64_local_addr_space_init (void);
2489+extern int aarch64_local_resume (unw_addr_space_t as, unw_cursor_t *cursor,
2490+ void *arg);
2491+
2492+#endif /* unwind_i_h */
2493diff --git a/src/coredump/_UCD_access_reg_linux.c b/src/coredump/_UCD_access_reg_linux.c
2494index bc360ad..9dc0904 100644
2495--- a/src/coredump/_UCD_access_reg_linux.c
2496+++ b/src/coredump/_UCD_access_reg_linux.c
2497@@ -39,7 +39,10 @@ _UCD_access_reg (unw_addr_space_t as,
2498 return -UNW_EINVAL;
2499 }
2500
2501-#if defined(UNW_TARGET_ARM)
2502+#if defined(UNW_TARGET_AARCH64)
2503+ if (regnum < 0 || regnum >= UNW_AARCH64_FPCR)
2504+ goto badreg;
2505+#elif defined(UNW_TARGET_ARM)
2506 if (regnum < 0 || regnum >= 16)
2507 goto badreg;
2508 #elif defined(UNW_TARGET_SH)
2509diff --git a/src/ptrace/_UPT_reg_offset.c b/src/ptrace/_UPT_reg_offset.c
2510index 765f7d5..ced4896 100644
2511--- a/src/ptrace/_UPT_reg_offset.c
2512+++ b/src/ptrace/_UPT_reg_offset.c
2513@@ -1,6 +1,7 @@
2514 /* libunwind - a platform-independent unwind library
2515 Copyright (C) 2003-2004 Hewlett-Packard Co
2516 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
2517+ Copyright (C) 2013 Linaro Limited
2518
2519 This file is part of libunwind.
2520
2521@@ -501,6 +502,41 @@ const int _UPT_reg_offset[UNW_REG_LAST + 1] =
2522 [UNW_ARM_R15] = 0x3c,
2523 #elif defined(UNW_TARGET_MIPS)
2524 #elif defined(UNW_TARGET_SH)
2525+#elif defined(UNW_TARGET_AARCH64)
2526+ [UNW_AARCH64_X0] = 0x00,
2527+ [UNW_AARCH64_X1] = 0x08,
2528+ [UNW_AARCH64_X2] = 0x10,
2529+ [UNW_AARCH64_X3] = 0x18,
2530+ [UNW_AARCH64_X4] = 0x20,
2531+ [UNW_AARCH64_X5] = 0x28,
2532+ [UNW_AARCH64_X6] = 0x30,
2533+ [UNW_AARCH64_X7] = 0x38,
2534+ [UNW_AARCH64_X8] = 0x40,
2535+ [UNW_AARCH64_X9] = 0x48,
2536+ [UNW_AARCH64_X10] = 0x50,
2537+ [UNW_AARCH64_X11] = 0x58,
2538+ [UNW_AARCH64_X12] = 0x60,
2539+ [UNW_AARCH64_X13] = 0x68,
2540+ [UNW_AARCH64_X14] = 0x70,
2541+ [UNW_AARCH64_X15] = 0x78,
2542+ [UNW_AARCH64_X16] = 0x80,
2543+ [UNW_AARCH64_X17] = 0x88,
2544+ [UNW_AARCH64_X18] = 0x90,
2545+ [UNW_AARCH64_X19] = 0x98,
2546+ [UNW_AARCH64_X20] = 0xa0,
2547+ [UNW_AARCH64_X21] = 0xa8,
2548+ [UNW_AARCH64_X22] = 0xb0,
2549+ [UNW_AARCH64_X23] = 0xb8,
2550+ [UNW_AARCH64_X24] = 0xc0,
2551+ [UNW_AARCH64_X25] = 0xc8,
2552+ [UNW_AARCH64_X26] = 0xd0,
2553+ [UNW_AARCH64_X27] = 0xd8,
2554+ [UNW_AARCH64_X28] = 0xe0,
2555+ [UNW_AARCH64_X29] = 0xe8,
2556+ [UNW_AARCH64_X30] = 0xf0,
2557+ [UNW_AARCH64_SP] = 0xf8,
2558+ [UNW_AARCH64_PC] = 0x100,
2559+ [UNW_AARCH64_PSTATE] = 0x108
2560 #else
2561 # error Fix me.
2562 #endif