Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2008 CodeSourcery |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 3 | Copyright 2011 Linaro Limited |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 25 | |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 26 | #include "unwind_i.h" |
Ken Werner | 36511d3 | 2011-04-21 16:54:39 +0200 | [diff] [blame] | 27 | #include "offsets.h" |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 28 | |
| 29 | #ifndef UNW_REMOTE_ONLY |
| 30 | |
| 31 | HIDDEN inline int |
| 32 | arm_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg) |
| 33 | { |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 34 | #ifdef __linux__ |
| 35 | struct cursor *c = (struct cursor *) cursor; |
| 36 | ucontext_t *uc = c->dwarf.as_arg; |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 37 | |
Ken Werner | 36511d3 | 2011-04-21 16:54:39 +0200 | [diff] [blame] | 38 | 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 Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 53 | |
Ken Werner | 36511d3 | 2011-04-21 16:54:39 +0200 | [diff] [blame] | 54 | 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 Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 93 | #else |
| 94 | printf ("%s: implement me\n", __FUNCTION__); |
| 95 | #endif |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 96 | return -UNW_EINVAL; |
| 97 | } |
| 98 | |
| 99 | #endif /* !UNW_REMOTE_ONLY */ |
| 100 | |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 101 | static inline void |
| 102 | establish_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 Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 128 | PROTECTED int |
| 129 | unw_resume (unw_cursor_t *cursor) |
| 130 | { |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame] | 131 | 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 Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 147 | } |