1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright (C) 2014 Tilera Corp.
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 TILEGX_LIBUNWIND_I_H
27 #define TILEGX_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 Tilegx-specific fast trace */
46 struct unw_accessors acc;
50 unsigned int addr_size;
52 unw_caching_policy_t caching_policy;
53 #ifdef HAVE_ATOMIC_OPS_H
54 AO_t cache_generation;
56 uint32_t cache_generation;
58 unw_word_t dyn_generation; /* see dyn-common.h */
59 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
60 struct dwarf_rs_cache global_cache;
61 struct unw_debug_frame_list *debug_frames;
64 #define tdep_big_endian(as) ((as)->big_endian)
68 struct dwarf_cursor dwarf; /* must be first */
69 unw_word_t sigcontext_addr;
70 unw_word_t sigcontext_sp;
71 unw_word_t sigcontext_pc;
74 #define DWARF_GET_LOC(l) ((l).val)
76 #ifndef UNW_REMOTE_ONLY
77 typedef long tilegx_reg_t;
81 #define DWARF_NULL_LOC DWARF_LOC (0, 0)
82 #define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
83 #define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
84 #define DWARF_IS_REG_LOC(l) 0
85 #define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
86 tdep_uc_addr((c)->as_arg, (r)), 0))
87 #define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
88 #define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
89 tdep_uc_addr((c)->as_arg, (r)), 0))
91 /* Tilegx has no FP. */
93 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
95 Debug (1, "Tielgx has no fp!\n");
101 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
103 Debug (1, "Tielgx has no fp!\n");
109 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
111 if (!DWARF_GET_LOC (loc))
114 *val = *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc);
119 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
121 if (!DWARF_GET_LOC (loc))
124 *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc) = val;
128 #else /* !UNW_LOCAL_ONLY */
129 #define DWARF_LOC_TYPE_FP (1 << 0)
130 #define DWARF_LOC_TYPE_REG (1 << 1)
131 #define DWARF_NULL_LOC DWARF_LOC (0, 0)
132 #define DWARF_IS_NULL_LOC(l) \
133 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
134 #define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
135 #define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
136 #define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
137 #define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
138 #define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
139 #define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
140 | DWARF_LOC_TYPE_FP))
142 /* TILEGX has no fp. */
144 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
146 Debug (1, "Tielgx has no fp!\n");
152 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
154 Debug (1, "Tielgx has no fp!\n");
160 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
162 if (DWARF_IS_NULL_LOC (loc))
165 /* If a code-generator were to save a value of type unw_word_t in a
166 floating-point register, we would have to support this case. I
167 suppose it could happen with MMX registers, but does it really
169 assert (!DWARF_IS_FP_LOC (loc));
171 if (DWARF_IS_REG_LOC (loc))
172 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
175 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
180 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
182 if (DWARF_IS_NULL_LOC (loc))
185 /* If a code-generator were to save a value of type unw_word_t in a
186 floating-point register, we would have to support this case. I
187 suppose it could happen with MMX registers, but does it really
189 assert (!DWARF_IS_FP_LOC (loc));
191 if (DWARF_IS_REG_LOC (loc))
192 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
195 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
199 #endif /* !UNW_LOCAL_ONLY */
201 #define tdep_getcontext_trace unw_getcontext
202 #define tdep_init_done UNW_OBJ(init_done)
203 #define tdep_needs_initialization UNW_OBJ(needs_initialization)
204 #define tdep_init UNW_OBJ(init)
205 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
206 tdep_search_unwind_table. */
207 #define tdep_search_unwind_table dwarf_search_unwind_table
208 #define tdep_find_unwind_table dwarf_find_unwind_table
209 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
210 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
211 #define tdep_get_exe_image_path UNW_ARCH_OBJ(get_exe_image_path)
212 #define tdep_access_reg UNW_OBJ(access_reg)
213 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
214 #define tdep_fetch_frame(c,ip,n) do {} while(0)
215 #define tdep_cache_frame(c) 0
216 #define tdep_reuse_frame(c,frame) do {} while(0)
217 #define tdep_stash_frame(c,rs) do {} while(0)
218 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
220 #ifdef UNW_LOCAL_ONLY
221 #define tdep_find_proc_info(c,ip,n) \
222 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
224 #define tdep_put_unwind_info(as,pi,arg) \
225 dwarf_put_unwind_info((as), (pi), (arg))
227 #define tdep_find_proc_info(c,ip,n) \
228 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
230 #define tdep_put_unwind_info(as,pi,arg) \
231 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
234 #define tdep_get_as(c) ((c)->dwarf.as)
235 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
236 #define tdep_get_ip(c) ((c)->dwarf.ip)
238 extern int tdep_init_done;
240 extern void tdep_init (void);
241 extern int tdep_search_unwind_table (unw_addr_space_t as,
245 int need_unwind_info,
247 extern void *tdep_uc_addr (ucontext_t *uc, int reg);
248 extern int tdep_get_elf_image (struct elf_image *ei,
249 pid_t pid, unw_word_t ip,
250 unsigned long *segbase,
251 unsigned long *mapoff,
252 char *path, size_t pathlen);
253 extern void tdep_get_exe_image_path (char *path);
254 extern int tdep_access_reg (struct cursor *c,
258 extern int tdep_access_fpreg (struct cursor *c,
263 #endif /* TILEGX_LIBUNWIND_I_H */