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 1115

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

powered by: WebSVN 2.1.0

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