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 874

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

powered by: WebSVN 2.1.0

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