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 364

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

powered by: WebSVN 2.1.0

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