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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [or1k-tdep.c] - Blame information for rev 1183

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

Line No. Rev Author Line
1 1183 sfurman
/* Target-dependent code for the or1k architecture, for GDB, the GNU Debugger.
2
 
3
   Copyright 1988-1999, Free Software Foundation, Inc.
4
   Contributed by Alessandro Forin(af@cs.cmu.edu at CMU
5
   and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6
 
7
   This file is part of GDB.
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 2 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program; if not, write to the Free Software
21
   Foundation, Inc., 59 Temple Place - Suite 330,
22
   Boston, MA 02111-1307, USA.  */
23
 
24
#include "demangle.h"
25
#include "defs.h"
26
#include "gdb_string.h"
27
#include "frame.h"
28
#include "inferior.h"
29
#include "symtab.h"
30
#include "value.h"
31
#include "gdbcmd.h"
32
#include "language.h"
33
#include "gdbcore.h"
34
#include "symfile.h"
35
#include "objfiles.h"
36
#include "gdbtypes.h"
37
#include "target.h"
38
 
39
#include "opcode/or32.h"
40
 
41
/* *INDENT-OFF* */
42
 
43
/* Group reg name size.  See or1k_reg_names.  */
44
int or1k_group_name_sizes[OR1K_NUM_SPR_GROUPS] = {
45
  80,   0,   0, 6, 4, 3,
46
  22, 16, 1, 3, 2, 8
47
};
48
 
49
/* Generated reg names (max valid alias index).
50
   See or1k_spr_reg_name.  */
51
int or1k_spr_valid_aliases[OR1K_NUM_SPR_GROUPS] = {
52
  2047+1, 2047+1, 2047+1, 258+1, 257+1, 257+1,
53
  78+1, 263+1, 16+1, 18+1, 256+1, 7+1
54
};
55
 
56
/* Register names.  */
57
char *or1k_reg_names[] = {
58
 
59
  /* group 0 - general*/
60
  "VR", "UPR", "CPUCFGR", "DMMUCFGR", "IMMUCFGR", "DCCFGR", "ICCFGR", "DCFGR",
61
  "PCCFGR", "SPR0_9", "SPR0_10", "SPR0_11", "SPR0_12", "SPR0_13", "SPR0_14", "SPR0_15",
62
  "NPC", "SR", "PPC", "SPR0_19", "SPR0_20", "SPR0_21", "SPR0_22", "SPR0_23",
63
  "SPR0_24", "SPR0_25", "SPR0_26", "SPR0_27", "SPR0_28", "SPR0_29", "SPR0_30", "SPR0_31",
64
  "EPCR0", "EPCR1", "EPCR2", "EPCR3", "EPCR4", "EPCR5", "EPCR6", "EPCR7",
65
  "EPCR8", "EPCR9", "EPCR10", "EPCR11", "EPCR12", "EPCR13", "EPCR14", "EPCR15",
66
  "EEAR0","EEAR1", "EEAR2", "EEAR3", "EEAR4", "EEAR5", "EEAR6", "EEAR7",
67
  "EEAR8", "EEAR9", "EEAR10", "EEAR11", "EEAR12", "EEAR13", "EEAR14", "EEAR15",
68
  "ESR0", "ESR1", "ESR2", "ESR3", "ESR4", "ESR5", "ESR6", "ESR7",
69
  "ESR8", "ESR9", "ESR10", "ESR11", "ESR12", "ESR13", "ESR14", "ESR15",
70
 
71
  /* gpr+vf registers generated */
72
  /* group 1 - Data MMU - not listed, generated */
73
  /* group 2 - Instruction MMU - not listed, generated */
74
 
75
  /* group 3 - Data cache */
76
  "DCCR", "DCBPR", "DCBFR", "DCBIR", "DCBWR", "DCBLR",
77
 
78
  /* group 4 - Instruction cache */
79
  "ICCR", "ICBPR", "ICBIR", "ICBLR",
80
 
81
  /* group 5 - MAC */
82
  "SPR5_0", "MACLO", "MACHI",
83
 
84
  /* group 6 - debug */
85
  "DVR0", "DVR1", "DVR2", "DVR3", "DVR4", "DVR5", "DVR6", "DVR7",
86
  "DCR0", "DCR1", "DCR2", "DCR3", "DCR4", "DCR5", "DCR6", "DCR7",
87
  "DMR1", "DMR2", "DCWR0","DCWR1","DSR",  "DRR",
88
 
89
  /* group 7 - performance counters unit */
90
  "PCCR0",  "PCCR1", "PCCR2", "PCCR3", "PCCR4", "PCCR5", "PCCR6", "PCCR7",
91
  "PCCMR0", "PCMR1", "PCMR2", "PCMR3", "PCMR4", "PCMR5", "PCMR6", "PCMR7",
92
 
93
  /* group 8 - power management */
94
  "PMR",
95
 
96
  /* group 9 - PIC */
97
  "PICMR", /* now-defunct PICPR */ "SPR9_1", "PICSR",
98
  /* group 10 - tick timer */
99
  "TTMR", "TTCR",
100
 
101
  /* group 11 - configuration */
102
  "CPUCFGR", "DMMUCFGR", "IMMUCFGR", "DCCFGR", "ICCFGR", "SPR11_5", "DCFGR", "PCCFGR"
103
};
104
 
105
static char *or1k_gdb_reg_names[] = {
106
 
107
  /* general purpose registers */
108
  "R0",  "R1",  "R2",  "R3",  "R4",  "R5",  "R6",  "R7",
109
  "R8",  "R9",  "R10", "R11", "R12", "R13", "R14", "R15",
110
  "R16", "R17", "R18", "R19", "R20", "R21", "R22", "R23",
111
  "R24", "R25", "R26", "R27", "R28", "R29", "R30", "R31",
112
 
113
  /* Modified by CZ 12/09/01 */
114
  /* vector/floating point registers */
115
  "VFA0",  "VFA1",  "VFA2",  "VFA3",  "VFA4",  "VFA5",  "VFRV ", "VFR7",
116
  "VFR8",  "VFR9",  "VFR10", "VFR11", "VFR12", "VFR13", "VFR14", "VFR15",
117
  "VFR16", "VFR17", "VFR18", "VFR19", "VFR20", "VFR21", "VFR22", "VFR23",
118
  "VFR24", "VFR25", "VFR26", "VFR27", "VFR28", "VFR29", "VFR30", "VFR31",
119
  "PC",    "SR",    "EPCR", "ExPC", "ExEAR", "ExSR"
120
};
121
 
122
static char *or1k_group_names[] = {
123
  "SYS", "DMMU", "IMMU", "DCACHE", "ICACHE", "MAC", "DEBUG", "PERF",
124
  "POWER", "PIC", "TIMER", "CONFIG"
125
};
126
 
127
/* Table of or1k signals.  */
128
static struct
129
  {
130
  char *name;
131
  char *string;
132
  } or1k_signals [NUM_OR1K_SIGNALS + 1] =
133
  {
134
    {"RSTE", "Reset Exception"},
135
    {"BUSE", "Bus Error" },
136
    {"DFPE", "Data Page Fault Exception"},
137
    {"IFPE", "Instruction Page Fault Exception"},
138
    {"LPINTE", "Low Priority Interrupt Exception"},
139
    {"AE", "Alignment Exception"},
140
    {"ILINSE" "Illegal Instruction" },
141
    {"HPINTE", "High Priority Interrupt Exception"},
142
    {"DME", "DTLB Miss Exception"},
143
    {"IME", "ITLB Miss Exception"},
144
    {"RE", "Range Exception"},
145
    {"SCE", "SCE Exception"},
146
    {"BRKPTE", "Breakpoint Exception"},
147
    {NULL, NULL}
148
  };
149
 
150
const char *compare_to_names[NUM_CT_NAMES] =
151
  {
152
    "DISABLED", "FETCH", "LEA", "SEA", "LDATA", "SDATA", "AEA", "ADATA"
153
  };
154
 
155
const char *or1k_record_names[MAX_RECORD_NAMES] =
156
  {
157
    "PC", "LSEA", "LDATA", "SDATA", "READSPR", "WRITESPR", "INSTR"
158
  };
159
 
160
const char *or1k_is_names[MAX_IS_NAMES] =
161
  {
162
    "IF_NONE", "IF_NORMAL", "IF_BRANCH", "IF_DELAY"
163
  };
164
 
165
const char *or1k_ls_names[MAX_LS_NAMES] =
166
  {
167
    "LS_NONE", " ", "LBZ", "LBS", "LHZ", "LHS", "LWZ", "LWS",
168
    " ", " ", "SB", " ", "SH", " ", "SW", " "
169
  };
170
 
171
/* *INDENT-ON* */
172
 
173
/* The list of available "set or1k " and "show or1k " commands */
174
static struct cmd_list_element *htrace_cmdlist = NULL;
175
static struct cmd_list_element *htrace_mode_cmdlist = NULL;
176
 
177
struct htrace_struct or1k_htrace;
178
struct hwatch_struct or1k_hwatch[MAX_HW_WATCHES];
179
int num_hw_watches = 0;
180
 
181
/* Trace data.  */
182
char trace_filename[TRACE_FILENAME_SIZE] = "trace.dat";
183
 
184
/* Size of trace file in records.  */
185
int trace_size = 0;
186
 
187
/* Previous values for buffer display.  */
188
static int prev_length = 10;
189
static int prev_from = 0;
190
 
191
/* Converts regno to sprno.  or1k debug unit has GPRs mapped to SPRs,
192
   which are not compact, so we are mapping them for GDB.  */
193
/* Rewritten by CZ 12/09/01 */
194
int
195
or1k_regnum_to_sprnum (int regno)
196
{
197
  if(regno < MAX_GPR_REGS)
198
    return SPR_REG(SPR_SYSTEM_GROUP, regno + CURRENT_CID * MAX_GPR_REGS + SPR_GPR_START);
199
 
200
  if (regno < MAX_GPR_REGS + MAX_VF_REGS)
201
    return SPR_REG(SPR_SYSTEM_GROUP, regno - MAX_GPR_REGS
202
                   + CURRENT_CID * MAX_GPR_REGS + SPR_VFPR_START);
203
 
204
  switch(regno)
205
    {
206
    case PS_REGNUM:         return SR_SPRNUM;
207
    case PC_REGNUM:         return PC_SPRNUM;
208
    /*case CCR_REGNUM:        return CCR_SPRNUM(CURRENT_CID);*/
209
    case EPCR_REGNUM:        return EPCR_SPRNUM(CURRENT_CID);
210
    /*case EAR_REGNUM:        return EAR_SPRNUM(CURRENT_CID);
211
    case ESR_REGNUM:        return ESR_SPRNUM(CURRENT_CID);*/
212
    default:
213
      error("Invalid register number!");
214
      break;
215
    }
216
 
217
  return 0;
218
}
219
 
220
/* Builds and returns register name.  */
221
 
222
static char tmp_name[16];
223
static char *
224
or1k_spr_register_name (i)
225
     int i;
226
{
227
  int group = i >> SPR_GROUP_SIZE_BITS;
228
  int index = i & (SPR_GROUP_SIZE - 1);
229
  switch (group)
230
    {
231
      /* Names covered in or1k_reg_names.  */
232
    case 0:
233
 
234
      /* Generate upper names.  */
235
      if (index >= SPR_GPR_START)
236
        {
237
          if (index < SPR_VFPR_START)
238
            sprintf (tmp_name, "GPR%i", index - SPR_GPR_START);
239
          else
240
            sprintf (tmp_name, "VFR%i", index - SPR_VFPR_START);
241
          return (char *)&tmp_name;
242
        }
243
    case 3:
244
    case 4:
245
    case 5:
246
    case 6:
247
    case 7:
248
    case 8:
249
    case 9:
250
    case 10:
251
      {
252
        int group_start = 0;
253
        for (i = 0; i < group; i++)
254
          group_start += or1k_group_name_sizes[i];
255
 
256
        if (index >= or1k_group_name_sizes[group])
257
          {
258
            sprintf (tmp_name, "SPR%i_%i", group, index);
259
            return (char *)&tmp_name;
260
          }
261
        else
262
          return or1k_reg_names[group_start + index];
263
      }
264
 
265
      /* Build names for DMMU group.  */
266
    case 1:
267
    case 2:
268
      strcpy (tmp_name, (group == 1)?"D":"I");
269
      switch (index)
270
        {
271
        case 16:
272
          return strcat (tmp_name, "MMUCR");
273
        case 17:
274
          return strcat (tmp_name, "MMUPR");
275
        case 18:
276
          return strcat (tmp_name, "TLBEIR");
277
        case 24:
278
          return strcat (tmp_name, "ATBMR0");
279
        case 25:
280
          return strcat (tmp_name, "ATBMR1");
281
        case 26:
282
          return strcat (tmp_name, "ATBMR2");
283
        case 27:
284
          return strcat (tmp_name, "ATBMR3");
285
        case 28:
286
          return strcat (tmp_name, "ATBTR0");
287
        case 29:
288
          return strcat (tmp_name, "ATBTR0");
289
        case 30:
290
          return strcat (tmp_name, "ATBTR0");
291
        case 31:
292
          return strcat (tmp_name, "ATBTR0");
293
        default:
294
          if (index >= 1024) {
295
            index -= 1024;
296
            sprintf (tmp_name, "%sTLBW%iMR%i", (group == 1)?"D":"I", index / 128, index % 128);
297
            return (char *)&tmp_name;
298
          }
299
          sprintf (tmp_name, "SPR%i_%i", group, index);
300
          return (char *)&tmp_name;
301
      }
302
    default:
303
      sprintf (tmp_name, "SPR%i_%i", group, index);
304
      return (char *)&tmp_name;
305
    }
306
}
307
 
308
/* Get register index in group from name.  Negative if no match.  */
309
 
310
static int
311
or1k_regno_from_name (group, name)
312
     int group;
313
     char *name;
314
{
315
  int i;
316
  if (toupper(name[0]) == 'S' && toupper(name[1]) == 'P' && toupper(name[2]) == 'R')
317
    {
318
      char *ptr_c;
319
      name += 3;
320
      i = (int) strtoul (name, &ptr_c, 10);
321
      if (*ptr_c != '_' || i != group)
322
        return -1;
323
      ptr_c++;
324
      i = (int) strtoul (name, &ptr_c, 10);
325
      if (*ptr_c)
326
        return -1;
327
      else return i;
328
    }
329
  for (i = 0; i < or1k_spr_valid_aliases[group]; i++)
330
    {
331
      char *s;
332
      s = or1k_spr_register_name (SPR_REG(group, i));
333
      if (strcasecmp (name, s) == 0)
334
        return i;
335
    }
336
  return -1;
337
}
338
 
339
/* Returns gdb register name.  */
340
 
341
char *
342
or1k_register_name (regno)
343
     int regno;
344
{
345
  return or1k_gdb_reg_names[regno];
346
}
347
 
348
/* Utility function to display vf regs.  */
349
 
350
static int
351
do_vf_register (regnum)
352
     int regnum;
353
{
354
  /* do values for FP (float) regs */
355
  char *raw_buffer;
356
 
357
   /* doubles extracted from raw hex data */
358
  double doub, flt;
359
  int inv1, inv3, byte;
360
 
361
  raw_buffer = (char *) alloca (OR1K_VF_REGSIZE);
362
 
363
  /* Get the data in raw format.  */
364
  read_register_gen (regnum, raw_buffer);
365
 
366
  flt = unpack_double (builtin_type_float, raw_buffer, &inv1);
367
  doub = unpack_double (builtin_type_double, raw_buffer, &inv3);
368
 
369
  if (inv1)
370
    printf_filtered (" %-5s flt: <invalid float>", REGISTER_NAME (regnum));
371
  else
372
    printf_filtered (" %-5s flt:%-17.9g", REGISTER_NAME (regnum), flt);
373
  printf_filtered (inv3 ? " dbl: <invalid double> " :
374
                   " dbl: %-24.17g ", doub);
375
 
376
  /* pad small registers */
377
  for (byte = 0; byte < (OR1K_GPR_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
378
    printf_filtered ("  ");
379
 
380
  /* Now print the register value in hex, endian order. */
381
  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
382
    for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
383
         byte < REGISTER_RAW_SIZE (regnum);
384
         byte++)
385
      printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
386
  else
387
    for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
388
         byte >= 0;
389
         byte--)
390
      printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
391
  printf_filtered ("\n");
392
 
393
  regnum++;
394
  return regnum;
395
}
396
 
397
/* Print a row's worth of GP (int) registers, with name labels above */
398
 
399
static int
400
do_gp_register_row (regnum)
401
     int regnum;
402
{
403
  /* do values for GP (int) regs */
404
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
405
 
406
  /* display cols per row */
407
  int ncols = (OR1K_64BIT_IMPLEMENTATION ? 4 : 8);
408
  int col, byte;
409
  int start_regnum = regnum;
410
  int numregs = NUM_REGS;
411
 
412
  /* For GP registers, we print a separate row of names above the vals */
413
  printf_filtered ("     ");
414
  for (col = 0; col < ncols && regnum < numregs; regnum++)
415
    {
416
      if (*REGISTER_NAME (regnum) == '\0')
417
        continue;               /* unused register */
418
      if (OR1K_IS_VF(regnum))
419
        break;                  /* end the row: reached VF register */
420
      printf_filtered (OR1K_64BIT_IMPLEMENTATION ? "%17s" : "%9s",
421
                       REGISTER_NAME (regnum));
422
      col++;
423
    }
424
  printf_filtered ("\n      ");
425
 
426
  regnum = start_regnum;        /* go back to start of row */
427
 
428
  /* now print the values in hex, 4 or 8 to the row */
429
  for (col = 0; col < ncols && regnum < numregs; regnum++)
430
    {
431
      /* unused register? */
432
      if (*REGISTER_NAME (regnum) == '\0')
433
        continue;
434
 
435
      /* end row: reached VF register? */
436
      if (OR1K_IS_VF(regnum))
437
        break;
438
 
439
      /* OK: get the data in raw format.  */
440
      read_register_gen (regnum, raw_buffer);
441
 
442
      /* pad small registers */
443
      for (byte = 0; byte < (OR1K_GPR_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
444
        printf_filtered ("  ");
445
 
446
      /* Now print the register value in hex, endian order. */
447
      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
448
        for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
449
             byte < REGISTER_RAW_SIZE (regnum);
450
             byte++)
451
          printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
452
      else
453
        for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
454
             byte >= 0;
455
             byte--)
456
          printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
457
      printf_filtered (" ");
458
      col++;
459
    }
460
 
461
  /* ie. if we actually printed anything... */
462
  if (col > 0)
463
    printf_filtered ("\n");
464
 
465
  return regnum;
466
}
467
 
468
/* Replacement for generic do_registers_info.
469
   Print regs in pretty columns.  */
470
 
471
static void
472
print_register (regnum, all)
473
     int regnum, all;
474
{
475
  int offset;
476
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
477
 
478
  /* Get the data in raw format.  */
479
  read_register_gen (regnum, raw_buffer);
480
 
481
  /* If virtual format is floating, print it that way.  */
482
  if (OR1K_IS_VF (regnum))
483
    do_vf_register (regnum);
484
  else
485
    {
486
      int byte;
487
      printf_filtered ("%-16s\t", REGISTER_NAME (regnum));
488
 
489
      /* pad small registers */
490
      for (byte = 0; byte < (OR1K_GPR_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
491
        printf_filtered ("  ");
492
 
493
      /* Now print the register value in hex, endian order. */
494
      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
495
        for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
496
             byte < REGISTER_RAW_SIZE (regnum);
497
             byte++)
498
          printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
499
      else
500
        for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
501
             byte >= 0;
502
             byte--)
503
          printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
504
      printf_filtered (" ");
505
    }
506
}
507
 
508
/* DO_REGISTERS_INFO: called by "info register" command */
509
 
510
void
511
or1k_do_registers_info (regnum, fpregs)
512
     int regnum;
513
     int fpregs;
514
{
515
  if (fpregs && !or1k_implementation.vf_present)
516
    {
517
      warning ("VF register set not present in this implementation.");
518
      fpregs = 0;
519
    }
520
  if (regnum != -1)
521
    {
522
      /* do one specified register */
523
      if (*(REGISTER_NAME (regnum)) == '\0')
524
        error ("Not a valid register for the current processor type");
525
 
526
      print_register (regnum, 0);
527
      printf_filtered ("\n");
528
    }
529
  else
530
    /* do all (or most) registers */
531
    {
532
      regnum = 0;
533
      while (regnum < NUM_REGS)
534
        {
535
          if (OR1K_IS_VF (regnum))
536
            /* true for "INFO ALL-REGISTERS" command */
537
            if (fpregs)
538
              /* FP regs */
539
              regnum = do_vf_register (regnum);
540
            else
541
              /* skip floating point regs */
542
              regnum++;
543
          else
544
            /* GP (int) regs */
545
            regnum = do_gp_register_row (regnum);
546
        }
547
    }
548
}
549
 
550
/* Given the address at which to insert a breakpoint (BP_ADDR),
551
   what will that breakpoint be?
552
 
553
   For or1k, we have a breakpoint instruction. Since all or1k
554
   instructions are 32 bits, this is all we need, regardless of
555
   address. K is not used.  */
556
 
557
unsigned char *
558
or1k_breakpoint_from_pc (bp_addr, bp_size)
559
     CORE_ADDR * bp_addr;
560
     int *bp_size;
561
{
562
  static char breakpoint[] = BRK_INSTR_STRUCT;
563
  *bp_size = OR1K_INSTLEN;
564
  return breakpoint;
565
}
566
 
567
/* Return the string for a signal.
568
   Replacement for target_signal_to_string (sig).  NOT USED.  */
569
 
570
char
571
*or1k_signal_to_string (sig)
572
     enum target_signal sig;
573
{
574
  if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST))
575
    return or1k_signals[sig].string;
576
  else
577
    if (sig <= TARGET_SIGNAL_LAST + NUM_OR1K_SIGNALS)
578
      return or1k_signals[sig - TARGET_SIGNAL_LAST].string;
579
    else
580
      return 0;
581
}
582
 
583
/* Return the name for a signal.  */
584
 
585
char *
586
or1k_signal_to_name (sig)
587
     enum target_signal sig;
588
{
589
  if (sig >= TARGET_SIGNAL_LAST)
590
    if (sig <= TARGET_SIGNAL_LAST + NUM_OR1K_SIGNALS)
591
      return or1k_signals[sig - TARGET_SIGNAL_LAST].name;
592
    else
593
 
594
    /* I think the code which prints this will always print it along with
595
       the string, so no need to be verbose.  */
596
      return "?";
597
  if (sig == TARGET_SIGNAL_UNKNOWN)
598
    return "?";
599
  return 0;
600
}
601
 
602
/* Given a name, return its signal.  NOT USED.  */
603
enum target_signal
604
or1k_signal_from_name (name)
605
     char *name;
606
{
607
  enum target_signal sig;
608
 
609
  /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
610
     for TARGET_SIGNAL_SIGCHLD.  SIGIOT, on the other hand, is more
611
     questionable; seems like by now people should call it SIGABRT
612
     instead.  */
613
 
614
  /* This ugly cast brought to you by the native VAX compiler.  */
615
  for (sig = TARGET_SIGNAL_FIRST;
616
       or1k_signal_to_name (sig) != NULL;
617
       sig = (enum target_signal) ((int) sig + 1))
618
    if (STREQ (name, or1k_signal_to_name (sig)))
619
      return sig;
620
  return TARGET_SIGNAL_UNKNOWN;
621
}
622
 
623
/* Given a return value in `regbuf' with a type `valtype', extract and
624
   copy its value into `valbuf'. */
625
 
626
void
627
or1k_extract_return_value (valtype, regbuf, valbuf)
628
     struct type *valtype;
629
     char regbuf[REGISTER_BYTES];
630
     char *valbuf;
631
{
632
  if (TYPE_CODE_FLT == TYPE_CODE (valtype))
633
    memcpy (valbuf, &regbuf[REGISTER_BYTE (VFRV_REGNUM)], TYPE_LENGTH (valtype));
634
  else
635
    memcpy (valbuf, &regbuf[REGISTER_BYTE (RV_REGNUM)], TYPE_LENGTH (valtype));
636
}
637
 
638
/* Given a register index, return the first byte of the register within a remote
639
   protocol packet.  This applies only to serial targets, not jtag or sim. */
640
int
641
or1k_register_byte(regnum)
642
     int regnum;
643
{
644
  int byte_offset;
645
 
646
  byte_offset = 0;
647
  if (regnum < MAX_GPR_REGS) {
648
    if (regnum < NUM_GPR_REGS)
649
      return byte_offset + regnum * OR1K_GPR_REGSIZE;
650
    else
651
      return -1;
652
  }
653
 
654
  byte_offset += NUM_GPR_REGS * OR1K_GPR_REGSIZE;
655
  regnum -= MAX_GPR_REGS;
656
  if (regnum < MAX_VF_REGS) {
657
    if (regnum < NUM_VF_REGS)
658
      return byte_offset + regnum * OR1K_VF_REGSIZE;
659
    else
660
      return -1;
661
  }
662
 
663
  /* Must be PC, SR, or EPC */
664
  byte_offset += NUM_VF_REGS * OR1K_VF_REGSIZE;
665
  regnum -= MAX_VF_REGS;
666
  if (regnum < 3)
667
    return byte_offset + regnum * OR1K_SPR_REGSIZE;
668
 
669
  /* Illegal register */
670
  return -1;
671
}
672
 
673
/* Number of bytes of storage in the actual machine representation for
674
   register N.  NOTE: This indirectly defines the register size
675
   transfered by the GDB protocol.  If we have 64bit processor
676
   implementation, GPR register raw size is 8B, otherwise 4B.  */
677
int
678
or1k_register_raw_size(int regnum)
679
{
680
  int byte_offset;
681
 
682
  if (regnum < MAX_GPR_REGS) {
683
    if (regnum < NUM_GPR_REGS)
684
      return OR1K_GPR_REGSIZE;
685
    else
686
      return 0;
687
  }
688
 
689
  regnum -= MAX_GPR_REGS;
690
  if (regnum < MAX_VF_REGS) {
691
    if (regnum < NUM_VF_REGS)
692
      return OR1K_VF_REGSIZE;
693
    else
694
      return 0;
695
  }
696
 
697
  /* Must be PC, SR, or EPC */
698
  regnum -= MAX_VF_REGS;
699
  if (regnum < 3)
700
    return OR1K_SPR_REGSIZE;
701
 
702
  /* Illegal register */
703
  return 0;
704
}
705
 
706
/* Extra arch-specific data tied to frame */
707
struct frame_extra_info
708
{
709
  /* Size of stack frame, in bytes.  Produced by skip_prologue() */
710
  int frame_size;
711
 
712
  /* List of frame offsets of all registers saved in a function's
713
     prologue.  This is deduced by skip_prologue().  Offset is in bytes,
714
     relative to sp.  If value is -1, corresponding reg is not saved by
715
     the prologue code. */
716
  int saved_reg_frame_offset[NUM_REGS];
717
 
718
  /* Address of first instruction after the last prologue instruction;
719
     Note that there may be instructions from the function's body
720
     intermingled with the prologue.
721
     If value is -1, not initialized. */
722
  CORE_ADDR after_prologue;
723
};
724
 
725
/* Initialize arch-specific frame data */
726
void
727
or1k_init_extra_frame_info (int fromleaf, struct frame_info *frame)
728
{
729
  int i;
730
 
731
  frame->extra_info = (struct frame_extra_info *)
732
    frame_obstack_alloc (sizeof (struct frame_extra_info));
733
 
734
  frame->extra_info->after_prologue = -1;
735
  frame->extra_info->frame_size = -1;
736
  for (i = 0; i < NUM_REGS; i++)
737
    frame->extra_info->saved_reg_frame_offset[i] = -1;
738
}
739
 
740
/* For stack frame sizes less than 0x8000, the or1k version of gcc
741
   emits the following prologue:
742
 
743
     l.addi    r1, r1, -<STACK_FRAME_SIZE>
744
     l.sw      <FP_OFFSET>(r1),r2
745
     l.addi    r2, r1, <STACK_FRAME_SIZE>
746
 
747
     ; Save regs that will be clobbered
748
     l.sw      <OFFSET_Rx>(r1),rx
749
     l.sw      <OFFSET_Ry>(r1),ry
750
     ; ...
751
 
752
*/
753
 
754
/* FIXME: Does not work with frames greater than 0x7fff in size */
755
 
756
/* If pframeless is non-NULL, only parse enough of the prologue to
757
   determine if a function has a frame or not and return the result in
758
   *pframeless.  This may save some remote transactions with the
759
   target. */
760
CORE_ADDR
761
or1k_skip_prologue (CORE_ADDR pc, struct frame_info *fi)
762
{
763
  unsigned long insn;
764
  CORE_ADDR skip_pc;
765
  CORE_ADDR func_addr, func_end;
766
  struct symtab_and_line sal;
767
  int i, frameless;
768
  int offset = 0;
769
  int rB, immediate, immediate_hi;
770
  int* saved_reg_frame_offset;
771
 
772
  /* Check to see if prologue analysis is cached from prior call */
773
  if (fi && fi->extra_info->after_prologue != -1)
774
    return fi->extra_info->after_prologue;
775
 
776
  if (fi)
777
    saved_reg_frame_offset = &fi->extra_info->saved_reg_frame_offset[0];
778
 
779
  /* Is there a prologue?  */
780
  insn = or1k_fetch_instruction (pc);
781
  if ((insn & 0xFFFF0000) != 0x9c210000) /* l.addi r1,r1,I */
782
    goto done;
783
 
784
  pc += OR1K_INSTLEN;
785
 
786
  insn = or1k_fetch_instruction (pc);
787
  if ((insn & 0xfc1ff800) != 0xd4011000) /* l.sw I(r1),r2 */
788
    goto done;
789
  immediate_hi = (insn & 0x03E00000) >> 10;
790
  immediate    = (insn & 0x000007FF) | immediate_hi;
791
  pc += OR1K_INSTLEN;
792
  if (fi)
793
    saved_reg_frame_offset[2] = immediate;
794
 
795
  insn = or1k_fetch_instruction (pc);
796
  if ((insn & 0xFFFF0000) != 0x9c410000) /* l.addi r2,r1,I */
797
    goto done;
798
  if (fi)
799
    fi->extra_info->frame_size = insn & 0xFFFF;
800
  pc += OR1K_INSTLEN;
801
 
802
  /* Skip stored registers.  */
803
  insn = or1k_fetch_instruction (pc);
804
  while ((insn & 0xfc1f0000) == 0xd4010000)  /* l.sw I(r1),rx */
805
    {
806
      rB           = (insn & 0x0000F800) >> 11;
807
      immediate_hi = (insn & 0x03E00000) >> 10;
808
      immediate    = (insn & 0x000007FF) | immediate_hi;
809
 
810
      /* get saved reg. */
811
      if (fi)
812
        saved_reg_frame_offset[rB] = immediate;
813
      pc += OR1K_INSTLEN;
814
      insn = or1k_fetch_instruction (pc);
815
    }
816
 done:
817
  if (fi)
818
    fi->extra_info->after_prologue = pc;
819
  return pc;
820
}
821
 
822
/* Determines whether this function has frame.  */
823
 
824
int
825
or1k_frameless_function_invocation (struct frame_info *fi)
826
{
827
  int frameless;
828
  CORE_ADDR func_start, after_prologue;
829
  func_start = (get_pc_function_start ((fi)->pc) + FUNCTION_START_OFFSET);
830
 
831
  /* If we don't skip pc, we don't have even shortest possible  prologue.  */
832
  after_prologue = or1k_skip_prologue (func_start, fi);
833
  frameless = (after_prologue <= func_start);
834
  return frameless;
835
}
836
 
837
/* Given a GDB frame, determine the address of the calling function's frame.
838
   This will be used to create a new GDB frame struct, and then
839
   INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. */
840
 
841
CORE_ADDR
842
or1k_frame_chain (frame)
843
     struct frame_info *frame;
844
{
845
  CORE_ADDR fp = 0;
846
  if (USE_GENERIC_DUMMY_FRAMES)
847
    {
848
      if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
849
        /* dummy frame same as caller's frame */
850
        return frame->frame;
851
    }
852
 
853
  if (inside_entry_file (frame->pc) ||
854
      frame->pc == entry_point_address ())
855
    return 0;
856
 
857
  if (frame->signal_handler_caller)
858
    fp = read_memory_integer (frame->frame, 4);
859
  else if (frame->next != NULL
860
           && frame->next->signal_handler_caller
861
           && FRAMELESS_FUNCTION_INVOCATION (frame))
862
    /* A frameless function interrupted by a signal did not change the
863
       frame pointer.  */
864
    fp = FRAME_FP (frame);
865
  else
866
    {
867
      unsigned long func_pc = get_pc_function_start(frame->pc);
868
      unsigned long insn = read_memory_integer(func_pc,4);
869
      int i;
870
      int offset = 0;
871
 
872
      /* The first instruction should tell us the number of bytes
873
         in our frame. If it isn't we're in trouble because
874
         the function is without a prologue... */
875
      if ((insn & 0xFFFF0000) == 0x9c210000) /* l.addi r1,r1,I */
876
        {
877
          /* Sign extend immediate */
878
          int immediate = (long)(insn << 16) >> 16;
879
          int frame_size = -immediate;
880
 
881
          /* Look for the storage of the frame pointer in the
882
             function prologue.. */
883
          unsigned long insn = read_memory_integer(func_pc+4,4);
884
 
885
          /* If bits are 31 - 26 are %110101,
886
             and bits 20 - 16 are %00001,
887
             and bits 15 - 11 are %00010,
888
             then our frame pointer lies at the offset specified
889
             by bits [25-21][10-0]. */
890
 
891
          int code = insn >> 26;
892
          int r1    = (insn & 0x001F0000) >> 16;
893
          int r2    = (insn & 0x0000F800) >> 11;
894
          int idx_h = (insn & 0x03E00000) >> 10;
895
          int idx   = (insn & 0x000007FF) | idx_h;
896
 
897
          if(code == 0x35 && r1 == 1 && r2 == 2)
898
            {
899
              offset = idx - frame_size;
900
              fp = read_memory_integer (frame->frame + offset, 4);
901
            }
902
        }
903
    }
904
 
905
  if (USE_GENERIC_DUMMY_FRAMES)
906
    {
907
      CORE_ADDR fpp, lr;
908
 
909
      lr = read_register (LR_REGNUM);
910
      if (lr == entry_point_address ())
911
        if (fp != 0 && (fpp = read_memory_integer (fp, 4)) != 0)
912
          if (PC_IN_CALL_DUMMY (lr, fpp, fpp))
913
            return fpp;
914
    }
915
 
916
  return fp;
917
}
918
 
919
/* The code to store, into a struct frame_saved_regs,
920
   the addresses of the saved registers of frame described by FRAME_INFO.
921
   This includes special registers such as pc and fp saved in special
922
   ways in the stack frame.  sp is even more special:
923
   the address we return for it IS the sp for the next frame.  */
924
void
925
or1k_init_saved_regs (struct frame_info *fi)
926
{
927
  int i;
928
  CORE_ADDR frame_addr;
929
  CORE_ADDR func_pc = get_pc_function_start ((fi)->pc) + FUNCTION_START_OFFSET;
930
  int pc_found = 0;
931
 
932
  frame_saved_regs_zalloc (fi);
933
 
934
  /* Skip prologue sets frame_size and register frame save offsets
935
     which will both be used shortly. */
936
  or1k_skip_prologue (func_pc, fi);
937
 
938
  /* If the frame_size is less than 0, we have hit an assembly
939
     routine which we can't traverse beyond. Let's give up here,
940
     because attempting to continue will only lead to trouble. */
941
  if(fi->extra_info->frame_size < 0)
942
    {
943
      printf("Found a function without a prologue at 0x%08x\n",func_pc);
944
      printf("Frame pc was at 0x%08x\n",fi->pc);
945
      return;
946
    }
947
 
948
  for (i = 0; i < NUM_GPR_REGS + NUM_VF_REGS; i++)
949
    if (fi->extra_info->saved_reg_frame_offset[i] >= 0)
950
      fi->saved_regs[i] =
951
        fi->frame + (fi->extra_info->saved_reg_frame_offset[i] - fi->extra_info->frame_size);
952
 
953
  /* We want to make sure we fill in the PC with the value of the
954
     r9 register from the NEXT frame, and that the value of r1 is
955
     the correct value of r1 for the next frame, which can be
956
     calculated by adding the frame_size to the frame pointer. */
957
  fi->saved_regs[1] = fi->frame - fi->extra_info->frame_size;
958
 
959
  if(fi->saved_regs[LR_REGNUM])
960
    fi->saved_regs[PC_REGNUM] = read_memory_integer(fi->saved_regs[LR_REGNUM],4);
961
  else
962
    fi->saved_regs[PC_REGNUM] = read_register(LR_REGNUM);
963
}
964
 
965
static CORE_ADDR
966
read_next_frame_reg (fi, regno)
967
     struct frame_info *fi;
968
     int regno;
969
{
970
  for (; fi; fi = fi->next)
971
    {
972
      /* We have to get the saved sp from the sigcontext
973
         if it is a signal handler frame.  */
974
      if (regno == SP_REGNUM && !fi->signal_handler_caller)
975
        return fi->frame;
976
      else
977
        {
978
          if (fi->saved_regs == NULL)
979
            or1k_init_saved_regs (fi);
980
          if (fi->saved_regs[regno])
981
            {
982
              if(regno == SP_REGNUM || regno == PC_REGNUM)
983
                return fi->saved_regs[regno];
984
              else
985
                return read_memory_integer (ADDR_BITS_REMOVE (fi->saved_regs[regno]), OR1K_GPR_REGSIZE);
986
            }
987
        }
988
    }
989
  return read_register (regno);
990
}
991
 
992
/* Find the caller of this frame.  We do this by seeing if LR_REGNUM
993
   is saved in the stack anywhere, otherwise we get it from the
994
   registers.  */
995
 
996
CORE_ADDR
997
or1k_frame_saved_pc (fi)
998
     struct frame_info *fi;
999
{
1000
  CORE_ADDR saved_pc;
1001
 
1002
  /* We have to get the saved pc from the sigcontext
1003
     if it is a signal handler frame.  */
1004
  if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1005
    saved_pc = read_memory_integer (fi->frame, OR1K_GPR_REGSIZE);
1006
  else
1007
    saved_pc = read_next_frame_reg (fi, PC_REGNUM);
1008
 
1009
  return ADDR_BITS_REMOVE (saved_pc);
1010
}
1011
 
1012
/* Discard from the stack the innermost frame, restoring all registers.  */
1013
 
1014
void
1015
or1k_pop_frame ()
1016
{
1017
  register int regnum;
1018
  struct frame_info *frame = get_current_frame ();
1019
  CORE_ADDR new_sp = FRAME_FP (frame);
1020
 
1021
  write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1022
  if (frame->saved_regs == NULL)
1023
    or1k_init_saved_regs (frame);
1024
  for (regnum = 0; regnum < NUM_REGS; regnum++)    {
1025
      if (regnum != SP_REGNUM && regnum != PC_REGNUM
1026
          && frame->saved_regs[regnum] >= 0)
1027
        write_register (regnum,
1028
                        read_memory_integer (frame->saved_regs[regnum],
1029
                                             OR1K_GPR_REGSIZE));
1030
    }
1031
  write_register (SP_REGNUM, new_sp);
1032
  flush_cached_frames ();
1033
}
1034
 
1035
CORE_ADDR
1036
or1k_push_arguments (nargs, args, sp, struct_return, struct_addr)
1037
     int nargs;
1038
     struct value* *args;
1039
     CORE_ADDR sp;
1040
     int struct_return;
1041
     CORE_ADDR struct_addr;
1042
{
1043
  int argreg;
1044
  int float_argreg;
1045
  int argnum;
1046
  int len = 0;
1047
  int stack_offset = 0;
1048
 
1049
  /* Initialize the integer and float register pointers.  */
1050
  argreg = A0_REGNUM;
1051
  float_argreg = VFA0_REGNUM;
1052
 
1053
  /* The struct_return pointer occupies the RV value register.  */
1054
  if (struct_return)
1055
    write_register (RV_REGNUM, struct_addr);
1056
 
1057
  /* Now load as many as possible of the first arguments into
1058
     registers, and push the rest onto the stack.  Loop thru args
1059
     from first to last.  */
1060
  for (argnum = 0; argnum < nargs; argnum++)
1061
    {
1062
      char *val;
1063
      char valbuf[MAX_REGISTER_RAW_SIZE];
1064
      struct value * arg = args[argnum];
1065
      struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1066
      int len = TYPE_LENGTH (arg_type);
1067
      enum type_code typecode = TYPE_CODE (arg_type);
1068
 
1069
      /* The EABI passes structures that do not fit in a register by
1070
         reference. In all other cases, pass the structure by value.  */
1071
      if (len > OR1K_GPR_REGSIZE &&
1072
          (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
1073
        {
1074
          store_address (valbuf, OR1K_GPR_REGSIZE, VALUE_ADDRESS (arg));
1075
          typecode = TYPE_CODE_PTR;
1076
          len = OR1K_GPR_REGSIZE;
1077
          val = valbuf;
1078
        }
1079
      else
1080
        {
1081
          val = (char *) VALUE_CONTENTS (arg);
1082
 
1083
          if (typecode == TYPE_CODE_FLT
1084
              /* Doubles are not stored in regs on 32b target.  */
1085
              && len <= OR1K_VF_REGSIZE
1086
              && OR1K_VF_PRESENT)
1087
            {
1088
              if (float_argreg <= OR1K_LAST_FP_ARG_REGNUM)
1089
                {
1090
                  CORE_ADDR regval = extract_address (val, len);
1091
                  write_register (float_argreg++, regval);
1092
                }
1093
              else
1094
                {
1095
                  write_memory ((CORE_ADDR) sp, val, OR1K_VF_REGSIZE);
1096
                  sp -= OR1K_STACK_ALIGN;
1097
                }
1098
            }
1099
          else
1100
            {
1101
              if (argreg <= OR1K_LAST_ARG_REGNUM)
1102
                {
1103
                  CORE_ADDR regval = extract_address (val, len);
1104
                  write_register (argreg++, regval);
1105
                }
1106
              else
1107
                {
1108
                  write_memory ((CORE_ADDR) sp, val, OR1K_GPR_REGSIZE);
1109
                  sp -= OR1K_STACK_ALIGN;
1110
                }
1111
            }
1112
        }
1113
    }
1114
 
1115
  /* Return adjusted stack pointer.  */
1116
  return sp;
1117
}
1118
 
1119
/* Return nonzero when instruction has delay slot.  */
1120
 
1121
int
1122
is_delayed (insn)
1123
     unsigned long insn;
1124
{
1125
  int index;
1126
  index = insn_decode (insn);
1127
  return or32_opcodes[index].flags & OR32_IF_DELAY;
1128
}
1129
 
1130
int
1131
or1k_step_skips_delay (pc)
1132
     CORE_ADDR pc;
1133
{
1134
  char buf[OR1K_INSTLEN];
1135
 
1136
  if (target_read_memory (pc, buf, OR1K_INSTLEN) != 0)
1137
    /* If error reading memory, guess that it is not a delayed branch.  */
1138
    return 0;
1139
  return is_delayed ((unsigned long) extract_unsigned_integer (buf, OR1K_INSTLEN));
1140
}
1141
 
1142
CORE_ADDR
1143
or1k_push_return_address (pc, sp)
1144
     CORE_ADDR pc;
1145
     CORE_ADDR sp;
1146
{
1147
  /* Set the return address register to point to the entry
1148
     point of the program, where a breakpoint lies in wait.  */
1149
  write_register (LR_REGNUM, CALL_DUMMY_ADDRESS ());
1150
  return sp;
1151
}
1152
 
1153
/* Parses args for spr name and puts result into group and index.  */
1154
 
1155
static char *
1156
parse_spr_params (args, group, index)
1157
                  char *args;
1158
                  int *group, *index;
1159
{
1160
  *index = -1;
1161
  if (args)
1162
    {
1163
      int i;
1164
      char *ptr_c;
1165
 
1166
      /* Check if group number was supplied.  */
1167
      ptr_c = args;
1168
      while (*ptr_c != ' ' && *ptr_c != 0)
1169
        ptr_c++;
1170
      *ptr_c = 0;
1171
 
1172
      *group = (int) strtoul (args, &ptr_c, 0);
1173
      if (*ptr_c != 0)
1174
        {
1175
          *group = OR1K_NUM_SPR_GROUPS;
1176
 
1177
          /* check for group name */
1178
          for (i = 0; i < OR1K_NUM_SPR_GROUPS; i++)
1179
            if (strcasecmp (or1k_group_names[i], args) == 0)
1180
              {
1181
                *group = i;
1182
                break;
1183
              }
1184
 
1185
          /* Invalid group => check all register names in all groups.  */
1186
          if (*group >= OR1K_NUM_SPR_GROUPS)
1187
            {
1188
              for (i = 0; i < OR1K_NUM_SPR_GROUPS; i++)
1189
                {
1190
                  int regno;
1191
                  regno = or1k_regno_from_name (i, args);
1192
                  if (regno >= 0)
1193
                    {
1194
                      *group = i;
1195
                      *index = regno;
1196
                      break;
1197
                    }
1198
                }
1199
            }
1200
        }
1201
      if (*group < 0 || *group >= OR1K_NUM_SPR_GROUPS)
1202
        error ("Invalid group or register.\n");
1203
 
1204
      if (*index < 0)
1205
        {
1206
          printf ("a'%s'\n", args);
1207
          args += strlen(args) + 1;
1208
          printf ("b'%s'\n", args);
1209
          if (*args != 0)
1210
            {
1211
              ptr_c = args;
1212
              while (*ptr_c != ' ' && *ptr_c != 0)
1213
                ptr_c++;
1214
              *ptr_c = 0;
1215
 
1216
              *index = (int) strtoul (args, &ptr_c, 0);
1217
              if (*ptr_c != 0)
1218
                *index = or1k_regno_from_name (*group, args);
1219
            }
1220
 
1221
          if (*index < 0)
1222
            {
1223
              printf_filtered ("No register supplied. Valid registers are:\n");
1224
              for (i = 0; i < or1k_spr_valid_aliases[*group]; i++)
1225
                {
1226
                  char reg_name[16];
1227
                  char *gen_name = or1k_spr_register_name (SPR_REG(*group, i));
1228
                  sprintf (reg_name, "SPR%i_%i", *group, i);
1229
                  if (strcmp (reg_name, gen_name) != 0)
1230
                    printf_filtered ("%s\t", gen_name);
1231
                }
1232
              printf_filtered ("\n");
1233
              return args + strlen(args) + 1;
1234
            }
1235
        }
1236
    }
1237
  else
1238
    {
1239
      /* No parameters - print groups */
1240
      int i;
1241
      printf_filtered ("No parameter supplied. Valid groups are:\n");
1242
      for (i = 0; i < OR1K_NUM_SPR_GROUPS; i++)
1243
        printf_filtered ("%s\t", or1k_group_names[i]);
1244
      printf_filtered ("\nSingle register name or register name or number after the group can be also supplied.\n");
1245
      return args;
1246
    }
1247
  return args + strlen(args) + 1;
1248
}
1249
 
1250
/* SPR register info.  */
1251
 
1252
void
1253
info_spr_command (args, from_tty)
1254
     char *args;
1255
     int from_tty;
1256
{
1257
  int group, index;
1258
  parse_spr_params (args, &group, &index);
1259
  if (index >= 0)
1260
    {
1261
      unsigned long value = or1k_read_spr_reg (SPR_REG(group, index));
1262
      printf_unfiltered ("%s.%s = SPR%i_%i = %i(%x)\n", or1k_group_names[group],
1263
                         or1k_spr_register_name (SPR_REG(group, index)), group, index, value, value);
1264
    }
1265
}
1266
 
1267
void
1268
info_trace_command (args, from_tty)
1269
     char *args;
1270
     int from_tty;
1271
{
1272
  unsigned char i;
1273
  int j;
1274
  printf_filtered ("        add      insn     res     time\n");
1275
  i = or1k_read_spr_reg (SPR_REG(6, 255));
1276
  for (j = 0; j < 256; j++, i++)
1277
    printf_filtered ("%03d %03u %08x %08x %08x %08x\n", 255 - j, i,
1278
                      or1k_read_spr_reg (SPR_REG(6, 0x100 + i)),
1279
                      or1k_read_spr_reg (SPR_REG(6, 0x200 + i)),
1280
                      or1k_read_spr_reg (SPR_REG(6, 0x300 + i)),
1281
                      or1k_read_spr_reg (SPR_REG(6, 0x400 + i)));
1282
 
1283
}
1284
 
1285
/* Set SPR register.  */
1286
 
1287
void
1288
spr_command (args, from_tty)
1289
     char *args;
1290
     int from_tty;
1291
{
1292
  int group, index;
1293
  char *nargs = parse_spr_params (args, &group, &index);
1294
  if (index >= 0)
1295
    {
1296
      unsigned long prev;
1297
      unsigned long value;
1298
      char *ptr_c;
1299
 
1300
      /* Any arguments left?  */
1301
      if (args + strlen(args) >= nargs)
1302
        error ("Invalid register value.");
1303
 
1304
      prev = or1k_read_spr_reg (SPR_REG(group, index));
1305
 
1306
      ptr_c = nargs;
1307
      while (*ptr_c != ' ' && *ptr_c != 0)
1308
        ptr_c++;
1309
      *ptr_c = 0;
1310
      value = strtoul (nargs, &ptr_c, 0);
1311
      if (*ptr_c != 0)
1312
                                error ("Invalid register value.");
1313
                        or1k_write_spr_reg (SPR_REG(group, index), value);
1314
      printf_unfiltered ("%s.%s (SPR%i_%i) set to %i(%x), was:%i(%x)\n", or1k_group_names[group],
1315
                         or1k_spr_register_name (SPR_REG(group, index)), group, index,
1316
                         value, value, prev, prev);
1317
    }
1318
}
1319
 
1320
/* Calls extended command on target.  */
1321
 
1322
void
1323
sim_command (args, from_tty)
1324
     char *args;
1325
     int from_tty;
1326
{
1327
  or1k_sim_cmd (args, from_tty);
1328
}
1329
 
1330
 
1331
static union exp_element exp_error;
1332
 
1333
/* Parses compare variable and returns it into ct.  */
1334
 
1335
union exp_element * or1k_parse_ct (exp, ct)
1336
     union exp_element *exp;
1337
     int *ct;
1338
{
1339
  int i;
1340
  if (exp->opcode != OP_INTERNALVAR)
1341
    error ("Valid lvalue expected.");
1342
  exp++;
1343
 
1344
  for (i = 1; i < NUM_CT_NAMES; i++)
1345
    if (strcasecmp (compare_to_names[i], exp->internalvar->name) == 0) break;
1346
 
1347
  if (i >= NUM_CT_NAMES)
1348
    error ("Invalid compare to operand.");
1349
  *ct = i;
1350
  exp++;
1351
 
1352
  if (exp->opcode != OP_INTERNALVAR)
1353
    return &exp_error;
1354
  exp++;
1355
  return exp;
1356
}
1357
 
1358
/* Parses compare value and returns it into cv.  */
1359
 
1360
union exp_element * or1k_parse_cv (exp, cv)
1361
     union exp_element *exp;
1362
     unsigned int *cv;
1363
{
1364
  switch (exp->opcode)
1365
    {
1366
    case UNOP_IND:
1367
      exp++;
1368
      exp = or1k_parse_cv (exp, cv);
1369
      *cv = or1k_fetch_word (*cv);
1370
      break;
1371
    case OP_LONG:
1372
      exp += 2;
1373
      *cv = exp->longconst;
1374
      exp += 2;
1375
      break;
1376
    case OP_REGISTER:
1377
      exp++;
1378
      *cv = read_register (exp->longconst);
1379
      exp += 2;
1380
      break;
1381
    default:
1382
      error ("Value expected.");
1383
    }
1384
  return exp;
1385
}
1386
 
1387
/* Parse conditional.
1388
   Puts freshly allocated array of matchpoints into match.  */
1389
 
1390
union exp_element *
1391
or1k_parse_cond (exp, match, nmatch)
1392
     union exp_element *exp;
1393
     struct matchpoint **match;
1394
     int *nmatch;
1395
{
1396
  unsigned int ct;
1397
  *match = (struct matchpoint *) malloc (sizeof (struct matchpoint));
1398
  *nmatch = 1;
1399
  switch (exp->opcode)
1400
    {
1401
    case BINOP_EQUAL:
1402
      (*match)->dcr.cc = CC_EQUAL;
1403
      break;
1404
    case BINOP_NOTEQUAL:
1405
      (*match)->dcr.cc = CC_NEQUAL;
1406
      break;
1407
    case BINOP_LESS:
1408
      (*match)->dcr.cc = CC_LESS;
1409
      break;
1410
    case BINOP_GTR:
1411
      (*match)->dcr.cc = CC_GREAT;
1412
      break;
1413
    case BINOP_LEQ:
1414
      (*match)->dcr.cc = CC_LESSE;
1415
      break;
1416
    case BINOP_GEQ:
1417
      (*match)->dcr.cc = CC_GREATE;
1418
      break;
1419
    case BINOP_BITWISE_AND:
1420
      (*match)->dcr.cc = CC_MASKED;
1421
      break;
1422
    default:
1423
      return &exp_error;
1424
    }
1425
 
1426
  exp++;
1427
  (*match)->dcr.dp = 1;
1428
  (*match)->dcr.sc = 0;
1429
  if (exp->opcode == OP_INTERNALVAR)
1430
    {
1431
      exp = or1k_parse_ct (exp, &ct);
1432
      exp = or1k_parse_cv (exp, &(*match)->dvr);
1433
    }
1434
  else
1435
    {
1436
      exp = or1k_parse_cv (exp, &(*match)->dvr);
1437
      exp = or1k_parse_ct (exp, &ct);
1438
    }
1439
 
1440
  (*match)->dcr.ct = ct;
1441
  (*match)->chain_type = CHAINING_NONE;
1442
  (*match)->cause_breakpoint = 0;
1443
  return exp;
1444
}
1445
 
1446
/* Parses expression with && or || operators.
1447
   Puts freshly allocated array of matchpoints into match.
1448
   valid & 1: && is allowed,
1449
   valid & 2: || is allowed.  */
1450
 
1451
union exp_element *
1452
or1k_parse_any (exp, match, nmatch, valid)
1453
     union exp_element *exp;
1454
     struct matchpoint **match;
1455
     int *nmatch;
1456
     int valid;
1457
{
1458
  union exp_element *tmp;
1459
  int first_and_only = 0, first_or_only = 0;
1460
  struct matchpoint *tmp_match1, *tmp_match2, *tmpm;
1461
  int tmp_nmatch1, tmp_nmatch2, tmpn;
1462
 
1463
  switch (exp->opcode)
1464
    {
1465
    case BINOP_LOGICAL_AND:
1466
      if (!(valid & 1))
1467
        return &exp_error;
1468
      exp++;
1469
 
1470
      /* Parse first argument.  */
1471
      tmp = or1k_parse_any (exp, &tmp_match1, &tmp_nmatch1, 1);
1472
      if (tmp == &exp_error)
1473
        exp = or1k_parse_any (exp, &tmp_match1, &tmp_nmatch1, valid);
1474
      else
1475
        {
1476
          /* and_only successful */
1477
          exp = tmp;
1478
          first_and_only = 1;
1479
        }
1480
      if (exp == &exp_error)
1481
        return &exp_error;
1482
 
1483
      /* Parse second argument.  */
1484
      if (first_and_only)
1485
        exp = or1k_parse_any (exp, &tmp_match2, &tmp_nmatch2, valid);
1486
      else
1487
        exp = or1k_parse_any (exp, &tmp_match2, &tmp_nmatch2, 1);
1488
 
1489
      if (exp == &exp_error)
1490
        return &exp_error;
1491
 
1492
      if (first_and_only)
1493
        {
1494
          /* Exchange structures, so that and_only is listed last.  */
1495
          struct matchpoint *tmpm = tmp_match1;
1496
          int tmpn = tmp_nmatch1;
1497
          tmp_match1 = tmp_match2;
1498
          tmp_nmatch1 = tmp_nmatch2;
1499
          tmp_match2 = tmpm;
1500
          tmp_nmatch2 = tmpn;
1501
        }
1502
 
1503
      *nmatch = tmp_nmatch1 + tmp_nmatch2;
1504
      *match = (struct matchpoint *)malloc (*nmatch * sizeof (struct matchpoint));
1505
      memcpy (*match, tmp_match1, tmp_nmatch1 * sizeof (struct matchpoint));
1506
      free (tmp_match1);
1507
      tmp_match2[0].chain_type = CHAINING_AND;
1508
      memcpy (*match + tmp_nmatch1, tmp_match2, tmp_nmatch2 * sizeof (struct matchpoint));
1509
      free (tmp_match2);
1510
      return exp;
1511
 
1512
    case BINOP_LOGICAL_OR:
1513
      if (!(valid & 2))
1514
        return &exp_error;
1515
      exp++;
1516
 
1517
      /* Parse first argument.  */
1518
      tmp = or1k_parse_any (exp, &tmp_match1, &tmp_nmatch1, 2);
1519
      if (tmp == &exp_error)
1520
        exp = or1k_parse_any (exp, &tmp_match1, &tmp_nmatch1, valid);
1521
      else
1522
        {
1523
          /* and_only successful */
1524
          exp = tmp;
1525
          first_or_only = 1;
1526
        }
1527
      if (exp == &exp_error)
1528
        return &exp_error;
1529
 
1530
      /* Parse second argument.  */
1531
      if (first_or_only)
1532
        exp = or1k_parse_any (exp, &tmp_match2, &tmp_nmatch2, valid);
1533
      else
1534
        exp = or1k_parse_any (exp, &tmp_match2, &tmp_nmatch2, 2);
1535
 
1536
      if (exp == &exp_error)
1537
        return &exp_error;
1538
 
1539
      if (first_or_only)
1540
        {
1541
          /* Exchange structures, so that and_only is listed first.  */
1542
          struct matchpoint *tmpm = tmp_match1;
1543
          int tmpn = tmp_nmatch1;
1544
          tmp_match1 = tmp_match2;
1545
          tmp_nmatch1 = tmp_nmatch2;
1546
          tmp_match2 = tmpm;
1547
          tmp_nmatch2 = tmpn;
1548
        }
1549
 
1550
      *nmatch = tmp_nmatch1 + tmp_nmatch2;
1551
      *match = (struct matchpoint *)malloc (*nmatch * sizeof (struct matchpoint));
1552
      memcpy (*match, tmp_match1, tmp_nmatch1 * sizeof (struct matchpoint));
1553
      free (tmp_match1);
1554
      tmp_match2[0].chain_type = CHAINING_OR;
1555
      memcpy (*match + tmp_nmatch1, tmp_match2, tmp_nmatch2 * sizeof (struct matchpoint));
1556
      free (tmp_match2);
1557
      return exp;
1558
 
1559
    default:
1560
      return or1k_parse_cond (exp, match, nmatch);
1561
    }
1562
}
1563
 
1564
/* Parses sequence of ||s.
1565
   Puts freshly allocated array of matchpoints into match.  */
1566
 
1567
union exp_element *
1568
or1k_parse_or (exp, match, nmatch, set_break)
1569
     union exp_element *exp;
1570
     struct matchpoint **match;
1571
     int *nmatch;
1572
     int set_break;
1573
{
1574
  struct matchpoint *tmp_match1, *tmp_match2;
1575
  int tmp_nmatch1, tmp_nmatch2;
1576
 
1577
  switch (exp->opcode)
1578
    {
1579
    case BINOP_LOGICAL_OR:
1580
      exp++;
1581
      exp = or1k_parse_or (exp, &tmp_match1, &tmp_nmatch1);
1582
      if (exp == &exp_error)
1583
        return &exp_error;
1584
 
1585
      exp = or1k_parse_any (exp, &tmp_match2, &tmp_nmatch2, 3);
1586
      if (set_break)
1587
        {
1588
          tmp_match1[tmp_nmatch1 - 1].cause_breakpoint = 1;
1589
          tmp_match2[tmp_nmatch2 - 1].cause_breakpoint = 1;
1590
        }
1591
      *nmatch = tmp_nmatch1 + tmp_nmatch2;
1592
      *match = (struct matchpoint *)malloc (*nmatch * sizeof (struct matchpoint));
1593
      memcpy (*match, tmp_match1, tmp_nmatch1 * sizeof (struct matchpoint));
1594
      free (tmp_match1);
1595
      memcpy (*match + tmp_nmatch1, tmp_match2, tmp_nmatch2 * sizeof (struct matchpoint));
1596
      free (tmp_match2);
1597
      return exp;
1598
 
1599
    default:
1600
      return or1k_parse_any (exp, match, nmatch, 3);
1601
      if (set_break)
1602
        (*match)[*nmatch - 1].cause_breakpoint = 1;
1603
    }
1604
}
1605
 
1606
/* Prints single matchpoint from specified struct.  */
1607
 
1608
static void
1609
print_matchpoint_struct (mp)
1610
     struct matchpoint *mp;
1611
{
1612
  printf_filtered ("%-6s (%i) %u, ON=%i, chain_type=%i, cause break=%i\n", compare_to_names[mp->dcr.ct],
1613
                   mp->dcr.cc, mp->dvr, mp->dcr.dp, mp->chain_type, mp->cause_breakpoint);
1614
}
1615
 
1616
/* Build watchpoint(s) based on given structure.  */
1617
 
1618
static void
1619
set_matchpoints (match, nmatch)
1620
     struct matchpoint *match;
1621
     int nmatch;
1622
{
1623
  int i;
1624
  debug_regs_changed = 1;
1625
  sift_matchpoints ();
1626
  for (i = 0; i < nmatch; i++)
1627
    {
1628
      int num = or1k_implementation.num_used_matchpoints;
1629
      dcr[num] = match[i].dcr;
1630
      dvr[num] = match[i].dvr;
1631
 
1632
      /* Set chaining bits.  */
1633
      dmr1 &= ~(3 << (2 * num));
1634
      dmr1 |= match[i].chain_type << (2 * num);
1635
 
1636
      /* Set watchpoint bits */
1637
      dmr2 &= 1 << num;
1638
      dmr2 |= match[i].cause_breakpoint << num;
1639
      matchpoint_user_count[i]++;
1640
      or1k_implementation.num_used_matchpoints++;
1641
    }
1642
}
1643
 
1644
/* Returns nonzero, if matchpoints [start .. start+nmatch-1] are
1645
   equal to match record. */
1646
 
1647
static int
1648
matchpoint_matches (start, match, nmatch)
1649
     int start;
1650
     struct matchpoint *match;
1651
     int nmatch;
1652
{
1653
  int i;
1654
  if (nmatch + start >= or1k_implementation.num_matchpoints)
1655
    return 0;
1656
 
1657
  for (i = 0; i < nmatch; i++)
1658
    {
1659
      int j = i + start;
1660
 
1661
      /* Everything exept cause breakpoint must match.  */
1662
      if (dcr[j].dp != match[i].dcr.dp
1663
          || dcr[j].ct != match[i].dcr.ct
1664
          || dcr[j].cc != match[i].dcr.cc
1665
          || dcr[j].sc != match[i].dcr.sc
1666
          || dvr[j] != match[i].dvr
1667
          || match[i].chain_type != (dmr1 >> (2 * j)) & 3)
1668
        return 0;
1669
    }
1670
  return 1;
1671
}
1672
 
1673
static void
1674
hwatch_command (arg, from_tty)
1675
     char *arg;
1676
     int from_tty;
1677
{
1678
  struct expression *exp;
1679
  int i, nfree, nmatch, remove = 0;
1680
  struct matchpoint *match;
1681
 
1682
  if (arg == NULL)
1683
    arg = "";
1684
  if (strncasecmp ("remove ", arg, 7) == 0)
1685
    {
1686
      arg += 7;
1687
      remove = 1;
1688
    }
1689
 
1690
  /* Parse arguments.  */
1691
  exp = parse_exp_1 (&arg, 0, 0);
1692
 
1693
#ifdef DEBUG
1694
  dump_prefix_expression (exp, gdb_stdout, "expr1");
1695
#endif  
1696
 
1697
  if (or1k_parse_or (&exp->elts[0], &match, &nmatch, 1) == &exp_error)
1698
    error ("Watchpoint too complex.");
1699
 
1700
  for (i = 0; i < nmatch; i++)
1701
    print_matchpoint_struct (&match[i]);
1702
 
1703
  if (remove)
1704
    {
1705
      int start = -1;
1706
      int cleared = 0;
1707
 
1708
      if (num_hw_watches <= 0)
1709
        error ("No extended hardware supported watchpoints present.");
1710
 
1711
      for (i = 0; i < num_hw_watches; i++)
1712
        if (matchpoint_matches (or1k_hwatch[i].matchpoint_start, match, nmatch))
1713
          {
1714
            start = or1k_hwatch[i].matchpoint_start;
1715
            break;
1716
          }
1717
 
1718
      if (start < 0)
1719
        error ("Watchpoint not found.");
1720
 
1721
      for (i = 0; i < nmatch; i++)
1722
        {
1723
          int j = start + i;
1724
          if (--matchpoint_user_count[j] <= 0)
1725
            {
1726
              debug_regs_changed = 1;
1727
              memset (&dcr[j], 0, sizeof (dcr[j]));
1728
              or1k_implementation.num_used_matchpoints--;
1729
              cleared = 1;
1730
            }
1731
        }
1732
      if (!cleared)
1733
        warning ("No matchpoint(s) freed. Resources are busy.");
1734
    }
1735
  else
1736
    {
1737
      if (num_hw_watches >= MAX_HW_WATCHES)
1738
        error ("Number of watchpoints too large.");
1739
 
1740
      /* Now we have to find out if given prefix expression matches
1741
         our HW based support. It may take up to
1742
         or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints. */
1743
      nfree = or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints;
1744
 
1745
      if (nmatch > nfree)
1746
        error ("Not enough free matchpoint resources.");
1747
 
1748
      /* Build watchpoint(s) based on just built structure.  */
1749
      or1k_hwatch[num_hw_watches].matchpoint_start = or1k_implementation.num_used_matchpoints;
1750
      set_matchpoints (match, nmatch);
1751
      num_hw_watches++;
1752
      printf_unfiltered ("Watchpoint successfully allocated.\n");
1753
    }
1754
  free (match);
1755
  free (exp);
1756
}
1757
 
1758
static void
1759
htrace_command (args, from_tty)
1760
     char *args;
1761
     int from_tty;
1762
{
1763
  help_list (htrace_cmdlist, "htrace ", all_commands, gdb_stdout);
1764
}
1765
 
1766
static void
1767
htrace_mode_command (args, from_tty)
1768
     char *args;
1769
     int from_tty;
1770
{
1771
  help_list (htrace_mode_cmdlist, "htrace mode ", all_commands, gdb_stdout);
1772
}
1773
 
1774
static void
1775
htrace_mode_contin_command (args, from_tty)
1776
     char *args;
1777
     int from_tty;
1778
{
1779
  or1k_htrace.moder.contin = 1;
1780
  printf_unfiltered ("Continuous trace mode set.\n");
1781
}
1782
 
1783
static void
1784
htrace_mode_suspend_command (args, from_tty)
1785
     char *args;
1786
     int from_tty;
1787
{
1788
  or1k_htrace.moder.contin = 0;
1789
  printf_unfiltered ("Suspend trace mode set.\n");
1790
}
1791
 
1792
static void print_event_struct (event, stop)
1793
     struct htrace_event_struct *event;
1794
     int stop;
1795
{
1796
  int i;
1797
  if (event->operation == TRIGOP_ANY)
1798
    if (stop)
1799
      printf_filtered ("not active");
1800
    else
1801
      printf_filtered ("always active");
1802
  else
1803
    {
1804
      char *comma;
1805
      if (event->operation == TRIGOP_AND)
1806
        comma = "&(";
1807
      else
1808
        comma = "|(";
1809
 
1810
      if (event->is_valid)
1811
        {
1812
          printf_filtered ("%s%s", comma, or1k_is_names[event->is_trig]);
1813
          comma = ", ";
1814
        }
1815
      if (event->ls_valid)
1816
        {
1817
          printf_filtered ("%s%s", comma, or1k_ls_names[event->ls_trig]);
1818
          comma = ", ";
1819
        }
1820
      if (event->bp_valid)
1821
        {
1822
          printf_filtered ("%sbreak", comma);
1823
          comma = ", ";
1824
        }
1825
      if (event->wp_valid)
1826
        for (i = 0; i < 11; i++)
1827
          if ((event->wp_trig >> i) & 1)
1828
            {
1829
              printf_filtered ("%sWP%i", comma, i);
1830
              comma = ", ";
1831
            }
1832
      if (comma[0] == ',')
1833
        printf_filtered (")");
1834
      else
1835
        printf_filtered ("not active");
1836
    }
1837
}
1838
 
1839
static void
1840
print_record_struct (record)
1841
     struct htrace_record_struct *record;
1842
{
1843
  int i;
1844
  char *comma = "";
1845
  for (i = 0; i < MAX_RECORD_NAMES; i++)
1846
    {
1847
      if ((record->rec >> i)&1)
1848
        {
1849
          printf_filtered ("%s%s", comma, or1k_record_names[i]);
1850
          comma = ", ";
1851
        }
1852
    }
1853
  if (!*comma)
1854
    printf_unfiltered ("none");
1855
}
1856
 
1857
static void
1858
htrace_info_command (args, from_tty)
1859
     char *args;
1860
     int from_tty;
1861
{
1862
  int i;
1863
  printf_filtered ("Trace trigger: ");
1864
  print_event_struct (&or1k_htrace.trig, 0);
1865
  printf_filtered ("\nTrace qualifier: ");
1866
  print_event_struct (&or1k_htrace.qual, 0);
1867
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1868
    {
1869
      printf_filtered ("\n WP%i records: ", i);
1870
      print_record_struct (&or1k_htrace.recwp[i]);
1871
    }
1872
  printf_filtered ("\n BP records: ");
1873
  print_record_struct (&or1k_htrace.recbp);
1874
  printf_filtered ("\nTrace stop: ");
1875
  print_event_struct (&or1k_htrace.stop, 1);
1876
  printf_filtered ("\n");
1877
}
1878
 
1879
/* Parses event from given string.
1880
   Result is placed into event structure, and previously allocated
1881
   resources are freed.  Parameter stop is nonzero, when we are parsing
1882
   for stop criteria.  */
1883
 
1884
static void
1885
parse_event (args, event, stop)
1886
     char *args;
1887
     struct htrace_event_struct *event;
1888
     int stop;
1889
{
1890
  int i, op_type = 0, was_last_op = 1, any = 0;
1891
 
1892
  /* Release previous resources.  */
1893
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1894
    {
1895
      if ((event->wp_trig << i) & 1)
1896
        if (--matchpoint_user_count[i] <= 0)
1897
          {
1898
            memset (&dcr[i], 0, sizeof (dcr[i]));
1899
            debug_regs_changed = 1;
1900
            or1k_implementation.num_used_matchpoints--;
1901
          }
1902
    }
1903
 
1904
  event->is_valid = event->is_trig = 0;
1905
  event->ls_valid = event->ls_trig = 0;
1906
  event->bp_valid = event->bp_trig = 0;
1907
  event->wp_valid = event->wp_trig = 0;
1908
 
1909
  if (args == NULL)
1910
    args = "";
1911
  while (*args == ' ')
1912
    args++;
1913
 
1914
  while (*args != '\0')
1915
    {
1916
      if (strncasecmp ("breakpoint", args, 10) == 0)
1917
        {
1918
          if (!was_last_op)
1919
            error ("Syntax error.");
1920
          was_last_op = 0;
1921
          event->bp_valid = event->bp_trig = 1;
1922
        }
1923
      else if (!stop && strncasecmp ("any", args, 3) == 0
1924
               || stop && strncasecmp ("none", args, 4) == 0)
1925
        {
1926
          if (!was_last_op)
1927
            error ("Syntax error.");
1928
          was_last_op = 0;
1929
          any = 1;
1930
        }
1931
      else if (strncasecmp ("||", args, 2) == 0)
1932
        {
1933
          if (op_type == TRIGOP_AND)
1934
            error ("Only one type of logical operator allowed at a time.");
1935
          op_type = TRIGOP_OR;
1936
          if (was_last_op)
1937
            error ("Syntax error.");
1938
          was_last_op = 1;
1939
          args += 2;
1940
        }
1941
      else if (strncasecmp ("&&", args, 2) == 0)
1942
        {
1943
          if (op_type == TRIGOP_OR)
1944
            error ("Only one type of logical operator allowed at a time.");
1945
          op_type = TRIGOP_AND;
1946
          if (was_last_op)
1947
            error ("Syntax error.");
1948
          was_last_op = 1;
1949
          args += 2;
1950
        }
1951
      else
1952
        {
1953
          int found = 0;
1954
          if (!was_last_op)
1955
            error ("Syntax error.");
1956
          was_last_op = 0;
1957
 
1958
          /* Search through is and ls tables for a match.  */
1959
          for (i = 0; i < MAX_IS_NAMES; i++)
1960
            if (strncasecmp (args, or1k_is_names[i], strlen (or1k_is_names[i])) == 0)
1961
              {
1962
                event->is_valid = 1;
1963
                event->is_trig = i;
1964
                args +=  strlen (or1k_is_names[i]);
1965
                found = 1;
1966
                break;
1967
              }
1968
          if (!found)
1969
            {
1970
              for (i = 0; i < MAX_LS_NAMES; i++)
1971
                if (strncasecmp (args, or1k_ls_names[i], strlen (or1k_ls_names[i])) == 0)
1972
                  {
1973
                    event->ls_valid = 1;
1974
                    event->ls_trig = i;
1975
                    args +=  strlen (or1k_ls_names[i]);
1976
                    found = 1;
1977
                    break;
1978
                  }
1979
            }
1980
          if (!found)
1981
            {
1982
              /* No special name was found => parse expression.  */
1983
              struct expression *exp;
1984
              struct matchpoint *match;
1985
              int nmatch, nfree;
1986
 
1987
              exp = parse_exp_1 (&args, 0, 0);
1988
 
1989
              if (or1k_parse_any (&exp->elts[0], &match, &nmatch, 3) == &exp_error)
1990
                error ("Expression too complex.");
1991
              for (i = 0; i < nmatch; i++)
1992
                print_matchpoint_struct (&match[i]);
1993
 
1994
              /* Now we have to find out if given prefix expression matches
1995
                 our HW based support. It may take up to
1996
                 or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints. */
1997
              nfree = or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints;
1998
 
1999
              if (nmatch > nfree)
2000
                error ("Not enough free matchpoint resources.");
2001
 
2002
              /* Build matchpoint(s) based on just built structure.  */
2003
              set_matchpoints (match, nmatch);
2004
              event->wp_valid = 1;
2005
              event->wp_trig |= 1 << (or1k_implementation.num_used_matchpoints - 1);
2006
              printf_unfiltered ("Watchpoint successfully allocated.\n");
2007
              free (match);
2008
              free (exp);
2009
              found = 1;
2010
            }
2011
          if (!found)
2012
            warning ("Invalid event at '%s'", args);
2013
        }
2014
      while (*args == ' ') args++;
2015
    }
2016
  if (any)
2017
    event->operation = TRIGOP_ANY;
2018
  else
2019
    {
2020
      if (op_type == 0)
2021
        op_type = TRIGOP_AND;
2022
      event->operation = op_type;
2023
    }
2024
}
2025
 
2026
static void
2027
htrace_trigger_command (args, from_tty)
2028
     char *args;
2029
     int from_tty;
2030
{
2031
  parse_event (args, &or1k_htrace.trig, 0);
2032
  printf_filtered ("Trace starts, when:\n");
2033
  print_event_struct (&or1k_htrace.trig, 0);
2034
  printf_filtered ("\n");
2035
}
2036
 
2037
static void
2038
htrace_qualifier_command (args, from_tty)
2039
     char *args;
2040
     int from_tty;
2041
{
2042
  parse_event (args, &or1k_htrace.qual, 0);
2043
  printf_filtered ("Trace records, when:\n");
2044
  print_event_struct (&or1k_htrace.qual, 0);
2045
  printf_filtered ("\n");
2046
}
2047
 
2048
static void
2049
htrace_stop_command (args, from_tty)
2050
     char *args;
2051
     int from_tty;
2052
{
2053
  parse_event (args, &or1k_htrace.stop, 1);
2054
  printf_filtered ("Trace stops, when:\n");
2055
  print_event_struct (&or1k_htrace.stop, 1);
2056
  printf_filtered ("\n");
2057
}
2058
 
2059
static void
2060
htrace_clear_records_command (args, from_tty)
2061
     char *args;
2062
     int from_tty;
2063
{
2064
  int i, j, cleared = 0;
2065
 
2066
  /* Clear all. */
2067
  for (i = 0; i < MAX_MATCHPOINTS; i++)
2068
    {
2069
      for (j = 0; j < MAX_MATCHPOINTS; j++)
2070
        {
2071
          if ((or1k_htrace.wp_record_uses[i] << j) & 1)
2072
            if (--matchpoint_user_count[j] <= 0)
2073
            {
2074
              memset (&dcr[j], 0, sizeof (dcr[j]));
2075
              debug_regs_changed = 1;
2076
              cleared = 1;
2077
              or1k_implementation.num_used_matchpoints--;
2078
            }
2079
        }
2080
      or1k_htrace.wp_record_uses[i] = 0;
2081
    }
2082
  if (!cleared)
2083
    warning ("No matchpoints freed. Resources are busy.");
2084
}
2085
 
2086
/* Syntax: htrace record {data}* when {expr} */
2087
 
2088
static void
2089
htrace_record_command (args, from_tty)
2090
     char *args;
2091
     int from_tty;
2092
{
2093
  struct expression *exp;
2094
  int i, nfree, nmatch, wp;
2095
  struct matchpoint *match;
2096
  unsigned int recdata = 0;
2097
  char *c;
2098
 
2099
  if (args == '\0')
2100
    error ( "Please specify data to record, e.g.:\n"
2101
            "htrace record PC SDATA when $SEA == 100\n"
2102
            "htrace record when $SEA == 100 to remove record");
2103
 
2104
  for (i = 0; *args != '\0' && strncasecmp ("when ", args, 5); i++)
2105
    {
2106
      int j, found = 0;
2107
      for (j = 0; j < MAX_RECORD_NAMES; j++)
2108
        if (strncasecmp (args, or1k_record_names[j], strlen (or1k_record_names[j])) == 0)
2109
          {
2110
            recdata |= 1 << j;
2111
            found = 1;
2112
            break;
2113
          }
2114
      if (!found)
2115
        warning ("Invalid record data name at '%s'.", args);
2116
      while (*args != ' ' && *args != '\0') args++;
2117
      while (*args == ' ') args++;
2118
    }
2119
 
2120
  if (strncasecmp ("when ", args, 5) != 0)
2121
    if (*args == '\0')
2122
      {
2123
        warning ("Condition not set. Assuming breakpoint.");
2124
        wp = -1;
2125
      }
2126
    else
2127
      error ("Syntax error.");
2128
  else
2129
    {
2130
      args += 5;
2131
      if (strcasecmp ("breakpoint", args) == 0)
2132
        wp = -1;
2133
      else
2134
        {
2135
          /* Parse arguments.  */
2136
          exp = parse_exp_1 (&args, 0, 0);
2137
 
2138
#ifdef DEBUG
2139
          dump_prefix_expression (exp, gdb_stdout, "expr1");
2140
#endif
2141
          if (or1k_parse_any (&exp->elts[0], &match, &nmatch, 3) == &exp_error)
2142
            error ("Expression too complex.");
2143
 
2144
          for (i = 0; i < nmatch; i++)
2145
            print_matchpoint_struct (&match[i]);
2146
 
2147
          if (recdata)
2148
            {
2149
              /* Now we have to find out if given prefix expression matches
2150
                 our HW based support. It may take up to
2151
                 or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints. */
2152
              nfree = or1k_implementation.num_matchpoints - or1k_implementation.num_used_matchpoints;
2153
 
2154
              if (nmatch > nfree)
2155
                error ("Not enough free matchpoint resources.");
2156
 
2157
              wp = or1k_implementation.num_used_matchpoints - 1;
2158
              or1k_htrace.wp_record_uses[wp] = 0;
2159
              for (i = or1k_implementation.num_used_matchpoints; i <= wp; i++)
2160
                or1k_htrace.wp_record_uses[wp] |= 1 << i;
2161
              set_matchpoints (match, nmatch);
2162
            }
2163
          else
2164
            {
2165
              /* Remove record. */
2166
              int start = -1, cleared = 0;
2167
 
2168
              for (i = 0; i < MAX_MATCHPOINTS; i++)
2169
                {
2170
                  int mp_start = 0, j;
2171
                  j = or1k_htrace.wp_record_uses[i];
2172
                  while (j > 0 && j & 1 == 0)
2173
                    mp_start++;
2174
 
2175
                  if (matchpoint_matches (mp_start, match, nmatch))
2176
                    {
2177
                      start = mp_start;
2178
                      or1k_htrace.wp_record_uses[i] = 0;
2179
                      break;
2180
                    }
2181
                }
2182
              if (start < 0)
2183
                error ("Record with such expression not found.");
2184
 
2185
              for (i = 0; i < nmatch; i++)
2186
                {
2187
                  int j = i + start;
2188
                  if (--matchpoint_user_count[j] <= 0)
2189
                    {
2190
                      memset (&dcr[j], 0, sizeof (dcr[j]));
2191
                      debug_regs_changed = 1;
2192
                      cleared = 1;
2193
                    }
2194
                }
2195
              if (!cleared)
2196
                warning ("No matchpoint(s) freed.");
2197
            }
2198
        }
2199
    }
2200
 
2201
  /* If we reached this point we have matchpoints set, and wp
2202
     holds the value of that watchpoint.  wp == -1, if breakpoint
2203
     was specified.  */
2204
  if (wp < 0)
2205
    or1k_htrace.recbp.rec = recdata;
2206
  else
2207
    or1k_htrace.recwp[wp].rec = recdata;
2208
 
2209
  if (recdata)
2210
    {
2211
      printf_unfiltered ("Data");
2212
      for (i = 0; i < MAX_RECORD_NAMES; i++)
2213
        if ((recdata >> i) & 1)
2214
          printf_unfiltered (" %s,", or1k_record_names[i]);
2215
    }
2216
  else
2217
    printf_unfiltered ("No data");
2218
  if (wp < 0)
2219
    printf_unfiltered (" will be recorded when breakpoint occurs\n");
2220
  else
2221
    printf_unfiltered (" will be recorded when watchpoint #%i occurs\n", wp);
2222
}
2223
 
2224
static void
2225
htrace_enable_command (args, from_tty)
2226
     char *args;
2227
     int from_tty;
2228
{
2229
  or1k_htrace.moder.trace_enable = 1;
2230
  printf_unfiltered ("HW Trace enabled.\n");
2231
}
2232
 
2233
static void
2234
htrace_disable_command (args, from_tty)
2235
     char *args;
2236
     int from_tty;
2237
{
2238
  or1k_htrace.moder.trace_enable = 0;
2239
  printf_unfiltered ("HW Trace disabled.\n");
2240
}
2241
 
2242
static void
2243
htrace_rewind_command (args, from_tty)
2244
     char *args;
2245
     int from_tty;
2246
{
2247
  FILE *f;
2248
  if (args != NULL && *args != '\0')
2249
    strncpy (TRACE_FILENAME, args, TRACE_FILENAME_SIZE);
2250
 
2251
  /* Just empty it.  */
2252
  if ((f = fopen (TRACE_FILENAME, "wb+")) == NULL)
2253
    error ("Cannot open trace file.");
2254
  fclose (f);
2255
  printf_unfiltered ("Trace data cleared.\n");
2256
}
2257
 
2258
static void
2259
print_data_struct (pos, data)
2260
     unsigned int pos;
2261
     struct htrace_data_struct *data;
2262
{
2263
  struct symbol *func;
2264
  char *funname = NULL;
2265
 
2266
  if (data->type < 4)
2267
    {
2268
      /* Determine function name - copied from stack.c  */
2269
      func = find_pc_function (data->data);
2270
      if (func)
2271
        {
2272
          struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (data->data);
2273
          if (msymbol != NULL
2274
              && (SYMBOL_VALUE_ADDRESS (msymbol)
2275
                  > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
2276
            funname = SYMBOL_NAME (msymbol);
2277
          else
2278
            {
2279
              char *demangled;
2280
              funname = SYMBOL_NAME (func);
2281
              if (SYMBOL_LANGUAGE (func) == language_cplus)
2282
                {
2283
                  demangled = cplus_demangle (funname, DMGL_ANSI);
2284
                  if (demangled == NULL)
2285
                    funname = SYMBOL_SOURCE_NAME (func);
2286
                }
2287
            }
2288
        }
2289
      else
2290
        {
2291
          struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (data->data);
2292
          if (msymbol != NULL)
2293
            funname = SYMBOL_NAME (msymbol);
2294
        }
2295
    }
2296
 
2297
  printf_filtered ("%06X%c %-8s %08X", pos, data->valid ? '>' : ':',
2298
                   or1k_record_names[data->type], data->data);
2299
  if (funname)
2300
    printf_filtered (" (%s)\n", funname);
2301
  else
2302
    printf_filtered ("\n");
2303
}
2304
 
2305
/* Prints out trace buffer.  */
2306
 
2307
static void
2308
htrace_print_command (args, from_tty)
2309
     char *args;
2310
     int from_tty;
2311
{
2312
  int i, from = 0, length = prev_length;
2313
  FILE *f;
2314
  struct htrace_data_struct *td;
2315
 
2316
  if (args == NULL) args = "";
2317
  while (*args == ' ') args++;
2318
  if (*args == '\0')
2319
    {
2320
      /* We will display buffer further. */
2321
      from = prev_from + prev_length;
2322
    }
2323
  else
2324
    {
2325
      /* Display buffer range.  */
2326
      int numbers = 0;
2327
      char *cnum = args;
2328
      while (*args != ' ' && *args != '\0')
2329
        args++;
2330
 
2331
      /* Any arguments?  */
2332
      if (*args == '\0')
2333
        numbers = 1;
2334
      else
2335
        {
2336
          *args = 0;
2337
          args++;
2338
          numbers = 2;
2339
        }
2340
      from = strtoul (cnum, &cnum, 0);
2341
      if (*cnum != 0)
2342
        error ("Invalid from value.");
2343
      if (from < 0) from += trace_size;
2344
      if (numbers == 2)
2345
        {
2346
          while (*args == ' ') args++;
2347
          length = strtoul (cnum, &cnum, 0);
2348
          if (*args != 0)
2349
            error ("Invalid length value.");
2350
          if (length < 0)
2351
            {
2352
              from += length;
2353
              length = -length;
2354
            }
2355
        }
2356
    }
2357
 
2358
  if (from >= trace_size)
2359
    from = trace_size - 1;
2360
  if (from < 0)
2361
    from = 0;
2362
  if (from + length >= trace_size)
2363
    length = trace_size - from;
2364
 
2365
  prev_length = length;
2366
  prev_from = from;
2367
  if (length == 0)
2368
    error ("Nothing to print.");
2369
 
2370
  printf_filtered ("Trace buffer %06x:%06x (size = %i)\n", from, from + length - 1, length);
2371
  if ((f = fopen (TRACE_FILENAME, "rb")) == NULL)
2372
    error ("Cannot open trace file.");
2373
  if (fseek (f, TRACE_DATA_SIZE * from, SEEK_SET))
2374
    error ("Error reading trace file.");
2375
  td = (struct htrace_data_struct *) malloc (TRACE_DATA_SIZE * length);
2376
  length = fread (td, TRACE_DATA_SIZE, length, f);
2377
  for (i = 0; i < length; i++)
2378
    print_data_struct (from + i, td[i]);
2379
  fclose (f);
2380
}
2381
 
2382
int print_insn_big_or32 (bfd_vma,struct disassemble_info*);
2383
int print_insn_little_or32 (bfd_vma,struct disassemble_info*);
2384
 
2385
void
2386
_initialize_or1k_tdep ()
2387
{
2388
  build_automata ();
2389
  /* Added by CZ 26/06/01 */
2390
  if(TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2391
    tm_print_insn = print_insn_big_or32;
2392
  else
2393
    tm_print_insn = print_insn_little_or32;
2394
 
2395
  /* Commands to show and set sprs.  */
2396
  add_info ("spr", info_spr_command, "Show information about the spr registers.");
2397
  add_info ("trace", info_trace_command, "Display trace buffer contents.");
2398
  add_com ("spr", class_support, spr_command, "Set specified SPR register.");
2399
 
2400
  /* hwatch command.  */
2401
  add_com ("hwatch", class_breakpoint, hwatch_command, "Set hardware watch"
2402
           "point.\nExample: ($LEA == my_var)&&($LDATA < 50)||($SEA == my_"
2403
           "var)&&($SDATA >= 50).\nSee OR1k Architecture document for more"
2404
           " info.");
2405
 
2406
  /* htrace commands.  */
2407
  add_prefix_cmd ("htrace", class_breakpoint, htrace_command,
2408
                  "Group of commands for handling hardware assisted trace\n\n"
2409
                  "See OR1k Architecture and gdb for or1k documents for more info.",
2410
                  &htrace_cmdlist, "htrace ", 0, &cmdlist);
2411
  add_cmd ("info", class_breakpoint, htrace_info_command, "Display information about HW trace.",
2412
           &htrace_cmdlist);
2413
  add_alias_cmd ("i", "info", class_breakpoint, 1, &htrace_cmdlist);
2414
  add_cmd ("trigger", class_breakpoint, htrace_trigger_command, "Set starting criteria for trace.",
2415
           &htrace_cmdlist);
2416
  add_alias_cmd ("t", "trigger", class_breakpoint, 1, &htrace_cmdlist);
2417
  add_cmd ("qualifier", class_breakpoint, htrace_qualifier_command, "Set acquisition qualifier for HW trace.",
2418
           &htrace_cmdlist);
2419
  add_alias_cmd ("q", "qualifier", class_breakpoint, 1, &htrace_cmdlist);
2420
  add_cmd ("stop", class_breakpoint, htrace_stop_command, "Set HW trace stopping criteria.",
2421
           &htrace_cmdlist);
2422
  add_alias_cmd ("s", "stop", class_breakpoint, 1, &htrace_cmdlist);
2423
  add_cmd ("record", class_breakpoint, htrace_record_command, "Sets data to be recorded when expression occurs.",
2424
           &htrace_cmdlist);
2425
  add_alias_cmd ("r", "record", class_breakpoint, 1, &htrace_cmdlist);
2426
  add_cmd ("clear records", class_breakpoint, htrace_clear_records_command,
2427
           "Disposes all matchpoints used by records.", &htrace_cmdlist);
2428
  add_cmd ("enable", class_breakpoint, htrace_enable_command, "Enables the HW trace.", &htrace_cmdlist);
2429
  add_alias_cmd ("e", "enable", class_breakpoint, 1, &htrace_cmdlist);
2430
  add_cmd ("disable", class_breakpoint, htrace_disable_command, "Disables the HW trace.", &htrace_cmdlist);
2431
  add_alias_cmd ("d", "disable", class_breakpoint, 1, &htrace_cmdlist);
2432
  add_cmd ("rewind", class_breakpoint, htrace_rewind_command, "Clears currently recorded trace data.\n"
2433
           "If filename is specified, new trace file is made and any newly collected data\n"
2434
           "will be written there.", &htrace_cmdlist);
2435
  add_cmd ("print", class_breakpoint, htrace_print_command,
2436
           "Prints trace buffer, using current record configuration.\n"
2437
           "htrace print [<start> [<len>]]\n"
2438
           "htrace print"
2439
           , &htrace_cmdlist);
2440
  add_alias_cmd ("p", "print", class_breakpoint, 1, &htrace_cmdlist);
2441
  add_prefix_cmd ("mode", class_breakpoint, htrace_mode_command,
2442
           "Configures the HW trace.\n"
2443
           "htrace mode [continuous|suspend]"
2444
           , &htrace_mode_cmdlist, "htrace mode ", 0, &htrace_cmdlist);
2445
  add_alias_cmd ("m", "mode", class_breakpoint, 1, &htrace_cmdlist);
2446
  add_cmd ("continuous", class_breakpoint, htrace_mode_contin_command,
2447
           "Set continuous trace mode.\n", &htrace_mode_cmdlist);
2448
  add_cmd ("suspend", class_breakpoint, htrace_mode_suspend_command,
2449
           "Set suspend trace mode.\n", &htrace_mode_cmdlist);
2450
 
2451
  /* Extra functions supported by simulator.  */
2452
  add_com ("sim", class_obscure, sim_command,
2453
           "Send a extended command to the simulator.");
2454
}
2455
 

powered by: WebSVN 2.1.0

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