1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2006-2007 IBM
4 Corey Ashford <cjashfor@us.ibm.com>
5 Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
7 Copied from libunwind-x86_64.h, modified slightly for building
8 frysk successfully on ppc64, by Wu Zhou <woodzltc@cn.ibm.com>
9 Will be replaced when libunwind is ready on ppc64 platform.
11 This file is part of libunwind.
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
21 The above copyright notice and this permission notice shall be
22 included in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
32 #ifndef PPC32_LIBUNWIND_I_H
33 #define PPC32_LIBUNWIND_I_H
35 /* Target-dependent definitions that are internal to libunwind but need
36 to be shared with target-independent code. */
39 #include <libunwind.h>
47 /* no ppc32-specific fast trace */
53 struct unw_accessors acc
;
54 unw_caching_policy_t caching_policy
;
55 #ifdef HAVE_ATOMIC_OPS_H
56 AO_t cache_generation
;
58 uint32_t cache_generation
;
60 unw_word_t dyn_generation
; /* see dyn-common.h */
61 unw_word_t dyn_info_list_addr
; /* (cached) dyn_info_list_addr */
62 struct dwarf_rs_cache global_cache
;
63 struct unw_debug_frame_list
*debug_frames
;
69 struct dwarf_cursor dwarf
; /* must be first */
71 /* Format of sigcontext structure and address at which it is
75 PPC_SCF_NONE
, /* no signal frame encountered */
76 PPC_SCF_LINUX_RT_SIGFRAME
/* POSIX ucontext_t */
79 unw_word_t sigcontext_addr
;
82 #define DWARF_GET_LOC(l) ((l).val)
85 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
86 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
87 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
88 # define DWARF_IS_REG_LOC(l) 0
89 # define DWARF_IS_FP_LOC(l) 0
90 # define DWARF_IS_V_LOC(l) 0
91 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
92 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
93 tdep_uc_addr((c)->as_arg, (r)), 0))
94 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
95 tdep_uc_addr((c)->as_arg, (r)), 0))
96 # define DWARF_VREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
97 tdep_uc_addr((c)->as_arg, (r)), 0))
98 #else /* !UNW_LOCAL_ONLY */
100 # define DWARF_LOC_TYPE_FP (1 << 0)
101 # define DWARF_LOC_TYPE_REG (1 << 1)
102 # define DWARF_LOC_TYPE_V (1 << 2)
103 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
104 # define DWARF_IS_NULL_LOC(l) \
105 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
106 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
107 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
108 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
109 # define DWARF_IS_V_LOC(l) (((l).type & DWARF_LOC_TYPE_V) != 0)
110 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
111 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
112 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
113 | DWARF_LOC_TYPE_FP))
114 # define DWARF_VREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
117 #endif /* !UNW_LOCAL_ONLY */
120 dwarf_getvr (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
* val
)
122 unw_word_t
*valp
= (unw_word_t
*) val
;
126 if (DWARF_IS_NULL_LOC (loc
))
129 assert (DWARF_IS_V_LOC (loc
));
130 assert (!DWARF_IS_FP_LOC (loc
));
132 if (DWARF_IS_REG_LOC (loc
))
133 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
136 addr
= DWARF_GET_LOC (loc
);
138 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, valp
,
142 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 8, valp
+ 1, 0, c
->as_arg
);
146 dwarf_putvr (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
148 unw_word_t
*valp
= (unw_word_t
*) & val
;
152 if (DWARF_IS_NULL_LOC (loc
))
155 assert (DWARF_IS_V_LOC (loc
));
156 assert (!DWARF_IS_FP_LOC (loc
));
158 if (DWARF_IS_REG_LOC (loc
))
159 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
162 addr
= DWARF_GET_LOC (loc
);
163 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, valp
,
167 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 8, valp
+ 1, 1, c
->as_arg
);
171 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
* val
)
173 unw_word_t
*valp
= (unw_word_t
*) val
;
176 if (DWARF_IS_NULL_LOC (loc
))
179 assert (DWARF_IS_FP_LOC (loc
));
180 assert (!DWARF_IS_V_LOC (loc
));
182 if (DWARF_IS_REG_LOC (loc
))
183 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
186 addr
= DWARF_GET_LOC (loc
);
187 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, valp
, 0, c
->as_arg
);
192 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
194 unw_word_t
*valp
= (unw_word_t
*) & val
;
197 if (DWARF_IS_NULL_LOC (loc
))
200 assert (DWARF_IS_FP_LOC (loc
));
201 assert (!DWARF_IS_V_LOC (loc
));
203 if (DWARF_IS_REG_LOC (loc
))
204 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
207 addr
= DWARF_GET_LOC (loc
);
209 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, valp
, 1, c
->as_arg
);
213 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
* val
)
215 if (DWARF_IS_NULL_LOC (loc
))
218 /* If a code-generator were to save a value of type unw_word_t in a
219 floating-point register, we would have to support this case. I
220 suppose it could happen with MMX registers, but does it really
222 assert (!DWARF_IS_FP_LOC (loc
));
223 assert (!DWARF_IS_V_LOC (loc
));
225 if (DWARF_IS_REG_LOC (loc
))
226 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), val
,
229 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), val
,
234 dwarf_put (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
));
244 assert (!DWARF_IS_V_LOC (loc
));
246 if (DWARF_IS_REG_LOC (loc
))
247 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
250 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
254 #define tdep_getcontext_trace unw_getcontext
255 #define tdep_init_done UNW_OBJ(init_done)
256 #define tdep_init UNW_OBJ(init)
257 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
258 tdep_search_unwind_table. */
259 #define tdep_search_unwind_table dwarf_search_unwind_table
260 #define tdep_find_unwind_table dwarf_find_unwind_table
261 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
262 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
263 #define tdep_access_reg UNW_OBJ(access_reg)
264 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
265 #define tdep_fetch_frame(c,ip,n) do {} while(0)
266 #define tdep_cache_frame(c,rs) do {} while(0)
267 #define tdep_reuse_frame(c,rs) do {} while(0)
268 #define tdep_stash_frame(c,rs) do {} while(0)
269 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
270 #define tdep_get_func_addr UNW_OBJ(get_func_addr)
272 #ifdef UNW_LOCAL_ONLY
273 # define tdep_find_proc_info(c,ip,n) \
274 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
276 # define tdep_put_unwind_info(as,pi,arg) \
277 dwarf_put_unwind_info((as), (pi), (arg))
279 # define tdep_find_proc_info(c,ip,n) \
280 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
282 # define tdep_put_unwind_info(as,pi,arg) \
283 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
286 extern int tdep_fetch_proc_info_post (struct dwarf_cursor
*c
, unw_word_t ip
,
287 int need_unwind_info
);
289 #define tdep_get_as(c) ((c)->dwarf.as)
290 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
291 #define tdep_get_ip(c) ((c)->dwarf.ip)
292 #define tdep_big_endian(as) 1
294 extern int tdep_init_done
;
296 extern void tdep_init (void);
297 extern int tdep_search_unwind_table (unw_addr_space_t as
, unw_word_t ip
,
299 unw_proc_info_t
* pi
,
300 int need_unwind_info
, void *arg
);
301 extern void *tdep_uc_addr (ucontext_t
* uc
, int reg
);
302 extern int tdep_get_elf_image (struct elf_image
*ei
, pid_t pid
, unw_word_t ip
,
303 unsigned long *segbase
, unsigned long *mapoff
,
304 char *path
, size_t pathlen
);
305 extern int tdep_access_reg (struct cursor
*c
, unw_regnum_t reg
,
306 unw_word_t
* valp
, int write
);
307 extern int tdep_access_fpreg (struct cursor
*c
, unw_regnum_t reg
,
308 unw_fpreg_t
* valp
, int write
);
309 extern int tdep_get_func_addr (unw_addr_space_t as
, unw_word_t addr
,
310 unw_word_t
*entry_point
);
312 #endif /* PPC64_LIBUNWIND_I_H */