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