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 207

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

powered by: WebSVN 2.1.0

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