LCOV - code coverage report
Current view: top level - backends - riscv_regs.c (source / functions) Hit Total Coverage
Test: elfutils-0.181 Lines: 101 104 97.1 %
Date: 2020-09-08 14:07:57 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13