1 /* Register names and numbers for RISC-V DWARF.
2 This file is part of elfutils.
3
4 This file is free software; you can redistribute it and/or modify
5 it under the terms of either
6
7 * the GNU Lesser General Public License as published by the Free
8 Software Foundation; either version 3 of the License, or (at
9 your option) any later version
10
11 or
12
13 * the GNU General Public License as published by the Free
14 Software Foundation; either version 2 of the License, or (at
15 your option) any later version
16
17 or both in parallel, as here.
18
19 elfutils is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received copies of the GNU General Public License and
25 the GNU Lesser General Public License along with this program. If
26 not, see <http://www.gnu.org/licenses/>. */
27
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
32 #include <string.h>
33 #include <dwarf.h>
34
35 #define BACKEND riscv_
36 #include "libebl_CPU.h"
37
38 ssize_t
riscv_register_info(Ebl * ebl,int regno,char * name,size_t namelen,const char ** prefix,const char ** setname,int * bits,int * type)39 riscv_register_info (Ebl *ebl, int regno, char *name, size_t namelen,
40 const char **prefix, const char **setname,
41 int *bits, int *type)
42 {
43 if (name == NULL)
44 return 64;
45
46 *prefix = "";
47
48 if (regno < 32)
49 {
50 *setname = "integer";
51 *type = DW_ATE_signed;
52 *bits = ebl->class == ELFCLASS64 ? 64 : 32;
53 }
54 else
55 {
56 *setname = "FPU";
57 *type = DW_ATE_float;
58 *bits = 64;
59 }
60
61 switch (regno)
62 {
63 case 0:
64 return stpcpy (name, "zero") + 1 - name;
65
66 case 1:
67 *type = DW_ATE_address;
68 return stpcpy (name, "ra") + 1 - name;
69
70 case 2:
71 *type = DW_ATE_address;
72 return stpcpy (name, "sp") + 1 - name;
73
74 case 3:
75 *type = DW_ATE_address;
76 return stpcpy (name, "gp") + 1 - name;
77
78 case 4:
79 *type = DW_ATE_address;
80 return stpcpy (name, "tp") + 1 - name;
81
82 case 5 ... 7:
83 name[0] = 't';
84 name[1] = regno - 5 + '0';
85 namelen = 2;
86 break;
87
88 case 8 ... 9:
89 name[0] = 's';
90 name[1] = regno - 8 + '0';
91 namelen = 2;
92 break;
93
94 case 10 ... 17:
95 name[0] = 'a';
96 name[1] = regno - 10 + '0';
97 namelen = 2;
98 break;
99
100 case 18 ... 25:
101 name[0] = 's';
102 name[1] = regno - 18 + '2';
103 namelen = 2;
104 break;
105
106 case 26 ... 27:
107 name[0] = 's';
108 name[1] = '1';
109 name[2] = regno - 26 + '0';
110 namelen = 3;
111 break;
112
113 case 28 ... 31:
114 name[0] = 't';
115 name[1] = regno - 28 + '3';
116 namelen = 2;
117 break;
118
119 case 32 ... 39:
120 name[0] = 'f';
121 name[1] = 't';
122 name[2] = regno - 32 + '0';
123 namelen = 3;
124 break;
125
126 case 40 ... 41:
127 name[0] = 'f';
128 name[1] = 's';
129 name[2] = regno - 40 + '0';
130 namelen = 3;
131 break;
132
133 case 42 ... 49:
134 name[0] = 'f';
135 name[1] = 'a';
136 name[2] = regno - 42 + '0';
137 namelen = 3;
138 break;
139
140 case 50 ... 57:
141 name[0] = 'f';
142 name[1] = 's';
143 name[2] = regno - 50 + '2';
144 namelen = 3;
145 break;
146
147 case 58 ... 59:
148 name[0] = 'f';
149 name[1] = 's';
150 name[2] = '1';
151 name[3] = regno - 58 + '0';
152 namelen = 4;
153 break;
154
155 case 60 ... 61:
156 name[0] = 'f';
157 name[1] = 't';
158 name[2] = regno - 60 + '8';
159 namelen = 3;
160 break;
161
162 case 62 ... 63:
163 name[0] = 'f';
164 name[1] = 't';
165 name[2] = '1';
166 name[3] = regno - 62 + '0';
167 namelen = 4;
168 break;
169
170 default:
171 *setname = NULL;
172 return 0;
173 }
174
175 name[namelen++] = '\0';
176 return namelen;
177 }
178