1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2001-2005 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 Copyright (C) 2013 Linaro Limited
6 This file is part of libunwind.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27 #ifndef AARCH64_LIBUNWIND_I_H
28 #define AARCH64_LIBUNWIND_I_H
30 /* Target-dependent definitions that are internal to libunwind but need
31 to be shared with target-independent code. */
34 #include <libunwind.h>
42 UNW_AARCH64_FRAME_STANDARD
= -2, /* regular fp, sp +/- offset */
43 UNW_AARCH64_FRAME_SIGRETURN
= -1, /* special sigreturn frame */
44 UNW_AARCH64_FRAME_OTHER
= 0, /* not cacheable (special or unrecognised) */
45 UNW_AARCH64_FRAME_GUESSED
= 1 /* guessed it was regular, but not known */
47 unw_tdep_frame_type_t
;
51 uint64_t virtual_address
;
52 int64_t frame_type
: 2; /* unw_tdep_frame_type_t classification */
53 int64_t last_frame
: 1; /* non-zero if last frame in chain */
54 int64_t cfa_reg_sp
: 1; /* cfa dwarf base register is sp vs. fp */
55 int64_t cfa_reg_offset
: 30; /* cfa is at this offset from base register value */
56 int64_t fp_cfa_offset
: 30; /* fp saved at this offset from cfa (-1 = not saved) */
57 int64_t lr_cfa_offset
: 30; /* lr saved at this offset from cfa (-1 = not saved) */
58 int64_t sp_cfa_offset
: 30; /* sp saved at this offset from cfa (-1 = not saved) */
64 typedef unw_word_t aarch64_loc_t
;
66 #else /* !UNW_LOCAL_ONLY */
68 typedef struct aarch64_loc
74 #endif /* !UNW_LOCAL_ONLY */
78 struct unw_accessors acc
;
80 unw_caching_policy_t caching_policy
;
81 #ifdef HAVE_ATOMIC_OPS_H
82 AO_t cache_generation
;
84 uint32_t cache_generation
;
86 unw_word_t dyn_generation
; /* see dyn-common.h */
87 unw_word_t dyn_info_list_addr
; /* (cached) dyn_info_list_addr */
88 struct dwarf_rs_cache global_cache
;
89 struct unw_debug_frame_list
*debug_frames
;
94 struct dwarf_cursor dwarf
; /* must be first */
96 unw_tdep_frame_t frame_info
; /* quick tracing assist info */
101 AARCH64_SCF_LINUX_RT_SIGFRAME
,
104 unw_word_t sigcontext_addr
;
105 unw_word_t sigcontext_sp
;
106 unw_word_t sigcontext_pc
;
110 #define DWARF_GET_LOC(l) ((l).val)
112 #ifdef UNW_LOCAL_ONLY
113 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
114 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
115 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
116 # define DWARF_IS_REG_LOC(l) 0
117 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
118 tdep_uc_addr((c)->as_arg, (r)), 0))
119 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
120 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
121 tdep_uc_addr((c)->as_arg, (r)), 0))
124 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
126 if (!DWARF_GET_LOC (loc
))
128 *val
= *(unw_fpreg_t
*) DWARF_GET_LOC (loc
);
133 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
135 if (!DWARF_GET_LOC (loc
))
137 *(unw_fpreg_t
*) DWARF_GET_LOC (loc
) = val
;
142 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
144 if (!DWARF_GET_LOC (loc
))
146 *val
= *(unw_word_t
*) DWARF_GET_LOC (loc
);
151 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
153 if (!DWARF_GET_LOC (loc
))
155 *(unw_word_t
*) DWARF_GET_LOC (loc
) = val
;
159 #else /* !UNW_LOCAL_ONLY */
160 # define DWARF_LOC_TYPE_FP (1 << 0)
161 # define DWARF_LOC_TYPE_REG (1 << 1)
162 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
163 # define DWARF_IS_NULL_LOC(l) \
164 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
165 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
166 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
167 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
168 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
169 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
170 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
171 | DWARF_LOC_TYPE_FP))
174 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
176 char *valp
= (char *) &val
;
180 if (DWARF_IS_NULL_LOC (loc
))
183 if (DWARF_IS_REG_LOC (loc
))
184 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
187 addr
= DWARF_GET_LOC (loc
);
188 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
192 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1, 0,
197 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
199 char *valp
= (char *) &val
;
203 if (DWARF_IS_NULL_LOC (loc
))
206 if (DWARF_IS_REG_LOC (loc
))
207 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
210 addr
= DWARF_GET_LOC (loc
);
211 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
215 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1,
220 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
222 if (DWARF_IS_NULL_LOC (loc
))
225 /* If a code-generator were to save a value of type unw_word_t in a
226 floating-point register, we would have to support this case. I
227 suppose it could happen with MMX registers, but does it really
229 assert (!DWARF_IS_FP_LOC (loc
));
231 if (DWARF_IS_REG_LOC (loc
))
232 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), val
,
235 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), val
,
240 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
242 if (DWARF_IS_NULL_LOC (loc
))
245 /* If a code-generator were to save a value of type unw_word_t in a
246 floating-point register, we would have to support this case. I
247 suppose it could happen with MMX registers, but does it really
249 assert (!DWARF_IS_FP_LOC (loc
));
251 if (DWARF_IS_REG_LOC (loc
))
252 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
255 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
259 #endif /* !UNW_LOCAL_ONLY */
263 #define tdep_getcontext_trace UNW_ARCH_OBJ(getcontext_trace)
264 #define tdep_init_done UNW_OBJ(init_done)
265 #define tdep_init UNW_OBJ(init)
266 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
267 tdep_search_unwind_table. */
268 #define tdep_search_unwind_table dwarf_search_unwind_table
269 #define tdep_find_unwind_table dwarf_find_unwind_table
270 #define tdep_uc_addr UNW_OBJ(uc_addr)
271 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
272 #define tdep_access_reg UNW_OBJ(access_reg)
273 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
274 #define tdep_fetch_frame(c,ip,n) do {} while(0)
275 #define tdep_cache_frame(c,rs) do {} while(0)
276 #define tdep_reuse_frame(c,rs) do {} while(0)
277 #define tdep_stash_frame UNW_OBJ(tdep_stash_frame)
278 #define tdep_trace UNW_OBJ(tdep_trace)
280 #ifdef UNW_LOCAL_ONLY
281 # define tdep_find_proc_info(c,ip,n) \
282 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
284 # define tdep_put_unwind_info(as,pi,arg) \
285 dwarf_put_unwind_info((as), (pi), (arg))
287 # define tdep_find_proc_info(c,ip,n) \
288 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
290 # define tdep_put_unwind_info(as,pi,arg) \
291 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
294 #define tdep_get_as(c) ((c)->dwarf.as)
295 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
296 #define tdep_get_ip(c) ((c)->dwarf.ip)
297 #define tdep_big_endian(as) ((as)->big_endian)
299 extern int tdep_init_done
;
301 extern void tdep_init (void);
302 extern int tdep_search_unwind_table (unw_addr_space_t as
, unw_word_t ip
,
303 unw_dyn_info_t
*di
, unw_proc_info_t
*pi
,
304 int need_unwind_info
, void *arg
);
305 extern void *tdep_uc_addr (unw_tdep_context_t
*uc
, int reg
);
306 extern int tdep_get_elf_image (struct elf_image
*ei
, pid_t pid
, unw_word_t ip
,
307 unsigned long *segbase
, unsigned long *mapoff
,
308 char *path
, size_t pathlen
);
309 extern int tdep_access_reg (struct cursor
*c
, unw_regnum_t reg
,
310 unw_word_t
*valp
, int write
);
311 extern int tdep_access_fpreg (struct cursor
*c
, unw_regnum_t reg
,
312 unw_fpreg_t
*valp
, int write
);
313 extern int tdep_trace (unw_cursor_t
*cursor
, void **addresses
, int *n
);
314 extern void tdep_stash_frame (struct dwarf_cursor
*c
,
315 struct dwarf_reg_state
*rs
);
316 extern int tdep_getcontext_trace (unw_tdep_context_t
*);
318 #endif /* AARCH64_LIBUNWIND_I_H */