blob: e334c2a66e30eb847c421d9a94498fc15c655f84 [file] [log] [blame]
mostang.com!davidm51095502003-03-11 01:11:18 +00001/* libunwind - a platform-independent unwind library
hp.com!davidm25b87952004-01-22 08:36:15 +00002 Copyright (C) 2002-2004 Hewlett-Packard Co
mostang.com!davidm51095502003-03-11 01:11:18 +00003 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 TDEP_X86_H
27#define TDEP_X86_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
hp.com!davidm497018e2003-11-27 06:52:54 +000035#include "elf32.h"
hp.com!davidm468aacc2003-12-20 11:50:00 +000036#include "dwarf.h"
mostang.com!davidm51095502003-03-11 01:11:18 +000037
38struct unw_addr_space
39 {
40 struct unw_accessors acc;
41 unw_caching_policy_t caching_policy;
42 uint32_t cache_generation;
43 unw_word_t dyn_generation; /* see dyn-common.h */
44 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
45 };
46
47struct cursor
48 {
hp.com!davidm468aacc2003-12-20 11:50:00 +000049 struct dwarf_cursor dwarf; /* must be first */
mostang.com!davidm51095502003-03-11 01:11:18 +000050 };
51
hp.com!davidm468aacc2003-12-20 11:50:00 +000052#define DWARF_GET_LOC(l) ((l).val)
53
54#ifdef UNW_LOCAL_ONLY
55# define DWARF_NULL_LOC DWARF_LOC (0, 0)
56# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
57# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
58# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
59 tdep_uc_addr((c)->as_arg, (r)), 0))
60# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
61# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
62 tdep_uc_addr((c)->as_arg, (r)), 0))
63
64static inline int
65dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
66{
67 if (!DWARF_GET_LOC (loc))
68 return -1;
69 *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
70 return 0;
71}
72
73static inline int
74dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
75{
76 if (!DWARF_GET_LOC (loc))
77 return -1;
78 *(unw_fpreg_t *) DWARF_GET_LOC (loc) = *val;
79 return 0;
80}
81
82static inline int
83dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
84{
85 if (!DWARF_GET_LOC (loc))
86 return -1;
87 *val = *(unw_word_t *) DWARF_GET_LOC (loc);
88 return 0;
89}
90
91static inline int
92dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
93{
94 if (!DWARF_GET_LOC (loc))
95 return -1;
96 *(unw_word_t *) DWARF_GET_LOC (loc) = val;
97 return 0;
98}
99
100#else /* !UNW_LOCAL_ONLY */
101# define DWARF_LOC_TYPE_FP (1 << 0)
102# define DWARF_LOC_TYPE_REG (1 << 1)
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_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
110# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
111# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
112 | DWARF_LOC_TYPE_FP))
113
114static inline int
115dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
116{
117 abort ();
118}
119
120static inline int
121dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
122{
123 abort ();
124}
125
126static inline int
127dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
128{
129 if (DWARF_IS_FP_LOC (loc))
130 abort ();
131
132 if (DWARF_IS_REG_LOC (loc))
133 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
134 0, c->as_arg);
135 else
136 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
137 0, c->as_arg);
138}
139
140static inline int
141dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
142{
143 if (DWARF_IS_FP_LOC (loc))
144 abort ();
145
146 if (DWARF_IS_REG_LOC (loc))
147 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
148 1, c->as_arg);
149 else
150 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
151 1, c->as_arg);
152}
153
154#endif /* !UNW_LOCAL_ONLY */
155
mostang.com!davidm51095502003-03-11 01:11:18 +0000156/* Platforms that support UNW_INFO_FORMAT_TABLE need to define
157 tdep_search_unwind_table. */
hp.com!davidm468aacc2003-12-20 11:50:00 +0000158#define tdep_search_unwind_table dwarf_search_unwind_table
159#define tdep_find_proc_info dwarf_find_proc_info
160#define tdep_put_unwind_info dwarf_put_unwind_info
mostang.com!davidm51095502003-03-11 01:11:18 +0000161#define tdep_uc_addr(uc,reg) UNW_ARCH_OBJ(uc_addr)(uc,reg)
hp.com!davidmf9cc1e42003-03-29 07:32:50 +0000162#define tdep_get_elf_image(a,b,c,d,e) UNW_ARCH_OBJ(get_elf_image) (a, b, c, \
163 d, e)
mostang.com!davidm51095502003-03-11 01:11:18 +0000164extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
165 unw_dyn_info_t *di, unw_proc_info_t *pi,
166 int need_unwind_info, void *arg);
mostang.com!davidm51095502003-03-11 01:11:18 +0000167extern void tdep_put_unwind_info (unw_addr_space_t as,
168 unw_proc_info_t *pi, void *arg);
169extern void *tdep_uc_addr (ucontext_t *uc, int reg);
hp.com!davidmf9cc1e42003-03-29 07:32:50 +0000170extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
171 unsigned long *segbase, unsigned long *mapoff);
mostang.com!davidm51095502003-03-11 01:11:18 +0000172
173#endif /* TDEP_X86_H */