OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [or32-tdep.c] - Blame information for rev 244

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.