* gas/config/tc-avr.c: Change ISA for devices with USB support to
[external/binutils.git] / sim / ppc / registers.c
1 /*  This file is part of the program psim.
2
3     Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 3 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, see <http://www.gnu.org/licenses/>.
17  
18     */
19
20
21 #ifndef _REGISTERS_C_
22 #define _REGISTERS_C_
23
24 #include <ctype.h>
25
26 #include "basics.h"
27 #include "registers.h"
28
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
32
33 #ifdef HAVE_STRING_H
34 #include <string.h>
35 #else
36 #ifdef HAVE_STRINGS_H
37 #include <strings.h>
38 #endif
39 #endif
40
41
42 INLINE_REGISTERS\
43 (void)
44 registers_dump(registers *registers)
45 {
46   int i;
47   int j;
48   for (i = 0; i < 8; i++) {
49     printf_filtered("GPR %2d:", i*4);
50     for (j = 0; j < 4; j++) {
51       printf_filtered(" 0x%08lx", (long)registers->gpr[i*4 + j]);
52     }
53     printf_filtered("\n");
54   }
55 }
56
57 STATIC_INLINE_REGISTERS\
58 (sprs)
59 find_spr(const char name[])
60 {
61   sprs spr;
62   for (spr = 0; spr < nr_of_sprs; spr++)
63     if (spr_is_valid(spr)
64         && !strcmp(name, spr_name(spr))
65         && spr_index(spr) == spr)
66       return spr;
67   return nr_of_sprs;
68 }
69
70 STATIC_INLINE_REGISTERS\
71 (int)
72 are_digits(const char *digits)
73 {
74   while (isdigit(*digits))
75     digits++;
76   return *digits == '\0';
77 }
78
79
80 INLINE_REGISTERS\
81 (register_descriptions)
82 register_description(const char reg[])
83 {
84   register_descriptions description;
85
86   /* try for a general-purpose integer or floating point register */
87   if (reg[0] == 'r' && are_digits(reg + 1)) {
88     description.type = reg_gpr;
89     description.index = atoi(reg+1);
90     description.size = sizeof(gpreg);
91   }
92   else if (reg[0] == 'f' && are_digits(reg + 1)) {
93     description.type = reg_fpr;
94     description.index = atoi(reg+1);
95     description.size = sizeof(fpreg);
96   }
97   else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) {
98     description.type = reg_pc;
99     description.index = 0;
100     description.size = sizeof(unsigned_word);
101   }
102   else if (!strcmp(reg, "sp")) {
103     description.type = reg_gpr;
104     description.index = 1;
105     description.size = sizeof(gpreg);
106   }
107   else if (!strcmp(reg, "toc")) {
108     description.type = reg_gpr;
109     description.index = 2;
110     description.size = sizeof(gpreg);
111   }
112   else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) {
113     description.type = reg_cr;
114     description.index = 0;
115     description.size = sizeof(creg); /* FIXME */
116   }
117   else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) {
118     description.type = reg_msr;
119     description.index = 0;
120     description.size = sizeof(msreg);
121   }
122   else if (!strcmp(reg, "fpscr")) {
123     description.type = reg_fpscr;
124     description.index = 0;
125     description.size = sizeof(fpscreg);
126   }
127   else if (!strncmp(reg, "sr", 2) && are_digits(reg + 2)) {
128     description.type = reg_sr;
129     description.index = atoi(reg+2);
130     description.size = sizeof(sreg);
131   }
132   else if (!strcmp(reg, "cnt")) {
133     description.type = reg_spr;
134     description.index = spr_ctr;
135     description.size = sizeof(spreg);
136   }
137   else if (!strcmp(reg, "insns")) {
138     description.type = reg_insns;
139     description.index = spr_ctr;
140     description.size = sizeof(unsigned_word);
141   }
142   else if (!strcmp(reg, "stalls")) {
143     description.type = reg_stalls;
144     description.index = spr_ctr;
145     description.size = sizeof(unsigned_word);
146   }
147   else if (!strcmp(reg, "cycles")) {
148     description.type = reg_cycles;
149     description.index = spr_ctr;
150     description.size = sizeof(unsigned_word);
151   }
152 #ifdef WITH_ALTIVEC
153   else if (reg[0] == 'v' && reg[1] == 'r' && are_digits(reg + 2)) {
154     description.type = reg_vr;
155     description.index = atoi(reg+2);
156     description.size = sizeof(vreg);
157   }
158    else if (!strcmp(reg, "vscr")) {
159     description.type = reg_vscr;
160     description.index = 0;
161     description.size = sizeof(vscreg);
162   }
163 #endif
164 #ifdef WITH_E500
165   else if (reg[0] == 'e' && reg[1] == 'v' && are_digits(reg + 2)) {
166     description.type = reg_evr;
167     description.index = atoi(reg+2);
168     description.size = sizeof(unsigned64);
169   }
170   else if (reg[0] == 'r' && reg[1] == 'h' && are_digits(reg + 2)) {
171     description.type = reg_gprh;
172     description.index = atoi(reg+2);
173     description.size = sizeof(gpreg);
174   }
175   else if (!strcmp(reg, "acc")) {
176     description.type = reg_acc;
177     description.index = 0;
178     description.size = sizeof(unsigned64);
179   }
180 #endif
181   else {
182     sprs spr = find_spr(reg);
183     if (spr != nr_of_sprs) {
184       description.type = reg_spr;
185       description.index = spr;
186       description.size = sizeof(spreg);
187     }
188     else {
189       description.type = reg_invalid;
190       description.index = 0;
191       description.size = 0;
192     }
193   }
194   return description;
195 }
196
197 #endif /* _REGISTERS_C_ */