Gregs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2004 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. HIDDEN int
  23. tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
  24. int write)
  25. {
  26. struct dwarf_loc loc;
  27. switch (reg)
  28. {
  29. case UNW_HPPA_IP:
  30. if (write)
  31. c->dwarf.ip = *valp; /* update the IP cache */
  32. if (c->dwarf.pi_valid && (*valp < c->dwarf.pi.start_ip
  33. || *valp >= c->dwarf.pi.end_ip))
  34. c->dwarf.pi_valid = 0; /* new IP outside of current proc */
  35. break;
  36. case UNW_HPPA_CFA:
  37. case UNW_HPPA_SP:
  38. if (write)
  39. return -UNW_EREADONLYREG;
  40. *valp = c->dwarf.cfa;
  41. return 0;
  42. /* Do the exception-handling register remapping: */
  43. case UNW_HPPA_EH0: reg = UNW_HPPA_GR + 20; break;
  44. case UNW_HPPA_EH1: reg = UNW_HPPA_GR + 21; break;
  45. case UNW_HPPA_EH2: reg = UNW_HPPA_GR + 22; break;
  46. case UNW_HPPA_EH3: reg = UNW_HPPA_GR + 31; break;
  47. default:
  48. break;
  49. }
  50. if ((unsigned) (reg - UNW_HPPA_GR) >= 32)
  51. return -UNW_EBADREG;
  52. loc = c->dwarf.loc[reg];
  53. if (write)
  54. return dwarf_put (&c->dwarf, loc, *valp);
  55. else
  56. return dwarf_get (&c->dwarf, loc, valp);
  57. }
  58. HIDDEN int
  59. tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
  60. int write)
  61. {
  62. struct dwarf_loc loc;
  63. if ((unsigned) (reg - UNW_HPPA_FR) >= 32)
  64. return -UNW_EBADREG;
  65. loc = c->dwarf.loc[reg];
  66. if (write)
  67. return dwarf_putfp (&c->dwarf, loc, *valp);
  68. else
  69. return dwarf_getfp (&c->dwarf, loc, valp);
  70. }