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
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25
26#include "unwind_i.h"
27
28HIDDEN int
29tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
30                 int write)
31{
32  struct dwarf_loc loc;
33
34  switch (reg)
35    {
36    case UNW_HPPA_IP:
37      if (write)
38        c->dwarf.ip = *valp;            /* update the IP cache */
39      if (c->dwarf.pi_valid && (*valp < c->dwarf.pi.start_ip
40                                || *valp >= c->dwarf.pi.end_ip))
41        c->dwarf.pi_valid = 0;          /* new IP outside of current proc */
42      break;
43
44    case UNW_HPPA_CFA:
45    case UNW_HPPA_SP:
46      if (write)
47        return -UNW_EREADONLYREG;
48      *valp = c->dwarf.cfa;
49      return 0;
50
51      /* Do the exception-handling register remapping: */
52    case UNW_HPPA_EH0: reg = UNW_HPPA_GR + 20; break;
53    case UNW_HPPA_EH1: reg = UNW_HPPA_GR + 21; break;
54    case UNW_HPPA_EH2: reg = UNW_HPPA_GR + 22; break;
55    case UNW_HPPA_EH3: reg = UNW_HPPA_GR + 31; break;
56
57    default:
58      break;
59    }
60
61  if ((unsigned) (reg - UNW_HPPA_GR) >= 32)
62    return -UNW_EBADREG;
63
64  loc = c->dwarf.loc[reg];
65
66  if (write)
67    return dwarf_put (&c->dwarf, loc, *valp);
68  else
69    return dwarf_get (&c->dwarf, loc, valp);
70}
71
72HIDDEN int
73tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
74                   int write)
75{
76  struct dwarf_loc loc;
77
78  if ((unsigned) (reg - UNW_HPPA_FR) >= 32)
79    return -UNW_EBADREG;
80
81  loc = c->dwarf.loc[reg];
82
83  if (write)
84    return dwarf_putfp (&c->dwarf, loc, *valp);
85  else
86    return dwarf_getfp (&c->dwarf, loc, valp);
87}
88