blob: c870f5f6ab54e166dac7c81eaa91f15789d95178 [file] [log] [blame]
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -07001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
Ken Werner1e10c292011-04-21 15:52:51 +02003 Copyright 2011 Linaro Limited
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -07004
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070026#include "unwind_i.h"
Ken Werner36511d32011-04-21 16:54:39 +020027#include "offsets.h"
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070028
29#ifndef UNW_REMOTE_ONLY
30
31HIDDEN inline int
32arm_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
33{
Ken Werner1e10c292011-04-21 15:52:51 +020034#ifdef __linux__
35 struct cursor *c = (struct cursor *) cursor;
36 ucontext_t *uc = c->dwarf.as_arg;
Ken Werner1e10c292011-04-21 15:52:51 +020037
Ken Werner36511d32011-04-21 16:54:39 +020038 if (c->sigcontext_format == ARM_SCF_NONE)
39 {
40 /* Since there are no signals involved here we restore the non scratch
41 registers only. */
42 unsigned long regs[10];
43 regs[0] = uc->uc_mcontext.arm_r4;
44 regs[1] = uc->uc_mcontext.arm_r5;
45 regs[2] = uc->uc_mcontext.arm_r6;
46 regs[3] = uc->uc_mcontext.arm_r7;
47 regs[4] = uc->uc_mcontext.arm_r8;
48 regs[5] = uc->uc_mcontext.arm_r9;
49 regs[6] = uc->uc_mcontext.arm_r10;
50 regs[7] = uc->uc_mcontext.arm_fp;
51 regs[8] = uc->uc_mcontext.arm_sp;
52 regs[9] = uc->uc_mcontext.arm_lr;
Ken Werner1e10c292011-04-21 15:52:51 +020053
Ken Werner36511d32011-04-21 16:54:39 +020054 asm __volatile__ (
55 "ldmia %0, {r4-r12, lr}\n"
56 "mov sp, r12\n"
57 "bx lr\n"
58 : : "r" (regs) :
59 );
60 }
61 else
62 {
63 /* In case a signal frame is involved, we're using its trampoline which
64 calls sigreturn. */
65 struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
66 sc->arm_r0 = uc->uc_mcontext.arm_r0;
67 sc->arm_r1 = uc->uc_mcontext.arm_r1;
68 sc->arm_r2 = uc->uc_mcontext.arm_r2;
69 sc->arm_r3 = uc->uc_mcontext.arm_r3;
70 sc->arm_r4 = uc->uc_mcontext.arm_r4;
71 sc->arm_r5 = uc->uc_mcontext.arm_r5;
72 sc->arm_r6 = uc->uc_mcontext.arm_r6;
73 sc->arm_r7 = uc->uc_mcontext.arm_r7;
74 sc->arm_r8 = uc->uc_mcontext.arm_r8;
75 sc->arm_r9 = uc->uc_mcontext.arm_r9;
76 sc->arm_r10 = uc->uc_mcontext.arm_r10;
77 sc->arm_fp = uc->uc_mcontext.arm_fp;
78 sc->arm_ip = uc->uc_mcontext.arm_ip;
79 sc->arm_sp = uc->uc_mcontext.arm_sp;
80 sc->arm_lr = uc->uc_mcontext.arm_lr;
81 sc->arm_pc = uc->uc_mcontext.arm_pc;
82 /* clear the ITSTATE bits. */
83 sc->arm_cpsr &= 0xf9ff03ffUL;
84
85 /* Set the SP and the PC in order to continue execution at the modified
86 trampoline which restores the signal mask and the registers. */
87 asm __volatile__ (
88 "mov sp, %0\n"
89 "bx %1\n"
90 : : "r" (c->sigcontext_sp), "r" (c->sigcontext_pc) :
91 );
92 }
Ken Werner1e10c292011-04-21 15:52:51 +020093#else
94 printf ("%s: implement me\n", __FUNCTION__);
95#endif
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070096 return -UNW_EINVAL;
97}
98
99#endif /* !UNW_REMOTE_ONLY */
100
Ken Werner1e10c292011-04-21 15:52:51 +0200101static inline void
102establish_machine_state (struct cursor *c)
103{
104 unw_addr_space_t as = c->dwarf.as;
105 void *arg = c->dwarf.as_arg;
106 unw_fpreg_t fpval;
107 unw_word_t val;
108 int reg;
109
110 Debug (8, "copying out cursor state\n");
111
112 for (reg = 0; reg <= UNW_REG_LAST; ++reg)
113 {
114 Debug (16, "copying %s %d\n", unw_regname (reg), reg);
115 if (unw_is_fpreg (reg))
116 {
117 if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
118 as->acc.access_fpreg (as, reg, &fpval, 1, arg);
119 }
120 else
121 {
122 if (tdep_access_reg (c, reg, &val, 0) >= 0)
123 as->acc.access_reg (as, reg, &val, 1, arg);
124 }
125 }
126}
127
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -0700128PROTECTED int
129unw_resume (unw_cursor_t *cursor)
130{
Ken Werner1e10c292011-04-21 15:52:51 +0200131 struct cursor *c = (struct cursor *) cursor;
132
133 Debug (1, "(cursor=%p)\n", c);
134
135 if (!c->dwarf.ip)
136 {
137 /* This can happen easily when the frame-chain gets truncated
138 due to bad or missing unwind-info. */
139 Debug (1, "refusing to resume execution at address 0\n");
140 return -UNW_EINVAL;
141 }
142
143 establish_machine_state (c);
144
145 return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
146 c->dwarf.as_arg);
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -0700147}