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" |
| 27 | |
| 28 | #ifndef UNW_REMOTE_ONLY |
| 29 | |
| 30 | HIDDEN inline int |
| 31 | arm_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg) |
| 32 | { |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame^] | 33 | #ifdef __linux__ |
| 34 | struct cursor *c = (struct cursor *) cursor; |
| 35 | ucontext_t *uc = c->dwarf.as_arg; |
| 36 | unsigned long regs[10]; |
| 37 | |
| 38 | /* Copy the register contents to be restored. */ |
| 39 | regs[0] = uc->uc_mcontext.arm_r4; |
| 40 | regs[1] = uc->uc_mcontext.arm_r5; |
| 41 | regs[2] = uc->uc_mcontext.arm_r6; |
| 42 | regs[3] = uc->uc_mcontext.arm_r7; |
| 43 | regs[4] = uc->uc_mcontext.arm_r8; |
| 44 | regs[5] = uc->uc_mcontext.arm_r9; |
| 45 | regs[6] = uc->uc_mcontext.arm_r10; |
| 46 | regs[7] = uc->uc_mcontext.arm_fp; |
| 47 | regs[8] = uc->uc_mcontext.arm_sp; |
| 48 | regs[9] = uc->uc_mcontext.arm_lr; |
| 49 | |
| 50 | /* Restore the registers. */ |
| 51 | asm __volatile__ ( |
| 52 | "ldmia %0, {r4-r12, lr}\n" |
| 53 | "mov sp, r12\n" |
| 54 | "bx lr\n" |
| 55 | : : "r" (regs) : |
| 56 | ); |
| 57 | #else |
| 58 | printf ("%s: implement me\n", __FUNCTION__); |
| 59 | #endif |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 60 | return -UNW_EINVAL; |
| 61 | } |
| 62 | |
| 63 | #endif /* !UNW_REMOTE_ONLY */ |
| 64 | |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame^] | 65 | static inline void |
| 66 | establish_machine_state (struct cursor *c) |
| 67 | { |
| 68 | unw_addr_space_t as = c->dwarf.as; |
| 69 | void *arg = c->dwarf.as_arg; |
| 70 | unw_fpreg_t fpval; |
| 71 | unw_word_t val; |
| 72 | int reg; |
| 73 | |
| 74 | Debug (8, "copying out cursor state\n"); |
| 75 | |
| 76 | for (reg = 0; reg <= UNW_REG_LAST; ++reg) |
| 77 | { |
| 78 | Debug (16, "copying %s %d\n", unw_regname (reg), reg); |
| 79 | if (unw_is_fpreg (reg)) |
| 80 | { |
| 81 | if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0) |
| 82 | as->acc.access_fpreg (as, reg, &fpval, 1, arg); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | if (tdep_access_reg (c, reg, &val, 0) >= 0) |
| 87 | as->acc.access_reg (as, reg, &val, 1, arg); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 92 | PROTECTED int |
| 93 | unw_resume (unw_cursor_t *cursor) |
| 94 | { |
Ken Werner | 1e10c29 | 2011-04-21 15:52:51 +0200 | [diff] [blame^] | 95 | struct cursor *c = (struct cursor *) cursor; |
| 96 | |
| 97 | Debug (1, "(cursor=%p)\n", c); |
| 98 | |
| 99 | if (!c->dwarf.ip) |
| 100 | { |
| 101 | /* This can happen easily when the frame-chain gets truncated |
| 102 | due to bad or missing unwind-info. */ |
| 103 | Debug (1, "refusing to resume execution at address 0\n"); |
| 104 | return -UNW_EINVAL; |
| 105 | } |
| 106 | |
| 107 | establish_machine_state (c); |
| 108 | |
| 109 | return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c, |
| 110 | c->dwarf.as_arg); |
Daniel Jacobowitz | 3842dac | 2008-02-04 17:16:37 -0700 | [diff] [blame] | 111 | } |