1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright (C) 2011-2013 Linaro Limited
4 Copyright (C) 2012 Tommi Rantala <tt.rantala@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. */
30 #ifndef UNW_REMOTE_ONLY
33 aarch64_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
36 struct cursor *c = (struct cursor *) cursor;
37 unw_tdep_context_t *uc = c->dwarf.as_arg;
39 if (c->sigcontext_format == AARCH64_SCF_NONE)
41 /* Since there are no signals involved here we restore EH and non scratch
43 unsigned long regs[15];
44 regs[0] = uc->uc_mcontext.regs[0];
45 regs[1] = uc->uc_mcontext.regs[1];
46 regs[2] = uc->uc_mcontext.regs[2];
47 regs[3] = uc->uc_mcontext.regs[3];
48 regs[4] = uc->uc_mcontext.regs[19];
49 regs[5] = uc->uc_mcontext.regs[20];
50 regs[6] = uc->uc_mcontext.regs[21];
51 regs[7] = uc->uc_mcontext.regs[22];
52 regs[8] = uc->uc_mcontext.regs[23];
53 regs[9] = uc->uc_mcontext.regs[24];
54 regs[10] = uc->uc_mcontext.regs[25];
55 regs[11] = uc->uc_mcontext.regs[26];
56 regs[12] = uc->uc_mcontext.regs[27];
57 regs[13] = uc->uc_mcontext.regs[28];
58 regs[14] = uc->uc_mcontext.regs[30]; /* LR */
59 unsigned long sp = uc->uc_mcontext.sp;
69 "ldp x2, x3, [x4,16]\n"
70 "ldp x19, x20, [x4,32]\n"
71 "ldp x21, x22, [x4,48]\n"
72 "ldp x23, x24, [x4,64]\n"
73 "ldp x25, x26, [x4,80]\n"
74 "ldp x27, x28, [x4,96]\n"
81 "m" (*(struct regs_overlay *)regs)
86 struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
88 if (c->dwarf.eh_valid_mask & 0x1) sc->regs[0] = c->dwarf.eh_args[0];
89 if (c->dwarf.eh_valid_mask & 0x2) sc->regs[1] = c->dwarf.eh_args[1];
90 if (c->dwarf.eh_valid_mask & 0x4) sc->regs[2] = c->dwarf.eh_args[2];
91 if (c->dwarf.eh_valid_mask & 0x8) sc->regs[3] = c->dwarf.eh_args[3];
93 sc->regs[4] = uc->uc_mcontext.regs[4];
94 sc->regs[5] = uc->uc_mcontext.regs[5];
95 sc->regs[6] = uc->uc_mcontext.regs[6];
96 sc->regs[7] = uc->uc_mcontext.regs[7];
97 sc->regs[8] = uc->uc_mcontext.regs[8];
98 sc->regs[9] = uc->uc_mcontext.regs[9];
99 sc->regs[10] = uc->uc_mcontext.regs[10];
100 sc->regs[11] = uc->uc_mcontext.regs[11];
101 sc->regs[12] = uc->uc_mcontext.regs[12];
102 sc->regs[13] = uc->uc_mcontext.regs[13];
103 sc->regs[14] = uc->uc_mcontext.regs[14];
104 sc->regs[15] = uc->uc_mcontext.regs[15];
105 sc->regs[16] = uc->uc_mcontext.regs[16];
106 sc->regs[17] = uc->uc_mcontext.regs[17];
107 sc->regs[18] = uc->uc_mcontext.regs[18];
108 sc->regs[19] = uc->uc_mcontext.regs[19];
109 sc->regs[20] = uc->uc_mcontext.regs[20];
110 sc->regs[21] = uc->uc_mcontext.regs[21];
111 sc->regs[22] = uc->uc_mcontext.regs[22];
112 sc->regs[23] = uc->uc_mcontext.regs[23];
113 sc->regs[24] = uc->uc_mcontext.regs[24];
114 sc->regs[25] = uc->uc_mcontext.regs[25];
115 sc->regs[26] = uc->uc_mcontext.regs[26];
116 sc->regs[27] = uc->uc_mcontext.regs[27];
117 sc->regs[28] = uc->uc_mcontext.regs[28];
118 sc->regs[29] = uc->uc_mcontext.regs[29];
119 sc->regs[30] = uc->uc_mcontext.regs[30];
120 sc->sp = uc->uc_mcontext.sp;
121 sc->pc = uc->uc_mcontext.pc;
122 sc->pstate = uc->uc_mcontext.pstate;
127 : : "r" (c->sigcontext_sp), "r" (c->sigcontext_pc)
132 printf ("%s: implement me\n", __FUNCTION__);
137 #endif /* !UNW_REMOTE_ONLY */
140 establish_machine_state (struct cursor *c)
142 unw_addr_space_t as = c->dwarf.as;
143 void *arg = c->dwarf.as_arg;
148 Debug (8, "copying out cursor state\n");
150 for (reg = 0; reg <= UNW_AARCH64_PSTATE; ++reg)
152 Debug (16, "copying %s %d\n", unw_regname (reg), reg);
153 if (unw_is_fpreg (reg))
155 if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
156 as->acc.access_fpreg (as, reg, &fpval, 1, arg);
160 if (tdep_access_reg (c, reg, &val, 0) >= 0)
161 as->acc.access_reg (as, reg, &val, 1, arg);
167 unw_resume (unw_cursor_t *cursor)
169 struct cursor *c = (struct cursor *) cursor;
171 Debug (1, "(cursor=%p)\n", c);
175 /* This can happen easily when the frame-chain gets truncated
176 due to bad or missing unwind-info. */
177 Debug (1, "refusing to resume execution at address 0\n");
181 establish_machine_state (c);
183 return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,