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