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 2 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "registers.h"
45 registers_dump(registers
*registers
)
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
]);
54 printf_filtered("\n");
58 STATIC_INLINE_REGISTERS\
60 find_spr(const char name
[])
63 for (spr
= 0; spr
< nr_of_sprs
; spr
++)
65 && !strcmp(name
, spr_name(spr
))
66 && spr_index(spr
) == spr
)
71 STATIC_INLINE_REGISTERS\
73 are_digits(const char *digits
)
75 while (isdigit(*digits
))
77 return *digits
== '\0';
82 (register_descriptions
)
83 register_description(const char reg
[])
85 register_descriptions description
;
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
);
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
);
98 else if (!strcmp(reg
, "pc") || !strcmp(reg
, "nia")) {
99 description
.type
= reg_pc
;
100 description
.index
= 0;
101 description
.size
= sizeof(unsigned_word
);
103 else if (!strcmp(reg
, "sp")) {
104 description
.type
= reg_gpr
;
105 description
.index
= 1;
106 description
.size
= sizeof(gpreg
);
108 else if (!strcmp(reg
, "toc")) {
109 description
.type
= reg_gpr
;
110 description
.index
= 2;
111 description
.size
= sizeof(gpreg
);
113 else if (!strcmp(reg
, "cr") || !strcmp(reg
, "cnd")) {
114 description
.type
= reg_cr
;
115 description
.index
= 0;
116 description
.size
= sizeof(creg
); /* FIXME */
118 else if (!strcmp(reg
, "msr") || !strcmp(reg
, "ps")) {
119 description
.type
= reg_msr
;
120 description
.index
= 0;
121 description
.size
= sizeof(msreg
);
123 else if (!strcmp(reg
, "fpscr")) {
124 description
.type
= reg_fpscr
;
125 description
.index
= 0;
126 description
.size
= sizeof(fpscreg
);
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
);
133 else if (!strcmp(reg
, "cnt")) {
134 description
.type
= reg_spr
;
135 description
.index
= spr_ctr
;
136 description
.size
= sizeof(spreg
);
138 else if (!strcmp(reg
, "insns")) {
139 description
.type
= reg_insns
;
140 description
.index
= spr_ctr
;
141 description
.size
= sizeof(unsigned_word
);
143 else if (!strcmp(reg
, "stalls")) {
144 description
.type
= reg_stalls
;
145 description
.index
= spr_ctr
;
146 description
.size
= sizeof(unsigned_word
);
148 else if (!strcmp(reg
, "cycles")) {
149 description
.type
= reg_cycles
;
150 description
.index
= spr_ctr
;
151 description
.size
= sizeof(unsigned_word
);
154 else if (reg
[0] == 'v' && reg
[1] == 'r' && are_digits(reg
+ 2)) {
155 description
.type
= reg_vr
;
156 description
.index
= atoi(reg
+2);
157 description
.size
= sizeof(vreg
);
159 else if (!strcmp(reg
, "vscr")) {
160 description
.type
= reg_vscr
;
161 description
.index
= 0;
162 description
.size
= sizeof(vscreg
);
166 else if (reg
[0] == 'e' && reg
[1] == 'v' && are_digits(reg
+ 2)) {
167 description
.type
= reg_evr
;
168 description
.index
= atoi(reg
+2);
169 description
.size
= sizeof(unsigned64
);
171 else if (reg
[0] == 'r' && reg
[1] == 'h' && are_digits(reg
+ 2)) {
172 description
.type
= reg_gprh
;
173 description
.index
= atoi(reg
+2);
174 description
.size
= sizeof(gpreg
);
176 else if (!strcmp(reg
, "acc")) {
177 description
.type
= reg_acc
;
178 description
.index
= 0;
179 description
.size
= sizeof(unsigned64
);
183 sprs spr
= find_spr(reg
);
184 if (spr
!= nr_of_sprs
) {
185 description
.type
= reg_spr
;
186 description
.index
= spr
;
187 description
.size
= sizeof(spreg
);
190 description
.type
= reg_invalid
;
191 description
.index
= 0;
192 description
.size
= 0;
198 #endif /* _REGISTERS_C_ */