1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3 Copyright 2011 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 sh_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
== SH_SCF_NONE
)
41 /* Since there are no signals involved here we restore the non scratch
43 unsigned long regs
[8];
44 regs
[0] = uc
->uc_mcontext
.gregs
[8];
45 regs
[1] = uc
->uc_mcontext
.gregs
[9];
46 regs
[2] = uc
->uc_mcontext
.gregs
[10];
47 regs
[3] = uc
->uc_mcontext
.gregs
[11];
48 regs
[4] = uc
->uc_mcontext
.gregs
[12];
49 regs
[5] = uc
->uc_mcontext
.gregs
[13];
50 regs
[6] = uc
->uc_mcontext
.gregs
[14];
51 regs
[7] = uc
->uc_mcontext
.gregs
[15];
52 unsigned long pc
= uc
->uc_mcontext
.pr
;
73 "m" (*(struct regs_overlay
*)regs
)
78 /* In case a signal frame is involved, we're using its trampoline which
80 struct sigcontext
*sc
= (struct sigcontext
*) c
->sigcontext_addr
;
81 sc
->sc_regs
[0] = uc
->uc_mcontext
.gregs
[0];
82 sc
->sc_regs
[1] = uc
->uc_mcontext
.gregs
[1];
83 sc
->sc_regs
[2] = uc
->uc_mcontext
.gregs
[2];
84 sc
->sc_regs
[3] = uc
->uc_mcontext
.gregs
[3];
85 sc
->sc_regs
[4] = uc
->uc_mcontext
.gregs
[4];
86 sc
->sc_regs
[5] = uc
->uc_mcontext
.gregs
[5];
87 sc
->sc_regs
[6] = uc
->uc_mcontext
.gregs
[6];
88 sc
->sc_regs
[7] = uc
->uc_mcontext
.gregs
[7];
89 sc
->sc_regs
[8] = uc
->uc_mcontext
.gregs
[8];
90 sc
->sc_regs
[9] = uc
->uc_mcontext
.gregs
[9];
91 sc
->sc_regs
[10] = uc
->uc_mcontext
.gregs
[10];
92 sc
->sc_regs
[11] = uc
->uc_mcontext
.gregs
[11];
93 sc
->sc_regs
[12] = uc
->uc_mcontext
.gregs
[12];
94 sc
->sc_regs
[13] = uc
->uc_mcontext
.gregs
[13];
95 sc
->sc_regs
[14] = uc
->uc_mcontext
.gregs
[14];
96 sc
->sc_regs
[15] = uc
->uc_mcontext
.gregs
[15];
97 sc
->sc_pc
= uc
->uc_mcontext
.pc
;
98 sc
->sc_pr
= uc
->uc_mcontext
.pr
;
100 /* Set the SP and the PC in order to continue execution at the modified
101 trampoline which restores the signal mask and the registers. */
108 : "r" (c
->sigcontext_sp
),
109 "r" (c
->sigcontext_pc
)
117 #endif /* !UNW_REMOTE_ONLY */
120 establish_machine_state (struct cursor
*c
)
122 unw_addr_space_t as
= c
->dwarf
.as
;
123 void *arg
= c
->dwarf
.as_arg
;
128 Debug (8, "copying out cursor state\n");
130 for (reg
= 0; reg
<= UNW_REG_LAST
; ++reg
)
132 Debug (16, "copying %s %d\n", unw_regname (reg
), reg
);
133 if (unw_is_fpreg (reg
))
135 if (tdep_access_fpreg (c
, reg
, &fpval
, 0) >= 0)
136 as
->acc
.access_fpreg (as
, reg
, &fpval
, 1, arg
);
140 if (tdep_access_reg (c
, reg
, &val
, 0) >= 0)
141 as
->acc
.access_reg (as
, reg
, &val
, 1, arg
);
147 unw_resume (unw_cursor_t
*cursor
)
149 struct cursor
*c
= (struct cursor
*) cursor
;
151 Debug (1, "(cursor=%p)\n", c
);
155 /* This can happen easily when the frame-chain gets truncated
156 due to bad or missing unwind-info. */
157 Debug (1, "refusing to resume execution at address 0\n");
161 establish_machine_state (c
);
163 return (*c
->dwarf
.as
->acc
.resume
) (c
->dwarf
.as
, (unw_cursor_t
*) c
,