Gresume.c 4.3 KB

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