aboutsummaryrefslogtreecommitdiff
path: root/sim/ppc/registers.c
blob: 832360103f7fb9da6a8870e0df8a64254723e367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*  This file is part of the program psim.

    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
    */


#ifndef _REGISTERS_C_
#define _REGISTERS_C_

#include <ctype.h>

#include "basics.h"
#include "registers.h"

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#else
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#endif


INLINE_REGISTERS\
(void)
registers_dump(registers *registers)
{
  int i;
  int j;
  for (i = 0; i < 8; i++) {
    printf_filtered("GPR %2d:", i*4);
    for (j = 0; j < 4; j++) {
      printf_filtered(" 0x%08lx", (long)registers->gpr[i*4 + j]);
    }
    printf_filtered("\n");
  }
}

STATIC_INLINE_REGISTERS\
(sprs)
find_spr(const char name[])
{
  sprs spr;
  for (spr = 0; spr < nr_of_sprs; spr++)
    if (spr_is_valid(spr)
	&& !strcmp(name, spr_name(spr))
	&& spr_index(spr) == spr)
      return spr;
  return nr_of_sprs;
}

STATIC_INLINE_REGISTERS\
(int)
are_digits(const char *digits)
{
  while (isdigit(*digits))
    digits++;
  return *digits == '\0';
}


INLINE_REGISTERS\
(register_descriptions)
register_description(const char reg[])
{
  register_descriptions description;

  /* try for a general-purpose integer or floating point register */
  if (reg[0] == 'r' && are_digits(reg + 1)) {
    description.type = reg_gpr;
    description.index = atoi(reg+1);
    description.size = sizeof(gpreg);
  }
  else if (reg[0] == 'f' && are_digits(reg + 1)) {
    description.type = reg_fpr;
    description.index = atoi(reg+1);
    description.size = sizeof(fpreg);
  }
  else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) {
    description.type = reg_pc;
    description.index = 0;
    description.size = sizeof(unsigned_word);
  }
  else if (!strcmp(reg, "sp")) {
    description.type = reg_gpr;
    description.index = 1;
    description.size = sizeof(gpreg);
  }
  else if (!strcmp(reg, "toc")) {
    description.type = reg_gpr;
    description.index = 2;
    description.size = sizeof(gpreg);
  }
  else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) {
    description.type = reg_cr;
    description.index = 0;
    description.size = sizeof(creg); /* FIXME */
  }
  else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) {
    description.type = reg_msr;
    description.index = 0;
    description.size = sizeof(msreg);
  }
  else if (!strcmp(reg, "fpscr")) {
    description.type = reg_fpscr;
    description.index = 0;
    description.size = sizeof(fpscreg);
  }
  else if (!strncmp(reg, "sr", 2) && are_digits(reg + 2)) {
    description.type = reg_sr;
    description.index = atoi(reg+2);
    description.size = sizeof(sreg);
  }
  else if (!strcmp(reg, "cnt")) {
    description.type = reg_spr;
    description.index = spr_ctr;
    description.size = sizeof(spreg);
  }
  else if (!strcmp(reg, "insns")) {
    description.type = reg_insns;
    description.index = spr_ctr;
    description.size = sizeof(unsigned_word);
  }
  else if (!strcmp(reg, "stalls")) {
    description.type = reg_stalls;
    description.index = spr_ctr;
    description.size = sizeof(unsigned_word);
  }
  else if (!strcmp(reg, "cycles")) {
    description.type = reg_cycles;
    description.index = spr_ctr;
    description.size = sizeof(unsigned_word);
  }
#ifdef WITH_ALTIVEC
  else if (reg[0] == 'v' && reg[1] == 'r' && are_digits(reg + 2)) {
    description.type = reg_vr;
    description.index = atoi(reg+2);
    description.size = sizeof(vreg);
  }
   else if (!strcmp(reg, "vscr")) {
    description.type = reg_vscr;
    description.index = 0;
    description.size = sizeof(vscreg);
  }
#endif
#ifdef WITH_E500
  else if (reg[0] == 'e' && reg[1] == 'v' && are_digits(reg + 2)) {
    description.type = reg_evr;
    description.index = atoi(reg+2);
    description.size = sizeof(unsigned64);
  }
  else if (reg[0] == 'r' && reg[1] == 'h' && are_digits(reg + 2)) {
    description.type = reg_gprh;
    description.index = atoi(reg+2);
    description.size = sizeof(gpreg);
  }
  else if (!strcmp(reg, "acc")) {
    description.type = reg_acc;
    description.index = 0;
    description.size = sizeof(unsigned64);
  }
#endif
  else {
    sprs spr = find_spr(reg);
    if (spr != nr_of_sprs) {
      description.type = reg_spr;
      description.index = spr;
      description.size = sizeof(spreg);
    }
    else {
      description.type = reg_invalid;
      description.index = 0;
      description.size = 0;
    }
  }
  return description;
}

#endif /* _REGISTERS_C_ */