/src/elfutils/backends/riscv_regs.c
Line | Count | Source |
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 |
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 | 0 | { |
43 | 0 | if (name == NULL) |
44 | 0 | return 64; |
45 | | |
46 | 0 | *prefix = ""; |
47 | |
|
48 | 0 | if (regno < 32) |
49 | 0 | { |
50 | 0 | *setname = "integer"; |
51 | 0 | *type = DW_ATE_signed; |
52 | 0 | *bits = ebl->class == ELFCLASS64 ? 64 : 32; |
53 | 0 | } |
54 | 0 | else |
55 | 0 | { |
56 | 0 | *setname = "FPU"; |
57 | 0 | *type = DW_ATE_float; |
58 | 0 | *bits = 64; |
59 | 0 | } |
60 | |
|
61 | 0 | switch (regno) |
62 | 0 | { |
63 | 0 | case 0: |
64 | 0 | return stpcpy (name, "zero") + 1 - name; |
65 | | |
66 | 0 | case 1: |
67 | 0 | *type = DW_ATE_address; |
68 | 0 | return stpcpy (name, "ra") + 1 - name; |
69 | | |
70 | 0 | case 2: |
71 | 0 | *type = DW_ATE_address; |
72 | 0 | return stpcpy (name, "sp") + 1 - name; |
73 | | |
74 | 0 | case 3: |
75 | 0 | *type = DW_ATE_address; |
76 | 0 | return stpcpy (name, "gp") + 1 - name; |
77 | | |
78 | 0 | case 4: |
79 | 0 | *type = DW_ATE_address; |
80 | 0 | return stpcpy (name, "tp") + 1 - name; |
81 | | |
82 | 0 | case 5 ... 7: |
83 | 0 | name[0] = 't'; |
84 | 0 | name[1] = regno - 5 + '0'; |
85 | 0 | namelen = 2; |
86 | 0 | break; |
87 | | |
88 | 0 | case 8 ... 9: |
89 | 0 | name[0] = 's'; |
90 | 0 | name[1] = regno - 8 + '0'; |
91 | 0 | namelen = 2; |
92 | 0 | break; |
93 | | |
94 | 0 | case 10 ... 17: |
95 | 0 | name[0] = 'a'; |
96 | 0 | name[1] = regno - 10 + '0'; |
97 | 0 | namelen = 2; |
98 | 0 | break; |
99 | | |
100 | 0 | case 18 ... 25: |
101 | 0 | name[0] = 's'; |
102 | 0 | name[1] = regno - 18 + '2'; |
103 | 0 | namelen = 2; |
104 | 0 | break; |
105 | | |
106 | 0 | case 26 ... 27: |
107 | 0 | name[0] = 's'; |
108 | 0 | name[1] = '1'; |
109 | 0 | name[2] = regno - 26 + '0'; |
110 | 0 | namelen = 3; |
111 | 0 | break; |
112 | | |
113 | 0 | case 28 ... 31: |
114 | 0 | name[0] = 't'; |
115 | 0 | name[1] = regno - 28 + '3'; |
116 | 0 | namelen = 2; |
117 | 0 | break; |
118 | | |
119 | 0 | case 32 ... 39: |
120 | 0 | name[0] = 'f'; |
121 | 0 | name[1] = 't'; |
122 | 0 | name[2] = regno - 32 + '0'; |
123 | 0 | namelen = 3; |
124 | 0 | break; |
125 | | |
126 | 0 | case 40 ... 41: |
127 | 0 | name[0] = 'f'; |
128 | 0 | name[1] = 's'; |
129 | 0 | name[2] = regno - 40 + '0'; |
130 | 0 | namelen = 3; |
131 | 0 | break; |
132 | | |
133 | 0 | case 42 ... 49: |
134 | 0 | name[0] = 'f'; |
135 | 0 | name[1] = 'a'; |
136 | 0 | name[2] = regno - 42 + '0'; |
137 | 0 | namelen = 3; |
138 | 0 | break; |
139 | | |
140 | 0 | case 50 ... 57: |
141 | 0 | name[0] = 'f'; |
142 | 0 | name[1] = 's'; |
143 | 0 | name[2] = regno - 50 + '2'; |
144 | 0 | namelen = 3; |
145 | 0 | break; |
146 | | |
147 | 0 | case 58 ... 59: |
148 | 0 | name[0] = 'f'; |
149 | 0 | name[1] = 's'; |
150 | 0 | name[2] = '1'; |
151 | 0 | name[3] = regno - 58 + '0'; |
152 | 0 | namelen = 4; |
153 | 0 | break; |
154 | | |
155 | 0 | case 60 ... 61: |
156 | 0 | name[0] = 'f'; |
157 | 0 | name[1] = 't'; |
158 | 0 | name[2] = regno - 60 + '8'; |
159 | 0 | namelen = 3; |
160 | 0 | break; |
161 | | |
162 | 0 | case 62 ... 63: |
163 | 0 | name[0] = 'f'; |
164 | 0 | name[1] = 't'; |
165 | 0 | name[2] = '1'; |
166 | 0 | name[3] = regno - 62 + '0'; |
167 | 0 | namelen = 4; |
168 | 0 | break; |
169 | | |
170 | 0 | default: |
171 | 0 | *setname = NULL; |
172 | 0 | return 0; |
173 | 0 | } |
174 | | |
175 | 0 | name[namelen++] = '\0'; |
176 | 0 | return namelen; |
177 | 0 | } |