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 1775

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

powered by: WebSVN 2.1.0

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