Make UEFI boot-platform build again
[haiku.git] / src / libs / libunwind / aarch64 / Ginit.c
blobaf0359a69c59bfebd07d67d50e2c270c0e75c6f2
1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
4 Copyright (C) 2013 Linaro Limited
6 This file is part of libunwind.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27 #include <stdlib.h>
28 #include <string.h>
30 #include "unwind_i.h"
32 #ifdef UNW_REMOTE_ONLY
34 /* unw_local_addr_space is a NULL pointer in this case. */
35 PROTECTED unw_addr_space_t unw_local_addr_space;
37 #else /* !UNW_REMOTE_ONLY */
39 static struct unw_addr_space local_addr_space;
41 PROTECTED unw_addr_space_t unw_local_addr_space = &local_addr_space;
43 static inline void *
44 uc_addr (ucontext_t *uc, int reg)
46 if (reg >= UNW_AARCH64_X0 && reg < UNW_AARCH64_V0)
47 return &uc->uc_mcontext.regs[reg];
48 else if (reg >= UNW_AARCH64_V0 && reg <= UNW_AARCH64_V31)
49 return &GET_FPCTX(uc)->vregs[reg - UNW_AARCH64_V0];
50 else
51 return NULL;
54 # ifdef UNW_LOCAL_ONLY
56 HIDDEN void *
57 tdep_uc_addr (ucontext_t *uc, int reg)
59 return uc_addr (uc, reg);
62 # endif /* UNW_LOCAL_ONLY */
64 HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
66 /* XXX fix me: there is currently no way to locate the dyn-info list
67 by a remote unwinder. On ia64, this is done via a special
68 unwind-table entry. Perhaps something similar can be done with
69 DWARF2 unwind info. */
71 static void
72 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
74 /* it's a no-op */
77 static int
78 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
79 void *arg)
81 *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
82 return 0;
85 static int
86 access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write,
87 void *arg)
89 if (write)
91 Debug (16, "mem[%lx] <- %lx\n", addr, *val);
92 *(unw_word_t *) addr = *val;
94 else
96 *val = *(unw_word_t *) addr;
97 Debug (16, "mem[%lx] -> %lx\n", addr, *val);
99 return 0;
102 static int
103 access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, int write,
104 void *arg)
106 unw_word_t *addr;
107 ucontext_t *uc = arg;
109 if (unw_is_fpreg (reg))
110 goto badreg;
112 if (!(addr = uc_addr (uc, reg)))
113 goto badreg;
115 if (write)
117 *(unw_word_t *) addr = *val;
118 Debug (12, "%s <- %lx\n", unw_regname (reg), *val);
120 else
122 *val = *(unw_word_t *) addr;
123 Debug (12, "%s -> %lx\n", unw_regname (reg), *val);
125 return 0;
127 badreg:
128 Debug (1, "bad register number %u\n", reg);
129 return -UNW_EBADREG;
132 static int
133 access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
134 int write, void *arg)
136 ucontext_t *uc = arg;
137 unw_fpreg_t *addr;
139 if (!unw_is_fpreg (reg))
140 goto badreg;
142 if (!(addr = uc_addr (uc, reg)))
143 goto badreg;
145 if (write)
147 Debug (12, "%s <- %08lx.%08lx.%08lx\n", unw_regname (reg),
148 ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
149 *(unw_fpreg_t *) addr = *val;
151 else
153 *val = *(unw_fpreg_t *) addr;
154 Debug (12, "%s -> %08lx.%08lx.%08lx\n", unw_regname (reg),
155 ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
157 return 0;
159 badreg:
160 Debug (1, "bad register number %u\n", reg);
161 /* attempt to access a non-preserved register */
162 return -UNW_EBADREG;
165 static int
166 get_static_proc_name (unw_addr_space_t as, unw_word_t ip,
167 char *buf, size_t buf_len, unw_word_t *offp,
168 void *arg)
170 return _Uelf64_get_proc_name (as, getpid (), ip, buf, buf_len, offp);
173 HIDDEN void
174 aarch64_local_addr_space_init (void)
176 memset (&local_addr_space, 0, sizeof (local_addr_space));
177 local_addr_space.caching_policy = UNW_CACHE_GLOBAL;
178 local_addr_space.acc.find_proc_info = dwarf_find_proc_info;
179 local_addr_space.acc.put_unwind_info = put_unwind_info;
180 local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
181 local_addr_space.acc.access_mem = access_mem;
182 local_addr_space.acc.access_reg = access_reg;
183 local_addr_space.acc.access_fpreg = access_fpreg;
184 local_addr_space.acc.resume = aarch64_local_resume;
185 local_addr_space.acc.get_proc_name = get_static_proc_name;
186 local_addr_space.big_endian = (__BYTE_ORDER == __BIG_ENDIAN);
187 unw_flush_cache (&local_addr_space, 0, 0);
190 #endif /* !UNW_REMOTE_ONLY */