sim: clean up C11 header includes
[deliverable/binutils-gdb.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 #include <stdlib.h>
30 #include <string.h>
31
32 INLINE_REGISTERS\
33 (void)
34 registers_dump(registers *registers)
35 {
36 int i;
37 int j;
38 for (i = 0; i < 8; i++) {
39 printf_filtered("GPR %2d:", i*4);
40 for (j = 0; j < 4; j++) {
41 printf_filtered(" 0x%08lx", (long)registers->gpr[i*4 + j]);
42 }
43 printf_filtered("\n");
44 }
45 }
46
47 STATIC_INLINE_REGISTERS\
48 (sprs)
49 find_spr(const char name[])
50 {
51 sprs spr;
52 for (spr = 0; spr < nr_of_sprs; spr++)
53 if (spr_is_valid(spr)
54 && !strcmp(name, spr_name(spr))
55 && spr_index(spr) == spr)
56 return spr;
57 return nr_of_sprs;
58 }
59
60 STATIC_INLINE_REGISTERS\
61 (int)
62 are_digits(const char *digits)
63 {
64 while (isdigit(*digits))
65 digits++;
66 return *digits == '\0';
67 }
68
69
70 INLINE_REGISTERS\
71 (register_descriptions)
72 register_description(const char reg[])
73 {
74 register_descriptions description;
75
76 /* try for a general-purpose integer or floating point register */
77 if (reg[0] == 'r' && are_digits(reg + 1)) {
78 description.type = reg_gpr;
79 description.index = atoi(reg+1);
80 description.size = sizeof(gpreg);
81 }
82 else if (reg[0] == 'f' && are_digits(reg + 1)) {
83 description.type = reg_fpr;
84 description.index = atoi(reg+1);
85 description.size = sizeof(fpreg);
86 }
87 else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) {
88 description.type = reg_pc;
89 description.index = 0;
90 description.size = sizeof(unsigned_word);
91 }
92 else if (!strcmp(reg, "sp")) {
93 description.type = reg_gpr;
94 description.index = 1;
95 description.size = sizeof(gpreg);
96 }
97 else if (!strcmp(reg, "toc")) {
98 description.type = reg_gpr;
99 description.index = 2;
100 description.size = sizeof(gpreg);
101 }
102 else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) {
103 description.type = reg_cr;
104 description.index = 0;
105 description.size = sizeof(creg); /* FIXME */
106 }
107 else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) {
108 description.type = reg_msr;
109 description.index = 0;
110 description.size = sizeof(msreg);
111 }
112 else if (!strcmp(reg, "fpscr")) {
113 description.type = reg_fpscr;
114 description.index = 0;
115 description.size = sizeof(fpscreg);
116 }
117 else if (!strncmp(reg, "sr", 2) && are_digits(reg + 2)) {
118 description.type = reg_sr;
119 description.index = atoi(reg+2);
120 description.size = sizeof(sreg);
121 }
122 else if (!strcmp(reg, "cnt")) {
123 description.type = reg_spr;
124 description.index = spr_ctr;
125 description.size = sizeof(spreg);
126 }
127 else if (!strcmp(reg, "insns")) {
128 description.type = reg_insns;
129 description.index = spr_ctr;
130 description.size = sizeof(unsigned_word);
131 }
132 else if (!strcmp(reg, "stalls")) {
133 description.type = reg_stalls;
134 description.index = spr_ctr;
135 description.size = sizeof(unsigned_word);
136 }
137 else if (!strcmp(reg, "cycles")) {
138 description.type = reg_cycles;
139 description.index = spr_ctr;
140 description.size = sizeof(unsigned_word);
141 }
142 #ifdef WITH_ALTIVEC
143 else if (reg[0] == 'v' && reg[1] == 'r' && are_digits(reg + 2)) {
144 description.type = reg_vr;
145 description.index = atoi(reg+2);
146 description.size = sizeof(vreg);
147 }
148 else if (!strcmp(reg, "vscr")) {
149 description.type = reg_vscr;
150 description.index = 0;
151 description.size = sizeof(vscreg);
152 }
153 #endif
154 #ifdef WITH_E500
155 else if (reg[0] == 'e' && reg[1] == 'v' && are_digits(reg + 2)) {
156 description.type = reg_evr;
157 description.index = atoi(reg+2);
158 description.size = sizeof(unsigned64);
159 }
160 else if (reg[0] == 'r' && reg[1] == 'h' && are_digits(reg + 2)) {
161 description.type = reg_gprh;
162 description.index = atoi(reg+2);
163 description.size = sizeof(gpreg);
164 }
165 else if (!strcmp(reg, "acc")) {
166 description.type = reg_acc;
167 description.index = 0;
168 description.size = sizeof(unsigned64);
169 }
170 #endif
171 else {
172 sprs spr = find_spr(reg);
173 if (spr != nr_of_sprs) {
174 description.type = reg_spr;
175 description.index = spr;
176 description.size = sizeof(spreg);
177 }
178 else {
179 description.type = reg_invalid;
180 description.index = 0;
181 description.size = 0;
182 }
183 }
184 return description;
185 }
186
187 #endif /* _REGISTERS_C_ */
This page took 0.037259 seconds and 4 git commands to generate.