1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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.
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.
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/>.
27 #include "registers.h"
44 registers_dump(registers
*registers
)
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
]);
53 printf_filtered("\n");
57 STATIC_INLINE_REGISTERS\
59 find_spr(const char name
[])
62 for (spr
= 0; spr
< nr_of_sprs
; spr
++)
64 && !strcmp(name
, spr_name(spr
))
65 && spr_index(spr
) == spr
)
70 STATIC_INLINE_REGISTERS\
72 are_digits(const char *digits
)
74 while (isdigit(*digits
))
76 return *digits
== '\0';
81 (register_descriptions
)
82 register_description(const char reg
[])
84 register_descriptions description
;
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
);
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
);
97 else if (!strcmp(reg
, "pc") || !strcmp(reg
, "nia")) {
98 description
.type
= reg_pc
;
99 description
.index
= 0;
100 description
.size
= sizeof(unsigned_word
);
102 else if (!strcmp(reg
, "sp")) {
103 description
.type
= reg_gpr
;
104 description
.index
= 1;
105 description
.size
= sizeof(gpreg
);
107 else if (!strcmp(reg
, "toc")) {
108 description
.type
= reg_gpr
;
109 description
.index
= 2;
110 description
.size
= sizeof(gpreg
);
112 else if (!strcmp(reg
, "cr") || !strcmp(reg
, "cnd")) {
113 description
.type
= reg_cr
;
114 description
.index
= 0;
115 description
.size
= sizeof(creg
); /* FIXME */
117 else if (!strcmp(reg
, "msr") || !strcmp(reg
, "ps")) {
118 description
.type
= reg_msr
;
119 description
.index
= 0;
120 description
.size
= sizeof(msreg
);
122 else if (!strcmp(reg
, "fpscr")) {
123 description
.type
= reg_fpscr
;
124 description
.index
= 0;
125 description
.size
= sizeof(fpscreg
);
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
);
132 else if (!strcmp(reg
, "cnt")) {
133 description
.type
= reg_spr
;
134 description
.index
= spr_ctr
;
135 description
.size
= sizeof(spreg
);
137 else if (!strcmp(reg
, "insns")) {
138 description
.type
= reg_insns
;
139 description
.index
= spr_ctr
;
140 description
.size
= sizeof(unsigned_word
);
142 else if (!strcmp(reg
, "stalls")) {
143 description
.type
= reg_stalls
;
144 description
.index
= spr_ctr
;
145 description
.size
= sizeof(unsigned_word
);
147 else if (!strcmp(reg
, "cycles")) {
148 description
.type
= reg_cycles
;
149 description
.index
= spr_ctr
;
150 description
.size
= sizeof(unsigned_word
);
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
);
158 else if (!strcmp(reg
, "vscr")) {
159 description
.type
= reg_vscr
;
160 description
.index
= 0;
161 description
.size
= sizeof(vscreg
);
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
);
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
);
175 else if (!strcmp(reg
, "acc")) {
176 description
.type
= reg_acc
;
177 description
.index
= 0;
178 description
.size
= sizeof(unsigned64
);
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
);
189 description
.type
= reg_invalid
;
190 description
.index
= 0;
191 description
.size
= 0;
197 #endif /* _REGISTERS_C_ */