init.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2002-2005 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  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. static ALWAYS_INLINE int
  23. common_init (struct cursor *c, unw_word_t sp, unw_word_t bsp)
  24. {
  25. unw_word_t bspstore, rbs_base;
  26. uint8_t *natp;
  27. int ret;
  28. if (c->as->caching_policy != UNW_CACHE_NONE)
  29. /* ensure cache doesn't have any stale contents: */
  30. ia64_validate_cache (c->as, c->as_arg);
  31. c->cfm_loc = IA64_REG_LOC (c, UNW_IA64_CFM);
  32. c->loc[IA64_REG_BSP] = IA64_NULL_LOC;
  33. c->loc[IA64_REG_BSPSTORE] = IA64_REG_LOC (c, UNW_IA64_AR_BSPSTORE);
  34. c->loc[IA64_REG_PFS] = IA64_REG_LOC (c, UNW_IA64_AR_PFS);
  35. c->loc[IA64_REG_RNAT] = IA64_REG_LOC (c, UNW_IA64_AR_RNAT);
  36. c->loc[IA64_REG_IP] = IA64_REG_LOC (c, UNW_IA64_IP);
  37. c->loc[IA64_REG_PRI_UNAT_MEM] = IA64_NULL_LOC; /* no primary UNaT location */
  38. c->loc[IA64_REG_UNAT] = IA64_REG_LOC (c, UNW_IA64_AR_UNAT);
  39. c->loc[IA64_REG_PR] = IA64_REG_LOC (c, UNW_IA64_PR);
  40. c->loc[IA64_REG_LC] = IA64_REG_LOC (c, UNW_IA64_AR_LC);
  41. c->loc[IA64_REG_FPSR] = IA64_REG_LOC (c, UNW_IA64_AR_FPSR);
  42. c->loc[IA64_REG_R4] = IA64_REG_LOC (c, UNW_IA64_GR + 4);
  43. c->loc[IA64_REG_R5] = IA64_REG_LOC (c, UNW_IA64_GR + 5);
  44. c->loc[IA64_REG_R6] = IA64_REG_LOC (c, UNW_IA64_GR + 6);
  45. c->loc[IA64_REG_R7] = IA64_REG_LOC (c, UNW_IA64_GR + 7);
  46. natp = c->nat_bitnr;
  47. c->loc[IA64_REG_NAT4] = IA64_REG_NAT_LOC (c, UNW_IA64_NAT + 4, &natp[0]);
  48. c->loc[IA64_REG_NAT5] = IA64_REG_NAT_LOC (c, UNW_IA64_NAT + 5, &natp[1]);
  49. c->loc[IA64_REG_NAT6] = IA64_REG_NAT_LOC (c, UNW_IA64_NAT + 6, &natp[2]);
  50. c->loc[IA64_REG_NAT7] = IA64_REG_NAT_LOC (c, UNW_IA64_NAT + 7, &natp[3]);
  51. c->loc[IA64_REG_B1] = IA64_REG_LOC (c, UNW_IA64_BR + 1);
  52. c->loc[IA64_REG_B2] = IA64_REG_LOC (c, UNW_IA64_BR + 2);
  53. c->loc[IA64_REG_B3] = IA64_REG_LOC (c, UNW_IA64_BR + 3);
  54. c->loc[IA64_REG_B4] = IA64_REG_LOC (c, UNW_IA64_BR + 4);
  55. c->loc[IA64_REG_B5] = IA64_REG_LOC (c, UNW_IA64_BR + 5);
  56. c->loc[IA64_REG_F2] = IA64_FPREG_LOC (c, UNW_IA64_FR + 2);
  57. c->loc[IA64_REG_F3] = IA64_FPREG_LOC (c, UNW_IA64_FR + 3);
  58. c->loc[IA64_REG_F4] = IA64_FPREG_LOC (c, UNW_IA64_FR + 4);
  59. c->loc[IA64_REG_F5] = IA64_FPREG_LOC (c, UNW_IA64_FR + 5);
  60. c->loc[IA64_REG_F16] = IA64_FPREG_LOC (c, UNW_IA64_FR + 16);
  61. c->loc[IA64_REG_F17] = IA64_FPREG_LOC (c, UNW_IA64_FR + 17);
  62. c->loc[IA64_REG_F18] = IA64_FPREG_LOC (c, UNW_IA64_FR + 18);
  63. c->loc[IA64_REG_F19] = IA64_FPREG_LOC (c, UNW_IA64_FR + 19);
  64. c->loc[IA64_REG_F20] = IA64_FPREG_LOC (c, UNW_IA64_FR + 20);
  65. c->loc[IA64_REG_F21] = IA64_FPREG_LOC (c, UNW_IA64_FR + 21);
  66. c->loc[IA64_REG_F22] = IA64_FPREG_LOC (c, UNW_IA64_FR + 22);
  67. c->loc[IA64_REG_F23] = IA64_FPREG_LOC (c, UNW_IA64_FR + 23);
  68. c->loc[IA64_REG_F24] = IA64_FPREG_LOC (c, UNW_IA64_FR + 24);
  69. c->loc[IA64_REG_F25] = IA64_FPREG_LOC (c, UNW_IA64_FR + 25);
  70. c->loc[IA64_REG_F26] = IA64_FPREG_LOC (c, UNW_IA64_FR + 26);
  71. c->loc[IA64_REG_F27] = IA64_FPREG_LOC (c, UNW_IA64_FR + 27);
  72. c->loc[IA64_REG_F28] = IA64_FPREG_LOC (c, UNW_IA64_FR + 28);
  73. c->loc[IA64_REG_F29] = IA64_FPREG_LOC (c, UNW_IA64_FR + 29);
  74. c->loc[IA64_REG_F30] = IA64_FPREG_LOC (c, UNW_IA64_FR + 30);
  75. c->loc[IA64_REG_F31] = IA64_FPREG_LOC (c, UNW_IA64_FR + 31);
  76. ret = ia64_get (c, c->loc[IA64_REG_IP], &c->ip);
  77. if (ret < 0)
  78. return ret;
  79. ret = ia64_get (c, c->cfm_loc, &c->cfm);
  80. if (ret < 0)
  81. return ret;
  82. ret = ia64_get (c, c->loc[IA64_REG_PR], &c->pr);
  83. if (ret < 0)
  84. return ret;
  85. c->sp = c->psp = sp;
  86. c->bsp = bsp;
  87. ret = ia64_get (c, c->loc[IA64_REG_BSPSTORE], &bspstore);
  88. if (ret < 0)
  89. return ret;
  90. c->rbs_curr = c->rbs_left_edge = 0;
  91. /* Try to find a base of the register backing-store. We may default
  92. to a reasonable value (e.g., half the address-space down from
  93. bspstore). If the BSPSTORE looks corrupt, we fail. */
  94. if ((ret = rbs_get_base (c, bspstore, &rbs_base)) < 0)
  95. return ret;
  96. c->rbs_area[0].end = bspstore;
  97. c->rbs_area[0].size = bspstore - rbs_base;
  98. c->rbs_area[0].rnat_loc = IA64_REG_LOC (c, UNW_IA64_AR_RNAT);
  99. Debug (10, "initial rbs-area: [0x%llx-0x%llx), rnat@%s\n",
  100. (long long) rbs_base, (long long) c->rbs_area[0].end,
  101. ia64_strloc (c->rbs_area[0].rnat_loc));
  102. c->pi.flags = 0;
  103. c->sigcontext_addr = 0;
  104. c->abi_marker = 0;
  105. c->last_abi_marker = 0;
  106. c->hint = 0;
  107. c->prev_script = 0;
  108. c->eh_valid_mask = 0;
  109. c->pi_valid = 0;
  110. return 0;
  111. }