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 404

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

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

powered by: WebSVN 2.1.0

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