1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
5 This file is part of libunwind.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
26 #ifndef SH_LIBUNWIND_I_H
27 #define SH_LIBUNWIND_I_H
29 /* Target-dependent definitions that are internal to libunwind but need
30 to be shared with target-independent code. */
33 #include <libunwind.h>
41 /* no sh-specific fast trace */
47 struct unw_accessors acc;
49 unw_caching_policy_t caching_policy;
50 #ifdef HAVE_ATOMIC_OPS_H
51 AO_t cache_generation;
53 uint32_t cache_generation;
55 unw_word_t dyn_generation; /* see dyn-common.h */
56 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
57 struct dwarf_rs_cache global_cache;
58 struct unw_debug_frame_list *debug_frames;
63 struct dwarf_cursor dwarf; /* must be first */
66 SH_SCF_NONE, /* no signal frame */
67 SH_SCF_LINUX_SIGFRAME, /* non-RT signal frame */
68 SH_SCF_LINUX_RT_SIGFRAME, /* RT signal frame */
71 unw_word_t sigcontext_addr;
72 unw_word_t sigcontext_sp;
73 unw_word_t sigcontext_pc;
76 #define DWARF_GET_LOC(l) ((l).val)
79 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
80 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
81 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
82 # define DWARF_IS_REG_LOC(l) 0
83 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
84 tdep_uc_addr((c)->as_arg, (r)), 0))
85 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
86 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
87 tdep_uc_addr((c)->as_arg, (r)), 0))
90 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
92 if (!DWARF_GET_LOC (loc))
94 *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
99 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
101 if (!DWARF_GET_LOC (loc))
103 *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
108 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
110 if (!DWARF_GET_LOC (loc))
112 *val = *(unw_word_t *) DWARF_GET_LOC (loc);
117 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
119 if (!DWARF_GET_LOC (loc))
121 *(unw_word_t *) DWARF_GET_LOC (loc) = val;
125 #else /* !UNW_LOCAL_ONLY */
126 # define DWARF_LOC_TYPE_FP (1 << 0)
127 # define DWARF_LOC_TYPE_REG (1 << 1)
128 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
129 # define DWARF_IS_NULL_LOC(l) \
130 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
131 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
132 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
133 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
134 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
135 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
136 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
137 | DWARF_LOC_TYPE_FP))
140 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
142 char *valp = (char *) &val;
146 if (DWARF_IS_NULL_LOC (loc))
149 if (DWARF_IS_REG_LOC (loc))
150 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
153 addr = DWARF_GET_LOC (loc);
154 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
158 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0,
163 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
165 char *valp = (char *) &val;
169 if (DWARF_IS_NULL_LOC (loc))
172 if (DWARF_IS_REG_LOC (loc))
173 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
176 addr = DWARF_GET_LOC (loc);
177 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
181 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1,
186 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
188 if (DWARF_IS_NULL_LOC (loc))
191 /* If a code-generator were to save a value of type unw_word_t in a
192 floating-point register, we would have to support this case. I
193 suppose it could happen with MMX registers, but does it really
195 assert (!DWARF_IS_FP_LOC (loc));
197 if (DWARF_IS_REG_LOC (loc))
198 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
201 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
206 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
208 if (DWARF_IS_NULL_LOC (loc))
211 /* If a code-generator were to save a value of type unw_word_t in a
212 floating-point register, we would have to support this case. I
213 suppose it could happen with MMX registers, but does it really
215 assert (!DWARF_IS_FP_LOC (loc));
217 if (DWARF_IS_REG_LOC (loc))
218 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
221 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
225 #endif /* !UNW_LOCAL_ONLY */
227 #define tdep_getcontext_trace unw_getcontext
228 #define tdep_init_done UNW_OBJ(init_done)
229 #define tdep_init UNW_OBJ(init)
230 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
231 tdep_search_unwind_table. */
232 #define tdep_search_unwind_table dwarf_search_unwind_table
233 #define tdep_find_unwind_table dwarf_find_unwind_table
234 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
235 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
236 #define tdep_access_reg UNW_OBJ(access_reg)
237 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
238 #define tdep_fetch_frame(c,ip,n) do {} while(0)
239 #define tdep_cache_frame(c,rs) do {} while(0)
240 #define tdep_reuse_frame(c,rs) do {} while(0)
241 #define tdep_stash_frame(c,rs) do {} while(0)
242 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
244 #ifdef UNW_LOCAL_ONLY
245 # define tdep_find_proc_info(c,ip,n) \
246 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
248 # define tdep_put_unwind_info(as,pi,arg) \
249 dwarf_put_unwind_info((as), (pi), (arg))
251 # define tdep_find_proc_info(c,ip,n) \
252 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
254 # define tdep_put_unwind_info(as,pi,arg) \
255 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
258 #define tdep_get_as(c) ((c)->dwarf.as)
259 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
260 #define tdep_get_ip(c) ((c)->dwarf.ip)
261 #define tdep_big_endian(as) ((as)->big_endian)
263 extern int tdep_init_done;
265 extern void tdep_init (void);
266 extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
267 unw_dyn_info_t *di, unw_proc_info_t *pi,
268 int need_unwind_info, void *arg);
269 extern void *tdep_uc_addr (unw_tdep_context_t *uc, int reg);
270 extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
271 unsigned long *segbase, unsigned long *mapoff,
272 char *path, size_t pathlen);
273 extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
274 unw_word_t *valp, int write);
275 extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
276 unw_fpreg_t *valp, int write);
278 #endif /* SH_LIBUNWIND_I_H */