1 |
330 |
jeremybenn |
/* Target-dependent code for the 32-bit OpenRISC 1000, for the GNU Debugger.
|
2 |
|
|
|
3 |
|
|
Copyright 1988-2008, Free Software Foundation, Inc.
|
4 |
|
|
Copyright (C) 2008, 2010 Embecosm Limited
|
5 |
|
|
|
6 |
|
|
Contributed by Alessandro Forin(af@cs.cmu.edu at CMU
|
7 |
|
|
and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
|
8 |
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
9 |
|
|
|
10 |
|
|
This file is part of GDB.
|
11 |
|
|
|
12 |
|
|
This program is free software; you can redistribute it and/or modify it
|
13 |
|
|
under the terms of the GNU General Public License as published by the Free
|
14 |
|
|
Software Foundation; either version 3 of the License, or (at your option)
|
15 |
|
|
any later version.
|
16 |
|
|
|
17 |
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
18 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
20 |
|
|
more details.
|
21 |
|
|
|
22 |
|
|
You should have received a copy of the GNU General Public License along
|
23 |
|
|
with this program. If not, see <http://www.gnu.org/licenses/>. */
|
24 |
|
|
|
25 |
|
|
/*-----------------------------------------------------------------------------
|
26 |
|
|
This version for the OpenRISC 1000 architecture is a rewrite by Jeremy
|
27 |
522 |
jeremybenn |
Bennett of the old GDB 5.3 interface to make use of gdbarch for GDB 6.8. It
|
28 |
|
|
has since been updated for GDB 7.2.
|
29 |
330 |
jeremybenn |
|
30 |
|
|
The code tries to follow the GDB coding style.
|
31 |
|
|
|
32 |
|
|
Commenting is Doxygen compatible.
|
33 |
|
|
|
34 |
522 |
jeremybenn |
Notes on the GDB 7.2 version
|
35 |
|
|
============================
|
36 |
|
|
|
37 |
|
|
The primary change is to support the new GCC 4.5.1 compiler, which no
|
38 |
|
|
longer adds preceding underscores to global values and uses DWARF2 as its
|
39 |
|
|
default debug format.
|
40 |
|
|
|
41 |
|
|
This version now supports Or1ksim integrated as a simulator library, so
|
42 |
|
|
"target sim" will work. It does require Or1ksim to be available as a
|
43 |
|
|
library at configuration time, with the Or1ksim installation directory
|
44 |
|
|
specified by the argument --with-or1ksim.
|
45 |
|
|
|
46 |
|
|
The ad-hoc prologue analysis, which was always a weak point has been
|
47 |
|
|
stripped out and replaced with code based on the generic approach in
|
48 |
|
|
prologue-value.c and prologue-value.h.
|
49 |
|
|
|
50 |
|
|
The objective with this version is to get reasonable results on regression
|
51 |
|
|
testing. Something the older versions never achieved.
|
52 |
|
|
|
53 |
|
|
Notes on the GDB 6.8 version
|
54 |
|
|
============================
|
55 |
|
|
|
56 |
330 |
jeremybenn |
Much has been stripped out in the interests of getting a basic working
|
57 |
|
|
system. This is described as the OpenRISC 1000 target architecture, so
|
58 |
522 |
jeremybenn |
should work with 32 and 64 bit versions of that architecture and should
|
59 |
|
|
work whether or not they have floating point and/or vector registers,
|
60 |
|
|
although to date it has only been tested with the 32-bit integer
|
61 |
|
|
archtiecture.
|
62 |
330 |
jeremybenn |
|
63 |
|
|
The info trace command has been removed. The meaning of this is not clear -
|
64 |
|
|
it relies on a value in register 255 of the debug group, which is
|
65 |
|
|
undocumented.
|
66 |
|
|
|
67 |
|
|
All the hardware trace has been removed for the time being. The new debug
|
68 |
|
|
interface does not support hardware trace, so there is no plan to reinstate
|
69 |
|
|
this functionality.
|
70 |
|
|
|
71 |
|
|
Support for multiple contexts (which was rudimentary, and not working) has
|
72 |
522 |
jeremybenn |
been removed. */
|
73 |
330 |
jeremybenn |
/*---------------------------------------------------------------------------*/
|
74 |
|
|
|
75 |
|
|
#include "demangle.h"
|
76 |
|
|
#include "defs.h"
|
77 |
|
|
#include "gdb_string.h"
|
78 |
|
|
#include "frame.h"
|
79 |
|
|
#include "inferior.h"
|
80 |
|
|
#include "symtab.h"
|
81 |
|
|
#include "value.h"
|
82 |
|
|
#include "gdbcmd.h"
|
83 |
|
|
#include "language.h"
|
84 |
|
|
#include "gdbcore.h"
|
85 |
|
|
#include "symfile.h"
|
86 |
|
|
#include "objfiles.h"
|
87 |
|
|
#include "gdbtypes.h"
|
88 |
|
|
#include "target.h"
|
89 |
|
|
#include "regcache.h"
|
90 |
|
|
|
91 |
|
|
#include "opcode/or32.h"
|
92 |
|
|
#include "or32-tdep.h"
|
93 |
|
|
|
94 |
|
|
#include "safe-ctype.h"
|
95 |
|
|
#include "block.h"
|
96 |
|
|
#include "reggroups.h"
|
97 |
|
|
#include "arch-utils.h"
|
98 |
|
|
#include "frame.h"
|
99 |
|
|
#include "frame-unwind.h"
|
100 |
|
|
#include "frame-base.h"
|
101 |
|
|
#include "dwarf2-frame.h"
|
102 |
|
|
#include "trad-frame.h"
|
103 |
|
|
|
104 |
|
|
#include <inttypes.h>
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
/* Support functions for the architecture definition */
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
/*----------------------------------------------------------------------------*/
|
113 |
|
|
/*!Get an instruction
|
114 |
|
|
|
115 |
|
|
This reads from memory. The old version relied on the frame, this relies
|
116 |
|
|
just on the architecture. The old version also guaranteed not to get a
|
117 |
|
|
software breakpoint if one had been set. However that seems to happen just
|
118 |
|
|
before execution and is removed immediately after, so we believe should not
|
119 |
|
|
happen. The old function from GDB 6.8 to do this has been deleted.
|
120 |
|
|
|
121 |
|
|
@param[in] gdbarch Architecture for which we are getting the instruction.
|
122 |
|
|
@param[in] addr Address from which to get the instruction
|
123 |
|
|
|
124 |
|
|
@return The instruction */
|
125 |
|
|
/*---------------------------------------------------------------------------*/
|
126 |
|
|
|
127 |
|
|
static ULONGEST
|
128 |
|
|
or32_fetch_instruction (struct gdbarch *gdbarch,
|
129 |
|
|
CORE_ADDR addr)
|
130 |
|
|
{
|
131 |
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
132 |
|
|
char buf[OR32_INSTLEN];
|
133 |
|
|
int status;
|
134 |
|
|
|
135 |
|
|
status = target_read_memory (addr, buf, OR32_INSTLEN);
|
136 |
|
|
|
137 |
|
|
if (status)
|
138 |
|
|
{
|
139 |
|
|
memory_error (status, addr);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
return extract_unsigned_integer (buf, OR32_INSTLEN, byte_order);
|
143 |
|
|
|
144 |
|
|
} /* or32_fetch_instruction() */
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
/*---------------------------------------------------------------------------*/
|
148 |
|
|
/*!Generic function to read bits from an instruction
|
149 |
|
|
|
150 |
|
|
printf style. Basic syntax
|
151 |
|
|
|
152 |
|
|
or32_analyse_inst (inst, format, &arg1, &arg2 ...)
|
153 |
|
|
|
154 |
|
|
Format string can contain the following characters:
|
155 |
|
|
|
156 |
|
|
- SPACE: Ignored, just for layout
|
157 |
|
|
- 0: Match with a zero bit
|
158 |
|
|
- 1: Match with a one bit
|
159 |
|
|
- %<n>b: Match <n> bits to the next argument (n decimal)
|
160 |
|
|
|
161 |
|
|
If the arg corresponding to a bit field is non-null, the value will be
|
162 |
|
|
assigned to that argument (using NULL allows fields to be skipped).
|
163 |
|
|
|
164 |
|
|
Any bad string will cause a fatal error. These are constant strings, so
|
165 |
|
|
should be correct.
|
166 |
|
|
|
167 |
|
|
The bit field must be 32 bits long. A failure here will cause a fatal error
|
168 |
|
|
for the same reason.
|
169 |
|
|
|
170 |
|
|
@note The format string is presented MS field to LS field, left to
|
171 |
|
|
right. This means that it is read lowest numbered char first.
|
172 |
|
|
|
173 |
|
|
@note Some of the arg fields may be populated, even if recognition
|
174 |
|
|
ultimately fails.
|
175 |
|
|
|
176 |
|
|
@param[in] inst The instruction to analyse
|
177 |
|
|
@param[in] format The format string
|
178 |
|
|
@param[out] ... Argument fields
|
179 |
|
|
|
180 |
|
|
@return 1 (TRUE) if the instruction matches, 0 (FALSE) otherwise. */
|
181 |
|
|
/*---------------------------------------------------------------------------*/
|
182 |
|
|
static int
|
183 |
|
|
or32_analyse_inst (uint32_t inst,
|
184 |
|
|
const char *format,
|
185 |
|
|
...)
|
186 |
|
|
{
|
187 |
|
|
/* Break out each field in turn, validating as we go. */
|
188 |
|
|
va_list ap;
|
189 |
|
|
|
190 |
|
|
int i;
|
191 |
|
|
int iptr = 0; /* Instruction pointer */
|
192 |
|
|
|
193 |
|
|
va_start (ap, format);
|
194 |
|
|
|
195 |
|
|
for (i = 0; 0 != format[i];)
|
196 |
|
|
{
|
197 |
|
|
const char *start_ptr;
|
198 |
|
|
char *end_ptr;
|
199 |
|
|
|
200 |
|
|
uint32_t bits; /* Bit substring of interest */
|
201 |
|
|
uint32_t width; /* Substring width */
|
202 |
|
|
uint32_t *arg_ptr;
|
203 |
|
|
|
204 |
|
|
switch (format[i])
|
205 |
|
|
{
|
206 |
|
|
case ' ': i++; break; /* Formatting: ignored */
|
207 |
|
|
|
208 |
|
|
case '0': case '1': /* Constant bit field */
|
209 |
|
|
bits = (inst >> (OR32_INSTBITLEN - iptr - 1)) & 0x1;
|
210 |
|
|
|
211 |
|
|
if ((format[i] - '0') != bits)
|
212 |
|
|
{
|
213 |
|
|
return 0;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
iptr++;
|
217 |
|
|
i++;
|
218 |
|
|
break;
|
219 |
|
|
|
220 |
|
|
case '%': /* Bit field */
|
221 |
|
|
i++;
|
222 |
|
|
start_ptr = &(format[i]);
|
223 |
|
|
width = strtoul (start_ptr, &end_ptr, 10);
|
224 |
|
|
|
225 |
|
|
/* Check we got something, and if so skip on */
|
226 |
|
|
if (start_ptr == end_ptr)
|
227 |
|
|
{
|
228 |
|
|
fatal ("bitstring \"%s\" at offset %d has no length field.\n",
|
229 |
|
|
format, i);
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
i += end_ptr - start_ptr;
|
233 |
|
|
|
234 |
|
|
/* Look for and skip the terminating 'b'. If it's not there, we
|
235 |
|
|
still give a fatal error, because these are fixed strings that
|
236 |
|
|
just should not be wrong. */
|
237 |
|
|
if ('b' != format[i++])
|
238 |
|
|
{
|
239 |
|
|
fatal ("bitstring \"%s\" at offset %d has no terminating 'b'.\n",
|
240 |
|
|
format, i);
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
/* Break out the field. There is a special case with a bit width of
|
244 |
|
|
32. */
|
245 |
|
|
if (32 == width)
|
246 |
|
|
{
|
247 |
|
|
bits = inst;
|
248 |
|
|
}
|
249 |
|
|
else
|
250 |
|
|
{
|
251 |
|
|
bits = (inst >> (OR32_INSTBITLEN - iptr - width)) & ((1 << width) - 1);
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
arg_ptr = va_arg (ap, uint32_t *);
|
255 |
|
|
*arg_ptr = bits;
|
256 |
|
|
iptr += width;
|
257 |
|
|
break;
|
258 |
|
|
|
259 |
|
|
default:
|
260 |
|
|
fatal ("invalid character in bitstring \"%s\" at offset %d.\n",
|
261 |
|
|
format, i);
|
262 |
|
|
break;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
/* Is the length OK? */
|
267 |
|
|
gdb_assert (OR32_INSTBITLEN == iptr);
|
268 |
|
|
|
269 |
|
|
return 1; /* We succeeded */
|
270 |
|
|
|
271 |
|
|
} /* or32_analyse_inst () */
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
/*---------------------------------------------------------------------------*/
|
275 |
|
|
/*!Analyse a l.addi instruction
|
276 |
|
|
|
277 |
|
|
General form is:
|
278 |
|
|
|
279 |
|
|
l.addi rD,rA,I
|
280 |
|
|
|
281 |
|
|
Makes use of the generic analysis function (@see or32_analyse_inst ()).
|
282 |
|
|
|
283 |
|
|
@param[in] inst The instruction to analyse.
|
284 |
|
|
@param[out] rd_ptr Pointer to the rD value.
|
285 |
|
|
@param[out] ra_ptr Pointer to the rA value.
|
286 |
|
|
@param[out] simm_ptr Pointer to the signed immediate value.
|
287 |
|
|
|
288 |
|
|
@return 1 (TRUE) if the instruction matches, 0 (FALSE) otherwise. */
|
289 |
|
|
/*---------------------------------------------------------------------------*/
|
290 |
|
|
static int
|
291 |
|
|
or32_analyse_l_addi (uint32_t inst,
|
292 |
|
|
unsigned int *rd_ptr,
|
293 |
|
|
unsigned int *ra_ptr,
|
294 |
|
|
int *simm_ptr)
|
295 |
|
|
{
|
296 |
|
|
/* Instruction fields */
|
297 |
|
|
uint32_t rd, ra, i;
|
298 |
|
|
|
299 |
|
|
if (or32_analyse_inst (inst, "10 0111 %5b %5b %16b", &rd, &ra, &i))
|
300 |
|
|
{
|
301 |
|
|
/* Found it. Construct the result fields */
|
302 |
|
|
*rd_ptr = (unsigned int) rd;
|
303 |
|
|
*ra_ptr = (unsigned int) ra;
|
304 |
|
|
*simm_ptr = (int) (((i & 0x8000) == 0x8000) ? 0xffff0000 | i : i);
|
305 |
|
|
|
306 |
|
|
return 1; /* Success */
|
307 |
|
|
}
|
308 |
|
|
else
|
309 |
|
|
{
|
310 |
|
|
return 0; /* Failure */
|
311 |
|
|
}
|
312 |
|
|
} /* or32_analyse_l_addi () */
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
/*---------------------------------------------------------------------------*/
|
316 |
|
|
/*!Analyse a l.sw instruction
|
317 |
|
|
|
318 |
|
|
General form is:
|
319 |
|
|
|
320 |
|
|
l.sw I(rA),rB
|
321 |
|
|
|
322 |
|
|
Makes use of the generic analysis function (@see or32_analyse_inst ()).
|
323 |
|
|
|
324 |
|
|
@param[in] inst The instruction to analyse.
|
325 |
|
|
@param[out] simm_ptr Pointer to the signed immediate value.
|
326 |
|
|
@param[out] ra_ptr Pointer to the rA value.
|
327 |
|
|
@param[out] rb_ptr Pointer to the rB value.
|
328 |
|
|
|
329 |
|
|
@return 1 (TRUE) if the instruction matches, 0 (FALSE) otherwise. */
|
330 |
|
|
/*---------------------------------------------------------------------------*/
|
331 |
|
|
static int
|
332 |
|
|
or32_analyse_l_sw (uint32_t inst,
|
333 |
|
|
int *simm_ptr,
|
334 |
|
|
unsigned int *ra_ptr,
|
335 |
|
|
unsigned int *rb_ptr)
|
336 |
|
|
{
|
337 |
|
|
/* Instruction fields */
|
338 |
|
|
uint32_t ihi, ilo, ra, rb;
|
339 |
|
|
|
340 |
|
|
if (or32_analyse_inst (inst, "11 0101 %5b %5b %5b %11b", &ihi, &ra, &rb,
|
341 |
|
|
&ilo))
|
342 |
|
|
|
343 |
|
|
{
|
344 |
|
|
/* Found it. Construct the result fields */
|
345 |
|
|
*simm_ptr = (int) ((ihi << 11) | ilo);
|
346 |
|
|
*simm_ptr |= ((ihi & 0x10) == 0x10) ? 0xffff0000 : 0;
|
347 |
|
|
|
348 |
|
|
*ra_ptr = (unsigned int) ra;
|
349 |
|
|
*rb_ptr = (unsigned int) rb;
|
350 |
|
|
|
351 |
|
|
return 1; /* Success */
|
352 |
|
|
}
|
353 |
|
|
else
|
354 |
|
|
{
|
355 |
|
|
return 0; /* Failure */
|
356 |
|
|
}
|
357 |
|
|
} /* or32_analyse_l_sw () */
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
/* Functions defining the architecture */
|
363 |
|
|
|
364 |
|
|
|
365 |
|
|
/*----------------------------------------------------------------------------*/
|
366 |
|
|
/*!Determine the return convention used for a given type
|
367 |
|
|
|
368 |
|
|
Optionally, fetch or set the return value via "readbuf" or "writebuf"
|
369 |
|
|
respectively using "regcache" for the register values.
|
370 |
|
|
|
371 |
|
|
The OpenRISC 1000 returns scalar values via R11 and (for 64 bit values on
|
372 |
|
|
32 bit architectures) R12. Structs and unions are returned by reference,
|
373 |
|
|
with the address in R11
|
374 |
|
|
|
375 |
|
|
The result returned is independent of the function type, so we ignore that.
|
376 |
|
|
|
377 |
|
|
Throughout use read_memory(), not target_read_memory(), since the address
|
378 |
|
|
may be invalid and we want an error reported (read_memory() is
|
379 |
|
|
target_read_memory() with error reporting).
|
380 |
|
|
|
381 |
|
|
@todo This implementation is labelled OR32, but in fact is just for the 32
|
382 |
|
|
bit version, OR32. This should be made explicit
|
383 |
|
|
|
384 |
|
|
@param[in] gdbarch The GDB architecture being used
|
385 |
|
|
@param[in] functype The type of the function to be called (may be NULL)
|
386 |
|
|
@param[in] valtype The type of the entity to be returned
|
387 |
|
|
@param[in] regcache The register cache
|
388 |
|
|
@param[in] readbuf Buffer into which the return value should be written
|
389 |
|
|
@param[out] writebuf Buffer from which the return value should be written
|
390 |
|
|
|
391 |
|
|
@return The type of return value */
|
392 |
|
|
/*---------------------------------------------------------------------------*/
|
393 |
|
|
|
394 |
|
|
static enum return_value_convention
|
395 |
|
|
or32_return_value (struct gdbarch *gdbarch,
|
396 |
|
|
struct type *functype,
|
397 |
|
|
struct type *valtype,
|
398 |
|
|
struct regcache *regcache,
|
399 |
|
|
gdb_byte *readbuf,
|
400 |
|
|
const gdb_byte *writebuf)
|
401 |
|
|
{
|
402 |
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
403 |
|
|
enum type_code rv_type = TYPE_CODE (valtype);
|
404 |
|
|
unsigned int rv_size = TYPE_LENGTH (valtype);
|
405 |
|
|
ULONGEST tmp;
|
406 |
|
|
|
407 |
|
|
/* Deal with struct/union and large scalars first. Large (> 4 byte) scalars
|
408 |
|
|
are returned via a pointer (despite what is says in the architecture
|
409 |
|
|
document). Result pointed to by R11 */
|
410 |
|
|
|
411 |
|
|
if((TYPE_CODE_STRUCT == rv_type) ||
|
412 |
|
|
(TYPE_CODE_UNION == rv_type) ||
|
413 |
|
|
(rv_size > 4))
|
414 |
|
|
{
|
415 |
|
|
if (readbuf)
|
416 |
|
|
{
|
417 |
|
|
regcache_cooked_read_unsigned (regcache, OR32_RV_REGNUM, &tmp);
|
418 |
|
|
read_memory (tmp, readbuf, rv_size);
|
419 |
|
|
}
|
420 |
|
|
if (writebuf)
|
421 |
|
|
{
|
422 |
|
|
regcache_cooked_read_unsigned (regcache, OR32_RV_REGNUM, &tmp);
|
423 |
|
|
write_memory (tmp, writebuf, rv_size);
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
return RETURN_VALUE_ABI_RETURNS_ADDRESS;
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
/* 1-4 byte scalars are returned in R11 */
|
430 |
|
|
|
431 |
|
|
if (readbuf)
|
432 |
|
|
{
|
433 |
|
|
regcache_cooked_read_unsigned (regcache, OR32_RV_REGNUM, &tmp);
|
434 |
|
|
store_unsigned_integer (readbuf, rv_size, byte_order, tmp);
|
435 |
|
|
}
|
436 |
|
|
if (writebuf)
|
437 |
|
|
{
|
438 |
|
|
gdb_byte buf[4];
|
439 |
|
|
memset (buf, 0, sizeof (buf)); /* Pad with zeros if < 4 bytes */
|
440 |
|
|
|
441 |
|
|
if (BFD_ENDIAN_BIG == byte_order)
|
442 |
|
|
{
|
443 |
|
|
memcpy (buf + sizeof (buf) - rv_size, writebuf, rv_size);
|
444 |
|
|
}
|
445 |
|
|
else
|
446 |
|
|
{
|
447 |
|
|
memcpy (buf, writebuf, rv_size);
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
regcache_cooked_write (regcache, OR32_RV_REGNUM, buf);
|
451 |
|
|
}
|
452 |
|
|
|
453 |
|
|
return RETURN_VALUE_REGISTER_CONVENTION;
|
454 |
|
|
|
455 |
|
|
} /* or32_return_value() */
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
/*----------------------------------------------------------------------------*/
|
459 |
|
|
/*!Determine the instruction to use for a breakpoint.
|
460 |
|
|
|
461 |
|
|
Given the address at which to insert a breakpoint (bp_addr), what will
|
462 |
|
|
that breakpoint be?
|
463 |
|
|
|
464 |
|
|
For or32, we have a breakpoint instruction. Since all or32 instructions
|
465 |
|
|
are 32 bits, this is all we need, regardless of address.
|
466 |
|
|
|
467 |
|
|
@param[in] gdbarch The GDB architecture being used
|
468 |
|
|
@param[in] bp_addr The breakpoint address in question
|
469 |
|
|
@param[out] bp_size The size of instruction selected
|
470 |
|
|
|
471 |
|
|
@return The chosen breakpoint instruction */
|
472 |
|
|
/*---------------------------------------------------------------------------*/
|
473 |
|
|
|
474 |
|
|
static const gdb_byte *
|
475 |
|
|
or32_breakpoint_from_pc (struct gdbarch *gdbarch,
|
476 |
|
|
CORE_ADDR *bp_addr,
|
477 |
|
|
int *bp_size)
|
478 |
|
|
{
|
479 |
|
|
static const gdb_byte breakpoint[] = OR32_BRK_INSTR_STRUCT;
|
480 |
|
|
|
481 |
|
|
*bp_size = OR32_INSTLEN;
|
482 |
|
|
return breakpoint;
|
483 |
|
|
|
484 |
|
|
} /* or32_breakpoint_from_pc() */
|
485 |
|
|
|
486 |
|
|
|
487 |
|
|
/*----------------------------------------------------------------------------*/
|
488 |
|
|
/*!Determine if we are executing a delay slot
|
489 |
|
|
|
490 |
|
|
Looks at the instruction at the previous instruction to see if it was one
|
491 |
|
|
with a delay slot. But it also has to be the address prior to NPC, because
|
492 |
|
|
we may have just taken an exception.
|
493 |
|
|
|
494 |
|
|
@param[in] gdbarch The GDB architecture being used
|
495 |
|
|
@param[in] this_frame Information about THIS frame
|
496 |
|
|
|
497 |
|
|
@return 1 (true) if this instruction is executing a delay slot, 0 (false)
|
498 |
|
|
otherwise. */
|
499 |
|
|
/*--------------------------------------------------------------------------*/
|
500 |
|
|
|
501 |
|
|
static int
|
502 |
|
|
or32_single_step_through_delay( struct gdbarch *gdbarch,
|
503 |
|
|
struct frame_info *this_frame )
|
504 |
|
|
{
|
505 |
|
|
struct regcache *regcache = get_current_regcache ();
|
506 |
|
|
ULONGEST val;
|
507 |
|
|
CORE_ADDR ppc;
|
508 |
|
|
CORE_ADDR npc;
|
509 |
|
|
int index;
|
510 |
|
|
|
511 |
|
|
/* Get and the previous and current instruction addresses. If they are not
|
512 |
|
|
adjacent, we cannot be in a delay slot. */
|
513 |
|
|
regcache_cooked_read_unsigned (regcache, OR32_PPC_REGNUM, &val);
|
514 |
|
|
ppc = (CORE_ADDR) val;
|
515 |
|
|
regcache_cooked_read_unsigned (regcache, OR32_NPC_REGNUM, &val);
|
516 |
|
|
npc = (CORE_ADDR) val;
|
517 |
|
|
|
518 |
|
|
if (0x4 != (npc - ppc))
|
519 |
|
|
{
|
520 |
|
|
return 0;
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
/* Decode the previous instruction to see if it was a branch or a jump, and
|
524 |
|
|
hence we are in a delay slot. */
|
525 |
|
|
index = insn_decode (or32_fetch_instruction (gdbarch, ppc));
|
526 |
|
|
return or32_opcodes[index].flags & OR32_IF_DELAY;
|
527 |
|
|
|
528 |
|
|
} /* or32_single_step_through_delay() */
|
529 |
|
|
|
530 |
|
|
|
531 |
|
|
/*----------------------------------------------------------------------------*/
|
532 |
|
|
/*!Read a pseudo register
|
533 |
|
|
|
534 |
|
|
Since we have no pseudo registers this is a null function for now.
|
535 |
|
|
|
536 |
|
|
@todo The floating point and vector registers ought to be done as
|
537 |
|
|
pseudo-registers.
|
538 |
|
|
|
539 |
|
|
@param[in] gdbarch The GDB architecture to consider
|
540 |
|
|
@param[in] regcache The cached register values as an array
|
541 |
|
|
@param[in] regnum The register to read
|
542 |
|
|
@param[out] buf A buffer to put the result in */
|
543 |
|
|
/*---------------------------------------------------------------------------*/
|
544 |
|
|
|
545 |
|
|
static void
|
546 |
|
|
or32_pseudo_register_read (struct gdbarch *gdbarch,
|
547 |
|
|
struct regcache *regcache,
|
548 |
|
|
int regnum,
|
549 |
|
|
gdb_byte *buf)
|
550 |
|
|
{
|
551 |
|
|
return;
|
552 |
|
|
|
553 |
|
|
} /* or32_pseudo_register_read() */
|
554 |
|
|
|
555 |
|
|
|
556 |
|
|
/*----------------------------------------------------------------------------*/
|
557 |
|
|
/*!Write a pseudo register
|
558 |
|
|
|
559 |
|
|
Since we have no pseudo registers this is a null function for now.
|
560 |
|
|
|
561 |
|
|
@todo The floating point and vector registers ought to be done as
|
562 |
|
|
pseudo-registers.
|
563 |
|
|
|
564 |
|
|
@param[in] gdbarch The GDB architecture to consider
|
565 |
|
|
@param[in] regcache The cached register values as an array
|
566 |
|
|
@param[in] regnum The register to read
|
567 |
|
|
@param[in] buf A buffer with the value to write */
|
568 |
|
|
/*---------------------------------------------------------------------------*/
|
569 |
|
|
|
570 |
|
|
static void
|
571 |
|
|
or32_pseudo_register_write (struct gdbarch *gdbarch,
|
572 |
|
|
struct regcache *regcache,
|
573 |
|
|
int regnum,
|
574 |
|
|
const gdb_byte *buf)
|
575 |
|
|
{
|
576 |
|
|
return;
|
577 |
|
|
|
578 |
|
|
} /* or32_pseudo_register_write() */
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
/*----------------------------------------------------------------------------*/
|
582 |
|
|
/*!Return the register name for the OpenRISC 1000 architecture
|
583 |
|
|
|
584 |
|
|
This version converted to ANSI C, made static and incorporates the static
|
585 |
|
|
table of register names (this is the only place it is referenced).
|
586 |
|
|
|
587 |
|
|
@todo The floating point and vector registers ought to be done as
|
588 |
|
|
pseudo-registers.
|
589 |
|
|
|
590 |
|
|
@param[in] gdbarch The GDB architecture being used
|
591 |
|
|
@param[in] regnum The register number
|
592 |
|
|
|
593 |
|
|
@return The textual name of the register */
|
594 |
|
|
/*---------------------------------------------------------------------------*/
|
595 |
|
|
|
596 |
|
|
static const char *
|
597 |
|
|
or32_register_name (struct gdbarch *gdbarch,
|
598 |
|
|
int regnum)
|
599 |
|
|
{
|
600 |
|
|
static char *or32_gdb_reg_names[OR32_TOTAL_NUM_REGS] =
|
601 |
|
|
{
|
602 |
|
|
/* general purpose registers */
|
603 |
524 |
jeremybenn |
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
604 |
|
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
605 |
330 |
jeremybenn |
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
|
606 |
|
|
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
|
607 |
|
|
|
608 |
|
|
/* previous program counter, next program counter and status register */
|
609 |
524 |
jeremybenn |
"ppc", "npc", "sr"
|
610 |
330 |
jeremybenn |
|
611 |
|
|
/* Floating point and vector registers may appear as pseudo registers in
|
612 |
|
|
the future. */
|
613 |
|
|
};
|
614 |
|
|
|
615 |
|
|
return or32_gdb_reg_names[regnum];
|
616 |
|
|
|
617 |
|
|
} /* or32_register_name() */
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
/*----------------------------------------------------------------------------*/
|
621 |
|
|
/*!Identify the type of a register
|
622 |
|
|
|
623 |
|
|
@todo I don't fully understand exactly what this does, but I think this
|
624 |
|
|
makes sense!
|
625 |
|
|
|
626 |
|
|
@param[in] arch The GDB architecture to consider
|
627 |
|
|
@param[in] regnum The register to identify
|
628 |
|
|
|
629 |
|
|
@return The type of the register */
|
630 |
|
|
/*---------------------------------------------------------------------------*/
|
631 |
|
|
|
632 |
|
|
static struct type *
|
633 |
|
|
or32_register_type (struct gdbarch *arch,
|
634 |
|
|
int regnum)
|
635 |
|
|
{
|
636 |
|
|
static struct type *void_func_ptr = NULL;
|
637 |
|
|
static struct type *void_ptr = NULL;
|
638 |
|
|
|
639 |
|
|
/* Set up the static pointers once, the first time*/
|
640 |
|
|
if (NULL == void_func_ptr)
|
641 |
|
|
{
|
642 |
|
|
struct type *void_type = builtin_type (arch)->builtin_void;
|
643 |
|
|
|
644 |
|
|
void_ptr = lookup_pointer_type (void_type);
|
645 |
|
|
void_func_ptr = lookup_pointer_type (lookup_function_type (void_type));
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
if((regnum >= 0) && (regnum < OR32_TOTAL_NUM_REGS))
|
649 |
|
|
{
|
650 |
|
|
switch (regnum)
|
651 |
|
|
{
|
652 |
|
|
case OR32_PPC_REGNUM:
|
653 |
|
|
case OR32_NPC_REGNUM:
|
654 |
|
|
return void_func_ptr; /* Pointer to code */
|
655 |
|
|
|
656 |
|
|
case OR32_SP_REGNUM:
|
657 |
|
|
case OR32_FP_REGNUM:
|
658 |
|
|
return void_ptr; /* Pointer to data */
|
659 |
|
|
|
660 |
|
|
default:
|
661 |
|
|
return builtin_type (arch)->builtin_uint32; /* Data */
|
662 |
|
|
}
|
663 |
|
|
}
|
664 |
|
|
|
665 |
|
|
internal_error (__FILE__, __LINE__,
|
666 |
|
|
_("or32_register_type: illegal register number %d"), regnum);
|
667 |
|
|
|
668 |
|
|
} /* or32_register_type() */
|
669 |
|
|
|
670 |
|
|
|
671 |
|
|
/*----------------------------------------------------------------------------*/
|
672 |
|
|
/*!Handle the "info register" command
|
673 |
|
|
|
674 |
|
|
Print the identified register, unless it is -1, in which case print all
|
675 |
|
|
the registers. If all is 1 means all registers, otherwise only the core
|
676 |
|
|
GPRs.
|
677 |
|
|
|
678 |
|
|
@todo At present all registers are printed with the default method. Should
|
679 |
|
|
there be something special for FP registers?
|
680 |
|
|
|
681 |
|
|
@param[in] gdbarch The GDB architecture being used
|
682 |
|
|
@param[in] file File handle for use with any custom I/O
|
683 |
|
|
@param[in] frame Frame info for use with custom output
|
684 |
|
|
@param[in] regnum Register of interest, or -1 if all registers
|
685 |
|
|
@param[in] all 1 if all means all, 0 if all means just GPRs
|
686 |
|
|
|
687 |
|
|
@return The aligned stack frame address */
|
688 |
|
|
/*---------------------------------------------------------------------------*/
|
689 |
|
|
|
690 |
|
|
static void
|
691 |
|
|
or32_registers_info (struct gdbarch *gdbarch,
|
692 |
|
|
struct ui_file *file,
|
693 |
|
|
struct frame_info *frame,
|
694 |
|
|
int regnum,
|
695 |
|
|
int all)
|
696 |
|
|
{
|
697 |
|
|
if (-1 == regnum)
|
698 |
|
|
{
|
699 |
|
|
/* Do all (valid) registers */
|
700 |
|
|
unsigned int lim = all ? OR32_NUM_REGS : OR32_MAX_GPR_REGS;
|
701 |
|
|
|
702 |
|
|
for (regnum = 0; regnum < lim; regnum++) {
|
703 |
|
|
if ('\0' != *(or32_register_name (gdbarch, regnum)))
|
704 |
|
|
{
|
705 |
|
|
or32_registers_info (gdbarch, file, frame, regnum, all);
|
706 |
|
|
}
|
707 |
|
|
}
|
708 |
|
|
}
|
709 |
|
|
else
|
710 |
|
|
{
|
711 |
|
|
/* Do one specified register - if it is part of this architecture */
|
712 |
|
|
if ('\0' == *(or32_register_name (gdbarch, regnum)))
|
713 |
|
|
{
|
714 |
|
|
error ("Not a valid register for the current processor type");
|
715 |
|
|
}
|
716 |
|
|
else
|
717 |
|
|
{
|
718 |
|
|
default_print_registers_info (gdbarch, file, frame, regnum, all);
|
719 |
|
|
}
|
720 |
|
|
}
|
721 |
|
|
} /* or32_registers_info() */
|
722 |
|
|
|
723 |
|
|
|
724 |
|
|
/*----------------------------------------------------------------------------*/
|
725 |
|
|
/*!Identify if a register belongs to a specified group
|
726 |
|
|
|
727 |
|
|
Return true if the specified register is a member of the specified
|
728 |
|
|
register group.
|
729 |
|
|
|
730 |
|
|
These are the groups of registers that can be displayed via "info reg".
|
731 |
|
|
|
732 |
|
|
@todo The Vector and Floating Point registers ought to be displayed as
|
733 |
|
|
pseudo-registers.
|
734 |
|
|
|
735 |
|
|
@param[in] gdbarch The GDB architecture to consider
|
736 |
|
|
@param[in] regnum The register to consider
|
737 |
|
|
@param[in] group The group to consider
|
738 |
|
|
|
739 |
|
|
@return True (1) if regnum is a member of group */
|
740 |
|
|
/*---------------------------------------------------------------------------*/
|
741 |
|
|
|
742 |
|
|
static int
|
743 |
|
|
or32_register_reggroup_p (struct gdbarch *gdbarch,
|
744 |
|
|
int regnum,
|
745 |
|
|
struct reggroup *group)
|
746 |
|
|
{
|
747 |
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
748 |
|
|
|
749 |
|
|
/* All register group */
|
750 |
|
|
if (group == all_reggroup)
|
751 |
|
|
{
|
752 |
|
|
return ((regnum >= 0) &&
|
753 |
|
|
(regnum < OR32_TOTAL_NUM_REGS) &&
|
754 |
|
|
(or32_register_name (gdbarch, regnum)[0] != '\0'));
|
755 |
|
|
}
|
756 |
|
|
|
757 |
|
|
/* For now everything except the PC */
|
758 |
|
|
if (group == general_reggroup)
|
759 |
|
|
{
|
760 |
|
|
return ((regnum >= OR32_ZERO_REGNUM) &&
|
761 |
|
|
(regnum < tdep->num_gpr_regs) &&
|
762 |
|
|
(regnum != OR32_PPC_REGNUM) &&
|
763 |
|
|
(regnum != OR32_NPC_REGNUM));
|
764 |
|
|
}
|
765 |
|
|
|
766 |
|
|
if (group == float_reggroup)
|
767 |
|
|
{
|
768 |
|
|
return 0; /* No float regs. */
|
769 |
|
|
}
|
770 |
|
|
|
771 |
|
|
if (group == vector_reggroup)
|
772 |
|
|
{
|
773 |
|
|
return 0; /* No vector regs. */
|
774 |
|
|
}
|
775 |
|
|
|
776 |
|
|
/* For any that are not handled above. */
|
777 |
|
|
return default_register_reggroup_p (gdbarch, regnum, group);
|
778 |
|
|
|
779 |
|
|
} /* or32_register_reggroup_p() */
|
780 |
|
|
|
781 |
|
|
|
782 |
|
|
/*----------------------------------------------------------------------------*/
|
783 |
|
|
/*!Is this one of the registers used for passing arguments?
|
784 |
|
|
|
785 |
|
|
These are r3-r8 in the API.
|
786 |
|
|
|
787 |
|
|
@param[in] regnum The register to consider
|
788 |
|
|
|
789 |
|
|
@return Non-zero (TRUE) if it is an argument register, zero (FALSE)
|
790 |
|
|
otherwise. */
|
791 |
|
|
/*----------------------------------------------------------------------------*/
|
792 |
|
|
static int
|
793 |
|
|
or32_is_arg_reg (unsigned int regnum)
|
794 |
|
|
{
|
795 |
|
|
return (OR32_FIRST_ARG_REGNUM <= regnum) && (regnum <= OR32_LAST_ARG_REGNUM);
|
796 |
|
|
|
797 |
|
|
} /* or32_is_arg_reg () */
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
/*----------------------------------------------------------------------------*/
|
801 |
|
|
/*!Is this a callee saved register?
|
802 |
|
|
|
803 |
|
|
These are r10, r12, r14, r16, r18, r20, r22, r24, r26, r28 and r30 in the
|
804 |
|
|
API.
|
805 |
|
|
|
806 |
|
|
@param[in] regnum The register to consider
|
807 |
|
|
|
808 |
|
|
@return Non-zero (TRUE) if it is a callee saved register, zero (FALSE)
|
809 |
|
|
otherwise. */
|
810 |
|
|
/*----------------------------------------------------------------------------*/
|
811 |
|
|
static int
|
812 |
|
|
or32_is_callee_saved_reg (unsigned int regnum)
|
813 |
|
|
{
|
814 |
|
|
return (OR32_FIRST_SAVED_REGNUM <= regnum) && (0 == regnum % 2);
|
815 |
|
|
|
816 |
|
|
} /* or32_is_callee_saved_reg () */
|
817 |
|
|
|
818 |
|
|
|
819 |
|
|
/*----------------------------------------------------------------------------*/
|
820 |
|
|
/*!Skip a function prolog
|
821 |
|
|
|
822 |
|
|
If the input address, PC, is in a function prologue, return the address of
|
823 |
|
|
the end of the prologue, otherwise return the input address.
|
824 |
|
|
|
825 |
|
|
@see For details of the stack frame, see the function
|
826 |
|
|
or32_frame_cache().
|
827 |
|
|
|
828 |
|
|
@note The old version of this function used to use skip_prologue_using_sal
|
829 |
|
|
to skip the prologue without checking if it had actually worked. It
|
830 |
|
|
doesn't for STABS, so we had better check for a valid result.
|
831 |
|
|
|
832 |
|
|
This function reuses the helper functions from or32_frame_cache() to
|
833 |
|
|
locate the various parts of the prolog, any or all of which may be missing.
|
834 |
|
|
|
835 |
|
|
@param[in] gdbarch The GDB architecture being used
|
836 |
|
|
@param[in] pc Current program counter
|
837 |
|
|
|
838 |
|
|
@return The address of the end of the prolog if the PC is in a function
|
839 |
|
|
prologue, otherwise the input address. */
|
840 |
|
|
/*----------------------------------------------------------------------------*/
|
841 |
|
|
static CORE_ADDR
|
842 |
|
|
or32_skip_prologue (struct gdbarch *gdbarch,
|
843 |
|
|
CORE_ADDR pc)
|
844 |
|
|
{
|
845 |
|
|
CORE_ADDR start_pc;
|
846 |
|
|
CORE_ADDR addr;
|
847 |
|
|
uint32_t inst;
|
848 |
|
|
|
849 |
|
|
unsigned int ra, rb, rd; /* For instruction analysis */
|
850 |
|
|
int simm;
|
851 |
|
|
|
852 |
|
|
int frame_size = 0;
|
853 |
|
|
|
854 |
|
|
/* Try using SAL first if we have symbolic information available. This only
|
855 |
|
|
works for DWARF 2, not STABS. */
|
856 |
|
|
if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
|
857 |
|
|
{
|
858 |
|
|
CORE_ADDR prologue_end = skip_prologue_using_sal( gdbarch, pc );
|
859 |
|
|
|
860 |
|
|
if (0 != prologue_end)
|
861 |
|
|
{
|
862 |
|
|
struct symtab_and_line prologue_sal = find_pc_line (start_pc, 0);
|
863 |
|
|
char *debug_format = prologue_sal.symtab->debugformat;
|
864 |
|
|
|
865 |
|
|
if ((strlen ("dwarf") <= strlen (debug_format))
|
866 |
|
|
&& (0 == strncasecmp ("dwarf", debug_format, strlen ("dwarf"))))
|
867 |
|
|
{
|
868 |
|
|
return (prologue_end > pc) ? prologue_end : pc;
|
869 |
|
|
}
|
870 |
|
|
}
|
871 |
|
|
}
|
872 |
|
|
|
873 |
|
|
/* Look to see if we can find any of the standard prologue sequence. All
|
874 |
|
|
quite difficult, since any or all of it may be missing. So this is just a
|
875 |
|
|
best guess! */
|
876 |
|
|
addr = pc; /* Where we have got to */
|
877 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
878 |
|
|
|
879 |
|
|
/* Look for the new stack pointer being set up. */
|
880 |
|
|
if (or32_analyse_l_addi (inst, &rd, &ra, &simm) &&
|
881 |
|
|
(OR32_SP_REGNUM == rd) && (OR32_SP_REGNUM == ra) &&
|
882 |
|
|
(simm < 0) && (0 == (simm % 4)))
|
883 |
|
|
{
|
884 |
|
|
frame_size = -simm;
|
885 |
|
|
addr += OR32_INSTLEN;
|
886 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
887 |
|
|
}
|
888 |
|
|
|
889 |
|
|
/* Look for the frame pointer being manipulated. */
|
890 |
|
|
if (or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
891 |
|
|
(OR32_SP_REGNUM == ra) && (OR32_FP_REGNUM == rb) &&
|
892 |
|
|
(simm >= 0) && (0 == (simm % 4)))
|
893 |
|
|
{
|
894 |
|
|
addr += OR32_INSTLEN;
|
895 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
896 |
|
|
|
897 |
|
|
gdb_assert (or32_analyse_l_addi (inst, &rd, &ra, &simm) &&
|
898 |
|
|
(OR32_FP_REGNUM == rd) && (OR32_SP_REGNUM == ra) &&
|
899 |
|
|
(simm == frame_size));
|
900 |
|
|
|
901 |
|
|
addr += OR32_INSTLEN;
|
902 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
903 |
|
|
}
|
904 |
|
|
|
905 |
|
|
/* Look for the link register being saved */
|
906 |
|
|
if (or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
907 |
|
|
(OR32_SP_REGNUM == ra) && (OR32_LR_REGNUM == rb) &&
|
908 |
|
|
(simm >= 0) && (0 == (simm % 4)))
|
909 |
|
|
{
|
910 |
|
|
addr += OR32_INSTLEN;
|
911 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
912 |
|
|
}
|
913 |
|
|
|
914 |
|
|
/* Look for arguments or callee-saved register being saved. The register
|
915 |
|
|
must be one of the arguments (r3-r8) or the 10 callee saved registers
|
916 |
|
|
(r10, r12, r14, r16, r18, r20, r22, r24, r26, r28, r30). The base
|
917 |
|
|
register must be the FP (for the args) or the SP (for the callee_saved
|
918 |
|
|
registers). */
|
919 |
|
|
while (1)
|
920 |
|
|
{
|
921 |
|
|
if (or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
922 |
|
|
(((OR32_FP_REGNUM == ra) && or32_is_arg_reg (rb)) ||
|
923 |
|
|
((OR32_SP_REGNUM == ra) && or32_is_callee_saved_reg (rb))) &&
|
924 |
|
|
(0 == (simm % 4)))
|
925 |
|
|
{
|
926 |
|
|
addr += OR32_INSTLEN;
|
927 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
928 |
|
|
}
|
929 |
|
|
else
|
930 |
|
|
{
|
931 |
|
|
/* Nothing else to look for. We have found the end of the prologue. */
|
932 |
|
|
return addr;
|
933 |
|
|
}
|
934 |
|
|
}
|
935 |
|
|
} /* or32_skip_prologue() */
|
936 |
|
|
|
937 |
|
|
|
938 |
|
|
/*----------------------------------------------------------------------------*/
|
939 |
|
|
/*!Align the stack frame
|
940 |
|
|
|
941 |
|
|
OpenRISC 1000 uses a falling stack frame, so this aligns down to the
|
942 |
|
|
nearest 8 bytes. Useful when we'be building a dummy frame.
|
943 |
|
|
|
944 |
|
|
@param[in] gdbarch The GDB architecture being used
|
945 |
|
|
@param[in] sp Current stack pointer
|
946 |
|
|
|
947 |
|
|
@return The aligned stack frame address */
|
948 |
|
|
/*---------------------------------------------------------------------------*/
|
949 |
|
|
|
950 |
|
|
static CORE_ADDR
|
951 |
|
|
or32_frame_align (struct gdbarch *gdbarch,
|
952 |
|
|
CORE_ADDR sp)
|
953 |
|
|
{
|
954 |
|
|
return align_down (sp, OR32_STACK_ALIGN);
|
955 |
|
|
|
956 |
|
|
} /* or32_frame_align() */
|
957 |
|
|
|
958 |
|
|
|
959 |
|
|
/*----------------------------------------------------------------------------*/
|
960 |
|
|
/*!Unwind the program counter from a stack frame
|
961 |
|
|
|
962 |
|
|
This just uses the built in frame unwinder
|
963 |
|
|
|
964 |
|
|
@param[in] gdbarch The GDB architecture being used
|
965 |
|
|
@param[in] next_frame Frame info for the NEXT frame
|
966 |
|
|
|
967 |
|
|
@return The program counter for THIS frame */
|
968 |
|
|
/*---------------------------------------------------------------------------*/
|
969 |
|
|
|
970 |
|
|
static CORE_ADDR
|
971 |
|
|
or32_unwind_pc (struct gdbarch *gdbarch,
|
972 |
|
|
struct frame_info *next_frame)
|
973 |
|
|
{
|
974 |
524 |
jeremybenn |
if (frame_debug)
|
975 |
|
|
{
|
976 |
|
|
fprintf_unfiltered (gdb_stdlog, "or32_unwind_pc, next_frame=%d\n",
|
977 |
|
|
frame_relative_level (next_frame));
|
978 |
|
|
}
|
979 |
|
|
|
980 |
330 |
jeremybenn |
CORE_ADDR pc = frame_unwind_register_unsigned (next_frame, OR32_NPC_REGNUM);
|
981 |
|
|
|
982 |
522 |
jeremybenn |
if (frame_debug)
|
983 |
|
|
{
|
984 |
524 |
jeremybenn |
fprintf_unfiltered (gdb_stdlog, "or32_unwind_pc, pc=0x%p\n", (void *) pc);
|
985 |
522 |
jeremybenn |
}
|
986 |
|
|
|
987 |
330 |
jeremybenn |
return pc;
|
988 |
|
|
|
989 |
|
|
} /* or32_unwind_pc() */
|
990 |
|
|
|
991 |
|
|
|
992 |
|
|
/*----------------------------------------------------------------------------*/
|
993 |
|
|
/*!Unwind the stack pointer from a stack frame
|
994 |
|
|
|
995 |
|
|
This just uses the built in frame unwinder
|
996 |
|
|
|
997 |
|
|
@param[in] gdbarch The GDB architecture being used
|
998 |
|
|
@param[in] next_frame Frame info for the NEXT frame
|
999 |
|
|
|
1000 |
|
|
@return The stack pointer for THIS frame */
|
1001 |
|
|
/*---------------------------------------------------------------------------*/
|
1002 |
|
|
|
1003 |
|
|
static CORE_ADDR
|
1004 |
|
|
or32_unwind_sp (struct gdbarch *gdbarch,
|
1005 |
|
|
struct frame_info *next_frame)
|
1006 |
|
|
{
|
1007 |
524 |
jeremybenn |
if (frame_debug)
|
1008 |
|
|
{
|
1009 |
|
|
fprintf_unfiltered (gdb_stdlog, "or32_unwind_sp, next_frame=%d\n",
|
1010 |
|
|
frame_relative_level (next_frame));
|
1011 |
|
|
}
|
1012 |
|
|
|
1013 |
330 |
jeremybenn |
CORE_ADDR sp = frame_unwind_register_unsigned (next_frame, OR32_SP_REGNUM);
|
1014 |
|
|
|
1015 |
522 |
jeremybenn |
if (frame_debug)
|
1016 |
|
|
{
|
1017 |
524 |
jeremybenn |
fprintf_unfiltered (gdb_stdlog, "or32_unwind_sp, sp=0x%p\n", (void *) sp);
|
1018 |
522 |
jeremybenn |
}
|
1019 |
|
|
|
1020 |
330 |
jeremybenn |
return sp;
|
1021 |
|
|
|
1022 |
|
|
} /* or32_unwind_sp() */
|
1023 |
|
|
|
1024 |
|
|
|
1025 |
|
|
/*----------------------------------------------------------------------------*/
|
1026 |
|
|
/*!Create a dummy stack frame
|
1027 |
|
|
|
1028 |
|
|
The arguments are placed in registers and/or pushed on the stack as per the
|
1029 |
|
|
OR32 ABI.
|
1030 |
|
|
|
1031 |
|
|
@param[in] gdbarch The architecture to use
|
1032 |
|
|
@param[in] function Pointer to the function that will be called
|
1033 |
|
|
@param[in] regcache The register cache to use
|
1034 |
|
|
@param[in] bp_addr Breakpoint address
|
1035 |
|
|
@param[in] nargs Number of ags to push
|
1036 |
|
|
@param[in] args The arguments
|
1037 |
|
|
@param[in] sp The stack pointer
|
1038 |
|
|
@param[in] struct_return True (1) if this returns a structure
|
1039 |
|
|
@param[in] struct_addr Address for returning structures
|
1040 |
|
|
|
1041 |
|
|
@return The updated stack pointer */
|
1042 |
|
|
/*---------------------------------------------------------------------------*/
|
1043 |
|
|
|
1044 |
|
|
static CORE_ADDR
|
1045 |
|
|
or32_push_dummy_call (struct gdbarch *gdbarch,
|
1046 |
|
|
struct value *function,
|
1047 |
|
|
struct regcache *regcache,
|
1048 |
|
|
CORE_ADDR bp_addr,
|
1049 |
|
|
int nargs,
|
1050 |
|
|
struct value **args,
|
1051 |
|
|
CORE_ADDR sp,
|
1052 |
|
|
int struct_return,
|
1053 |
|
|
CORE_ADDR struct_addr)
|
1054 |
|
|
{
|
1055 |
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
1056 |
|
|
|
1057 |
|
|
int argreg;
|
1058 |
|
|
int argnum;
|
1059 |
|
|
int first_stack_arg;
|
1060 |
|
|
int stack_offset = 0;
|
1061 |
|
|
|
1062 |
|
|
unsigned int bpa = (gdbarch_tdep (gdbarch))->bytes_per_address;
|
1063 |
|
|
unsigned int bpw = (gdbarch_tdep (gdbarch))->bytes_per_word;
|
1064 |
|
|
|
1065 |
|
|
/* Return address */
|
1066 |
|
|
regcache_cooked_write_unsigned (regcache, OR32_LR_REGNUM, bp_addr);
|
1067 |
|
|
|
1068 |
|
|
/* Register for the next argument */
|
1069 |
|
|
argreg = OR32_FIRST_ARG_REGNUM;
|
1070 |
|
|
|
1071 |
|
|
/* Location for a returned structure. This is passed as a silent first
|
1072 |
|
|
argument. */
|
1073 |
|
|
|
1074 |
|
|
if (struct_return)
|
1075 |
|
|
{
|
1076 |
|
|
regcache_cooked_write_unsigned (regcache, OR32_FIRST_ARG_REGNUM,
|
1077 |
|
|
struct_addr);
|
1078 |
|
|
argreg++;
|
1079 |
|
|
}
|
1080 |
|
|
|
1081 |
|
|
/* Put as many args as possible in registers */
|
1082 |
|
|
for (argnum = 0; argnum < nargs; argnum++)
|
1083 |
|
|
{
|
1084 |
|
|
char *val;
|
1085 |
|
|
char valbuf[sizeof (ULONGEST) ];
|
1086 |
|
|
|
1087 |
|
|
struct value *arg = args[argnum];
|
1088 |
|
|
struct type *arg_type = check_typedef (value_type (arg));
|
1089 |
|
|
int len = arg_type->length;
|
1090 |
|
|
enum type_code typecode = arg_type->main_type->code;
|
1091 |
|
|
|
1092 |
|
|
/* The EABI passes structures that do not fit in a register by
|
1093 |
|
|
reference. In all other cases, pass the structure by value. */
|
1094 |
|
|
if((len > bpw) &&
|
1095 |
|
|
((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)))
|
1096 |
|
|
{
|
1097 |
|
|
|
1098 |
|
|
store_unsigned_integer (valbuf, bpa, byte_order, value_offset (arg));
|
1099 |
|
|
len = bpa;
|
1100 |
|
|
val = valbuf;
|
1101 |
|
|
}
|
1102 |
|
|
else
|
1103 |
|
|
{
|
1104 |
|
|
val = (char *)value_contents (arg);
|
1105 |
|
|
}
|
1106 |
|
|
|
1107 |
|
|
if((len > bpw) && (argreg <= (OR32_LAST_ARG_REGNUM - 1)))
|
1108 |
|
|
{
|
1109 |
|
|
|
1110 |
|
|
/* Big scalars use two registers, but need NOT be pair aligned. This
|
1111 |
|
|
code breaks if we can have quad-word scalars (e.g. long
|
1112 |
|
|
double). */
|
1113 |
|
|
ULONGEST regval = extract_unsigned_integer (val, len, byte_order);
|
1114 |
|
|
|
1115 |
|
|
unsigned int bits_per_word = bpw * 8;
|
1116 |
|
|
ULONGEST mask = (((ULONGEST) 1) << bits_per_word) - 1;
|
1117 |
|
|
ULONGEST lo = regval & mask;
|
1118 |
|
|
ULONGEST hi = regval >> bits_per_word;
|
1119 |
|
|
|
1120 |
|
|
gdb_assert (len <= (bpw * 2));
|
1121 |
|
|
|
1122 |
|
|
regcache_cooked_write_unsigned (regcache, argreg, hi);
|
1123 |
|
|
regcache_cooked_write_unsigned (regcache, argreg + 1, lo);
|
1124 |
|
|
argreg += 2;
|
1125 |
|
|
}
|
1126 |
|
|
else if (argreg <= OR32_LAST_ARG_REGNUM)
|
1127 |
|
|
{
|
1128 |
|
|
printf ("Writing 0x%08llx to r%d\n",
|
1129 |
|
|
extract_unsigned_integer (val, len, byte_order), argreg);
|
1130 |
|
|
|
1131 |
|
|
regcache_cooked_write_unsigned (regcache, argreg,
|
1132 |
|
|
extract_unsigned_integer (val, len,
|
1133 |
|
|
byte_order));
|
1134 |
|
|
argreg++;
|
1135 |
|
|
}
|
1136 |
|
|
else
|
1137 |
|
|
{
|
1138 |
|
|
/* Run out of regs */
|
1139 |
|
|
break;
|
1140 |
|
|
}
|
1141 |
|
|
}
|
1142 |
|
|
|
1143 |
|
|
first_stack_arg = argnum;
|
1144 |
|
|
|
1145 |
|
|
/* If we get here with argnum < nargs, then arguments remain to be placed on
|
1146 |
|
|
the stack. This is tricky, since they must be pushed in reverse order and
|
1147 |
|
|
the stack in the end must be aligned. The only solution is to do it in
|
1148 |
|
|
two stages, the first to compute the stack size, the second to save the
|
1149 |
|
|
args. */
|
1150 |
|
|
|
1151 |
|
|
for (argnum = first_stack_arg; argnum < nargs; argnum++)
|
1152 |
|
|
{
|
1153 |
|
|
struct value *arg = args[argnum];
|
1154 |
|
|
struct type *arg_type = check_typedef (value_type (arg));
|
1155 |
|
|
int len = arg_type->length;
|
1156 |
|
|
enum type_code typecode = arg_type->main_type->code;
|
1157 |
|
|
|
1158 |
|
|
if((len > bpw) &&
|
1159 |
|
|
((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)))
|
1160 |
|
|
{
|
1161 |
|
|
/* Large structures are passed as addresses */
|
1162 |
|
|
sp -= bpa;
|
1163 |
|
|
}
|
1164 |
|
|
else
|
1165 |
|
|
{
|
1166 |
|
|
/* Big scalars use more than one word. Code here allows for future
|
1167 |
|
|
quad-word entities (e.g. long double) */
|
1168 |
|
|
sp -= ((len + bpw - 1) / bpw) * bpw;
|
1169 |
|
|
}
|
1170 |
|
|
}
|
1171 |
|
|
|
1172 |
|
|
sp = gdbarch_frame_align (gdbarch, sp);
|
1173 |
|
|
stack_offset = 0;
|
1174 |
|
|
|
1175 |
|
|
/* Push the remaining args on the stack */
|
1176 |
|
|
for (argnum = first_stack_arg; argnum < nargs; argnum++)
|
1177 |
|
|
{
|
1178 |
|
|
char *val;
|
1179 |
|
|
char valbuf[sizeof (ULONGEST) ];
|
1180 |
|
|
|
1181 |
|
|
struct value *arg = args[argnum];
|
1182 |
|
|
struct type *arg_type = check_typedef (value_type (arg));
|
1183 |
|
|
int len = arg_type->length;
|
1184 |
|
|
enum type_code typecode = arg_type->main_type->code;
|
1185 |
|
|
|
1186 |
|
|
/* The EABI passes structures that do not fit in a register by
|
1187 |
|
|
reference. In all other cases, pass the structure by value. */
|
1188 |
|
|
if((len > bpw) &&
|
1189 |
|
|
((TYPE_CODE_STRUCT == typecode) || (TYPE_CODE_UNION == typecode)))
|
1190 |
|
|
{
|
1191 |
|
|
|
1192 |
|
|
store_unsigned_integer (valbuf, bpa, byte_order, value_offset (arg));
|
1193 |
|
|
len = bpa;
|
1194 |
|
|
val = valbuf;
|
1195 |
|
|
}
|
1196 |
|
|
else
|
1197 |
|
|
{
|
1198 |
|
|
val = (char *)value_contents (arg);
|
1199 |
|
|
}
|
1200 |
|
|
|
1201 |
|
|
gdb_assert (len <= (bpw * 2));
|
1202 |
|
|
|
1203 |
|
|
write_memory (sp + stack_offset, val, len);
|
1204 |
|
|
stack_offset += ((len + bpw - 1) / bpw) * bpw;
|
1205 |
|
|
}
|
1206 |
|
|
|
1207 |
|
|
/* Save the updated stack pointer */
|
1208 |
|
|
regcache_cooked_write_unsigned (regcache, OR32_SP_REGNUM, sp);
|
1209 |
|
|
|
1210 |
|
|
return sp;
|
1211 |
|
|
|
1212 |
|
|
} /* or32_push_dummy_call() */
|
1213 |
|
|
|
1214 |
|
|
|
1215 |
|
|
/*----------------------------------------------------------------------------*/
|
1216 |
|
|
/*!Return the frame ID for a dummy stack frame
|
1217 |
|
|
|
1218 |
|
|
Tear down a dummy frame created by or32_push_dummy_call(). This data has to
|
1219 |
|
|
be constructed manually from the data in our hand.
|
1220 |
|
|
|
1221 |
|
|
The stack pointer and program counter can be obtained from the frame info.
|
1222 |
|
|
|
1223 |
|
|
@param[in] gdbarch The architecture to use
|
1224 |
|
|
@param[in] this_frame Information about this frame
|
1225 |
|
|
|
1226 |
|
|
@return Frame ID of this frame */
|
1227 |
|
|
/*---------------------------------------------------------------------------*/
|
1228 |
|
|
|
1229 |
|
|
static struct frame_id
|
1230 |
|
|
or32_dummy_id (struct gdbarch *gdbarch,
|
1231 |
|
|
struct frame_info *this_frame)
|
1232 |
|
|
{
|
1233 |
|
|
return frame_id_build (get_frame_sp (this_frame), get_frame_pc (this_frame));
|
1234 |
|
|
|
1235 |
|
|
} /* or32_dummy_id() */
|
1236 |
|
|
|
1237 |
|
|
|
1238 |
|
|
|
1239 |
|
|
|
1240 |
|
|
/* Support functions for frame handling */
|
1241 |
|
|
|
1242 |
|
|
/* -------------------------------------------------------------------------- */
|
1243 |
|
|
/*!Initialize a prologue cache
|
1244 |
|
|
|
1245 |
|
|
This function is changed from its GDB 6.8 version (named
|
1246 |
|
|
or32_frame_unwind_cache), in that it is based on THIS frame, not the NEXT
|
1247 |
|
|
frame.
|
1248 |
|
|
|
1249 |
|
|
We build a cache, saying where registers of the PREV frame can be found
|
1250 |
|
|
from the data so far set up in this THIS.
|
1251 |
|
|
|
1252 |
|
|
We also compute a unique ID for this frame, based on the function start
|
1253 |
|
|
address and the stack pointer (as it will be, even if it has yet to be
|
1254 |
|
|
computed.
|
1255 |
|
|
|
1256 |
|
|
STACK FORMAT
|
1257 |
|
|
============
|
1258 |
|
|
|
1259 |
|
|
The OR32 has a falling stack frame and a simple prolog. The Stack pointer
|
1260 |
|
|
is R1 and the frame pointer R2. The frame base is therefore the address
|
1261 |
|
|
held in R2 and the stack pointer (R1) is the frame base of the NEXT frame.
|
1262 |
|
|
|
1263 |
|
|
@verbatim
|
1264 |
|
|
l.addi r1,r1,-frame_size # SP now points to end of new stack frame
|
1265 |
|
|
@endverbatim
|
1266 |
|
|
|
1267 |
|
|
The stack pointer may not be set up in a frameless function (e.g. a simple
|
1268 |
|
|
leaf function).
|
1269 |
|
|
|
1270 |
|
|
@verbatim
|
1271 |
|
|
l.sw fp_loc(r1),r2 # old FP saved in new stack frame
|
1272 |
|
|
l.addi r2,r1,frame_size # FP now points to base of new stack frame
|
1273 |
|
|
@endverbatim
|
1274 |
|
|
|
1275 |
|
|
The frame pointer is not necessarily saved right at the end of the stack
|
1276 |
|
|
frame - OR32 saves enough space for any args to called functions right at
|
1277 |
|
|
the end (this is a difference from the Architecture Manual).
|
1278 |
|
|
|
1279 |
|
|
@verbatim
|
1280 |
|
|
l.sw lr_loc(r1),r9 # Link (return) address
|
1281 |
|
|
@endverbatim
|
1282 |
|
|
|
1283 |
|
|
The link register is usally saved at fp_loc - 4. It may not be saved at all
|
1284 |
|
|
in a leaf function.
|
1285 |
|
|
|
1286 |
|
|
@verbatim
|
1287 |
|
|
l.sw reg_loc(r1),ry # Save any callee saved regs
|
1288 |
|
|
@endverbatim
|
1289 |
|
|
|
1290 |
|
|
The offsets x for the callee saved registers generally (always?) rise in
|
1291 |
|
|
increments of 4, starting at fp_loc + 4. If the frame pointer is omitted
|
1292 |
|
|
(an option to GCC), then it may not be saved at all. There may be no callee
|
1293 |
|
|
saved registers.
|
1294 |
|
|
|
1295 |
|
|
So in summary none of this may be present. However what is present seems
|
1296 |
|
|
always to follow this fixed order, and occur before any substantive code
|
1297 |
|
|
(it is possible for GCC to have more flexible scheduling of the prologue,
|
1298 |
|
|
but this does not seem to occur for OR32).
|
1299 |
|
|
|
1300 |
|
|
ANALYSIS
|
1301 |
|
|
========
|
1302 |
|
|
|
1303 |
|
|
This prolog is used, even for -O3 with GCC.
|
1304 |
|
|
|
1305 |
|
|
All this analysis must allow for the possibility that the PC is in the
|
1306 |
|
|
middle of the prologue. Data in the cache should only be set up insofar as
|
1307 |
|
|
it has been computed.
|
1308 |
|
|
|
1309 |
|
|
HOWEVER. The frame_id must be created with the SP *as it will be* at the
|
1310 |
|
|
end of the Prologue. Otherwise a recursive call, checking the frame with
|
1311 |
|
|
the PC at the start address will end up with the same frame_id as the
|
1312 |
|
|
caller.
|
1313 |
|
|
|
1314 |
|
|
A suite of "helper" routines are used, allowing reuse for
|
1315 |
|
|
or32_skip_prologue().
|
1316 |
|
|
|
1317 |
|
|
Reportedly, this is only valid for frames less than 0x7fff in size.
|
1318 |
|
|
|
1319 |
|
|
@param[in] this_frame Our stack frame.
|
1320 |
|
|
@param[in,out] prologue_cache The prologue cache. If not supplied, we
|
1321 |
|
|
build it.
|
1322 |
|
|
|
1323 |
|
|
@return The prolog cache (duplicates the return through the argument) */
|
1324 |
|
|
/* ---------------------------------------------------------------------------*/
|
1325 |
|
|
static struct trad_frame_cache *
|
1326 |
|
|
or32_frame_cache (struct frame_info *this_frame,
|
1327 |
|
|
void **prologue_cache)
|
1328 |
|
|
{
|
1329 |
|
|
struct gdbarch *gdbarch;
|
1330 |
|
|
struct trad_frame_cache *info;
|
1331 |
|
|
|
1332 |
|
|
CORE_ADDR this_pc;
|
1333 |
|
|
CORE_ADDR this_sp;
|
1334 |
|
|
CORE_ADDR this_sp_for_id;
|
1335 |
|
|
int frame_size = 0;
|
1336 |
|
|
|
1337 |
|
|
CORE_ADDR start_addr;
|
1338 |
|
|
CORE_ADDR end_addr;
|
1339 |
|
|
|
1340 |
522 |
jeremybenn |
if (frame_debug)
|
1341 |
|
|
{
|
1342 |
|
|
fprintf_unfiltered (gdb_stdlog,
|
1343 |
|
|
"or32_frame_cache, prologue_cache = 0x%p\n",
|
1344 |
|
|
*prologue_cache);
|
1345 |
|
|
}
|
1346 |
|
|
|
1347 |
330 |
jeremybenn |
/* Nothing to do if we already have this info */
|
1348 |
|
|
if (NULL != *prologue_cache)
|
1349 |
|
|
{
|
1350 |
|
|
return *prologue_cache;
|
1351 |
|
|
}
|
1352 |
|
|
|
1353 |
|
|
/* Get a new prologue cache and populate it with default values */
|
1354 |
|
|
info = trad_frame_cache_zalloc (this_frame);
|
1355 |
|
|
*prologue_cache = info;
|
1356 |
|
|
|
1357 |
|
|
/* Find the start address of THIS function (which is a NORMAL frame, even if
|
1358 |
|
|
the NEXT frame is the sentinel frame) and the end of its prologue. */
|
1359 |
|
|
this_pc = get_frame_pc (this_frame);
|
1360 |
|
|
find_pc_partial_function (this_pc, NULL, &start_addr, NULL);
|
1361 |
|
|
|
1362 |
|
|
/* Return early if GDB couldn't find the function. */
|
1363 |
|
|
if (start_addr == 0)
|
1364 |
|
|
{
|
1365 |
522 |
jeremybenn |
if (frame_debug)
|
1366 |
|
|
{
|
1367 |
|
|
fprintf_unfiltered (gdb_stdlog, " couldn't find function\n");
|
1368 |
|
|
}
|
1369 |
|
|
|
1370 |
330 |
jeremybenn |
return info;
|
1371 |
|
|
}
|
1372 |
|
|
|
1373 |
|
|
/* Get the stack pointer if we have one (if there's no process executing yet
|
1374 |
|
|
we won't have a frame. */
|
1375 |
|
|
this_sp = (NULL == this_frame) ? 0 :
|
1376 |
|
|
get_frame_register_unsigned (this_frame,
|
1377 |
|
|
OR32_SP_REGNUM);
|
1378 |
|
|
|
1379 |
|
|
/* The default frame base of THIS frame (for ID purposes only - frame base
|
1380 |
|
|
is an overloaded term) is its stack pointer. For now we use the value of
|
1381 |
|
|
the SP register in THIS frame. However if the PC is in the prologue of
|
1382 |
|
|
THIS frame, before the SP has been set up, then the value will actually
|
1383 |
|
|
be that of the PREV frame, and we'll need to adjust it later. */
|
1384 |
|
|
trad_frame_set_this_base (info, this_sp);
|
1385 |
|
|
this_sp_for_id = this_sp;
|
1386 |
|
|
|
1387 |
|
|
/* The default is to find the PC of the PREVIOUS frame in the link register
|
1388 |
|
|
of this frame. This may be changed if we find the link register was saved
|
1389 |
|
|
on the stack. */
|
1390 |
|
|
trad_frame_set_reg_realreg (info, OR32_NPC_REGNUM, OR32_LR_REGNUM);
|
1391 |
|
|
|
1392 |
|
|
/* We should only examine code that is in the prologue. This is all code up
|
1393 |
|
|
to (but not including) end_addr. We should only populate the cache while
|
1394 |
|
|
the address is up to (but not including) the PC or end_addr, whichever is
|
1395 |
|
|
first. */
|
1396 |
|
|
gdbarch = get_frame_arch (this_frame);
|
1397 |
|
|
end_addr = or32_skip_prologue (gdbarch, start_addr);
|
1398 |
|
|
|
1399 |
|
|
/* All the following analysis only occurs if we are in the prologue and have
|
1400 |
|
|
executed the code. Check we have a sane prologue size, and if zero we
|
1401 |
|
|
are frameless and can give up here. */
|
1402 |
|
|
if (end_addr < start_addr)
|
1403 |
|
|
{
|
1404 |
|
|
fatal ("end addr 0x%08x is less than start addr 0x%08x\n",
|
1405 |
|
|
(unsigned int) end_addr, (unsigned int) start_addr);
|
1406 |
|
|
}
|
1407 |
|
|
|
1408 |
|
|
if (end_addr == start_addr)
|
1409 |
|
|
{
|
1410 |
|
|
frame_size = 0;
|
1411 |
|
|
}
|
1412 |
|
|
else
|
1413 |
|
|
{
|
1414 |
|
|
/* have a frame. Look for the various components */
|
1415 |
|
|
CORE_ADDR addr = start_addr; /* Where we have got to */
|
1416 |
|
|
uint32_t inst = or32_fetch_instruction (gdbarch, addr);
|
1417 |
|
|
|
1418 |
|
|
unsigned int ra, rb, rd; /* For instruction analysis */
|
1419 |
|
|
int simm;
|
1420 |
|
|
|
1421 |
|
|
/* Look for the new stack pointer being set up. */
|
1422 |
|
|
if (or32_analyse_l_addi (inst, &rd, &ra, &simm) &&
|
1423 |
|
|
(OR32_SP_REGNUM == rd) && (OR32_SP_REGNUM == ra) &&
|
1424 |
|
|
(simm < 0) && (0 == (simm % 4)))
|
1425 |
|
|
{
|
1426 |
|
|
frame_size = -simm;
|
1427 |
|
|
addr += OR32_INSTLEN;
|
1428 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
1429 |
|
|
|
1430 |
|
|
/* If the PC has not actually got to this point, then the frame base
|
1431 |
|
|
will be wrong, and we adjust it.
|
1432 |
|
|
|
1433 |
|
|
If we are past this point, then we need to populate the stack
|
1434 |
|
|
accoringly. */
|
1435 |
|
|
if (this_pc <= addr)
|
1436 |
|
|
{
|
1437 |
|
|
/* Only do if executing */
|
1438 |
|
|
if (0 != this_sp)
|
1439 |
|
|
{
|
1440 |
|
|
this_sp_for_id = this_sp + frame_size;
|
1441 |
|
|
trad_frame_set_this_base (info, this_sp_for_id);
|
1442 |
|
|
}
|
1443 |
|
|
}
|
1444 |
|
|
else
|
1445 |
|
|
{
|
1446 |
|
|
/* We are past this point, so the stack pointer of the PREV
|
1447 |
|
|
frame is frame_size greater than the stack pointer of THIS
|
1448 |
|
|
frame. */
|
1449 |
|
|
trad_frame_set_reg_value (info, OR32_SP_REGNUM,
|
1450 |
|
|
this_sp + frame_size);
|
1451 |
|
|
}
|
1452 |
|
|
}
|
1453 |
|
|
|
1454 |
|
|
/* From now on we are only populating the cache, so we stop once we get
|
1455 |
|
|
to either the end OR the current PC. */
|
1456 |
|
|
end_addr = (this_pc < end_addr) ? this_pc : end_addr;
|
1457 |
|
|
|
1458 |
|
|
/* Look for the frame pointer being manipulated. */
|
1459 |
|
|
if ((addr < end_addr) &&
|
1460 |
|
|
or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
1461 |
|
|
(OR32_SP_REGNUM == ra) && (OR32_FP_REGNUM == rb) &&
|
1462 |
|
|
(simm >= 0) && (0 == (simm % 4)))
|
1463 |
|
|
{
|
1464 |
|
|
addr += OR32_INSTLEN;
|
1465 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
1466 |
|
|
|
1467 |
|
|
/* At this stage, we can find the frame pointer of the PREVIOUS
|
1468 |
|
|
frame on the stack of the current frame. */
|
1469 |
|
|
trad_frame_set_reg_addr (info, OR32_FP_REGNUM, this_sp + simm);
|
1470 |
|
|
|
1471 |
|
|
/* Look for the new frame pointer being set up */
|
1472 |
|
|
if (addr < end_addr)
|
1473 |
|
|
{
|
1474 |
|
|
gdb_assert (or32_analyse_l_addi (inst, &rd, &ra, &simm) &&
|
1475 |
|
|
(OR32_FP_REGNUM == rd) && (OR32_SP_REGNUM == ra) &&
|
1476 |
|
|
(simm == frame_size));
|
1477 |
|
|
|
1478 |
|
|
addr += OR32_INSTLEN;
|
1479 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
1480 |
|
|
|
1481 |
|
|
/* If we have got this far, the stack pointer of the PREVIOUS
|
1482 |
|
|
frame is the frame pointer of THIS frame. */
|
1483 |
|
|
trad_frame_set_reg_realreg (info, OR32_SP_REGNUM, OR32_FP_REGNUM);
|
1484 |
|
|
}
|
1485 |
|
|
}
|
1486 |
|
|
|
1487 |
|
|
/* Look for the link register being saved */
|
1488 |
|
|
if ((addr < end_addr) &&
|
1489 |
|
|
or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
1490 |
|
|
(OR32_SP_REGNUM == ra) && (OR32_LR_REGNUM == rb) &&
|
1491 |
|
|
(simm >= 0) && (0 == (simm % 4)))
|
1492 |
|
|
{
|
1493 |
|
|
addr += OR32_INSTLEN;
|
1494 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
1495 |
|
|
|
1496 |
|
|
/* If the link register is saved in the THIS frame, it holds the
|
1497 |
|
|
value of the PC in the PREVIOUS frame. This overwrites the
|
1498 |
|
|
previous information about finding the PC in the link
|
1499 |
|
|
register. */
|
1500 |
|
|
trad_frame_set_reg_addr (info, OR32_NPC_REGNUM, this_sp + simm);
|
1501 |
|
|
}
|
1502 |
|
|
|
1503 |
|
|
/* Look for arguments or callee-saved register being saved. The register
|
1504 |
|
|
must be one of the arguments (r3-r8) or the 10 callee saved registers
|
1505 |
|
|
(r10, r12, r14, r16, r18, r20, r22, r24, r26, r28, r30). The base
|
1506 |
|
|
register must be the FP (for the args) or the SP (for the
|
1507 |
|
|
callee_saved registers). */
|
1508 |
|
|
while (addr < end_addr)
|
1509 |
|
|
{
|
1510 |
|
|
if (or32_analyse_l_sw (inst, &simm, &ra, &rb) &&
|
1511 |
|
|
(((OR32_FP_REGNUM == ra) && or32_is_arg_reg (rb)) ||
|
1512 |
|
|
((OR32_SP_REGNUM == ra) && or32_is_callee_saved_reg (rb))) &&
|
1513 |
|
|
(0 == (simm % 4)))
|
1514 |
|
|
{
|
1515 |
|
|
addr += OR32_INSTLEN;
|
1516 |
|
|
inst = or32_fetch_instruction (gdbarch, addr);
|
1517 |
|
|
|
1518 |
|
|
/* The register in the PREVIOUS frame can be found at this
|
1519 |
|
|
location in THIS frame */
|
1520 |
|
|
trad_frame_set_reg_addr (info, rb, this_sp + simm);
|
1521 |
|
|
}
|
1522 |
|
|
else
|
1523 |
|
|
{
|
1524 |
|
|
break; /* Not a register save instruction */
|
1525 |
|
|
}
|
1526 |
|
|
}
|
1527 |
|
|
}
|
1528 |
|
|
|
1529 |
|
|
/* Build the frame ID */
|
1530 |
|
|
trad_frame_set_id (info, frame_id_build (this_sp_for_id, start_addr));
|
1531 |
|
|
|
1532 |
522 |
jeremybenn |
if (frame_debug)
|
1533 |
|
|
{
|
1534 |
|
|
fprintf_unfiltered (gdb_stdlog, " this_sp_for_id = 0x%p\n",
|
1535 |
|
|
(void *) this_sp_for_id);
|
1536 |
|
|
fprintf_unfiltered (gdb_stdlog, " start_addr = 0x%p\n",
|
1537 |
|
|
(void *) start_addr);
|
1538 |
|
|
}
|
1539 |
|
|
|
1540 |
330 |
jeremybenn |
return info;
|
1541 |
|
|
|
1542 |
|
|
} /* or32_frame_cache() */
|
1543 |
|
|
|
1544 |
|
|
|
1545 |
|
|
/* -------------------------------------------------------------------------- */
|
1546 |
|
|
/*!Find the frame ID of this frame
|
1547 |
|
|
|
1548 |
|
|
This function has changed since GDB 6.8 to use THIS frame, rather than the
|
1549 |
|
|
NEXT frame.
|
1550 |
|
|
|
1551 |
|
|
Given a GDB frame, return its frame_id.
|
1552 |
|
|
|
1553 |
|
|
@param[in] this_frame Our frame, for which the ID is wanted.
|
1554 |
|
|
@param[in] prologue_cache Any cached prologue for THIS function.
|
1555 |
|
|
@param[out] this_id Frame ID of our own frame.
|
1556 |
|
|
|
1557 |
|
|
@return Frame ID for THIS frame */
|
1558 |
|
|
/* ------------------------------------------------------------------------- */
|
1559 |
|
|
static void
|
1560 |
|
|
or32_frame_this_id (struct frame_info *this_frame,
|
1561 |
|
|
void **prologue_cache,
|
1562 |
|
|
struct frame_id *this_id)
|
1563 |
|
|
{
|
1564 |
|
|
struct trad_frame_cache *info =
|
1565 |
|
|
or32_frame_cache (this_frame, prologue_cache);
|
1566 |
|
|
|
1567 |
|
|
trad_frame_get_id (info, this_id);
|
1568 |
|
|
|
1569 |
|
|
} /* or32_frame_this_id() */
|
1570 |
|
|
|
1571 |
|
|
|
1572 |
|
|
/*----------------------------------------------------------------------------*/
|
1573 |
|
|
/*!Get a register from the PREVIOUS frame
|
1574 |
|
|
|
1575 |
|
|
This function has changed from GDB 6.8. It now takes a reference to THIS
|
1576 |
|
|
frame, not the NEXT frame. It returns it results via a structure, not its
|
1577 |
|
|
argument list.
|
1578 |
|
|
|
1579 |
|
|
Given a pointer to the THIS frame, return the details of a register in the
|
1580 |
|
|
PREVIOUS frame.
|
1581 |
|
|
|
1582 |
|
|
@param[in] this_frame The stack frame under consideration
|
1583 |
|
|
@param[in] prologue_cache Any cached prologue associated with THIS frame,
|
1584 |
|
|
which may therefore tell us about registers in
|
1585 |
|
|
the PREVIOUS frame.
|
1586 |
|
|
@param[in] regnum The register of interest in the PREVIOUS frame
|
1587 |
|
|
|
1588 |
|
|
@return A value structure representing the register. */
|
1589 |
|
|
/* -------------------------------------------------------------------------- */
|
1590 |
|
|
static struct value *
|
1591 |
|
|
or32_frame_prev_register (struct frame_info *this_frame,
|
1592 |
|
|
void **prologue_cache,
|
1593 |
|
|
int regnum)
|
1594 |
|
|
{
|
1595 |
|
|
struct trad_frame_cache *info = or32_frame_cache (this_frame,
|
1596 |
|
|
prologue_cache);
|
1597 |
|
|
|
1598 |
|
|
return trad_frame_get_register (info, this_frame, regnum);
|
1599 |
|
|
|
1600 |
|
|
} /* or32_frame_prev_register() */
|
1601 |
|
|
|
1602 |
|
|
|
1603 |
|
|
/* -------------------------------------------------------------------------- */
|
1604 |
|
|
/*!Structure defining the OR32 frame unwind functions
|
1605 |
|
|
|
1606 |
|
|
Must be global (to this file), since referred to by multiple functions.
|
1607 |
|
|
|
1608 |
|
|
Since we are the fallback unwinder, we use the default frame sniffer, which
|
1609 |
|
|
always accepts the frame
|
1610 |
|
|
|
1611 |
|
|
This applies to NORMAL frames only. We provide the following functions.
|
1612 |
|
|
- to give the ID of THIS frame
|
1613 |
|
|
- to give the details of a register in PREVIOUS frame
|
1614 |
|
|
- a frame sniffer. */
|
1615 |
|
|
/* -------------------------------------------------------------------------- */
|
1616 |
|
|
static const struct frame_unwind or32_frame_unwind = {
|
1617 |
|
|
.type = NORMAL_FRAME,
|
1618 |
|
|
.this_id = or32_frame_this_id,
|
1619 |
|
|
.prev_register = or32_frame_prev_register,
|
1620 |
|
|
.unwind_data = NULL,
|
1621 |
|
|
.sniffer = default_frame_sniffer,
|
1622 |
|
|
.dealloc_cache = NULL,
|
1623 |
|
|
.prev_arch = NULL
|
1624 |
|
|
};
|
1625 |
|
|
|
1626 |
|
|
|
1627 |
522 |
jeremybenn |
#if 0
|
1628 |
330 |
jeremybenn |
/*----------------------------------------------------------------------------*/
|
1629 |
|
|
/*!Return the base address of the frame
|
1630 |
|
|
|
1631 |
|
|
The implementations has changed since GDB 6.8, since we are now provided
|
1632 |
|
|
with the address of THIS frame, rather than the NEXT frame.
|
1633 |
|
|
|
1634 |
|
|
For the OR32, the base address is the frame pointer
|
1635 |
|
|
|
1636 |
|
|
@param[in] this_frame The current stack frame.
|
1637 |
|
|
@param[in] prologue_cache Any cached prologue for THIS function.
|
1638 |
|
|
|
1639 |
|
|
@return The frame base address */
|
1640 |
|
|
/*---------------------------------------------------------------------------*/
|
1641 |
|
|
|
1642 |
|
|
static CORE_ADDR
|
1643 |
|
|
or32_frame_base_address (struct frame_info *this_frame,
|
1644 |
|
|
void **prologue_cache)
|
1645 |
|
|
{
|
1646 |
|
|
return (CORE_ADDR) get_frame_register_unsigned (this_frame, OR32_FP_REGNUM);
|
1647 |
|
|
|
1648 |
|
|
} /* or32_frame_base_address() */
|
1649 |
|
|
|
1650 |
|
|
|
1651 |
|
|
/* -------------------------------------------------------------------------- */
|
1652 |
|
|
/*!Identify our frame base sniffer functions
|
1653 |
|
|
|
1654 |
|
|
This function just identifies our family of frame sniffing functions.
|
1655 |
|
|
|
1656 |
|
|
@param[in] this_frame The frame of THIS function. Not used here.
|
1657 |
|
|
|
1658 |
|
|
@return A pointer to a struct identifying the frame base sniffing
|
1659 |
|
|
functions. */
|
1660 |
|
|
/* -------------------------------------------------------------------------- */
|
1661 |
|
|
static const struct frame_base *
|
1662 |
|
|
or32_frame_base_sniffer (struct frame_info *this_frame)
|
1663 |
|
|
{
|
1664 |
|
|
/* Structure defining how the frame base is to be identified. */
|
1665 |
|
|
static const struct frame_base or32_frame_base =
|
1666 |
|
|
{
|
1667 |
|
|
.unwind = &or32_frame_unwind,
|
1668 |
|
|
.this_base = or32_frame_base_address,
|
1669 |
|
|
.this_locals = or32_frame_base_address,
|
1670 |
|
|
.this_args = or32_frame_base_address
|
1671 |
|
|
};
|
1672 |
|
|
|
1673 |
|
|
return &or32_frame_base;
|
1674 |
|
|
|
1675 |
|
|
} /* or32_frame_base_sniffer () */
|
1676 |
522 |
jeremybenn |
#endif
|
1677 |
330 |
jeremybenn |
|
1678 |
|
|
|
1679 |
|
|
/* -------------------------------------------------------------------------- */
|
1680 |
|
|
/*!Architecture initialization for OpenRISC 1000
|
1681 |
|
|
|
1682 |
|
|
Looks for a candidate architecture in the list of architectures supplied
|
1683 |
|
|
using the info supplied. If none match, create a new architecture.
|
1684 |
|
|
|
1685 |
|
|
@param[in] info Information about the target architecture
|
1686 |
|
|
@param[in] arches The list of currently know architectures
|
1687 |
|
|
|
1688 |
|
|
@return A structure describing the target architecture */
|
1689 |
|
|
/* -------------------------------------------------------------------------- */
|
1690 |
|
|
static struct gdbarch *
|
1691 |
|
|
or32_gdbarch_init (struct gdbarch_info info,
|
1692 |
|
|
struct gdbarch_list *arches)
|
1693 |
|
|
{
|
1694 |
|
|
static struct frame_base or32_frame_base;
|
1695 |
|
|
struct gdbarch *gdbarch;
|
1696 |
|
|
struct gdbarch_tdep *tdep;
|
1697 |
|
|
const struct bfd_arch_info *binfo;
|
1698 |
|
|
|
1699 |
|
|
/* Find a candidate among the list of pre-declared architectures. */
|
1700 |
|
|
arches = gdbarch_list_lookup_by_info (arches, &info);
|
1701 |
|
|
if (NULL != arches)
|
1702 |
|
|
{
|
1703 |
|
|
return arches->gdbarch;
|
1704 |
|
|
}
|
1705 |
|
|
|
1706 |
|
|
/* None found, create a new architecture from the information
|
1707 |
|
|
provided. Can't initialize all the target dependencies until we actually
|
1708 |
|
|
know which target we are talking to, but put in some defaults for now. */
|
1709 |
|
|
|
1710 |
|
|
binfo = info.bfd_arch_info;
|
1711 |
|
|
tdep = xmalloc (sizeof *tdep);
|
1712 |
|
|
tdep->num_matchpoints = OR32_MAX_MATCHPOINTS;
|
1713 |
|
|
tdep->num_gpr_regs = OR32_MAX_GPR_REGS;
|
1714 |
|
|
tdep->bytes_per_word = binfo->bits_per_word / binfo->bits_per_byte;
|
1715 |
|
|
tdep->bytes_per_address = binfo->bits_per_address / binfo->bits_per_byte;
|
1716 |
|
|
gdbarch = gdbarch_alloc (&info, tdep);
|
1717 |
|
|
|
1718 |
|
|
/* Target data types. */
|
1719 |
|
|
set_gdbarch_short_bit (gdbarch, 16);
|
1720 |
|
|
set_gdbarch_int_bit (gdbarch, 32);
|
1721 |
|
|
set_gdbarch_long_bit (gdbarch, 32);
|
1722 |
|
|
set_gdbarch_long_long_bit (gdbarch, 64);
|
1723 |
|
|
set_gdbarch_float_bit (gdbarch, 32);
|
1724 |
|
|
set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
|
1725 |
|
|
set_gdbarch_double_bit (gdbarch, 64);
|
1726 |
|
|
set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
|
1727 |
|
|
set_gdbarch_long_double_bit (gdbarch, 64);
|
1728 |
|
|
set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
|
1729 |
|
|
set_gdbarch_ptr_bit (gdbarch, binfo->bits_per_address);
|
1730 |
|
|
set_gdbarch_addr_bit (gdbarch, binfo->bits_per_address);
|
1731 |
|
|
set_gdbarch_char_signed (gdbarch, 1);
|
1732 |
|
|
|
1733 |
|
|
/* Information about the target architecture */
|
1734 |
|
|
set_gdbarch_return_value (gdbarch, or32_return_value);
|
1735 |
|
|
set_gdbarch_breakpoint_from_pc (gdbarch, or32_breakpoint_from_pc);
|
1736 |
|
|
set_gdbarch_single_step_through_delay
|
1737 |
|
|
(gdbarch, or32_single_step_through_delay);
|
1738 |
|
|
set_gdbarch_have_nonsteppable_watchpoint
|
1739 |
|
|
(gdbarch, 1);
|
1740 |
|
|
switch (gdbarch_byte_order (gdbarch))
|
1741 |
|
|
{
|
1742 |
|
|
case BFD_ENDIAN_BIG:
|
1743 |
|
|
set_gdbarch_print_insn (gdbarch, print_insn_big_or32);
|
1744 |
|
|
break;
|
1745 |
|
|
|
1746 |
|
|
case BFD_ENDIAN_LITTLE:
|
1747 |
|
|
set_gdbarch_print_insn (gdbarch, print_insn_little_or32);
|
1748 |
|
|
break;
|
1749 |
|
|
|
1750 |
|
|
case BFD_ENDIAN_UNKNOWN:
|
1751 |
|
|
error ("or32_gdbarch_init: Unknown endianness");
|
1752 |
|
|
break;
|
1753 |
|
|
}
|
1754 |
|
|
|
1755 |
|
|
/* Register architecture */
|
1756 |
|
|
set_gdbarch_pseudo_register_read (gdbarch, or32_pseudo_register_read);
|
1757 |
|
|
set_gdbarch_pseudo_register_write (gdbarch, or32_pseudo_register_write);
|
1758 |
|
|
set_gdbarch_num_regs (gdbarch, OR32_NUM_REGS);
|
1759 |
|
|
set_gdbarch_num_pseudo_regs (gdbarch, OR32_NUM_PSEUDO_REGS);
|
1760 |
|
|
set_gdbarch_sp_regnum (gdbarch, OR32_SP_REGNUM);
|
1761 |
|
|
set_gdbarch_pc_regnum (gdbarch, OR32_NPC_REGNUM);
|
1762 |
|
|
set_gdbarch_ps_regnum (gdbarch, OR32_SR_REGNUM);
|
1763 |
|
|
set_gdbarch_deprecated_fp_regnum (gdbarch, OR32_FP_REGNUM);
|
1764 |
|
|
|
1765 |
|
|
/* Functions to supply register information */
|
1766 |
|
|
set_gdbarch_register_name (gdbarch, or32_register_name);
|
1767 |
|
|
set_gdbarch_register_type (gdbarch, or32_register_type);
|
1768 |
|
|
set_gdbarch_print_registers_info (gdbarch, or32_registers_info);
|
1769 |
|
|
set_gdbarch_register_reggroup_p (gdbarch, or32_register_reggroup_p);
|
1770 |
|
|
|
1771 |
|
|
/* Functions to analyse frames */
|
1772 |
|
|
set_gdbarch_skip_prologue (gdbarch, or32_skip_prologue);
|
1773 |
|
|
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
|
1774 |
|
|
set_gdbarch_frame_align (gdbarch, or32_frame_align);
|
1775 |
|
|
set_gdbarch_frame_red_zone_size (gdbarch, OR32_FRAME_RED_ZONE_SIZE);
|
1776 |
|
|
|
1777 |
|
|
/* Functions to access frame data */
|
1778 |
|
|
set_gdbarch_unwind_pc (gdbarch, or32_unwind_pc);
|
1779 |
|
|
set_gdbarch_unwind_sp (gdbarch, or32_unwind_sp);
|
1780 |
|
|
|
1781 |
|
|
/* Functions handling dummy frames */
|
1782 |
|
|
set_gdbarch_push_dummy_call (gdbarch, or32_push_dummy_call);
|
1783 |
|
|
set_gdbarch_dummy_id (gdbarch, or32_dummy_id);
|
1784 |
|
|
|
1785 |
522 |
jeremybenn |
#if 0
|
1786 |
330 |
jeremybenn |
/* Set up sniffers for the frame base. Use DWARF debug info if available,
|
1787 |
|
|
otherwise use our own sniffer. */
|
1788 |
|
|
frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
|
1789 |
|
|
frame_base_append_sniffer (gdbarch, or32_frame_base_sniffer);
|
1790 |
522 |
jeremybenn |
#endif
|
1791 |
330 |
jeremybenn |
|
1792 |
|
|
/* Frame unwinders. Use DWARF debug info if available, otherwise use our
|
1793 |
|
|
own unwinder. */
|
1794 |
|
|
dwarf2_append_unwinders (gdbarch);
|
1795 |
|
|
frame_unwind_append_unwinder (gdbarch, &or32_frame_unwind);
|
1796 |
|
|
|
1797 |
|
|
return gdbarch;
|
1798 |
|
|
|
1799 |
|
|
} /* or32_gdbarch_init() */
|
1800 |
|
|
|
1801 |
|
|
|
1802 |
|
|
/*----------------------------------------------------------------------------*/
|
1803 |
|
|
/*!Dump the target specific data for this architecture
|
1804 |
|
|
|
1805 |
|
|
@param[in] gdbarch The architecture of interest
|
1806 |
|
|
@param[in] file Where to dump the data */
|
1807 |
|
|
/*---------------------------------------------------------------------------*/
|
1808 |
|
|
|
1809 |
|
|
static void
|
1810 |
|
|
or32_dump_tdep (struct gdbarch *gdbarch,
|
1811 |
|
|
struct ui_file *file)
|
1812 |
|
|
{
|
1813 |
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
1814 |
|
|
|
1815 |
|
|
if (NULL == tdep)
|
1816 |
|
|
{
|
1817 |
|
|
return; /* Nothing to report */
|
1818 |
|
|
}
|
1819 |
|
|
|
1820 |
|
|
fprintf_unfiltered (file, "or32_dump_tdep: %d matchpoints available\n",
|
1821 |
|
|
tdep->num_matchpoints);
|
1822 |
|
|
fprintf_unfiltered (file, "or32_dump_tdep: %d general purpose registers\n",
|
1823 |
|
|
tdep->num_gpr_regs);
|
1824 |
|
|
fprintf_unfiltered (file, "or32_dump_tdep: %d bytes per word\n",
|
1825 |
|
|
tdep->bytes_per_word);
|
1826 |
|
|
fprintf_unfiltered (file, "or32_dump_tdep: %d bytes per address\n",
|
1827 |
|
|
tdep->bytes_per_address);
|
1828 |
|
|
|
1829 |
|
|
} /* or32_dump_tdep() */
|
1830 |
|
|
|
1831 |
|
|
|
1832 |
|
|
|
1833 |
|
|
/* Functions to add extra commands to GDB */
|
1834 |
|
|
|
1835 |
|
|
|
1836 |
|
|
/*----------------------------------------------------------------------------*/
|
1837 |
|
|
/*!Returns a special purpose register group name
|
1838 |
|
|
|
1839 |
|
|
@param[in] group The SPR group number
|
1840 |
|
|
|
1841 |
|
|
@return The SPR name (pointer to the name argument) */
|
1842 |
|
|
/*---------------------------------------------------------------------------*/
|
1843 |
|
|
|
1844 |
|
|
static const char *
|
1845 |
|
|
or32_spr_group_name (int group)
|
1846 |
|
|
{
|
1847 |
|
|
static const char *or32_group_names[OR32_NUM_SPGS] =
|
1848 |
|
|
{
|
1849 |
|
|
"SYS",
|
1850 |
|
|
"DMMU",
|
1851 |
|
|
"IMMU",
|
1852 |
|
|
"DCACHE",
|
1853 |
|
|
"ICACHE",
|
1854 |
|
|
"MAC",
|
1855 |
|
|
"DEBUG",
|
1856 |
|
|
"PERF",
|
1857 |
|
|
"POWER",
|
1858 |
|
|
"PIC",
|
1859 |
|
|
"TIMER",
|
1860 |
|
|
"FPU"
|
1861 |
|
|
};
|
1862 |
|
|
|
1863 |
|
|
if ((0 <= group) && (group < OR32_NUM_SPGS))
|
1864 |
|
|
{
|
1865 |
|
|
return or32_group_names[group];
|
1866 |
|
|
}
|
1867 |
|
|
else
|
1868 |
|
|
{
|
1869 |
|
|
return "";
|
1870 |
|
|
}
|
1871 |
|
|
} /* or32_spr_group_name() */
|
1872 |
|
|
|
1873 |
|
|
|
1874 |
|
|
/*----------------------------------------------------------------------------*/
|
1875 |
|
|
/*!Returns a special purpose register name
|
1876 |
|
|
|
1877 |
|
|
@param[in] group The SPR group
|
1878 |
|
|
@param[in] index The index within the SPR group
|
1879 |
|
|
@param[out] name Array to put the name in
|
1880 |
|
|
|
1881 |
|
|
@return The SPR name (pointer to the name argument) */
|
1882 |
|
|
/*---------------------------------------------------------------------------*/
|
1883 |
|
|
|
1884 |
|
|
static char *
|
1885 |
|
|
or32_spr_register_name (int group,
|
1886 |
|
|
int index,
|
1887 |
|
|
char *name)
|
1888 |
|
|
{
|
1889 |
|
|
char di;
|
1890 |
|
|
|
1891 |
|
|
switch (group)
|
1892 |
|
|
{
|
1893 |
|
|
|
1894 |
|
|
case OR32_SPG_SYS:
|
1895 |
|
|
/* 1:1 names */
|
1896 |
|
|
switch (index)
|
1897 |
|
|
{
|
1898 |
|
|
case OR32_SPG_SYS_VR: sprintf (name, "VR" ); return name;
|
1899 |
|
|
case OR32_SPG_SYS_UPR: sprintf (name, "UPR" ); return name;
|
1900 |
|
|
case OR32_SPG_SYS_CPUCFGR: sprintf (name, "CPUCFGR" ); return name;
|
1901 |
|
|
case OR32_SPG_SYS_DMMUCFGR: sprintf (name, "DMMUCFGR"); return name;
|
1902 |
|
|
case OR32_SPG_SYS_IMMUCFGR: sprintf (name, "IMMUCFGR"); return name;
|
1903 |
|
|
case OR32_SPG_SYS_DCCFGR: sprintf (name, "DCCFGR" ); return name;
|
1904 |
|
|
case OR32_SPG_SYS_ICCFGR: sprintf (name, "ICCFGR" ); return name;
|
1905 |
|
|
case OR32_SPG_SYS_DCFGR: sprintf (name, "DCFGR" ); return name;
|
1906 |
|
|
case OR32_SPG_SYS_PCCFGR: sprintf (name, "PCCFGR" ); return name;
|
1907 |
|
|
case OR32_SPG_SYS_NPC: sprintf (name, "NPC" ); return name;
|
1908 |
|
|
case OR32_SPG_SYS_SR: sprintf (name, "SR" ); return name;
|
1909 |
|
|
case OR32_SPG_SYS_PPC: sprintf (name, "PPC" ); return name;
|
1910 |
|
|
case OR32_SPG_SYS_FPCSR: sprintf (name, "FPCSR" ); return name;
|
1911 |
|
|
}
|
1912 |
|
|
|
1913 |
|
|
/* Exception PC regs */
|
1914 |
|
|
if((OR32_SPG_SYS_EPCR <= index) &&
|
1915 |
|
|
(index <= OR32_SPG_SYS_EPCR_END))
|
1916 |
|
|
{
|
1917 |
|
|
sprintf (name, "EPCR%d", index - OR32_SPG_SYS_EPCR);
|
1918 |
|
|
return name;
|
1919 |
|
|
}
|
1920 |
|
|
|
1921 |
|
|
/* Exception EA regs */
|
1922 |
|
|
if((OR32_SPG_SYS_EEAR <= index) &&
|
1923 |
|
|
(index <= OR32_SPG_SYS_EEAR_END))
|
1924 |
|
|
{
|
1925 |
|
|
sprintf (name, "EEAR%d", index - OR32_SPG_SYS_EEAR);
|
1926 |
|
|
return name;
|
1927 |
|
|
}
|
1928 |
|
|
|
1929 |
|
|
/* Exception SR regs */
|
1930 |
|
|
if((OR32_SPG_SYS_ESR <= index) &&
|
1931 |
|
|
(index <= OR32_SPG_SYS_ESR_END))
|
1932 |
|
|
{
|
1933 |
|
|
sprintf (name, "ESR%d", index - OR32_SPG_SYS_ESR);
|
1934 |
|
|
return name;
|
1935 |
|
|
}
|
1936 |
|
|
|
1937 |
|
|
/* GPRs */
|
1938 |
|
|
if((OR32_SPG_SYS_GPR <= index) &&
|
1939 |
|
|
(index <= OR32_SPG_SYS_GPR_END))
|
1940 |
|
|
{
|
1941 |
|
|
sprintf (name, "GPR%d", index - OR32_SPG_SYS_GPR);
|
1942 |
|
|
return name;
|
1943 |
|
|
}
|
1944 |
|
|
|
1945 |
|
|
break;
|
1946 |
|
|
|
1947 |
|
|
case OR32_SPG_DMMU:
|
1948 |
|
|
case OR32_SPG_IMMU:
|
1949 |
|
|
/* MMU registers. Use DMMU constants throughout, but these are identical
|
1950 |
|
|
to the corresponding IMMU constants */
|
1951 |
|
|
di = OR32_SPG_DMMU == group ? 'D' : 'I';
|
1952 |
|
|
|
1953 |
|
|
/* 1:1 names */
|
1954 |
|
|
switch (index)
|
1955 |
|
|
{
|
1956 |
|
|
case OR32_SPG_DMMU_DMMUCR:
|
1957 |
|
|
sprintf (name, "%cMMUCR", di); return name;
|
1958 |
|
|
case OR32_SPG_DMMU_DMMUPR:
|
1959 |
|
|
sprintf (name, "%cMMUPR", di); return name;
|
1960 |
|
|
case OR32_SPG_DMMU_DTLBEIR:
|
1961 |
|
|
sprintf (name, "%cTLBEIR", di); return name;
|
1962 |
|
|
}
|
1963 |
|
|
|
1964 |
|
|
/* ATB Match registers */
|
1965 |
|
|
if((OR32_SPG_DMMU_DATBMR <= index) &&
|
1966 |
|
|
(index <= OR32_SPG_DMMU_DATBMR_END))
|
1967 |
|
|
{
|
1968 |
|
|
sprintf (name, "%cATBMR%d", di, index - OR32_SPG_DMMU_DATBMR);
|
1969 |
|
|
return name;
|
1970 |
|
|
}
|
1971 |
|
|
|
1972 |
|
|
/* ATB Translate registers */
|
1973 |
|
|
if((OR32_SPG_DMMU_DATBTR <= index) &&
|
1974 |
|
|
(index <= OR32_SPG_DMMU_DATBTR_END))
|
1975 |
|
|
{
|
1976 |
|
|
sprintf (name, "%cATBTR%d", di, index - OR32_SPG_DMMU_DATBTR);
|
1977 |
|
|
return name;
|
1978 |
|
|
}
|
1979 |
|
|
|
1980 |
|
|
/* TLB Way 1 Match registers */
|
1981 |
|
|
if((OR32_SPG_DMMU_DTLBW1MR <= index) &&
|
1982 |
|
|
(index <= OR32_SPG_DMMU_DTLBW1MR_END))
|
1983 |
|
|
{
|
1984 |
|
|
sprintf (name, "%cTLBW1MR%d", di, index - OR32_SPG_DMMU_DTLBW1MR);
|
1985 |
|
|
return name;
|
1986 |
|
|
}
|
1987 |
|
|
|
1988 |
|
|
/* TLB Way 1 Translate registers */
|
1989 |
|
|
if((OR32_SPG_DMMU_DTLBW1TR <= index) &&
|
1990 |
|
|
(index <= OR32_SPG_DMMU_DTLBW1TR_END))
|
1991 |
|
|
{
|
1992 |
|
|
sprintf (name, "%cTLBW1TR%d", di, index - OR32_SPG_DMMU_DTLBW1TR);
|
1993 |
|
|
return name;
|
1994 |
|
|
}
|
1995 |
|
|
|
1996 |
|
|
/* TLB Way 2 Match registers */
|
1997 |
|
|
if((OR32_SPG_DMMU_DTLBW2MR <= index) &&
|
1998 |
|
|
(index <= OR32_SPG_DMMU_DTLBW2MR_END))
|
1999 |
|
|
{
|
2000 |
|
|
sprintf (name, "%cTLBW2MR%d", di, index - OR32_SPG_DMMU_DTLBW2MR);
|
2001 |
|
|
return name;
|
2002 |
|
|
}
|
2003 |
|
|
|
2004 |
|
|
/* TLB Way 2 Translate registers */
|
2005 |
|
|
if((OR32_SPG_DMMU_DTLBW2TR <= index) &&
|
2006 |
|
|
(index <= OR32_SPG_DMMU_DTLBW2TR_END))
|
2007 |
|
|
{
|
2008 |
|
|
sprintf (name, "%cTLBW2TR%d", di, index - OR32_SPG_DMMU_DTLBW2TR);
|
2009 |
|
|
return name;
|
2010 |
|
|
}
|
2011 |
|
|
|
2012 |
|
|
/* TLB Way 3 Match registers */
|
2013 |
|
|
if((OR32_SPG_DMMU_DTLBW3MR <= index) &&
|
2014 |
|
|
(index <= OR32_SPG_DMMU_DTLBW3MR_END))
|
2015 |
|
|
{
|
2016 |
|
|
sprintf (name, "%cTLBW3MR%d", di, index - OR32_SPG_DMMU_DTLBW3MR);
|
2017 |
|
|
return name;
|
2018 |
|
|
}
|
2019 |
|
|
|
2020 |
|
|
/* TLB Way 3 Translate registers */
|
2021 |
|
|
if((OR32_SPG_DMMU_DTLBW3TR <= index) &&
|
2022 |
|
|
(index <= OR32_SPG_DMMU_DTLBW3TR_END))
|
2023 |
|
|
{
|
2024 |
|
|
sprintf (name, "%cTLBW3TR%d", di, index - OR32_SPG_DMMU_DTLBW3TR);
|
2025 |
|
|
return name;
|
2026 |
|
|
}
|
2027 |
|
|
|
2028 |
|
|
break;
|
2029 |
|
|
|
2030 |
|
|
case OR32_SPG_DC:
|
2031 |
|
|
/* Data cache registers. These do not have an exact correspondence with
|
2032 |
|
|
their instruction cache counterparts, so must be done separately. */
|
2033 |
|
|
|
2034 |
|
|
/* 1:1 names */
|
2035 |
|
|
switch (index)
|
2036 |
|
|
{
|
2037 |
|
|
case OR32_SPG_DC_DCCR: sprintf (name, "DCCR" ); return name;
|
2038 |
|
|
case OR32_SPG_DC_DCBPR: sprintf (name, "DCBPR"); return name;
|
2039 |
|
|
case OR32_SPG_DC_DCBFR: sprintf (name, "DCBFR"); return name;
|
2040 |
|
|
case OR32_SPG_DC_DCBIR: sprintf (name, "DCBIR"); return name;
|
2041 |
|
|
case OR32_SPG_DC_DCBWR: sprintf (name, "DCBWR"); return name;
|
2042 |
|
|
case OR32_SPG_DC_DCBLR: sprintf (name, "DCBLR"); return name;
|
2043 |
|
|
}
|
2044 |
|
|
|
2045 |
|
|
break;
|
2046 |
|
|
|
2047 |
|
|
case OR32_SPG_IC:
|
2048 |
|
|
/* Instruction cache registers */
|
2049 |
|
|
|
2050 |
|
|
/* 1:1 names */
|
2051 |
|
|
switch (index)
|
2052 |
|
|
{
|
2053 |
|
|
case OR32_SPG_IC_ICCR: sprintf (name, "ICCR" ); return name;
|
2054 |
|
|
case OR32_SPG_IC_ICBPR: sprintf (name, "ICBPR"); return name;
|
2055 |
|
|
case OR32_SPG_IC_ICBIR: sprintf (name, "ICBIR"); return name;
|
2056 |
|
|
case OR32_SPG_IC_ICBLR: sprintf (name, "ICBLR"); return name;
|
2057 |
|
|
}
|
2058 |
|
|
|
2059 |
|
|
break;
|
2060 |
|
|
|
2061 |
|
|
case OR32_SPG_MAC:
|
2062 |
|
|
/* MAC registers */
|
2063 |
|
|
|
2064 |
|
|
/* 1:1 names */
|
2065 |
|
|
switch (index)
|
2066 |
|
|
{
|
2067 |
|
|
case OR32_SPG_MAC_MACLO: sprintf (name, "MACLO"); return name;
|
2068 |
|
|
case OR32_SPG_MAC_MACHI: sprintf (name, "MACHI"); return name;
|
2069 |
|
|
}
|
2070 |
|
|
|
2071 |
|
|
break;
|
2072 |
|
|
|
2073 |
|
|
case OR32_SPG_DEBUG:
|
2074 |
|
|
/* Debug registers */
|
2075 |
|
|
|
2076 |
|
|
/* Debug Value registers */
|
2077 |
|
|
if((OR32_SPG_DEBUG_DVR <= index) &&
|
2078 |
|
|
(index <= OR32_SPG_DEBUG_DVR_END))
|
2079 |
|
|
{
|
2080 |
|
|
sprintf (name, "DVR%d", index - OR32_SPG_DEBUG_DVR);
|
2081 |
|
|
return name;
|
2082 |
|
|
}
|
2083 |
|
|
|
2084 |
|
|
/* Debug Control registers */
|
2085 |
|
|
if((OR32_SPG_DEBUG_DCR <= index) &&
|
2086 |
|
|
(index <= OR32_SPG_DEBUG_DCR_END))
|
2087 |
|
|
{
|
2088 |
|
|
sprintf (name, "DCR%d", index - OR32_SPG_DEBUG_DCR);
|
2089 |
|
|
return name;
|
2090 |
|
|
}
|
2091 |
|
|
|
2092 |
|
|
/* 1:1 names */
|
2093 |
|
|
switch (index)
|
2094 |
|
|
{
|
2095 |
|
|
case OR32_SPG_DEBUG_DMR1: sprintf (name, "DMR1" ); return name;
|
2096 |
|
|
case OR32_SPG_DEBUG_DMR2: sprintf (name, "DMR2" ); return name;
|
2097 |
|
|
case OR32_SPG_DEBUG_DCWR0: sprintf (name, "DCWR0"); return name;
|
2098 |
|
|
case OR32_SPG_DEBUG_DCWR1: sprintf (name, "DCWR1"); return name;
|
2099 |
|
|
case OR32_SPG_DEBUG_DSR: sprintf (name, "DSR" ); return name;
|
2100 |
|
|
case OR32_SPG_DEBUG_DRR: sprintf (name, "DRR" ); return name;
|
2101 |
|
|
}
|
2102 |
|
|
|
2103 |
|
|
break;
|
2104 |
|
|
|
2105 |
|
|
case OR32_SPG_PC:
|
2106 |
|
|
/* Performance Counter registers */
|
2107 |
|
|
|
2108 |
|
|
/* Performance Counters Count registers */
|
2109 |
|
|
if((OR32_SPG_PC_PCCR <= index) &&
|
2110 |
|
|
(index <= OR32_SPG_PC_PCCR_END))
|
2111 |
|
|
{
|
2112 |
|
|
sprintf (name, "PCCR%d", index - OR32_SPG_PC_PCCR);
|
2113 |
|
|
return name;
|
2114 |
|
|
}
|
2115 |
|
|
|
2116 |
|
|
/* Performance Counters Mode registers */
|
2117 |
|
|
if((OR32_SPG_PC_PCMR <= index) &&
|
2118 |
|
|
(index <= OR32_SPG_PC_PCMR_END))
|
2119 |
|
|
{
|
2120 |
|
|
sprintf (name, "PCMR%d", index - OR32_SPG_PC_PCMR);
|
2121 |
|
|
return name;
|
2122 |
|
|
}
|
2123 |
|
|
|
2124 |
|
|
break;
|
2125 |
|
|
|
2126 |
|
|
case OR32_SPG_PM:
|
2127 |
|
|
/* Power Management registers */
|
2128 |
|
|
|
2129 |
|
|
/* 1:1 names */
|
2130 |
|
|
switch (index)
|
2131 |
|
|
{
|
2132 |
|
|
case OR32_SPG_PM_PMR: sprintf (name, "PMR"); return name;
|
2133 |
|
|
}
|
2134 |
|
|
|
2135 |
|
|
break;
|
2136 |
|
|
|
2137 |
|
|
case OR32_SPG_PIC:
|
2138 |
|
|
/* Programmable Interrupt Controller registers */
|
2139 |
|
|
|
2140 |
|
|
/* 1:1 names */
|
2141 |
|
|
switch (index)
|
2142 |
|
|
{
|
2143 |
|
|
case OR32_SPG_PIC_PICMR: sprintf (name, "PICMR"); return name;
|
2144 |
|
|
case OR32_SPG_PIC_PICSR: sprintf (name, "PICSR"); return name;
|
2145 |
|
|
}
|
2146 |
|
|
|
2147 |
|
|
break;
|
2148 |
|
|
|
2149 |
|
|
case OR32_SPG_TT:
|
2150 |
|
|
/* Tick Timer registers */
|
2151 |
|
|
|
2152 |
|
|
/* 1:1 names */
|
2153 |
|
|
switch (index)
|
2154 |
|
|
{
|
2155 |
|
|
case OR32_SPG_TT_TTMR: sprintf (name, "TTMR"); return name;
|
2156 |
|
|
case OR32_SPG_TT_TTCR: sprintf (name, "TTCR"); return name;
|
2157 |
|
|
}
|
2158 |
|
|
|
2159 |
|
|
break;
|
2160 |
|
|
|
2161 |
|
|
case OR32_SPG_FPU:
|
2162 |
|
|
|
2163 |
|
|
break;
|
2164 |
|
|
}
|
2165 |
|
|
|
2166 |
|
|
/* Not a recognized register */
|
2167 |
|
|
strcpy (name, "");
|
2168 |
|
|
return name;
|
2169 |
|
|
|
2170 |
|
|
} /* or32_spr_register_name() */
|
2171 |
|
|
|
2172 |
|
|
|
2173 |
|
|
/*----------------------------------------------------------------------------*/
|
2174 |
|
|
/*!Get SPR group number from a name
|
2175 |
|
|
|
2176 |
|
|
@param[in] group_name SPR register group
|
2177 |
|
|
|
2178 |
|
|
@return The index, or negative if no match. */
|
2179 |
|
|
/*----------------------------------------------------------------------------*/
|
2180 |
|
|
|
2181 |
|
|
static int
|
2182 |
|
|
or32_groupnum_from_name (char *group_name)
|
2183 |
|
|
{
|
2184 |
|
|
int group;
|
2185 |
|
|
|
2186 |
|
|
for (group = 0; group < OR32_NUM_SPGS; group++)
|
2187 |
|
|
{
|
2188 |
|
|
if (0 == strcasecmp (group_name, or32_spr_group_name (group)))
|
2189 |
|
|
{
|
2190 |
|
|
return group;
|
2191 |
|
|
}
|
2192 |
|
|
}
|
2193 |
|
|
|
2194 |
|
|
return -1;
|
2195 |
|
|
|
2196 |
|
|
} /* or32_groupnum_from_name() */
|
2197 |
|
|
|
2198 |
|
|
|
2199 |
|
|
/*----------------------------------------------------------------------------*/
|
2200 |
|
|
/*!Get register index in special purpose register group from name
|
2201 |
|
|
|
2202 |
|
|
The name may either be SPR<group_num>_<index> or a known unique name. In
|
2203 |
|
|
either case the group number must match the supplied group number.
|
2204 |
|
|
|
2205 |
|
|
@param[in] group SPR register group
|
2206 |
|
|
@param[in] name Register name
|
2207 |
|
|
|
2208 |
|
|
@return The index, or negative if no match. */
|
2209 |
|
|
/*----------------------------------------------------------------------------*/
|
2210 |
|
|
|
2211 |
|
|
static int
|
2212 |
|
|
or32_regnum_from_name (int group,
|
2213 |
|
|
char *name)
|
2214 |
|
|
{
|
2215 |
|
|
/* Last valid register in each group. */
|
2216 |
|
|
static const int or32_spr_group_last[OR32_NUM_SPGS] =
|
2217 |
|
|
{
|
2218 |
|
|
OR32_SPG_SYS_LAST,
|
2219 |
|
|
OR32_SPG_DMMU_LAST,
|
2220 |
|
|
OR32_SPG_IMMU_LAST,
|
2221 |
|
|
OR32_SPG_DC_LAST,
|
2222 |
|
|
OR32_SPG_IC_LAST,
|
2223 |
|
|
OR32_SPG_MAC_LAST,
|
2224 |
|
|
OR32_SPG_DEBUG_LAST,
|
2225 |
|
|
OR32_SPG_PC_LAST,
|
2226 |
|
|
OR32_SPG_PM_LAST,
|
2227 |
|
|
OR32_SPG_PIC_LAST,
|
2228 |
|
|
OR32_SPG_TT_LAST,
|
2229 |
|
|
OR32_SPG_FPU_LAST
|
2230 |
|
|
};
|
2231 |
|
|
|
2232 |
|
|
int i;
|
2233 |
|
|
char spr_name[32];
|
2234 |
|
|
|
2235 |
|
|
if (0 == strcasecmp (name, "SPR"))
|
2236 |
|
|
{
|
2237 |
|
|
char *ptr_c;
|
2238 |
|
|
|
2239 |
|
|
/* Skip SPR */
|
2240 |
|
|
name += 3;
|
2241 |
|
|
|
2242 |
|
|
/* Get group number */
|
2243 |
|
|
i = (int) strtoul (name, &ptr_c, 10);
|
2244 |
|
|
if (*ptr_c != '_' || i != group)
|
2245 |
|
|
{
|
2246 |
|
|
return -1;
|
2247 |
|
|
}
|
2248 |
|
|
|
2249 |
|
|
/* Get index */
|
2250 |
|
|
ptr_c++;
|
2251 |
|
|
i = (int) strtoul (name, &ptr_c, 10);
|
2252 |
|
|
if (*ptr_c)
|
2253 |
|
|
{
|
2254 |
|
|
return -1;
|
2255 |
|
|
}
|
2256 |
|
|
else
|
2257 |
|
|
{
|
2258 |
|
|
return i;
|
2259 |
|
|
}
|
2260 |
|
|
}
|
2261 |
|
|
|
2262 |
|
|
/* Look for a "known" name in this group */
|
2263 |
|
|
for (i = 0; i <= or32_spr_group_last[group]; i++)
|
2264 |
|
|
{
|
2265 |
|
|
char *s = or32_spr_register_name (group, i, spr_name);
|
2266 |
|
|
|
2267 |
|
|
if (0 == strcasecmp (name, s))
|
2268 |
|
|
{
|
2269 |
|
|
return i;
|
2270 |
|
|
}
|
2271 |
|
|
}
|
2272 |
|
|
|
2273 |
|
|
/* Failure */
|
2274 |
|
|
return -1;
|
2275 |
|
|
|
2276 |
|
|
} /* or32_regnum_from_name() */
|
2277 |
|
|
|
2278 |
|
|
|
2279 |
|
|
/*----------------------------------------------------------------------------*/
|
2280 |
|
|
/*!Get the next token from a string
|
2281 |
|
|
|
2282 |
|
|
I can't believe there isn't a library argument for this, but strtok is
|
2283 |
|
|
deprecated.
|
2284 |
|
|
|
2285 |
|
|
Take a string and find the start of the next token and its length. A token
|
2286 |
|
|
is anything containing non-blank characters.
|
2287 |
|
|
|
2288 |
|
|
@param[in] str The string to look at (may be NULL).
|
2289 |
|
|
@param[out] tok Pointer to the start of the token within str. May be NULL
|
2290 |
|
|
if this result is not wanted (e.g. just the length is
|
2291 |
|
|
wanted. If no token is found will be the NULL char at the
|
2292 |
|
|
end of the string, if the original str was NULL, this will
|
2293 |
|
|
be NULL.
|
2294 |
|
|
|
2295 |
|
|
@return The length of the token found */
|
2296 |
|
|
/*----------------------------------------------------------------------------*/
|
2297 |
|
|
|
2298 |
|
|
static int
|
2299 |
|
|
or32_tokenize (char *str,
|
2300 |
|
|
char **tok)
|
2301 |
|
|
{
|
2302 |
|
|
char *ptr;
|
2303 |
|
|
int len;
|
2304 |
|
|
|
2305 |
|
|
/* Deal with NULL argument */
|
2306 |
|
|
if (NULL == str)
|
2307 |
|
|
{
|
2308 |
|
|
if (NULL != tok)
|
2309 |
|
|
{
|
2310 |
|
|
*tok = NULL;
|
2311 |
|
|
}
|
2312 |
|
|
return 0;
|
2313 |
|
|
}
|
2314 |
|
|
|
2315 |
|
|
/* Find the start */
|
2316 |
|
|
for (ptr = str; ISBLANK (*ptr) ; ptr++)
|
2317 |
|
|
{
|
2318 |
|
|
continue;
|
2319 |
|
|
}
|
2320 |
|
|
|
2321 |
|
|
/* Return the start pointer if requested */
|
2322 |
|
|
if (NULL != tok)
|
2323 |
|
|
{
|
2324 |
|
|
*tok = ptr;
|
2325 |
|
|
}
|
2326 |
|
|
|
2327 |
|
|
/* Find the end and put in EOS */
|
2328 |
|
|
for (len = 0; ('\0' != ptr[len]) && (!ISBLANK (ptr[len])); len++)
|
2329 |
|
|
{
|
2330 |
|
|
continue;
|
2331 |
|
|
}
|
2332 |
|
|
|
2333 |
|
|
return len;
|
2334 |
|
|
|
2335 |
|
|
} /* or32_tokenize() */
|
2336 |
|
|
|
2337 |
|
|
|
2338 |
|
|
/*----------------------------------------------------------------------------*/
|
2339 |
|
|
/*!Parses args for spr commands
|
2340 |
|
|
|
2341 |
|
|
Determines the special purpose register (SPR) name and puts result into
|
2342 |
|
|
group and index
|
2343 |
|
|
|
2344 |
|
|
Syntax is:
|
2345 |
|
|
|
2346 |
|
|
@verbatim
|
2347 |
|
|
<spr_args> -> <group_ref> | <reg_name>
|
2348 |
|
|
<group_ref> -> <group_id> <index>
|
2349 |
|
|
<group_id> -> <group_num> | <group_name>
|
2350 |
|
|
@endverbatim
|
2351 |
|
|
|
2352 |
|
|
Where the indices/names have to be valid.
|
2353 |
|
|
|
2354 |
|
|
So to parse, we look for 1 or 2 args. If 1 it must be a unique register
|
2355 |
|
|
name. If 2, the first must be a group number or name and the second an
|
2356 |
|
|
index within that group.
|
2357 |
|
|
|
2358 |
|
|
Also responsible for providing diagnostics if the arguments do not match.
|
2359 |
|
|
|
2360 |
|
|
Rewritten for GDB 6.8 to use the new UI calls and remove assorted
|
2361 |
|
|
bugs. Syntax also slightly restricted to be more comprehensible.
|
2362 |
|
|
|
2363 |
|
|
@param[in] arg_str The argument string
|
2364 |
|
|
@param[out] group The group this SPR belongs in, or -1 to indicate
|
2365 |
|
|
failure
|
2366 |
|
|
@param[out] index Index of the register within the group, or -1 to
|
2367 |
|
|
indicate the whole group
|
2368 |
|
|
@param[in] is_set 1 (true) if we are called from the "spr" command (so
|
2369 |
|
|
there is an extra arg) rather than the "info spr"
|
2370 |
|
|
command. Needed to distinguish between the case where
|
2371 |
|
|
info is sought from a register specified as group and
|
2372 |
|
|
index and setting a uniquely identified register to a
|
2373 |
|
|
value.
|
2374 |
|
|
|
2375 |
|
|
@return A pointer to any remaining args */
|
2376 |
|
|
/*---------------------------------------------------------------------------*/
|
2377 |
|
|
|
2378 |
|
|
static char *
|
2379 |
|
|
or32_parse_spr_params (char *arg_str,
|
2380 |
|
|
int *group,
|
2381 |
|
|
int *index,
|
2382 |
|
|
int is_set)
|
2383 |
|
|
{
|
2384 |
|
|
struct {
|
2385 |
|
|
char *str;
|
2386 |
|
|
int len;
|
2387 |
|
|
unsigned long int val;
|
2388 |
|
|
int is_num;
|
2389 |
|
|
} arg[3] = {
|
2390 |
|
|
{
|
2391 |
|
|
.str = NULL,
|
2392 |
|
|
.len = 0,
|
2393 |
|
|
.val = 0,
|
2394 |
|
|
.is_num = 0,
|
2395 |
|
|
},
|
2396 |
|
|
{
|
2397 |
|
|
.str = NULL,
|
2398 |
|
|
.len = 0,
|
2399 |
|
|
.val = 0,
|
2400 |
|
|
.is_num = 0,
|
2401 |
|
|
},
|
2402 |
|
|
{
|
2403 |
|
|
.str = NULL,
|
2404 |
|
|
.len = 0,
|
2405 |
|
|
.val = 0,
|
2406 |
|
|
.is_num = 0,
|
2407 |
|
|
}
|
2408 |
|
|
};
|
2409 |
|
|
|
2410 |
|
|
int num_args;
|
2411 |
|
|
char *trailer = arg_str;
|
2412 |
|
|
char *tmp_str;
|
2413 |
|
|
int i;
|
2414 |
|
|
|
2415 |
|
|
char spr_name[32];
|
2416 |
|
|
|
2417 |
|
|
/* Break out the arguments. Note that the strings are NOT null terminated
|
2418 |
|
|
(we don't want to change arg_str), so we must rely on len. The stroul
|
2419 |
|
|
call will still work, since there is always a non-digit char (possibly EOS)
|
2420 |
|
|
after the last digit. */
|
2421 |
|
|
if (NULL == arg_str)
|
2422 |
|
|
{
|
2423 |
|
|
num_args = 0;
|
2424 |
|
|
}
|
2425 |
|
|
else
|
2426 |
|
|
{
|
2427 |
|
|
for (num_args = 0; num_args < 3; num_args++)
|
2428 |
|
|
{
|
2429 |
|
|
arg[num_args].len = or32_tokenize (trailer, &(arg[num_args].str));
|
2430 |
|
|
trailer = arg[num_args].str + arg[num_args].len;
|
2431 |
|
|
|
2432 |
|
|
if (0 == arg[num_args].len)
|
2433 |
|
|
{
|
2434 |
|
|
break;
|
2435 |
|
|
}
|
2436 |
|
|
}
|
2437 |
|
|
}
|
2438 |
|
|
|
2439 |
|
|
/* Patch nulls into the arg strings and see about values. Couldn't do this
|
2440 |
|
|
earlier, since we needed the next char clean to check later args. This
|
2441 |
|
|
means advancing trailer, UNLESS it was already at EOS */
|
2442 |
|
|
|
2443 |
|
|
if((NULL != arg_str) && ('\0' != *trailer))
|
2444 |
|
|
{
|
2445 |
|
|
trailer++;
|
2446 |
|
|
}
|
2447 |
|
|
|
2448 |
|
|
for (i = 0; i < num_args; i++)
|
2449 |
|
|
{
|
2450 |
|
|
(arg[i].str)[arg[i].len] = '\0';
|
2451 |
|
|
errno = 0;
|
2452 |
|
|
arg[i].val = strtoul (arg[i].str, &tmp_str, 0);
|
2453 |
|
|
arg[i].is_num = (0 == errno) && ('\0' == *tmp_str);
|
2454 |
|
|
}
|
2455 |
|
|
|
2456 |
|
|
/* Deal with the case where we are setting a register, so the final argument
|
2457 |
|
|
should be disregarded (it is the trailer). Do this anyway if we get a
|
2458 |
|
|
third argument */
|
2459 |
|
|
if ((is_set & (num_args > 0)) || (num_args > 2))
|
2460 |
|
|
{
|
2461 |
|
|
trailer = arg[num_args - 1].str;
|
2462 |
|
|
num_args--;
|
2463 |
|
|
}
|
2464 |
|
|
|
2465 |
|
|
/* Deal with different numbers of args */
|
2466 |
|
|
|
2467 |
|
|
switch (num_args)
|
2468 |
|
|
{
|
2469 |
|
|
|
2470 |
|
|
case 0:
|
2471 |
|
|
ui_out_message (uiout, 0,
|
2472 |
|
|
"Usage: <command> <register> |\n"
|
2473 |
|
|
" <command> <group> |\n"
|
2474 |
|
|
" <command> <group> <index>\n"
|
2475 |
|
|
"Valid groups are:\n");
|
2476 |
|
|
for (i = 0; i < OR32_NUM_SPGS; i++)
|
2477 |
|
|
{
|
2478 |
|
|
ui_out_field_string (uiout, NULL, or32_spr_group_name (i));
|
2479 |
|
|
ui_out_spaces (uiout, 1);
|
2480 |
|
|
ui_out_wrap_hint (uiout, NULL);
|
2481 |
|
|
}
|
2482 |
|
|
ui_out_field_string (uiout, NULL, "\n");
|
2483 |
|
|
|
2484 |
|
|
*index = -1;
|
2485 |
|
|
return trailer;
|
2486 |
|
|
|
2487 |
|
|
case 1:
|
2488 |
|
|
/* See if it is a numeric group */
|
2489 |
|
|
if (arg[0].is_num)
|
2490 |
|
|
{
|
2491 |
|
|
if (arg[0].val < OR32_NUM_SPGS)
|
2492 |
|
|
{
|
2493 |
|
|
*group = arg[0].val;
|
2494 |
|
|
*index = -1;
|
2495 |
|
|
return trailer;
|
2496 |
|
|
}
|
2497 |
|
|
else
|
2498 |
|
|
{
|
2499 |
|
|
ui_out_message (uiout, 0,
|
2500 |
|
|
"Group index should be in the range 0 - %d\n",
|
2501 |
|
|
OR32_NUM_SPGS);
|
2502 |
|
|
*group = -1;
|
2503 |
|
|
*index = -1;
|
2504 |
|
|
return trailer;
|
2505 |
|
|
}
|
2506 |
|
|
}
|
2507 |
|
|
|
2508 |
|
|
/* Is is it a group name? */
|
2509 |
|
|
*group = or32_groupnum_from_name (arg[0].str);
|
2510 |
|
|
if (*group >= 0)
|
2511 |
|
|
{
|
2512 |
|
|
*index = -1;
|
2513 |
|
|
return trailer;
|
2514 |
|
|
}
|
2515 |
|
|
|
2516 |
|
|
/* See if it is a valid register name in any group */
|
2517 |
|
|
for (*group = 0; *group < OR32_NUM_SPGS; (*group)++)
|
2518 |
|
|
{
|
2519 |
|
|
*index = or32_regnum_from_name (*group, arg[0].str);
|
2520 |
|
|
|
2521 |
|
|
if (*index >= 0)
|
2522 |
|
|
{
|
2523 |
|
|
return trailer;
|
2524 |
|
|
}
|
2525 |
|
|
}
|
2526 |
|
|
|
2527 |
|
|
/* Couldn't find it - print out a rude message */
|
2528 |
|
|
ui_out_message (uiout, 0,
|
2529 |
|
|
"Group or register name not recognized.\n"
|
2530 |
|
|
"Valid groups are:\n");
|
2531 |
|
|
for (i = 0; i < OR32_NUM_SPGS; i++)
|
2532 |
|
|
{
|
2533 |
|
|
ui_out_field_string (uiout, NULL, or32_spr_group_name (i));
|
2534 |
|
|
ui_out_spaces (uiout, 1);
|
2535 |
|
|
ui_out_wrap_hint (uiout, NULL);
|
2536 |
|
|
}
|
2537 |
|
|
ui_out_field_string (uiout, NULL, "\n");
|
2538 |
|
|
|
2539 |
|
|
*group = -1;
|
2540 |
|
|
*index = -1;
|
2541 |
|
|
return trailer;
|
2542 |
|
|
|
2543 |
|
|
case 2:
|
2544 |
|
|
/* See if first arg is a numeric group */
|
2545 |
|
|
if (arg[0].is_num)
|
2546 |
|
|
{
|
2547 |
|
|
if (arg[0].val < OR32_NUM_SPGS)
|
2548 |
|
|
{
|
2549 |
|
|
*group = arg[0].val;
|
2550 |
|
|
*index = -1;
|
2551 |
|
|
}
|
2552 |
|
|
else
|
2553 |
|
|
{
|
2554 |
|
|
ui_out_message (uiout, 0,
|
2555 |
|
|
"Group index should be in the range 0 - %d\n",
|
2556 |
|
|
OR32_NUM_SPGS - 1);
|
2557 |
|
|
*group = -1;
|
2558 |
|
|
*index = -1;
|
2559 |
|
|
return trailer;
|
2560 |
|
|
}
|
2561 |
|
|
}
|
2562 |
|
|
else
|
2563 |
|
|
{
|
2564 |
|
|
/* Is is it a group name? */
|
2565 |
|
|
*group = or32_groupnum_from_name (arg[0].str);
|
2566 |
|
|
if (*group >= 0)
|
2567 |
|
|
{
|
2568 |
|
|
*index = -1;
|
2569 |
|
|
}
|
2570 |
|
|
else
|
2571 |
|
|
{
|
2572 |
|
|
ui_out_message (uiout, 0,
|
2573 |
|
|
"Group name not recognized.\n"
|
2574 |
|
|
"Valid groups are:\n");
|
2575 |
|
|
for (i = 0; i < OR32_NUM_SPGS; i++)
|
2576 |
|
|
{
|
2577 |
|
|
ui_out_field_string (uiout, NULL, or32_spr_group_name (i));
|
2578 |
|
|
ui_out_spaces (uiout, 1);
|
2579 |
|
|
ui_out_wrap_hint (uiout, NULL);
|
2580 |
|
|
}
|
2581 |
|
|
ui_out_field_string (uiout, NULL, "\n");
|
2582 |
|
|
|
2583 |
|
|
*group = -1;
|
2584 |
|
|
*index = -1;
|
2585 |
|
|
return trailer;
|
2586 |
|
|
}
|
2587 |
|
|
}
|
2588 |
|
|
|
2589 |
|
|
/* Is second arg an index or name? */
|
2590 |
|
|
if (arg[1].is_num)
|
2591 |
|
|
{
|
2592 |
|
|
if (arg[1].val < OR32_SPG_SIZE)
|
2593 |
|
|
{
|
2594 |
|
|
/* Check this really is a register */
|
2595 |
|
|
if (0 != strlen (or32_spr_register_name (*group, arg[1].val,
|
2596 |
|
|
spr_name)))
|
2597 |
|
|
{
|
2598 |
|
|
*index = arg[1].val;
|
2599 |
|
|
return trailer;
|
2600 |
|
|
}
|
2601 |
|
|
else
|
2602 |
|
|
{
|
2603 |
|
|
ui_out_message (uiout, 0,
|
2604 |
|
|
"No valid register at that index in group\n");
|
2605 |
|
|
*group = -1;
|
2606 |
|
|
*index = -1;
|
2607 |
|
|
return trailer;
|
2608 |
|
|
}
|
2609 |
|
|
}
|
2610 |
|
|
else
|
2611 |
|
|
{
|
2612 |
|
|
ui_out_message (uiout, 0,
|
2613 |
|
|
"Register index should be in the range 0 - %d\n",
|
2614 |
|
|
OR32_SPG_SIZE - 1);
|
2615 |
|
|
*group = -1;
|
2616 |
|
|
*index = -1;
|
2617 |
|
|
return trailer;
|
2618 |
|
|
}
|
2619 |
|
|
}
|
2620 |
|
|
|
2621 |
|
|
/* Must be a name */
|
2622 |
|
|
*index = or32_regnum_from_name (*group, arg[1].str);
|
2623 |
|
|
|
2624 |
|
|
if (*index >= 0)
|
2625 |
|
|
{
|
2626 |
|
|
return trailer;
|
2627 |
|
|
}
|
2628 |
|
|
|
2629 |
|
|
/* Couldn't find it - print out a rude message */
|
2630 |
|
|
ui_out_message (uiout, 0, "Register name not recognized in group.\n");
|
2631 |
|
|
*group = -1;
|
2632 |
|
|
*index = -1;
|
2633 |
|
|
return trailer;
|
2634 |
|
|
|
2635 |
|
|
default:
|
2636 |
|
|
/* Anything else is an error */
|
2637 |
|
|
ui_out_message (uiout, 0, "Unable to parse arguments\n");
|
2638 |
|
|
*group = -1;
|
2639 |
|
|
*index = -1;
|
2640 |
|
|
return trailer;
|
2641 |
|
|
}
|
2642 |
|
|
} /* or32_parse_spr_params() */
|
2643 |
|
|
|
2644 |
|
|
|
2645 |
|
|
/*---------------------------------------------------------------------------*/
|
2646 |
|
|
/*!Read a special purpose register from the target
|
2647 |
|
|
|
2648 |
|
|
This has to be done using the target remote command "readspr"
|
2649 |
|
|
|
2650 |
|
|
@param[in] regnum The register to read
|
2651 |
|
|
|
2652 |
|
|
@return The value read */
|
2653 |
|
|
/*---------------------------------------------------------------------------*/
|
2654 |
|
|
|
2655 |
|
|
static ULONGEST
|
2656 |
|
|
or32_read_spr (unsigned int regnum)
|
2657 |
|
|
{
|
2658 |
|
|
struct ui_file *uibuf = mem_fileopen ();
|
2659 |
|
|
char cmd[sizeof ("readspr ffff")];
|
2660 |
|
|
unsigned long int data;
|
2661 |
|
|
char *res;
|
2662 |
|
|
long int len;
|
2663 |
|
|
|
2664 |
|
|
/* Create the command string and pass it to target remote command function */
|
2665 |
|
|
sprintf (cmd, "readspr %4x", regnum);
|
2666 |
|
|
target_rcmd (cmd, uibuf);
|
2667 |
|
|
|
2668 |
|
|
/* Get the output for the UI file as a string */
|
2669 |
|
|
res = ui_file_xstrdup (uibuf, &len);
|
2670 |
|
|
sscanf (res, "%lx", &data);
|
2671 |
|
|
|
2672 |
|
|
/* Tidy up */
|
2673 |
|
|
xfree (res);
|
2674 |
|
|
ui_file_delete (uibuf);
|
2675 |
|
|
|
2676 |
|
|
return (ULONGEST)data;
|
2677 |
|
|
|
2678 |
|
|
} /* or32_read_spr() */
|
2679 |
|
|
|
2680 |
|
|
|
2681 |
|
|
/*---------------------------------------------------------------------------*/
|
2682 |
|
|
/*!Write a special purpose register on the target
|
2683 |
|
|
|
2684 |
|
|
This has to be done using the target remote command "writespr"
|
2685 |
|
|
|
2686 |
|
|
Since the SPRs may map to GPR's or the other GDB register (PPC, NPC, SR),
|
2687 |
|
|
any register cache is flushed.
|
2688 |
|
|
|
2689 |
|
|
@param[in] regnum The register to write
|
2690 |
|
|
@param[in] data The value to write */
|
2691 |
|
|
/*---------------------------------------------------------------------------*/
|
2692 |
|
|
|
2693 |
|
|
static void
|
2694 |
|
|
or32_write_spr (unsigned int regnum,
|
2695 |
|
|
ULONGEST data)
|
2696 |
|
|
{
|
2697 |
|
|
struct ui_file *uibuf = mem_fileopen ();
|
2698 |
|
|
char cmd[sizeof ("writespr ffff ffffffff")];
|
2699 |
|
|
char *res;
|
2700 |
|
|
long int len;
|
2701 |
|
|
|
2702 |
|
|
/* Create the command string and pass it to target remote command function */
|
2703 |
|
|
sprintf (cmd, "writespr %4x %8llx", regnum, (long long unsigned int)data);
|
2704 |
|
|
target_rcmd (cmd, uibuf);
|
2705 |
|
|
|
2706 |
|
|
/* Flush the register cache */
|
2707 |
|
|
registers_changed ();
|
2708 |
|
|
|
2709 |
|
|
/* We ignore the result - Rcmd can put out its own error messages. Just
|
2710 |
|
|
tidy up */
|
2711 |
|
|
ui_file_delete (uibuf);
|
2712 |
|
|
|
2713 |
|
|
} /* or32_write_spr() */
|
2714 |
|
|
|
2715 |
|
|
|
2716 |
|
|
/*----------------------------------------------------------------------------*/
|
2717 |
|
|
/*!Show the value of a special purpose register or group
|
2718 |
|
|
|
2719 |
|
|
This is a custom extension to the GDB info command.
|
2720 |
|
|
|
2721 |
|
|
@param[in] args
|
2722 |
|
|
@param[in] from_tty True (1) if GDB is running from a TTY, false (0)
|
2723 |
|
|
otherwise. */
|
2724 |
|
|
/*---------------------------------------------------------------------------*/
|
2725 |
|
|
|
2726 |
|
|
static void
|
2727 |
|
|
or32_info_spr_command (char *args,
|
2728 |
|
|
int from_tty)
|
2729 |
|
|
{
|
2730 |
|
|
int group;
|
2731 |
|
|
int index;
|
2732 |
|
|
|
2733 |
|
|
char spr_name[32];
|
2734 |
|
|
|
2735 |
|
|
or32_parse_spr_params (args, &group, &index, 0);
|
2736 |
|
|
|
2737 |
|
|
if (group < 0)
|
2738 |
|
|
{
|
2739 |
|
|
return; /* Couldn't parse the args */
|
2740 |
|
|
}
|
2741 |
|
|
|
2742 |
|
|
if (index >= 0)
|
2743 |
|
|
{
|
2744 |
|
|
ULONGEST value = or32_read_spr (OR32_SPR (group, index));
|
2745 |
|
|
|
2746 |
|
|
ui_out_field_fmt (uiout, NULL, "%s.%s = SPR%i_%i = %llu (0x%llx)\n",
|
2747 |
|
|
or32_spr_group_name (group),
|
2748 |
|
|
or32_spr_register_name (group, index, spr_name), group,
|
2749 |
|
|
index, (long long unsigned int)value, (long long unsigned int)value);
|
2750 |
|
|
}
|
2751 |
|
|
else
|
2752 |
|
|
{
|
2753 |
|
|
/* Print all valid registers in the group */
|
2754 |
|
|
for (index = 0; index < OR32_SPG_SIZE; index++)
|
2755 |
|
|
{
|
2756 |
|
|
if (0 != strlen (or32_spr_register_name (group, index, spr_name)))
|
2757 |
|
|
{
|
2758 |
|
|
ULONGEST value = or32_read_spr (OR32_SPR (group, index));
|
2759 |
|
|
|
2760 |
|
|
ui_out_field_fmt (uiout, NULL,
|
2761 |
|
|
"%s.%s = SPR%i_%i = %llu (0x%llx)\n",
|
2762 |
|
|
or32_spr_group_name (group),
|
2763 |
|
|
or32_spr_register_name (group, index, spr_name),
|
2764 |
|
|
group, index, (long long unsigned int)value, (long long unsigned int)value);
|
2765 |
|
|
}
|
2766 |
|
|
}
|
2767 |
|
|
}
|
2768 |
|
|
} /* or32_info_spr_command() */
|
2769 |
|
|
|
2770 |
|
|
|
2771 |
|
|
/*----------------------------------------------------------------------------*/
|
2772 |
|
|
/*!Set a special purpose register
|
2773 |
|
|
|
2774 |
|
|
This is a custom command added to GDB.
|
2775 |
|
|
|
2776 |
|
|
@param[in] args
|
2777 |
|
|
@param[in] from_tty True (1) if GDB is running from a TTY, false (0)
|
2778 |
|
|
otherwise. */
|
2779 |
|
|
/*---------------------------------------------------------------------------*/
|
2780 |
|
|
|
2781 |
|
|
static void
|
2782 |
|
|
or32_spr_command (char *args,
|
2783 |
|
|
int from_tty)
|
2784 |
|
|
{
|
2785 |
|
|
int group;
|
2786 |
|
|
int index;
|
2787 |
|
|
char *tmp_str;
|
2788 |
|
|
char *nargs = or32_parse_spr_params (args, &group, &index, 1);
|
2789 |
|
|
|
2790 |
|
|
ULONGEST old_val;
|
2791 |
|
|
ULONGEST new_val;
|
2792 |
|
|
|
2793 |
|
|
char spr_name[32];
|
2794 |
|
|
|
2795 |
|
|
/* Do we have a valid register spec? */
|
2796 |
|
|
if (index < 0)
|
2797 |
|
|
{
|
2798 |
|
|
return; /* Parser will have printed the error message */
|
2799 |
|
|
}
|
2800 |
|
|
|
2801 |
|
|
/* Do we have a value to set? */
|
2802 |
|
|
|
2803 |
|
|
errno = 0;
|
2804 |
|
|
new_val = (ULONGEST)strtoul (nargs, &tmp_str, 0);
|
2805 |
|
|
|
2806 |
|
|
if((0 != errno) || ('\0' != *tmp_str))
|
2807 |
|
|
{
|
2808 |
|
|
ui_out_message (uiout, 0, "Invalid value - register not changed\n");
|
2809 |
|
|
return;
|
2810 |
|
|
}
|
2811 |
|
|
|
2812 |
|
|
old_val = or32_read_spr (OR32_SPR (group, index));
|
2813 |
|
|
|
2814 |
|
|
or32_write_spr (OR32_SPR (group, index) , new_val);
|
2815 |
|
|
|
2816 |
|
|
ui_out_field_fmt (uiout, NULL,
|
2817 |
|
|
"%s.%s (SPR%i_%i) set to %llu (0x%llx), "
|
2818 |
|
|
"was: %llu (0x%llx)\n",
|
2819 |
|
|
or32_spr_group_name (group),
|
2820 |
|
|
or32_spr_register_name (group, index, spr_name) , group,
|
2821 |
|
|
index, (long long unsigned int)new_val, (long long unsigned int)new_val, (long long unsigned int)old_val, (long long unsigned int)old_val);
|
2822 |
|
|
|
2823 |
|
|
} /* or32_spr_command() */
|
2824 |
|
|
|
2825 |
|
|
|
2826 |
|
|
/*----------------------------------------------------------------------------*/
|
2827 |
|
|
/*!Main entry point for target architecture initialization
|
2828 |
|
|
|
2829 |
|
|
In this version initializes the architecture via
|
2830 |
|
|
registers_gdbarch_init(). Add a command to set and show special purpose
|
2831 |
|
|
registers. */
|
2832 |
|
|
/*---------------------------------------------------------------------------*/
|
2833 |
|
|
|
2834 |
|
|
void
|
2835 |
|
|
_initialize_or32_tdep (void)
|
2836 |
|
|
{
|
2837 |
|
|
/* Register this architecture. We should do this for or16 and or64 when
|
2838 |
|
|
they have their BFD defined. */
|
2839 |
|
|
gdbarch_register (bfd_arch_or32, or32_gdbarch_init, or32_dump_tdep);
|
2840 |
|
|
|
2841 |
|
|
/* Initialize the automata for the assembler */
|
2842 |
|
|
build_automata();
|
2843 |
|
|
|
2844 |
|
|
/* Commands to show and set special purpose registers */
|
2845 |
|
|
add_info ("spr", or32_info_spr_command,
|
2846 |
|
|
"Show the value of a special purpose register");
|
2847 |
|
|
add_com ("spr", class_support, or32_spr_command,
|
2848 |
|
|
"Set a special purpose register");
|
2849 |
|
|
|
2850 |
|
|
} /* _initialize_or32_tdep() */
|