Imported Upstream version 1.3.1
[platform/upstream/libunwind.git] / include / tdep-tilegx / libunwind_i.h
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3    Copyright (C) 2014 Tilera Corp.
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 TILEGX_LIBUNWIND_I_H
27 #define TILEGX_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 "elf64.h"
36 #include "mempool.h"
37 #include "dwarf.h"
38
39 typedef struct
40 {
41   /* no Tilegx-specific fast trace */
42 } unw_tdep_frame_t;
43
44 struct unw_addr_space
45 {
46   struct unw_accessors acc;
47
48   int big_endian;
49   tilegx_abi_t abi;
50   unsigned int addr_size;
51
52   unw_caching_policy_t caching_policy;
53 #ifdef HAVE_ATOMIC_OPS_H
54   AO_t cache_generation;
55 #else
56   uint32_t cache_generation;
57 #endif
58   unw_word_t dyn_generation;          /* see dyn-common.h */
59   unw_word_t dyn_info_list_addr;      /* (cached) dyn_info_list_addr */
60   struct dwarf_rs_cache global_cache;
61   struct unw_debug_frame_list *debug_frames;
62 };
63
64 #define tdep_big_endian(as)            ((as)->big_endian)
65
66 struct cursor
67 {
68   struct dwarf_cursor dwarf;         /* must be first */
69   unw_word_t sigcontext_addr;
70   unw_word_t sigcontext_sp;
71   unw_word_t sigcontext_pc;
72 };
73
74 #define DWARF_GET_LOC(l)      ((l).val)
75
76 #ifndef UNW_REMOTE_ONLY
77 typedef long tilegx_reg_t;
78 #endif
79
80 #ifdef UNW_LOCAL_ONLY
81 #define DWARF_NULL_LOC         DWARF_LOC (0, 0)
82 #define DWARF_IS_NULL_LOC(l)   (DWARF_GET_LOC (l) == 0)
83 #define DWARF_LOC(r, t)        ((dwarf_loc_t) { .val = (r) })
84 #define DWARF_IS_REG_LOC(l)    0
85 #define DWARF_REG_LOC(c,r)     (DWARF_LOC((unw_word_t) (intptr_t)       \
86                                           tdep_uc_addr((c)->as_arg, (r)), 0))
87 #define DWARF_MEM_LOC(c,m)     DWARF_LOC ((m), 0)
88 #define DWARF_FPREG_LOC(c,r)   (DWARF_LOC((unw_word_t) (intptr_t)       \
89                                           tdep_uc_addr((c)->as_arg, (r)), 0))
90
91 /* Tilegx has no FP. */
92 static inline int
93 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
94 {
95   Debug (1, "Tielgx has no fp!\n");
96   abort();
97   return 0;
98 }
99
100 static inline int
101 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
102 {
103   Debug (1, "Tielgx has no fp!\n");
104   abort();
105   return 0;
106 }
107
108 static inline int
109 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
110 {
111   if (!DWARF_GET_LOC (loc))
112     return -1;
113
114   *val = *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc);
115   return 0;
116 }
117
118 static inline int
119 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
120 {
121   if (!DWARF_GET_LOC (loc))
122     return -1;
123
124   *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc) = val;
125   return 0;
126 }
127
128 #else /* !UNW_LOCAL_ONLY */
129 #define DWARF_LOC_TYPE_FP      (1 << 0)
130 #define DWARF_LOC_TYPE_REG     (1 << 1)
131 #define DWARF_NULL_LOC         DWARF_LOC (0, 0)
132 #define DWARF_IS_NULL_LOC(l)                                    \
133   ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
134 #define DWARF_LOC(r, t)        ((dwarf_loc_t) { .val = (r), .type = (t) })
135 #define DWARF_IS_REG_LOC(l)    (((l).type & DWARF_LOC_TYPE_REG) != 0)
136 #define DWARF_IS_FP_LOC(l)     (((l).type & DWARF_LOC_TYPE_FP) != 0)
137 #define DWARF_REG_LOC(c,r)     DWARF_LOC((r), DWARF_LOC_TYPE_REG)
138 #define DWARF_MEM_LOC(c,m)     DWARF_LOC ((m), 0)
139 #define DWARF_FPREG_LOC(c,r)   DWARF_LOC((r), (DWARF_LOC_TYPE_REG       \
140                                                | DWARF_LOC_TYPE_FP))
141
142 /* TILEGX has no fp. */
143 static inline int
144 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
145 {
146   Debug (1, "Tielgx has no fp!\n");
147   abort();
148   return 0;
149 }
150
151 static inline int
152 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
153 {
154   Debug (1, "Tielgx has no fp!\n");
155   abort();
156   return 0;
157 }
158
159 static inline int
160 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
161 {
162   if (DWARF_IS_NULL_LOC (loc))
163     return -UNW_EBADREG;
164
165   /* If a code-generator were to save a value of type unw_word_t in a
166      floating-point register, we would have to support this case.  I
167      suppose it could happen with MMX registers, but does it really
168      happen?  */
169   assert (!DWARF_IS_FP_LOC (loc));
170
171   if (DWARF_IS_REG_LOC (loc))
172     return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
173                                      0, c->as_arg);
174
175   return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
176                                    0, c->as_arg);
177 }
178
179 static inline int
180 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
181 {
182   if (DWARF_IS_NULL_LOC (loc))
183     return -UNW_EBADREG;
184
185   /* If a code-generator were to save a value of type unw_word_t in a
186      floating-point register, we would have to support this case.  I
187      suppose it could happen with MMX registers, but does it really
188      happen?  */
189   assert (!DWARF_IS_FP_LOC (loc));
190
191   if (DWARF_IS_REG_LOC (loc))
192     return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
193                                      1, c->as_arg);
194
195   return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
196                                    1, c->as_arg);
197 }
198
199 #endif /* !UNW_LOCAL_ONLY */
200
201 #define tdep_getcontext_trace           unw_getcontext
202 #define tdep_init_done                  UNW_OBJ(init_done)
203 #define tdep_needs_initialization       UNW_OBJ(needs_initialization)
204 #define tdep_init                       UNW_OBJ(init)
205 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
206    tdep_search_unwind_table.  */
207 #define tdep_search_unwind_table        dwarf_search_unwind_table
208 #define tdep_find_unwind_table          dwarf_find_unwind_table
209 #define tdep_uc_addr                    UNW_ARCH_OBJ(uc_addr)
210 #define tdep_get_elf_image              UNW_ARCH_OBJ(get_elf_image)
211 #define tdep_get_exe_image_path         UNW_ARCH_OBJ(get_exe_image_path)
212 #define tdep_access_reg                 UNW_OBJ(access_reg)
213 #define tdep_access_fpreg               UNW_OBJ(access_fpreg)
214 #define tdep_fetch_frame(c,ip,n)        do {} while(0)
215 #define tdep_cache_frame(c)             0
216 #define tdep_reuse_frame(c,frame)       do {} while(0)
217 #define tdep_stash_frame(c,rs)          do {} while(0)
218 #define tdep_trace(cur,addr,n)          (-UNW_ENOINFO)
219
220 #ifdef UNW_LOCAL_ONLY
221 #define tdep_find_proc_info(c,ip,n)                            \
222   dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n),           \
223                        (c)->as_arg)
224 #define tdep_put_unwind_info(as,pi,arg)         \
225   dwarf_put_unwind_info((as), (pi), (arg))
226 #else
227 #define tdep_find_proc_info(c,ip,n)                                     \
228   (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n),          \
229                                  (c)->as_arg)
230 #define tdep_put_unwind_info(as,pi,arg)                 \
231   (*(as)->acc.put_unwind_info)((as), (pi), (arg))
232 #endif
233
234 #define tdep_get_as(c)                  ((c)->dwarf.as)
235 #define tdep_get_as_arg(c)              ((c)->dwarf.as_arg)
236 #define tdep_get_ip(c)                  ((c)->dwarf.ip)
237
238 extern int tdep_init_done;
239
240 extern void tdep_init (void);
241 extern int tdep_search_unwind_table (unw_addr_space_t as,
242                                      unw_word_t ip,
243                                      unw_dyn_info_t *di,
244                                      unw_proc_info_t *pi,
245                                      int need_unwind_info,
246                                      void *arg);
247 extern void *tdep_uc_addr (ucontext_t *uc, int reg);
248 extern int tdep_get_elf_image (struct elf_image *ei,
249                                pid_t pid, unw_word_t ip,
250                                unsigned long *segbase,
251                                unsigned long *mapoff,
252                                char *path, size_t pathlen);
253 extern void tdep_get_exe_image_path (char *path);
254 extern int tdep_access_reg (struct cursor *c,
255                             unw_regnum_t reg,
256                             unw_word_t *valp,
257                             int write);
258 extern int tdep_access_fpreg (struct cursor *c,
259                               unw_regnum_t reg,
260                               unw_fpreg_t *valp,
261                               int write);
262
263 #endif /* TILEGX_LIBUNWIND_I_H */