Make UEFI boot-platform build again
[haiku.git] / headers / libs / libunwind / tdep-tilegx / libunwind_i.h
blob9a4ec6a5ed3393eccfb0b20737f5b3f80c748738
1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright (C) 2014 Tilera Corp.
5 This file is part of libunwind.
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:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
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. */
26 #ifndef TILEGX_LIBUNWIND_I_H
27 #define TILEGX_LIBUNWIND_I_H
29 /* Target-dependent definitions that are internal to libunwind but need
30 to be shared with target-independent code. */
32 #include <stdlib.h>
33 #include <libunwind.h>
35 # include "elf64.h"
36 #include "mempool.h"
37 #include "dwarf.h"
39 #ifdef HAVE___THREAD
40 # undef HAVE___THREAD
41 #endif
43 typedef struct
45 /* no Tilegx-specific fast trace */
46 } unw_tdep_frame_t;
48 struct unw_addr_space
50 struct unw_accessors acc;
52 int big_endian;
53 tilegx_abi_t abi;
54 unsigned int addr_size;
56 unw_caching_policy_t caching_policy;
57 #ifdef HAVE_ATOMIC_OPS_H
58 AO_t cache_generation;
59 #else
60 uint32_t cache_generation;
61 #endif
62 unw_word_t dyn_generation; /* see dyn-common.h */
63 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
64 struct dwarf_rs_cache global_cache;
65 struct unw_debug_frame_list *debug_frames;
68 #define tdep_big_endian(as) ((as)->big_endian)
70 struct cursor
72 struct dwarf_cursor dwarf; /* must be first */
73 unw_word_t sigcontext_addr;
74 unw_word_t sigcontext_sp;
75 unw_word_t sigcontext_pc;
78 #define DWARF_GET_LOC(l) ((l).val)
80 #ifndef UNW_REMOTE_ONLY
81 typedef long tilegx_reg_t;
82 #endif
84 #ifdef UNW_LOCAL_ONLY
85 #define DWARF_NULL_LOC DWARF_LOC (0, 0)
86 #define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
87 #define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
88 #define DWARF_IS_REG_LOC(l) 0
89 #define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
90 tdep_uc_addr((c)->as_arg, (r)), 0))
91 #define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
92 #define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) (intptr_t) \
93 tdep_uc_addr((c)->as_arg, (r)), 0))
95 /* Tilegx has no FP. */
96 static inline int
97 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
99 Debug (1, "Tielgx has no fp!\n");
100 abort();
101 return 0;
104 static inline int
105 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
107 Debug (1, "Tielgx has no fp!\n");
108 abort();
109 return 0;
112 static inline int
113 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
115 if (!DWARF_GET_LOC (loc))
116 return -1;
118 *val = *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc);
119 return 0;
122 static inline int
123 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
125 if (!DWARF_GET_LOC (loc))
126 return -1;
128 *(tilegx_reg_t *) (intptr_t) DWARF_GET_LOC (loc) = val;
129 return 0;
132 #else /* !UNW_LOCAL_ONLY */
133 #define DWARF_LOC_TYPE_FP (1 << 0)
134 #define DWARF_LOC_TYPE_REG (1 << 1)
135 #define DWARF_NULL_LOC DWARF_LOC (0, 0)
136 #define DWARF_IS_NULL_LOC(l) \
137 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
138 #define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
139 #define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
140 #define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
141 #define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
142 #define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
143 #define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
144 | DWARF_LOC_TYPE_FP))
146 /* TILEGX has no fp. */
147 static inline int
148 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
150 Debug (1, "Tielgx has no fp!\n");
151 abort();
152 return 0;
155 static inline int
156 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
158 Debug (1, "Tielgx has no fp!\n");
159 abort();
160 return 0;
163 static inline int
164 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
166 if (DWARF_IS_NULL_LOC (loc))
167 return -UNW_EBADREG;
169 /* If a code-generator were to save a value of type unw_word_t in a
170 floating-point register, we would have to support this case. I
171 suppose it could happen with MMX registers, but does it really
172 happen? */
173 assert (!DWARF_IS_FP_LOC (loc));
175 if (DWARF_IS_REG_LOC (loc))
176 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
177 0, c->as_arg);
179 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
180 0, c->as_arg);
183 static inline int
184 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
186 if (DWARF_IS_NULL_LOC (loc))
187 return -UNW_EBADREG;
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));
195 if (DWARF_IS_REG_LOC (loc))
196 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
197 1, c->as_arg);
199 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
200 1, c->as_arg);
203 #endif /* !UNW_LOCAL_ONLY */
205 #define tdep_getcontext_trace unw_getcontext
206 #define tdep_init_done UNW_OBJ(init_done)
207 #define tdep_needs_initialization UNW_OBJ(needs_initialization)
208 #define tdep_init UNW_OBJ(init)
209 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
210 tdep_search_unwind_table. */
211 #define tdep_search_unwind_table dwarf_search_unwind_table
212 #define tdep_find_unwind_table dwarf_find_unwind_table
213 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
214 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
215 #define tdep_access_reg UNW_OBJ(access_reg)
216 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
217 #define tdep_fetch_frame(c,ip,n) do {} while(0)
218 #define tdep_cache_frame(c,rs) do {} while(0)
219 #define tdep_reuse_frame(c,rs) do {} while(0)
220 #define tdep_stash_frame(c,rs) do {} while(0)
221 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
223 #ifdef UNW_LOCAL_ONLY
224 #define tdep_find_proc_info(c,ip,n) \
225 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
226 (c)->as_arg)
227 #define tdep_put_unwind_info(as,pi,arg) \
228 dwarf_put_unwind_info((as), (pi), (arg))
229 #else
230 #define tdep_find_proc_info(c,ip,n) \
231 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
232 (c)->as_arg)
233 #define tdep_put_unwind_info(as,pi,arg) \
234 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
235 #endif
237 #define tdep_get_as(c) ((c)->dwarf.as)
238 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
239 #define tdep_get_ip(c) ((c)->dwarf.ip)
241 extern int tdep_init_done;
243 extern void tdep_init (void);
244 extern int tdep_search_unwind_table (unw_addr_space_t as,
245 unw_word_t ip,
246 unw_dyn_info_t *di,
247 unw_proc_info_t *pi,
248 int need_unwind_info,
249 void *arg);
250 extern void *tdep_uc_addr (ucontext_t *uc, int reg);
251 extern int tdep_get_elf_image (struct elf_image *ei,
252 pid_t pid, unw_word_t ip,
253 unsigned long *segbase,
254 unsigned long *mapoff,
255 char *path, size_t pathlen);
256 extern int tdep_access_reg (struct cursor *c,
257 unw_regnum_t reg,
258 unw_word_t *valp,
259 int write);
260 extern int tdep_access_fpreg (struct cursor *c,
261 unw_regnum_t reg,
262 unw_fpreg_t *valp,
263 int write);
265 #endif /* TILEGX_LIBUNWIND_I_H */