Make UEFI boot-platform build again
[haiku.git] / src / libs / libunwind / hppa / Ginit.c
blob89ad51caca629e7fd3d270a66781020eb776b82a
1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2002, 2004 Hewlett-Packard Co
3 Copyright (C) 2007 David Mosberger-Tang
4 Contributed by David Mosberger-Tang <dmosberger@gmail.com>
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 void *addr;
48 if ((unsigned) (reg - UNW_HPPA_GR) < 32)
49 addr = &uc->uc_mcontext.sc_gr[reg - UNW_HPPA_GR];
50 else if ((unsigned) (reg - UNW_HPPA_FR) < 32)
51 addr = &uc->uc_mcontext.sc_fr[reg - UNW_HPPA_FR];
52 else
53 addr = NULL;
54 return addr;
57 # ifdef UNW_LOCAL_ONLY
59 void *
60 _Uhppa_uc_addr (ucontext_t *uc, int reg)
62 return uc_addr (uc, reg);
65 # endif /* UNW_LOCAL_ONLY */
67 HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
69 /* XXX fix me: there is currently no way to locate the dyn-info list
70 by a remote unwinder. On ia64, this is done via a special
71 unwind-table entry. Perhaps something similar can be done with
72 DWARF2 unwind info. */
74 static void
75 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
77 /* it's a no-op */
80 static int
81 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
82 void *arg)
84 *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
85 return 0;
88 static int
89 access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write,
90 void *arg)
92 if (write)
94 Debug (12, "mem[%x] <- %x\n", addr, *val);
95 *(unw_word_t *) addr = *val;
97 else
99 *val = *(unw_word_t *) addr;
100 Debug (12, "mem[%x] -> %x\n", addr, *val);
102 return 0;
105 static int
106 access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, int write,
107 void *arg)
109 unw_word_t *addr;
110 ucontext_t *uc = arg;
112 if ((unsigned int) (reg - UNW_HPPA_FR) < 32)
113 goto badreg;
115 addr = uc_addr (uc, reg);
116 if (!addr)
117 goto badreg;
119 if (write)
121 *(unw_word_t *) addr = *val;
122 Debug (12, "%s <- %x\n", unw_regname (reg), *val);
124 else
126 *val = *(unw_word_t *) addr;
127 Debug (12, "%s -> %x\n", unw_regname (reg), *val);
129 return 0;
131 badreg:
132 Debug (1, "bad register number %u\n", reg);
133 return -UNW_EBADREG;
136 static int
137 access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
138 int write, void *arg)
140 ucontext_t *uc = arg;
141 unw_fpreg_t *addr;
143 if ((unsigned) (reg - UNW_HPPA_FR) > 32)
144 goto badreg;
146 addr = uc_addr (uc, reg);
147 if (!addr)
148 goto badreg;
150 if (write)
152 Debug (12, "%s <- %08x.%08x\n",
153 unw_regname (reg), val->raw.bits[1], val->raw.bits[0]);
154 *(unw_fpreg_t *) addr = *val;
156 else
158 *val = *(unw_fpreg_t *) addr;
159 Debug (12, "%s -> %08x.%08x\n",
160 unw_regname (reg), val->raw.bits[1], val->raw.bits[0]);
162 return 0;
164 badreg:
165 Debug (1, "bad register number %u\n", reg);
166 /* attempt to access a non-preserved register */
167 return -UNW_EBADREG;
170 static int
171 get_static_proc_name (unw_addr_space_t as, unw_word_t ip,
172 char *buf, size_t buf_len, unw_word_t *offp,
173 void *arg)
175 return _Uelf32_get_proc_name (as, getpid (), ip, buf, buf_len, offp);
178 HIDDEN void
179 hppa_local_addr_space_init (void)
181 memset (&local_addr_space, 0, sizeof (local_addr_space));
182 local_addr_space.caching_policy = UNW_CACHE_GLOBAL;
183 local_addr_space.acc.find_proc_info = dwarf_find_proc_info;
184 local_addr_space.acc.put_unwind_info = put_unwind_info;
185 local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
186 local_addr_space.acc.access_mem = access_mem;
187 local_addr_space.acc.access_reg = access_reg;
188 local_addr_space.acc.access_fpreg = access_fpreg;
189 local_addr_space.acc.resume = hppa_local_resume;
190 local_addr_space.acc.get_proc_name = get_static_proc_name;
191 unw_flush_cache (&local_addr_space, 0, 0);
194 #endif /* !UNW_REMOTE_ONLY */