Gregs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2006-2007 IBM
  3. Contributed by
  4. Corey Ashford <cjashfor@us.ibm.com>
  5. Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
  6. This file is part of libunwind.
  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. The above copyright notice and this permission notice shall be
  15. included in all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  23. #include "unwind_i.h"
  24. HIDDEN int
  25. tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
  26. int write)
  27. {
  28. struct dwarf_loc loc;
  29. switch (reg)
  30. {
  31. case UNW_TDEP_IP:
  32. if (write)
  33. {
  34. c->dwarf.ip = *valp; /* update the IP cache */
  35. if (c->dwarf.pi_valid && (*valp < c->dwarf.pi.start_ip
  36. || *valp >= c->dwarf.pi.end_ip))
  37. c->dwarf.pi_valid = 0; /* new IP outside of current proc */
  38. }
  39. else
  40. *valp = c->dwarf.ip;
  41. return 0;
  42. case UNW_TDEP_SP:
  43. if (write)
  44. return -UNW_EREADONLYREG;
  45. *valp = c->dwarf.cfa;
  46. return 0;
  47. default:
  48. break;
  49. }
  50. /* make sure it's not an FP or VR register */
  51. if ((((unsigned) (reg - UNW_PPC32_F0)) <= 31))
  52. return -UNW_EBADREG;
  53. loc = c->dwarf.loc[reg];
  54. if (write)
  55. return dwarf_put (&c->dwarf, loc, *valp);
  56. else
  57. return dwarf_get (&c->dwarf, loc, valp);
  58. }
  59. HIDDEN int
  60. tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
  61. int write)
  62. {
  63. struct dwarf_loc loc;
  64. if ((unsigned) (reg - UNW_PPC32_F0) < 32)
  65. {
  66. loc = c->dwarf.loc[reg];
  67. if (write)
  68. return dwarf_putfp (&c->dwarf, loc, *valp);
  69. else
  70. return dwarf_getfp (&c->dwarf, loc, valp);
  71. }
  72. return -UNW_EBADREG;
  73. }