1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
4 This file is part of libunwind.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25 #ifndef MIPS_LIBUNWIND_I_H
26 #define MIPS_LIBUNWIND_I_H
28 /* Target-dependent definitions that are internal to libunwind but need
29 to be shared with target-independent code. */
32 #include <libunwind.h>
34 #if !defined(UNW_REMOTE_ONLY) && _MIPS_SIM == _ABI64
44 /* no mips-specific fast trace */
50 struct unw_accessors acc
;
54 unsigned int addr_size
;
56 unw_caching_policy_t caching_policy
;
57 #ifdef HAVE_ATOMIC_OPS_H
58 AO_t cache_generation
;
60 uint32_t cache_generation
;
62 unw_word_t dyn_generation
; /* see dyn-common.h */
63 unw_word_t dyn_info_list_addr
; /* (cached) dyn_info_list_addr */
64 struct dwarf_rs_cache global_cache
;
65 struct unw_debug_frame_list
*debug_frames
;
68 #define tdep_big_endian(as) ((as)->big_endian)
72 struct dwarf_cursor dwarf
; /* must be first */
73 unw_word_t sigcontext_addr
;
76 #define DWARF_GET_LOC(l) ((l).val)
78 #ifndef UNW_REMOTE_ONLY
79 # if _MIPS_SIM == _ABIN32
80 typedef long long mips_reg_t
;
82 typedef long mips_reg_t
;
87 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
88 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
89 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
90 # define DWARF_IS_REG_LOC(l) 0
91 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
92 tdep_uc_addr((c)->as_arg, (r)), 0))
93 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
94 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
95 tdep_uc_addr((c)->as_arg, (r)), 0))
97 /* FIXME: Implement these for the MIPS FPU. */
99 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
101 if (!DWARF_GET_LOC (loc
))
103 *val
= *(unw_fpreg_t
*) (intptr_t) DWARF_GET_LOC (loc
);
108 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
110 if (!DWARF_GET_LOC (loc
))
112 *(unw_fpreg_t
*) (intptr_t) DWARF_GET_LOC (loc
) = val
;
117 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
119 if (!DWARF_GET_LOC (loc
))
121 *val
= *(mips_reg_t
*) (intptr_t) DWARF_GET_LOC (loc
);
126 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
128 if (!DWARF_GET_LOC (loc
))
130 *(mips_reg_t
*) (intptr_t) DWARF_GET_LOC (loc
) = val
;
134 #else /* !UNW_LOCAL_ONLY */
135 # define DWARF_LOC_TYPE_FP (1 << 0)
136 # define DWARF_LOC_TYPE_REG (1 << 1)
137 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
138 # define DWARF_IS_NULL_LOC(l) \
139 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
140 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
141 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
142 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
143 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
144 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
145 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
146 | DWARF_LOC_TYPE_FP))
149 read_s32 (struct dwarf_cursor
*c
, unw_word_t addr
, unw_word_t
*val
)
151 int offset
= addr
& 4;
155 ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
- offset
, &memval
, 0, c
->as_arg
);
159 if ((offset
!= 0) == tdep_big_endian (c
->as
))
160 *val
= (int32_t) memval
;
162 *val
= (int32_t) (memval
>> 32);
168 write_s32 (struct dwarf_cursor
*c
, unw_word_t addr
, const unw_word_t
*val
)
170 int offset
= addr
& 4;
174 ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
- offset
, &memval
, 0, c
->as_arg
);
178 if ((offset
!= 0) == tdep_big_endian (c
->as
))
179 memval
= (memval
& ~0xffffffffLL
) | (uint32_t) *val
;
181 memval
= (memval
& 0xffffffffLL
) | (uint32_t) (*val
<< 32);
183 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
- offset
, &memval
, 1, c
->as_arg
);
186 /* FIXME: Implement these for the MIPS FPU. */
188 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
190 char *valp
= (char *) &val
;
194 if (DWARF_IS_NULL_LOC (loc
))
197 if (DWARF_IS_REG_LOC (loc
))
198 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
201 addr
= DWARF_GET_LOC (loc
);
202 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
206 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1, 0,
211 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
213 char *valp
= (char *) &val
;
217 if (DWARF_IS_NULL_LOC (loc
))
220 if (DWARF_IS_REG_LOC (loc
))
221 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
224 addr
= DWARF_GET_LOC (loc
);
225 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
229 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1,
234 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
236 if (DWARF_IS_NULL_LOC (loc
))
239 /* If a code-generator were to save a value of type unw_word_t in a
240 floating-point register, we would have to support this case. I
241 suppose it could happen with MMX registers, but does it really
243 assert (!DWARF_IS_FP_LOC (loc
));
245 if (DWARF_IS_REG_LOC (loc
))
246 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), val
,
248 else if (c
->as
->abi
== UNW_MIPS_ABI_O32
)
249 return read_s32 (c
, DWARF_GET_LOC (loc
), val
);
251 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), val
,
256 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
258 if (DWARF_IS_NULL_LOC (loc
))
261 /* If a code-generator were to save a value of type unw_word_t in a
262 floating-point register, we would have to support this case. I
263 suppose it could happen with MMX registers, but does it really
265 assert (!DWARF_IS_FP_LOC (loc
));
267 if (DWARF_IS_REG_LOC (loc
))
268 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
270 else if (c
->as
->abi
== UNW_MIPS_ABI_O32
)
271 return write_s32 (c
, DWARF_GET_LOC (loc
), &val
);
273 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
277 #endif /* !UNW_LOCAL_ONLY */
279 #define tdep_getcontext_trace unw_getcontext
280 #define tdep_init_done UNW_OBJ(init_done)
281 #define tdep_init UNW_OBJ(init)
282 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
283 tdep_search_unwind_table. */
284 #define tdep_search_unwind_table dwarf_search_unwind_table
285 #define tdep_find_unwind_table dwarf_find_unwind_table
286 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
287 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
288 #define tdep_access_reg UNW_OBJ(access_reg)
289 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
290 #define tdep_fetch_frame(c,ip,n) do {} while(0)
291 #define tdep_cache_frame(c,rs) do {} while(0)
292 #define tdep_reuse_frame(c,rs) do {} while(0)
293 #define tdep_stash_frame(c,rs) do {} while(0)
294 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
296 #ifdef UNW_LOCAL_ONLY
297 # define tdep_find_proc_info(c,ip,n) \
298 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
300 # define tdep_put_unwind_info(as,pi,arg) \
301 dwarf_put_unwind_info((as), (pi), (arg))
303 # define tdep_find_proc_info(c,ip,n) \
304 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
306 # define tdep_put_unwind_info(as,pi,arg) \
307 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
310 #define tdep_get_as(c) ((c)->dwarf.as)
311 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
312 #define tdep_get_ip(c) ((c)->dwarf.ip)
314 extern int tdep_init_done
;
316 extern void tdep_init (void);
317 extern int tdep_search_unwind_table (unw_addr_space_t as
, unw_word_t ip
,
318 unw_dyn_info_t
*di
, unw_proc_info_t
*pi
,
319 int need_unwind_info
, void *arg
);
320 extern void *tdep_uc_addr (ucontext_t
*uc
, int reg
);
321 extern int tdep_get_elf_image (struct elf_image
*ei
, pid_t pid
, unw_word_t ip
,
322 unsigned long *segbase
, unsigned long *mapoff
,
323 char *path
, size_t pathlen
);
324 extern int tdep_access_reg (struct cursor
*c
, unw_regnum_t reg
,
325 unw_word_t
*valp
, int write
);
326 extern int tdep_access_fpreg (struct cursor
*c
, unw_regnum_t reg
,
327 unw_fpreg_t
*valp
, int write
);
329 #endif /* MIPS_LIBUNWIND_I_H */