libunwind_i.h revision 9e98f15e9aee12e67cd5956d06ccb559f6a06213
1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2006-2007 IBM 3 Contributed by 4 Corey Ashford <cjashfor@us.ibm.com> 5 Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com> 6 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. 10 11This file is part of libunwind. 12 13Permission is hereby granted, free of charge, to any person obtaining 14a copy of this software and associated documentation files (the 15"Software"), to deal in the Software without restriction, including 16without limitation the rights to use, copy, modify, merge, publish, 17distribute, sublicense, and/or sell copies of the Software, and to 18permit persons to whom the Software is furnished to do so, subject to 19the following conditions: 20 21The above copyright notice and this permission notice shall be 22included in all copies or substantial portions of the Software. 23 24THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 31 32#ifndef PPC32_LIBUNWIND_I_H 33#define PPC32_LIBUNWIND_I_H 34 35/* Target-dependent definitions that are internal to libunwind but need 36 to be shared with target-independent code. */ 37 38#include <stdlib.h> 39#include <libunwind.h> 40 41#include "elf32.h" 42#include "mempool.h" 43#include "dwarf.h" 44 45struct unw_addr_space 46{ 47 struct unw_accessors acc; 48 unw_caching_policy_t caching_policy; 49#ifdef HAVE_ATOMIC_OPS_H 50 AO_t cache_generation; 51#else 52 uint32_t cache_generation; 53#endif 54 unw_word_t dyn_generation; /* see dyn-common.h */ 55 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ 56 struct dwarf_rs_cache global_cache; 57 struct unw_debug_frame_list *debug_frames; 58 int validate; 59}; 60 61struct cursor 62{ 63 struct dwarf_cursor dwarf; /* must be first */ 64 65 /* Format of sigcontext structure and address at which it is 66 stored: */ 67 enum 68 { 69 PPC_SCF_NONE, /* no signal frame encountered */ 70 PPC_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */ 71 } 72 sigcontext_format; 73 unw_word_t sigcontext_addr; 74}; 75 76#define DWARF_GET_LOC(l) ((l).val) 77 78#ifdef UNW_LOCAL_ONLY 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_IS_FP_LOC(l) 0 84# define DWARF_IS_V_LOC(l) 0 85# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 86# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 87 tdep_uc_addr((c)->as_arg, (r)), 0)) 88# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 89 tdep_uc_addr((c)->as_arg, (r)), 0)) 90# define DWARF_VREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 91 tdep_uc_addr((c)->as_arg, (r)), 0)) 92#else /* !UNW_LOCAL_ONLY */ 93 94# define DWARF_LOC_TYPE_FP (1 << 0) 95# define DWARF_LOC_TYPE_REG (1 << 1) 96# define DWARF_LOC_TYPE_V (1 << 2) 97# define DWARF_NULL_LOC DWARF_LOC (0, 0) 98# define DWARF_IS_NULL_LOC(l) \ 99 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) 100# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) 101# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) 102# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) 103# define DWARF_IS_V_LOC(l) (((l).type & DWARF_LOC_TYPE_V) != 0) 104# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 105# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) 106# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 107 | DWARF_LOC_TYPE_FP)) 108# define DWARF_VREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 109 | DWARF_LOC_TYPE_V)) 110 111#endif /* !UNW_LOCAL_ONLY */ 112 113static inline int 114dwarf_getvr (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t * val) 115{ 116 unw_word_t *valp = (unw_word_t *) val; 117 unw_word_t addr; 118 int ret; 119 120 if (DWARF_IS_NULL_LOC (loc)) 121 return -UNW_EBADREG; 122 123 assert (DWARF_IS_V_LOC (loc)); 124 assert (!DWARF_IS_FP_LOC (loc)); 125 126 if (DWARF_IS_REG_LOC (loc)) 127 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 128 val, 0, c->as_arg); 129 130 addr = DWARF_GET_LOC (loc); 131 132 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, valp, 133 0, c->as_arg)) < 0) 134 return ret; 135 136 return (*c->as->acc.access_mem) (c->as, addr + 8, valp + 1, 0, c->as_arg); 137} 138 139static inline int 140dwarf_putvr (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 141{ 142 unw_word_t *valp = (unw_word_t *) & val; 143 unw_word_t addr; 144 int ret; 145 146 if (DWARF_IS_NULL_LOC (loc)) 147 return -UNW_EBADREG; 148 149 assert (DWARF_IS_V_LOC (loc)); 150 assert (!DWARF_IS_FP_LOC (loc)); 151 152 if (DWARF_IS_REG_LOC (loc)) 153 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 154 &val, 1, c->as_arg); 155 156 addr = DWARF_GET_LOC (loc); 157 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, valp, 158 1, c->as_arg)) < 0) 159 return ret; 160 161 return (*c->as->acc.access_mem) (c->as, addr + 8, valp + 1, 1, c->as_arg); 162} 163 164static inline int 165dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t * val) 166{ 167 unw_word_t *valp = (unw_word_t *) val; 168 unw_word_t addr; 169 170 if (DWARF_IS_NULL_LOC (loc)) 171 return -UNW_EBADREG; 172 173 assert (DWARF_IS_FP_LOC (loc)); 174 assert (!DWARF_IS_V_LOC (loc)); 175 176 if (DWARF_IS_REG_LOC (loc)) 177 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 178 val, 0, c->as_arg); 179 180 addr = DWARF_GET_LOC (loc); 181 return (*c->as->acc.access_mem) (c->as, addr + 0, valp, 0, c->as_arg); 182 183} 184 185static inline int 186dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 187{ 188 unw_word_t *valp = (unw_word_t *) & val; 189 unw_word_t addr; 190 191 if (DWARF_IS_NULL_LOC (loc)) 192 return -UNW_EBADREG; 193 194 assert (DWARF_IS_FP_LOC (loc)); 195 assert (!DWARF_IS_V_LOC (loc)); 196 197 if (DWARF_IS_REG_LOC (loc)) 198 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 199 &val, 1, c->as_arg); 200 201 addr = DWARF_GET_LOC (loc); 202 203 return (*c->as->acc.access_mem) (c->as, addr + 0, valp, 1, c->as_arg); 204} 205 206static inline int 207dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t * val) 208{ 209 if (DWARF_IS_NULL_LOC (loc)) 210 return -UNW_EBADREG; 211 212 /* If a code-generator were to save a value of type unw_word_t in a 213 floating-point register, we would have to support this case. I 214 suppose it could happen with MMX registers, but does it really 215 happen? */ 216 assert (!DWARF_IS_FP_LOC (loc)); 217 assert (!DWARF_IS_V_LOC (loc)); 218 219 if (DWARF_IS_REG_LOC (loc)) 220 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 221 0, c->as_arg); 222 else 223 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 224 0, c->as_arg); 225} 226 227static inline int 228dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 229{ 230 if (DWARF_IS_NULL_LOC (loc)) 231 return -UNW_EBADREG; 232 233 /* If a code-generator were to save a value of type unw_word_t in a 234 floating-point register, we would have to support this case. I 235 suppose it could happen with MMX registers, but does it really 236 happen? */ 237 assert (!DWARF_IS_FP_LOC (loc)); 238 assert (!DWARF_IS_V_LOC (loc)); 239 240 if (DWARF_IS_REG_LOC (loc)) 241 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, 242 1, c->as_arg); 243 else 244 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 245 1, c->as_arg); 246} 247 248#define tdep_needs_initialization UNW_OBJ(needs_initialization) 249#define tdep_init UNW_OBJ(init) 250/* Platforms that support UNW_INFO_FORMAT_TABLE need to define 251 tdep_search_unwind_table. */ 252#define tdep_search_unwind_table dwarf_search_unwind_table 253#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr) 254#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image) 255#define tdep_access_reg UNW_OBJ(access_reg) 256#define tdep_access_fpreg UNW_OBJ(access_fpreg) 257#define tdep_fetch_frame(c,ip,n) do {} while(0) 258#define tdep_cache_frame(c,rs) do {} while(0) 259#define tdep_reuse_frame(c,rs) do {} while(0) 260#define tdep_stash_frame(c,rs) do {} while(0) 261#define tdep_get_func_addr UNW_OBJ(get_func_addr) 262 263#ifdef UNW_LOCAL_ONLY 264# define tdep_find_proc_info(c,ip,n) \ 265 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \ 266 (c)->as_arg) 267# define tdep_put_unwind_info(as,pi,arg) \ 268 dwarf_put_unwind_info((as), (pi), (arg)) 269#else 270# define tdep_find_proc_info(c,ip,n) \ 271 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \ 272 (c)->as_arg) 273# define tdep_put_unwind_info(as,pi,arg) \ 274 (*(as)->acc.put_unwind_info)((as), (pi), (arg)) 275#endif 276 277extern int tdep_fetch_proc_info_post (struct dwarf_cursor *c, unw_word_t ip, 278 int need_unwind_info); 279 280#define tdep_get_as(c) ((c)->dwarf.as) 281#define tdep_get_as_arg(c) ((c)->dwarf.as_arg) 282#define tdep_get_ip(c) ((c)->dwarf.ip) 283#define tdep_big_endian(as) 1 284 285extern int tdep_needs_initialization; 286 287extern void tdep_init (void); 288extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, 289 unw_dyn_info_t * di, 290 unw_proc_info_t * pi, 291 int need_unwind_info, void *arg); 292extern void *tdep_uc_addr (ucontext_t * uc, int reg); 293extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, 294 unsigned long *segbase, unsigned long *mapoff, 295 char *path, size_t pathlen); 296extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg, 297 unw_word_t * valp, int write); 298extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, 299 unw_fpreg_t * valp, int write); 300extern int tdep_get_func_addr (unw_addr_space_t as, unw_word_t addr, 301 unw_word_t *entry_point); 302 303#endif /* PPC64_LIBUNWIND_I_H */ 304