Initial import
[external/libunwind.git] / include / tdep-hppa / libunwind_i.h
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2003-2005 Hewlett-Packard Co
3         Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5 This file is part of libunwind.
6
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:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
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.  */
25
26 #ifndef HPPA_LIBUNWIND_I_H
27 #define HPPA_LIBUNWIND_I_H
28
29 /* Target-dependent definitions that are internal to libunwind but need
30    to be shared with target-independent code.  */
31
32 #include <stdlib.h>
33 #include <libunwind.h>
34
35 #include "elf32.h"
36 #include "mempool.h"
37 #include "dwarf.h"
38
39 typedef struct
40   {
41     /* no hppa-specific fast trace */
42   }
43 unw_tdep_frame_t;
44
45 struct 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    };
59
60 struct cursor
61   {
62     struct dwarf_cursor dwarf;          /* must be first */
63
64     /* Format of sigcontext structure and address at which it is
65        stored: */
66     enum
67       {
68         HPPA_SCF_NONE,                  /* no signal frame encountered */
69         HPPA_SCF_LINUX_RT_SIGFRAME      /* POSIX ucontext_t */
70       }
71     sigcontext_format;
72     unw_word_t sigcontext_addr;
73   };
74
75 #define DWARF_GET_LOC(l)        ((l).val)
76
77 #ifdef UNW_LOCAL_ONLY
78 # define DWARF_NULL_LOC         DWARF_LOC (0, 0)
79 # define DWARF_IS_NULL_LOC(l)   (DWARF_GET_LOC (l) == 0)
80 # define DWARF_LOC(r, t)        ((dwarf_loc_t) { .val = (r) })
81 # define DWARF_IS_REG_LOC(l)    0
82 # define DWARF_REG_LOC(c,r)     (DWARF_LOC((unw_word_t)                      \
83                                  tdep_uc_addr((c)->as_arg, (r)), 0))
84 # define DWARF_MEM_LOC(c,m)     DWARF_LOC ((m), 0)
85 # define DWARF_FPREG_LOC(c,r)   (DWARF_LOC((unw_word_t)                      \
86                                  tdep_uc_addr((c)->as_arg, (r)), 0))
87
88 static inline int
89 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
90 {
91   if (!DWARF_GET_LOC (loc))
92     return -1;
93   *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
94   return 0;
95 }
96
97 static inline int
98 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
99 {
100   if (!DWARF_GET_LOC (loc))
101     return -1;
102   *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
103   return 0;
104 }
105
106 static inline int
107 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
108 {
109   if (!DWARF_GET_LOC (loc))
110     return -1;
111   *val = *(unw_word_t *) DWARF_GET_LOC (loc);
112   return 0;
113 }
114
115 static inline int
116 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
117 {
118   if (!DWARF_GET_LOC (loc))
119     return -1;
120   *(unw_word_t *) DWARF_GET_LOC (loc) = val;
121   return 0;
122 }
123
124 #else /* !UNW_LOCAL_ONLY */
125 # define DWARF_LOC_TYPE_FP      (1 << 0)
126 # define DWARF_LOC_TYPE_REG     (1 << 1)
127 # define DWARF_NULL_LOC         DWARF_LOC (0, 0)
128 # define DWARF_IS_NULL_LOC(l)                                           \
129                 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
130 # define DWARF_LOC(r, t)        ((dwarf_loc_t) { .val = (r), .type = (t) })
131 # define DWARF_IS_REG_LOC(l)    (((l).type & DWARF_LOC_TYPE_REG) != 0)
132 # define DWARF_IS_FP_LOC(l)     (((l).type & DWARF_LOC_TYPE_FP) != 0)
133 # define DWARF_REG_LOC(c,r)     DWARF_LOC((r), DWARF_LOC_TYPE_REG)
134 # define DWARF_MEM_LOC(c,m)     DWARF_LOC ((m), 0)
135 # define DWARF_FPREG_LOC(c,r)   DWARF_LOC((r), (DWARF_LOC_TYPE_REG      \
136                                                 | DWARF_LOC_TYPE_FP))
137
138 static inline int
139 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
140 {
141   char *valp = (char *) &val;
142   unw_word_t addr;
143   int ret;
144
145   if (DWARF_IS_NULL_LOC (loc))
146     return -UNW_EBADREG;
147
148   if (DWARF_IS_REG_LOC (loc))
149     return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
150                                        val, 0, c->as_arg);
151
152   addr = DWARF_GET_LOC (loc);
153   if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
154                                        0, c->as_arg)) < 0)
155     return ret;
156
157   return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0,
158                                    c->as_arg);
159 }
160
161 static inline int
162 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
163 {
164   char *valp = (char *) &val;
165   unw_word_t addr;
166   int ret;
167
168   if (DWARF_IS_NULL_LOC (loc))
169     return -UNW_EBADREG;
170
171   if (DWARF_IS_REG_LOC (loc))
172     return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
173                                        &val, 1, c->as_arg);
174
175   addr = DWARF_GET_LOC (loc);
176   if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp,
177                                        1, c->as_arg)) < 0)
178     return ret;
179
180   return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1,
181                                    1, c->as_arg);
182 }
183
184 static inline int
185 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
186 {
187   if (DWARF_IS_NULL_LOC (loc))
188     return -UNW_EBADREG;
189
190   /* If a code-generator were to save a value of type unw_word_t in a
191      floating-point register, we would have to support this case.  I
192      suppose it could happen with MMX registers, but does it really
193      happen?  */
194   assert (!DWARF_IS_FP_LOC (loc));
195
196   if (DWARF_IS_REG_LOC (loc))
197     return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
198                                      0, c->as_arg);
199   else
200     return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
201                                      0, c->as_arg);
202 }
203
204 static inline int
205 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
206 {
207   if (DWARF_IS_NULL_LOC (loc))
208     return -UNW_EBADREG;
209
210   /* If a code-generator were to save a value of type unw_word_t in a
211      floating-point register, we would have to support this case.  I
212      suppose it could happen with MMX registers, but does it really
213      happen?  */
214   assert (!DWARF_IS_FP_LOC (loc));
215
216   if (DWARF_IS_REG_LOC (loc))
217     return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
218                                      1, c->as_arg);
219   else
220     return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
221                                      1, c->as_arg);
222 }
223
224 #endif /* !UNW_LOCAL_ONLY */
225
226 #define tdep_getcontext_trace           unw_getcontext
227 #define tdep_init_done                  UNW_OBJ(init_done)
228 #define tdep_init                       UNW_OBJ(init)
229 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
230    tdep_search_unwind_table.  */
231 #define tdep_search_unwind_table        dwarf_search_unwind_table
232 #define tdep_find_unwind_table          dwarf_find_unwind_table
233 #define tdep_uc_addr                    UNW_ARCH_OBJ(uc_addr)
234 #define tdep_get_elf_image              UNW_ARCH_OBJ(get_elf_image)
235 #define tdep_access_reg                 UNW_OBJ(access_reg)
236 #define tdep_access_fpreg               UNW_OBJ(access_fpreg)
237 #define tdep_fetch_frame(c,ip,n)        do {} while(0)
238 #define tdep_cache_frame(c,rs)          do {} while(0)
239 #define tdep_reuse_frame(c,rs)          do {} while(0)
240 #define tdep_stash_frame(c,rs)          do {} while(0)
241 #define tdep_trace(cur,addr,n)          (-UNW_ENOINFO)
242
243 #ifdef UNW_LOCAL_ONLY
244 # define tdep_find_proc_info(c,ip,n)                            \
245         dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n),      \
246                                        (c)->as_arg)
247 # define tdep_put_unwind_info(as,pi,arg)                \
248         dwarf_put_unwind_info((as), (pi), (arg))
249 #else
250 # define tdep_find_proc_info(c,ip,n)                                    \
251         (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n),    \
252                                        (c)->as_arg)
253 # define tdep_put_unwind_info(as,pi,arg)                \
254         (*(as)->acc.put_unwind_info)((as), (pi), (arg))
255 #endif
256
257 #define tdep_get_as(c)                  ((c)->dwarf.as)
258 #define tdep_get_as_arg(c)              ((c)->dwarf.as_arg)
259 #define tdep_get_ip(c)                  ((c)->dwarf.ip)
260 #define tdep_big_endian(as)             1
261
262 extern int tdep_init_done;
263
264 extern void tdep_init (void);
265 extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
266                                      unw_dyn_info_t *di, unw_proc_info_t *pi,
267                                      int need_unwind_info, void *arg);
268 extern void *tdep_uc_addr (ucontext_t *uc, int reg);
269 extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
270                                unsigned long *segbase, unsigned long *mapoff,
271                                char *path, size_t pathlen);
272 extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
273                             unw_word_t *valp, int write);
274 extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
275                               unw_fpreg_t *valp, int write);
276
277 #endif /* HPPA_LIBUNWIND_I_H */