Fix _bfd_elf_find_function so that it can cope with overlapping symbols
[binutils-gdb.git] / sim / ppc / registers.c
blob0ebb2a7a99d040a7c4e48d546ebf68f107834c0b
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/>.
21 #ifndef _REGISTERS_C_
22 #define _REGISTERS_C_
24 #include <ctype.h>
26 #include "basics.h"
27 #include "registers.h"
29 #include <stdlib.h>
30 #include <string.h>
32 INLINE_REGISTERS\
33 (void)
34 registers_dump(registers *registers)
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]);
43 printf_filtered("\n");
47 STATIC_INLINE_REGISTERS\
48 (sprs)
49 find_spr(const char name[])
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;
60 STATIC_INLINE_REGISTERS\
61 (int)
62 are_digits(const char *digits)
64 while (isdigit(*digits))
65 digits++;
66 return *digits == '\0';
70 INLINE_REGISTERS\
71 (register_descriptions)
72 register_description(const char reg[])
74 register_descriptions description;
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);
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);
87 else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) {
88 description.type = reg_pc;
89 description.index = 0;
90 description.size = sizeof(unsigned_word);
92 else if (!strcmp(reg, "sp")) {
93 description.type = reg_gpr;
94 description.index = 1;
95 description.size = sizeof(gpreg);
97 else if (!strcmp(reg, "toc")) {
98 description.type = reg_gpr;
99 description.index = 2;
100 description.size = sizeof(gpreg);
102 else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) {
103 description.type = reg_cr;
104 description.index = 0;
105 description.size = sizeof(creg); /* FIXME */
107 else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) {
108 description.type = reg_msr;
109 description.index = 0;
110 description.size = sizeof(msreg);
112 else if (!strcmp(reg, "fpscr")) {
113 description.type = reg_fpscr;
114 description.index = 0;
115 description.size = sizeof(fpscreg);
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);
122 else if (!strcmp(reg, "cnt")) {
123 description.type = reg_spr;
124 description.index = spr_ctr;
125 description.size = sizeof(spreg);
127 else if (!strcmp(reg, "insns")) {
128 description.type = reg_insns;
129 description.index = spr_ctr;
130 description.size = sizeof(unsigned_word);
132 else if (!strcmp(reg, "stalls")) {
133 description.type = reg_stalls;
134 description.index = spr_ctr;
135 description.size = sizeof(unsigned_word);
137 else if (!strcmp(reg, "cycles")) {
138 description.type = reg_cycles;
139 description.index = spr_ctr;
140 description.size = sizeof(unsigned_word);
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);
148 else if (!strcmp(reg, "vscr")) {
149 description.type = reg_vscr;
150 description.index = 0;
151 description.size = sizeof(vscreg);
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(uint64_t);
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);
165 else if (!strcmp(reg, "acc")) {
166 description.type = reg_acc;
167 description.index = 0;
168 description.size = sizeof(uint64_t);
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);
178 else {
179 description.type = reg_invalid;
180 description.index = 0;
181 description.size = 0;
184 return description;
187 #endif /* _REGISTERS_C_ */