• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3    Copyright (C) 2021 Zhaofeng Li
4 
5 This file is part of libunwind.
6 
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 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25 
26 #include "unwind_i.h"
27 
28 HIDDEN int
tdep_access_reg(struct cursor * c,unw_regnum_t reg,unw_word_t * valp,int write)29 tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
30                  int write)
31 {
32   dwarf_loc_t loc;
33 
34   if (reg >= UNW_RISCV_F0 && reg <= UNW_RISCV_F31)
35     return -UNW_EBADREG;
36 
37   switch (reg)
38     {
39     case UNW_RISCV_X0:
40       if (write)
41         return -UNW_EREADONLYREG;
42       *valp = 0;
43       return 0;
44     case UNW_TDEP_IP:
45       if (write)
46         {
47           Debug (16, "pc is now 0x%lx\n", *valp);
48           c->dwarf.ip = *valp;
49         }
50 
51       /* We store PC in place of the hard-wired X0 */
52       loc = c->dwarf.loc[0];
53 
54       /* FIXME: Is IP valid? */
55       break;
56     case UNW_TDEP_SP:
57       if (write)
58         return -UNW_EREADONLYREG;
59       *valp = c->dwarf.cfa;
60       return 0;
61     default:
62       loc = c->dwarf.loc[reg];
63       break;
64     }
65 
66   if (write)
67     {
68       return dwarf_put (&c->dwarf, loc, *valp);
69     }
70   else
71     {
72       return dwarf_get (&c->dwarf, loc, valp);
73     }
74 }
75 
76 HIDDEN int
tdep_access_fpreg(struct cursor * c,unw_regnum_t reg,unw_fpreg_t * valp,int write)77 tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
78                    int write)
79 {
80   dwarf_loc_t loc;
81 
82   if (reg < UNW_RISCV_F0 || reg > UNW_RISCV_F31)
83     return -UNW_EBADREG;
84 
85   loc = c->dwarf.loc[reg];
86 
87   if (write)
88     {
89       return dwarf_putfp (&c->dwarf, loc, *valp);
90     }
91   else
92     {
93       return dwarf_getfp (&c->dwarf, loc, valp);
94     }
95 }
96