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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [or1k-tdep.c] - Blame information for rev 119

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

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

powered by: WebSVN 2.1.0

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