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