Coverage Report

Created: 2025-08-24 06:28

/src/elfutils/backends/loongarch_regs.c
Line
Count
Source (jump to first uncovered line)
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
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
0
{
45
0
  if (name == NULL)
46
0
    return 64;
47
48
0
  *prefix = "";
49
50
0
  if (regno < 32)
51
0
    {
52
0
      *setname = "integer";
53
0
      *type = DW_ATE_signed;
54
0
      *bits = ebl->class == ELFCLASS64 ? 64 : 32;
55
0
    }
56
0
  else
57
0
    {
58
0
      *setname = "FPU";
59
0
      *type = DW_ATE_float;
60
0
      *bits = 64;
61
0
    }
62
63
0
  switch (regno)
64
0
    {
65
0
    case 0:
66
0
      return stpcpy (name, "zero") + 1 - name;
67
68
0
    case 1:
69
0
      *type = DW_ATE_address;
70
0
      return stpcpy (name, "ra") + 1 - name;
71
72
0
    case 2:
73
0
      *type = DW_ATE_address;
74
0
      return stpcpy (name, "tp") + 1 - name;
75
76
0
    case 3:
77
0
      *type = DW_ATE_address;
78
0
      return stpcpy (name, "sp") + 1 - name;
79
80
0
    case 4 ... 11:
81
0
      name[0] = 'a';
82
0
      name[1] = regno - 4 + '0';
83
0
      namelen = 2;
84
0
      break;
85
86
0
    case 12 ... 20:
87
0
      name[0] = 't';
88
0
      name[1] = regno - 12 + '0';
89
0
      namelen = 2;
90
0
      break;
91
92
0
    case 21:
93
0
      return stpcpy (name, "u0") + 1 - name;
94
95
0
    case 22:
96
0
      *type = DW_ATE_address;
97
0
      return stpcpy (name, "fp") + 1 - name;
98
99
0
    case 23 ... 31:
100
0
      name[0] = 's';
101
0
      name[1] = regno - 23 + '0';
102
0
      namelen = 2;
103
0
      break;
104
105
0
    case 32 ... 39:
106
0
      name[0] = 'f';
107
0
      name[1] = 'a';
108
0
      name[2] = regno - 32 + '0';
109
0
      namelen = 3;
110
0
      break;
111
112
0
    case 40 ... 49:
113
0
      name[0] = 'f';
114
0
      name[1] = 't';
115
0
      name[2] = regno - 40 + '0';
116
0
      namelen = 3;
117
0
      break;
118
119
0
    case 50 ... 55:
120
0
      name[0] = 'f';
121
0
      name[1] = 't';
122
0
      name[2] = '1';
123
0
      name[3] = regno - 50 + '0';
124
0
      namelen = 4;
125
0
      break;
126
127
0
    case 56 ... 63:
128
0
      name[0] = 'f';
129
0
      name[1] = 's';
130
0
      name[2] = regno - 56 + '0';
131
0
      namelen = 3;
132
0
      break;
133
134
0
    default:
135
0
      *setname = NULL;
136
0
      return 0;
137
0
    }
138
139
0
  name[namelen++] = '\0';
140
0
  return namelen;
141
0
}