This commit was generated by cvs2svn to track changes on a CVS vendor
[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 2 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, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19     */
20
21
22 #ifndef _REGISTERS_C_
23 #define _REGISTERS_C_
24
25 #include <ctype.h>
26
27 #include "basics.h"
28 #include "registers.h"
29
30 #ifdef HAVE_STDLIB_H
31 #include <stdlib.h>
32 #endif
33
34 #ifdef HAVE_STRING_H
35 #include <string.h>
36 #else
37 #ifdef HAVE_STRINGS_H
38 #include <strings.h>
39 #endif
40 #endif
41
42
43 INLINE_REGISTERS\
44 (void)
45 registers_dump(registers *registers)
46 {
47   int i;
48   int j;
49   for (i = 0; i < 8; i++) {
50     printf_filtered("GPR %2d:", i*4);
51     for (j = 0; j < 4; j++) {
52       printf_filtered(" 0x%08lx", (long)registers->gpr[i*4 + j]);
53     }
54     printf_filtered("\n");
55   }
56 }
57
58 STATIC_INLINE_REGISTERS\
59 (sprs)
60 find_spr(const char name[])
61 {
62   sprs spr;
63   for (spr = 0; spr < nr_of_sprs; spr++)
64     if (spr_is_valid(spr)
65         && !strcmp(name, spr_name(spr))
66         && spr_index(spr) == spr)
67       return spr;
68   return nr_of_sprs;
69 }
70
71 STATIC_INLINE_REGISTERS\
72 (int)
73 are_digits(const char *digits)
74 {
75   while (isdigit(*digits))
76     digits++;
77   return *digits == '\0';
78 }
79
80
81 INLINE_REGISTERS\
82 (register_descriptions)
83 register_description(const char reg[])
84 {
85   register_descriptions description;
86
87   /* try for a general-purpose integer or floating point register */
88   if (reg[0] == 'r' && are_digits(reg + 1)) {
89     description.type = reg_gpr;
90     description.index = atoi(reg+1);
91     description.size = sizeof(gpreg);
92   }
93   else if (reg[0] == 'f' && are_digits(reg + 1)) {
94     description.type = reg_fpr;
95     description.index = atoi(reg+1);
96     description.size = sizeof(fpreg);
97   }
98   else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) {
99     description.type = reg_pc;
100     description.index = 0;
101     description.size = sizeof(unsigned_word);
102   }
103   else if (!strcmp(reg, "sp")) {
104     description.type = reg_gpr;
105     description.index = 1;
106     description.size = sizeof(gpreg);
107   }
108   else if (!strcmp(reg, "toc")) {
109     description.type = reg_gpr;
110     description.index = 2;
111     description.size = sizeof(gpreg);
112   }
113   else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) {
114     description.type = reg_cr;
115     description.index = 0;
116     description.size = sizeof(creg); /* FIXME */
117   }
118   else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) {
119     description.type = reg_msr;
120     description.index = 0;
121     description.size = sizeof(msreg);
122   }
123   else if (!strcmp(reg, "fpscr")) {
124     description.type = reg_fpscr;
125     description.index = 0;
126     description.size = sizeof(fpscreg);
127   }
128   else if (!strncmp(reg, "sr", 2) && are_digits(reg + 2)) {
129     description.type = reg_sr;
130     description.index = atoi(reg+2);
131     description.size = sizeof(sreg);
132   }
133   else if (!strcmp(reg, "cnt")) {
134     description.type = reg_spr;
135     description.index = spr_ctr;
136     description.size = sizeof(spreg);
137   }
138   else if (!strcmp(reg, "insns")) {
139     description.type = reg_insns;
140     description.index = spr_ctr;
141     description.size = sizeof(unsigned_word);
142   }
143   else if (!strcmp(reg, "stalls")) {
144     description.type = reg_stalls;
145     description.index = spr_ctr;
146     description.size = sizeof(unsigned_word);
147   }
148   else if (!strcmp(reg, "cycles")) {
149     description.type = reg_cycles;
150     description.index = spr_ctr;
151     description.size = sizeof(unsigned_word);
152   }
153   else {
154     sprs spr = find_spr(reg);
155     if (spr != nr_of_sprs) {
156       description.type = reg_spr;
157       description.index = spr;
158       description.size = sizeof(spreg);
159     }
160     else {
161       description.type = reg_invalid;
162       description.index = 0;
163       description.size = 0;
164     }
165   }
166   return description;
167 }
168
169 #endif /* _REGISTERS_C_ */