Ginit.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2008 CodeSourcery
  3. This file is part of libunwind.
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "unwind_i.h"
  23. #ifdef UNW_REMOTE_ONLY
  24. /* unw_local_addr_space is a NULL pointer in this case. */
  25. PROTECTED unw_addr_space_t unw_local_addr_space;
  26. #else /* !UNW_REMOTE_ONLY */
  27. static struct unw_addr_space local_addr_space;
  28. PROTECTED unw_addr_space_t unw_local_addr_space = &local_addr_space;
  29. static inline void *
  30. uc_addr (unw_tdep_context_t *uc, int reg)
  31. {
  32. if (reg >= UNW_ARM_R0 && reg < UNW_ARM_R0 + 16)
  33. return &uc->regs[reg - UNW_ARM_R0];
  34. else
  35. return NULL;
  36. }
  37. # ifdef UNW_LOCAL_ONLY
  38. HIDDEN void *
  39. tdep_uc_addr (unw_tdep_context_t *uc, int reg)
  40. {
  41. return uc_addr (uc, reg);
  42. }
  43. # endif /* UNW_LOCAL_ONLY */
  44. HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
  45. /* XXX fix me: there is currently no way to locate the dyn-info list
  46. by a remote unwinder. On ia64, this is done via a special
  47. unwind-table entry. Perhaps something similar can be done with
  48. DWARF2 unwind info. */
  49. static int
  50. get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
  51. void *arg)
  52. {
  53. *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
  54. return 0;
  55. }
  56. static int
  57. access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write,
  58. void *arg)
  59. {
  60. if (write)
  61. {
  62. Debug (16, "mem[%x] <- %x\n", addr, *val);
  63. *(unw_word_t *) addr = *val;
  64. }
  65. else
  66. {
  67. *val = *(unw_word_t *) addr;
  68. Debug (16, "mem[%x] -> %x\n", addr, *val);
  69. }
  70. return 0;
  71. }
  72. static int
  73. access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, int write,
  74. void *arg)
  75. {
  76. unw_word_t *addr;
  77. unw_tdep_context_t *uc = arg;
  78. if (unw_is_fpreg (reg))
  79. goto badreg;
  80. Debug (16, "reg = %s\n", unw_regname (reg));
  81. if (!(addr = uc_addr (uc, reg)))
  82. goto badreg;
  83. if (write)
  84. {
  85. *(unw_word_t *) addr = *val;
  86. Debug (12, "%s <- %x\n", unw_regname (reg), *val);
  87. }
  88. else
  89. {
  90. *val = *(unw_word_t *) addr;
  91. Debug (12, "%s -> %x\n", unw_regname (reg), *val);
  92. }
  93. return 0;
  94. badreg:
  95. Debug (1, "bad register number %u\n", reg);
  96. return -UNW_EBADREG;
  97. }
  98. static int
  99. access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
  100. int write, void *arg)
  101. {
  102. unw_tdep_context_t *uc = arg;
  103. unw_fpreg_t *addr;
  104. if (!unw_is_fpreg (reg))
  105. goto badreg;
  106. if (!(addr = uc_addr (uc, reg)))
  107. goto badreg;
  108. if (write)
  109. {
  110. Debug (12, "%s <- %08lx.%08lx.%08lx\n", unw_regname (reg),
  111. ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
  112. *(unw_fpreg_t *) addr = *val;
  113. }
  114. else
  115. {
  116. *val = *(unw_fpreg_t *) addr;
  117. Debug (12, "%s -> %08lx.%08lx.%08lx\n", unw_regname (reg),
  118. ((long *)val)[0], ((long *)val)[1], ((long *)val)[2]);
  119. }
  120. return 0;
  121. badreg:
  122. Debug (1, "bad register number %u\n", reg);
  123. /* attempt to access a non-preserved register */
  124. return -UNW_EBADREG;
  125. }
  126. static int
  127. get_static_proc_name (unw_addr_space_t as, unw_word_t ip,
  128. char *buf, size_t buf_len, unw_word_t *offp,
  129. void *arg)
  130. {
  131. return _Uelf32_get_proc_name (as, getpid (), ip, buf, buf_len, offp);
  132. }
  133. HIDDEN void
  134. arm_local_addr_space_init (void)
  135. {
  136. memset (&local_addr_space, 0, sizeof (local_addr_space));
  137. local_addr_space.caching_policy = UNW_CACHE_GLOBAL;
  138. local_addr_space.acc.find_proc_info = arm_find_proc_info;
  139. local_addr_space.acc.put_unwind_info = arm_put_unwind_info;
  140. local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
  141. local_addr_space.acc.access_mem = access_mem;
  142. local_addr_space.acc.access_reg = access_reg;
  143. local_addr_space.acc.access_fpreg = access_fpreg;
  144. local_addr_space.acc.resume = arm_local_resume;
  145. local_addr_space.acc.get_proc_name = get_static_proc_name;
  146. unw_flush_cache (&local_addr_space, 0, 0);
  147. }
  148. #endif /* !UNW_REMOTE_ONLY */