• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3    Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
4    Copyright (C) 2013 Linaro Limited
5 
6 This file is part of libunwind.
7 
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15 
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
26 
27 #include "unwind_i.h"
28 
29 HIDDEN int
tdep_access_reg(struct cursor * c,unw_regnum_t reg,unw_word_t * valp,int write)30 tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
31                  int write)
32 {
33   dwarf_loc_t loc = DWARF_NULL_LOC;
34   unsigned int mask;
35 
36   switch (reg)
37     {
38     case UNW_AARCH64_X0:
39     case UNW_AARCH64_X1:
40     case UNW_AARCH64_X2:
41     case UNW_AARCH64_X3:
42       mask = 1 << reg;
43       if (write)
44         {
45           c->dwarf.eh_args[reg] = *valp;
46           c->dwarf.eh_valid_mask |= mask;
47           return 0;
48         }
49       else if ((c->dwarf.eh_valid_mask & mask) != 0)
50         {
51           *valp = c->dwarf.eh_args[reg];
52           return 0;
53         }
54       else
55         loc = c->dwarf.loc[reg];
56       break;
57 
58     case UNW_AARCH64_X30:
59       if (write)
60         c->dwarf.ip = *valp;            /* update the IP cache */
61     case UNW_AARCH64_X4:
62     case UNW_AARCH64_X5:
63     case UNW_AARCH64_X6:
64     case UNW_AARCH64_X7:
65     case UNW_AARCH64_X8:
66     case UNW_AARCH64_X9:
67     case UNW_AARCH64_X10:
68     case UNW_AARCH64_X11:
69     case UNW_AARCH64_X12:
70     case UNW_AARCH64_X13:
71     case UNW_AARCH64_X14:
72     case UNW_AARCH64_X15:
73     case UNW_AARCH64_X16:
74     case UNW_AARCH64_X17:
75     case UNW_AARCH64_X18:
76     case UNW_AARCH64_X19:
77     case UNW_AARCH64_X20:
78     case UNW_AARCH64_X21:
79     case UNW_AARCH64_X22:
80     case UNW_AARCH64_X23:
81     case UNW_AARCH64_X24:
82     case UNW_AARCH64_X25:
83     case UNW_AARCH64_X26:
84     case UNW_AARCH64_X27:
85     case UNW_AARCH64_X28:
86     case UNW_AARCH64_X29:
87     case UNW_AARCH64_PC:
88     case UNW_AARCH64_PSTATE:
89       loc = c->dwarf.loc[reg];
90       break;
91 
92     case UNW_AARCH64_SP:
93       if (write)
94         return -UNW_EREADONLYREG;
95       *valp = c->dwarf.cfa;
96       return 0;
97 
98     default:
99       Debug (1, "bad register number %u\n", reg);
100       return -UNW_EBADREG;
101     }
102 
103   if (write)
104     return dwarf_put (&c->dwarf, loc, *valp);
105   else
106     return dwarf_get (&c->dwarf, loc, valp);
107 }
108 
109 HIDDEN int
tdep_access_fpreg(struct cursor * c,unw_regnum_t reg,unw_fpreg_t * valp,int write)110 tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
111                    int write)
112 {
113   dwarf_loc_t loc = c->dwarf.loc[reg];
114   if (write)
115     return dwarf_putfp (&c->dwarf, loc, *valp);
116   else
117     return dwarf_getfp (&c->dwarf, loc, valp);
118 }
119