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 1123

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

powered by: WebSVN 2.1.0

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