OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [remote-or1k.c] - Blame information for rev 1248

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1183 sfurman
/* Remote debugging interface for various or1k debugging protocols.
2
   Currently supported or1k targets are: simulator, jtag, dummy.
3
 
4
   Copyright 1993-1995, 2000 Free Software Foundation, Inc.
5
   Contributed by Cygnus Support.  Written by Marko Mlinar
6
   <markom@opencores.org>
7
 
8
   This file is part of GDB.
9
 
10
   This program is free software; you can redistribute it and/or modify
11
   it under the terms of the GNU General Public License as published by
12
   the Free Software Foundation; either version 2 of the License, or
13
   (at your option) any later version.
14
 
15
   This program is distributed in the hope that it will be useful,
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
   GNU General Public License for more details.
19
 
20
   You should have received a copy of the GNU General Public License
21
   along with this program; if not, write to the Free Software
22
   Foundation, Inc., 59 Temple Place - Suite 330,
23
   Boston, MA 02111-1307, USA.  */
24
 
25
#include "defs.h"
26
#include "inferior.h"
27
#include "bfd.h"
28
#include "symfile.h"
29
#include "gdb_wait.h"
30
#include "gdbcmd.h"
31
#include "gdbcore.h"
32
#include "target.h"
33
#include "remote-utils.h"
34
#include "gdb_string.h"
35
#include "tm.h"
36
#include "event-loop.h"
37
#include "event-top.h"
38
#include "inf-loop.h"
39 1248 hpanther
#include "regcache.h"
40 1183 sfurman
 
41
#include <signal.h>
42
#include <sys/types.h>
43
#include <sys/stat.h>
44
#include <sys/ioctl.h>
45
#include <fcntl.h>
46
 
47
#define debug if (remote_debug) printf_unfiltered
48
 
49
/* Prototypes for local functions */
50
static void or1k_interrupt PARAMS ((int signo));
51
static void or1k_interrupt_twice PARAMS ((int signo));
52
static void interrupt_query PARAMS ((void));
53
 
54
/* The following prototype is necessary or the compiler will not
55
   correctly promote the data argument to ULONGEST */
56
static void or1k_write_reg (unsigned int, ULONGEST);
57
static int insn_modifies_gprs (unsigned int insn);
58
 
59
/* JTAG or1k target ops.  */
60
extern void jtag_init PARAMS ((char * args));
61
extern ULONGEST jtag_read_reg PARAMS ((unsigned int regno));
62
extern void jtag_write_reg PARAMS ((unsigned int regno, ULONGEST data));
63
extern void jtag_done PARAMS ((void));
64
extern int jtag_read_block PARAMS ((unsigned int regno, void* block, int nRegisters));
65
extern int jtag_write_block PARAMS ((unsigned int regno, void* block, int nRegisters));
66
extern void jtag_set_chain PARAMS ((int chain));
67
struct target_ops or1k_jtag_ops;
68 1248 hpanther
 
69 1183 sfurman
static struct or1k_target_ops or1k_target_jtag =
70 1248 hpanther
{
71 1183 sfurman
    "jtag",
72
    jtag_init,
73
    jtag_done,
74
    jtag_read_reg,
75
    jtag_write_reg,
76
    jtag_read_block,
77
    jtag_write_block,
78
    jtag_set_chain,
79
    NULL,
80
    &or1k_jtag_ops,
81
    OPS_MAGIC
82 1248 hpanther
};
83 1183 sfurman
 
84
/* simulator or1k target ops.  */
85
struct target_ops or1k_sim_ops;
86
static struct or1k_target_ops or1k_target_sim =
87
  {
88
    "simulator",
89
    NULL,
90
    NULL,
91
    NULL,
92
    NULL,
93
    NULL,
94
    NULL,
95
    NULL,
96
    NULL,
97
    &or1k_sim_ops,
98
    OPS_MAGIC
99
  };
100
 
101
/* dummy or1k target ops.  */
102
struct target_ops or1k_dummy_ops;
103
static struct or1k_target_ops or1k_target_dummy =
104
  {
105
    "dummy",
106
    NULL,
107
    NULL,
108
    NULL,
109
    NULL,
110
    NULL,
111
    NULL,
112
    NULL,
113
    NULL,
114
    &or1k_dummy_ops,
115
    OPS_MAGIC
116
  };
117
 
118
const char *str_err[] =
119
  {
120
    "None", "CRC error"
121
  };
122
 
123
const char *status_name[] =
124
  {
125
    "UNDEFINED", "CONNECTING", "DISCONNECTING", "RUNNING", "STOPPED"
126
  };
127
 
128
/* Names for matchpoint related stuff.  */
129
static char *ct_names[] =
130
  {
131
    "DIS", "IFEA", "LEA", "SEA", "AEA", "LDATA", "SDATA", "ADATA"
132
  };
133
 
134
static char *cc_names[] =
135
  {
136
    "&", "==", "<", "<=", ">", ">=", "!=", "ERR"
137
  };
138
 
139
static char *ch_names[] =
140
  {
141
    "ERR", "&", "|", "ERR"
142
  };
143
 
144
/* Implementation specific information.  Set by or1k_initialize.  */
145
struct struct_or1k_implementation or1k_implementation =
146
  {
147
    num_gpr_regs:32,
148
    num_vfpr_regs:0
149
  };
150
 
151
/* Current target status.  */
152
static enum target_status or1k_status = TARGET_UNDEFINED;
153
 
154
/* The target vector.  */
155
struct target_ops or1k_dummy_ops, or1k_jtag_ops, or1k_sim_ops;
156
 
157
/* Currently active target description (if or1k_is_open == 1) */
158
static struct target_ops *current_ops;
159
 
160
/* Currently active or1k target operations.  */
161
static struct or1k_target_ops *current_or1k_target = NULL;
162
 
163
/* Set to 1 if the target is open.  */
164
static int or1k_is_open = 0;
165
 
166
/* Error last occured, zero = ok.  */
167
int err = 0;
168
 
169
/* Nonzero, if we changed something (except DMR1 which is updated on every run anyway).  */
170
int debug_regs_changed;
171
 
172
/* Number of interrupts while waiting for process.  */
173
static int interrupt_count = 0;
174
 
175
/* Last value of step in resume function */
176
static int resume_stepped = 0;
177
 
178
/* Reason of last stop.  */
179
static int hit_watchpoint = 0;
180
static int hit_breakpoint = 0;
181
static int step_link_insn = 0;
182
static int new_pc_set = 0;
183
 
184
/* Current register values.  */
185
unsigned int dmr1 = 0;
186
unsigned int dmr2 = 0;
187
unsigned int dsr = 0;
188
unsigned int drr = 0;
189
unsigned int lr = 0;
190
 
191
/* Current matchpoints.  */
192
unsigned int dvr[MAX_MATCHPOINTS];
193
struct dcr_struct dcr[MAX_MATCHPOINTS];
194
 
195
/* Number of matchpoint users */
196
int matchpoint_user_count[MAX_MATCHPOINTS] = {0};
197
 
198
/* Old SIGINT handler.  */
199
static void (*ofunc) PARAMS ((int));
200
 
201
/* Tokens for use by the asynchronous signal handlers for SIGINT */
202
PTR sigint_or1k_twice_token;
203
PTR sigint_or1k_token;
204
 
205
 
206
/* Handle low-level error that we can't recover from.  Note that just
207
   error()ing out from target_wait or some such low-level place will cause
208
   all hell to break loose--the rest of GDB will tend to get left in an
209
   inconsistent state.  */
210
 
211
static NORETURN void
212
or1k_error (char *string,...)
213
{
214
  va_list args;
215
 
216
  va_start (args, string);
217
 
218
  target_terminal_ours ();
219
  wrap_here ("");               /* Force out any buffered output */
220
  gdb_flush (gdb_stdout);
221
  if (error_pre_print)
222
    fprintf_filtered (gdb_stderr, error_pre_print);
223
  vfprintf_filtered (gdb_stderr, string, args);
224
  fprintf_filtered (gdb_stderr, "\n");
225
  va_end (args);
226
  gdb_flush (gdb_stderr);
227
 
228
  /* Clean up in such a way that or1k_close won't try to talk to the
229
     board (it almost surely won't work since we weren't able to talk to
230
     it).  */
231
  or1k_is_open = 0;
232
 
233
  printf_unfiltered ("Ending remote or1k debugging.\n");
234
  target_mourn_inferior ();
235
 
236
  throw_exception (RETURN_ERROR);
237
}
238
 
239
const char *
240
or1k_err_name (e)
241
     int e;
242
{
243
  return str_err[e];
244
}
245
 
246
/* putc_readable - print a character, displaying non-printable chars in
247
   ^x notation or in hex.  */
248
 
249
static void
250
fputc_readable (ch, file)
251
     int ch;
252
     struct ui_file *file;
253
{
254
  if (ch == '\n')
255
    fputc_unfiltered ('\n', file);
256
  else if (ch == '\r')
257
    fprintf_unfiltered (file, "\\r");
258
  else if (ch < 0x20)           /* ASCII control character */
259
    fprintf_unfiltered (file, "^%c", ch + '@');
260
  else if (ch >= 0x7f)          /* non-ASCII characters (rubout or greater) */
261
    fprintf_unfiltered (file, "[%02x]", ch & 0xff);
262
  else
263
    fputc_unfiltered (ch, file);
264
}
265
 
266
 
267
/* puts_readable - print a string, displaying non-printable chars in
268
   ^x notation or in hex.  */
269
 
270
static void
271
fputs_readable (string, file)
272
     char *string;
273
     struct ui_file *file;
274
{
275
  int c;
276
 
277
  while ((c = *string++) != '\0')
278
    fputc_readable (c, file);
279
}
280
 
281
/* Sets scan chain.  */
282
 
283
static void
284
or1k_set_chain (chain)
285
     int chain;
286
{
287
  if (current_or1k_target != NULL && current_or1k_target->to_set_chain != NULL)
288
    current_or1k_target->to_set_chain (chain);
289
}
290
 
291
/* Sets register/memory regno to data.  */
292
 
293
static void
294
or1k_write_reg (regno, data)
295
     unsigned int regno;
296
     ULONGEST data;
297
{
298
  if (current_or1k_target != NULL && current_or1k_target->to_write_reg != NULL)
299
    current_or1k_target->to_write_reg (regno, data);
300
}
301
 
302
/* Reads register/memory from regno.  */
303
 
304
static ULONGEST
305
or1k_read_reg (regno)
306
     unsigned int regno;
307
{
308
  if (current_or1k_target != NULL && current_or1k_target->to_read_reg != NULL)
309
    return current_or1k_target->to_read_reg (regno);
310
  else
311
    return 0x1234;
312
}
313
 
314
/* Sets SPR register regno to data.  */
315
 
316
void
317
or1k_write_spr_reg (regno, data)
318
     unsigned int regno;
319
     unsigned int data;
320
{
321
  or1k_set_chain (SC_RISC_DEBUG);
322
  or1k_write_reg (regno, (ULONGEST)data);
323
  if (regno == PC_SPRNUM) {
324
    hit_breakpoint = 0;
325
    step_link_insn = 0;
326
    new_pc_set = 1;
327
  }
328
}
329
 
330
/* Reads register SPR from regno.  */
331
 
332
unsigned int
333
or1k_read_spr_reg (regno)
334
     unsigned int regno;
335
{
336
  or1k_set_chain (SC_RISC_DEBUG);
337
  return or1k_read_reg (regno);
338
}
339
 
340
/* Sets mem to data.  */
341
 
342
void
343
or1k_write_mem (addr, data)
344
     unsigned int addr;
345
     unsigned int data;
346
{
347
  or1k_set_chain (SC_WISHBONE);
348
  or1k_write_reg (addr, (ULONGEST)data);
349
}
350
 
351
/* Reads register SPR from regno.  */
352
 
353
unsigned int
354
or1k_read_mem (addr)
355
     unsigned int addr;
356
{
357
  or1k_set_chain (SC_WISHBONE);
358
  return or1k_read_reg (addr);
359
}
360
 
361
/* Stalls the CPU.  */
362
 
363
static void
364
or1k_stall ()
365
{
366
  int val;
367
  or1k_set_chain (SC_REGISTER);
368
  val = or1k_read_reg (JTAG_RISCOP);
369
  or1k_write_reg (JTAG_RISCOP, val | 1);
370
  or1k_read_reg (JTAG_RISCOP);
371
 
372
  /* Be cautious - disable trace.  */
373
  val = or1k_read_reg (JTAG_MODER);
374
  or1k_write_reg (JTAG_MODER, val & ~2);
375
}
376
 
377
/* Unstalls the CPU.  */
378
 
379
static void
380
or1k_unstall ()
381
{
382
  unsigned int val;
383
 
384
 
385
  or1k_set_chain (SC_REGISTER);
386
  val = or1k_read_reg (JTAG_RISCOP);
387
  or1k_write_reg (JTAG_RISCOP, val & ~1);
388
  or1k_read_reg (JTAG_RISCOP);
389
}
390
 
391
/* Resets the CPU and stalls it.  */
392
 
393
static void
394
or1k_reset ()
395
{
396
  unsigned int val;
397
  int i;
398
  debug ("%08x\n", or1k_read_reg (JTAG_RISCOP));
399
  or1k_set_chain (SC_REGISTER);
400
 
401
  /* Be cautious - disable trace.  */
402
  val = or1k_read_reg (JTAG_MODER);
403
  or1k_write_reg (JTAG_MODER, val & ~2);
404
 
405
  val = or1k_read_reg (JTAG_RISCOP);
406
  val &= ~3;
407
  /* Assert reset signal.  */
408
  or1k_write_reg (JTAG_RISCOP, val | 3);
409
 
410
  /* Just do something */
411
  for (i = 0; i < 100; i++)
412
    or1k_read_reg (JTAG_RISCOP);
413
 
414
  /* give it some time */
415
  usleep (1000);
416
 
417
  or1k_set_chain (SC_REGISTER);
418
  /* Release reset signal, but keep in stall state.  */
419
  or1k_write_reg (JTAG_RISCOP, val | 1);
420
  or1k_read_reg (JTAG_RISCOP);
421
}
422
 
423
/* Synchronizes debug registers in memory with those on target,
424
   if there is any change.  */
425
 
426
static void
427
or1k_commit_debug_registers ()
428
{
429
  int i;
430
  unsigned int u;
431
  if (!debug_regs_changed)
432
    return;
433
 
434
  /* Matchpoints (breakpoints, watchpoints).  */
435
  for (i = 0; i < NUM_MATCHPOINTS; i++)
436
    {
437
      unsigned int u;
438
      or1k_write_spr_reg (DVR0_SPRNUM + i, dvr[i]);
439
      memcpy (&u, &dcr[i], sizeof(dcr[i]));
440
      or1k_write_spr_reg (DCR0_SPRNUM + i, u);
441
    }
442
  or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
443
  or1k_write_spr_reg (DMR2_SPRNUM, dmr2);
444
 
445
  /* Trace dependent.  */
446
  or1k_set_chain (SC_REGISTER);
447
  memcpy (&u, &or1k_htrace.trig, sizeof(or1k_htrace.trig));
448
  or1k_write_reg (JTAG_TSEL, u);
449
  memcpy (&u, &or1k_htrace.qual, sizeof(or1k_htrace.qual));
450
  or1k_write_reg (JTAG_QSEL, u);
451
  memcpy (&u, &or1k_htrace.stop, sizeof(or1k_htrace.stop));
452
  or1k_write_reg (JTAG_SSEL, u);
453
  debug_regs_changed = 0;
454
  for (i = 0; i < NUM_RECORDS; i++)
455
    {
456
      memcpy (&u, &or1k_htrace.recwp[i], sizeof(or1k_htrace.recwp[i]));
457
      or1k_write_reg (JTAG_RECWP0 + i, u);
458
    }
459
  memcpy (&u, &or1k_htrace.recbp, sizeof(or1k_htrace.recbp));
460
  or1k_write_reg (JTAG_RECBP0, u);
461
  memcpy (&u, &or1k_htrace.moder, sizeof(or1k_htrace.moder));
462
  or1k_write_reg (JTAG_MODER, u);
463
}
464
 
465
static void
466
or1k_set_undefined_cleanups (arg)
467
     PTR arg;
468
{
469
  or1k_status = TARGET_UNDEFINED;
470
}
471
 
472
/* Initialize a new connection to the or1k board, and make sure we are
473
   really connected.  */
474
 
475
static void
476
or1k_init (args)
477
     char *args;
478
{
479
  struct cleanup *old_cleanups = make_cleanup (or1k_set_undefined_cleanups, NULL);
480
  int i;
481
  unsigned int tmp;
482
  FILE *f;
483
 
484
  /* What is this code doing here?  I don't see any way it can happen, and
485
     it might mean or1k_initializing didn't get cleared properly.
486
     So I'll make it a warning.  */
487
 
488
  if (or1k_status == TARGET_CONNECTING)
489
    {
490
      warning ("internal error: or1k_initialize called twice");
491
      return;
492
    }
493
 
494
  or1k_status = TARGET_CONNECTING;
495
  if (current_or1k_target != NULL && current_or1k_target->to_init != NULL)
496
    current_or1k_target->to_init (args);
497
 
498
  debug("%08x\n", read_pc ());
499
  or1k_stall ();
500
  debug("%08x\n", read_pc ());
501
  usleep (1000);
502
 
503
  /* Determine implementation configuration.  */
504
  or1k_implementation.VR = or1k_read_spr_reg (VR_SPRNUM);
505
  or1k_implementation.UPR = or1k_read_spr_reg (UPR_SPRNUM);
506
 
507
  /* Determine number of gpr_regs.  */
508
  tmp = or1k_read_spr_reg (CPUCFGR_SPRNUM);
509
  or1k_implementation.num_gpr_regs = ((tmp >> 4) & 1)?(16):(32);
510
 
511
  /* Is any vector or floating point support present? */
512
  or1k_implementation.vf_present = ((tmp >> 7) & 7) != 0;
513
  or1k_implementation.num_vfpr_regs = (or1k_implementation.vf_present)?(32):(0);
514
 
515
  /* Determine max number of supported matchpoints.  */
516
  tmp = or1k_read_spr_reg (DCFGR_SPRNUM);
517
  or1k_implementation.num_matchpoints = tmp & 7;
518
  or1k_implementation.num_used_matchpoints = 0;
519
  or1k_implementation.has_counters = (tmp & 4) == 1;
520
 
521
  /* Is implementation supported? */
522
 
523
  /* First we should have system and debug groups implemented. */
524
  if ((or1k_implementation.UPR & SPR_UPR_UP) == 0)
525
    error ("System group should be available in the or1k implementation.");
526
  if ((or1k_implementation.UPR & SPR_UPR_DUP) == 0)
527
    error ("Debug group should be available in the or1k implementation.");
528
  if (or1k_implementation.has_counters)
529
    warning ("Counters not supported.");
530
 
531
  /* Delete break, watch, catch points.  */
532
  for(i = 0; i < NUM_MATCHPOINTS; i++)
533
    {
534
      memset (&dcr[i], 0, sizeof (dcr[i]));
535
      matchpoint_user_count[i] = 0;
536
    }
537
 
538
  dmr1 = 0;
539
  dmr2 = 0;
540
  memset (&or1k_htrace, 0, sizeof (or1k_htrace));
541
 
542
  /* RECSELDEPEND = 0 does not match our trace scheme. */
543
  or1k_htrace.moder.rec_sel_dep = 1;
544
 
545
  debug_regs_changed = 0;//1;
546
  or1k_commit_debug_registers ();
547
 
548
  if (err != 0)
549
    error ("Cannot connect.");
550
 
551
  /* Stop when breakpoint occurs.  */
552
  or1k_write_spr_reg (DSR_SPRNUM, dsr = 0x2000);
553
 
554
  do_cleanups (old_cleanups);
555
 
556
  /* This should cause an error if not connected.  */
557
  or1k_fetch_registers (-1);
558
 
559
  set_current_frame (create_new_frame (read_fp (), read_pc ()));
560
  select_frame (get_current_frame ());
561
 
562
  /* Just empty it.  */
563
  if ((f = fopen (TRACE_FILENAME, "wb+")) == NULL)
564
    error ("Cannot open trace file.");
565
  fclose (f);
566
  trace_size = 0;
567
  or1k_status = TARGET_STOPPED;
568
}
569
 
570
/* Kill the process running on the board.  */
571
 
572
void
573
or1k_kill ()
574
{
575
  if (or1k_status != TARGET_RUNNING)
576
    return;
577
  or1k_status = TARGET_UNDEFINED;
578
  or1k_reset();
579
  or1k_status = TARGET_STOPPED;
580
 
581
  /* obsolete inferior_pid = 0; */
582
}
583
 
584
/* Open a connection to the remote board.  */
585
 
586
static void
587
or1k_open (name, from_tty)
588
     char *name;
589
     int from_tty;
590
{
591
  or1k_init (name);
592
 
593
  /* Switch to using remote target now.  */
594
  current_ops = current_or1k_target->gdb_ops;
595
  or1k_is_open = 1;
596
  push_target (current_ops);
597
 
598
  /* FIXME: Should we call start_remote here?  */
599
 
600
/* This is really the job of start_remote however, that makes an assumption
601
   that the target is about to print out a status message of some sort.  That
602
   doesn't happen here (in fact, it may not be possible to get the monitor to
603
   send the appropriate packet).  */
604
 
605
  flush_cached_frames ();
606
  registers_changed ();
607
  stop_pc = read_pc ();
608
  set_current_frame (create_new_frame (read_fp (), stop_pc));
609
  select_frame (get_current_frame ());
610
  print_stack_frame (selected_frame, -1, 1);
611
}
612
 
613
/* This is the generic stop called via the target vector. When a target
614
   interrupt is requested, either by the command line or the GUI, we
615
   will eventually end up here. */
616
static void
617
or1k_stop ()
618
{
619
  /* Send a break or a ^C, depending on user preference.  */
620
  debug ("remote_stop called\n");
621
 
622
  /* We should not stop the target immediately, since it can be in an
623
     unfinished state.  So we do a single step.  This should not affect
624
     on anything.  */
625
  or1k_stall ();
626
  /* HW STEP.  Set DMR1_ST.  */
627
  dmr1 |= DMR1_ST;
628
  or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
629
  dmr1 &= ~DMR1_ST;
630
  or1k_unstall ();
631
  or1k_status = TARGET_STOPPED;
632
}
633
 
634
/* Close a connection to the remote board.  */
635
 
636
static void
637
or1k_close (quitting)
638
     int quitting;
639
{
640
  if (or1k_is_open)
641
    {
642
      if (current_or1k_target != NULL && current_or1k_target->to_done != NULL)
643
        current_or1k_target->to_done ();
644
      current_or1k_target = NULL;
645
    }
646
  generic_mourn_inferior ();
647
}
648
 
649
/* Detach from the remote board.  */
650
 
651
static void
652
or1k_detach (args, from_tty)
653
     char *args;
654
     int from_tty;
655
{
656
  if (args)
657
    error ("Argument given to \"detach\" when remotely debugging.");
658
 
659
  pop_target ();
660
 
661
  or1k_close (1);
662
 
663
  if (from_tty)
664
    printf_unfiltered ("Ending remote or1k debugging.\n");
665
}
666
 
667
/* Appends trace data to the trace file.  */
668
 
669
static void
670
or1k_read_trace ()
671
{
672
  struct htrace_data_struct data;
673
  ULONGEST tmp;
674
  int first = 1;
675
  FILE *fd;
676
  if ((fd = fopen (TRACE_FILENAME, "ab")) == NULL)
677
    {
678
      warning ("Cannot append to trace file.");
679
      return;
680
    }
681
 
682
  or1k_set_chain (SC_TRACE);
683
  while (1)
684
    {
685
      tmp = or1k_read_reg (0);
686
      memcpy (&data, &tmp, sizeof (data));
687
 
688
      /* Last record reached. */
689
      if (!data.valid)
690
        break;
691
      data.valid = first;
692
      first = 0;
693
      if (!fwrite (&data, sizeof (data), 1, fd))
694
        {
695
          warning ("Cannot write trace data");
696
          break;
697
        }
698
    }
699
  fclose (fd);
700
}
701
 
702
/* ^C Interrupt handling */
703
 
704
/* Ask the user what to do when an interrupt is received.  */
705
static void
706
interrupt_query ()
707
{
708
  target_terminal_ours ();
709
 
710
  if (query ("Interrupted while waiting for the program.\n\
711
Give up (and stop debugging it)? "))
712
    {
713
      target_mourn_inferior ();
714
      throw_exception (RETURN_QUIT);
715
    }
716
 
717
  target_terminal_inferior ();
718
}
719
 
720
/* Send ^C to target to halt it.  Target will respond, and send us a
721
   packet.  */
722
static void (*ofunc) PARAMS ((int));
723
 
724
/* The command line interface's stop routine. This function is installed
725
   as a signal handler for SIGINT. The first time a user requests a
726
   stop, we call remote_stop to send a break or ^C. If there is no
727
   response from the target (it didn't stop when the user requested it),
728
   we ask the user if he'd like to detach from the target. */
729
static void
730
or1k_interrupt (signo)
731
     int signo;
732
{
733
  /* If this doesn't work, try more severe steps. */
734
  signal (signo, or1k_interrupt_twice);
735
 
736
  /* If we are stepping we should stop the command, rather than stop
737
     the processor */
738
  if (resume_stepped)
739
    quit_flag = 1;
740
 
741
  interrupt_count++;
742
 
743
  if (remote_debug)
744
    fprintf_unfiltered (gdb_stdlog, "or1k_interrupt called\n");
745
}
746
 
747
/* The user typed ^C twice.  */
748
 
749
static void
750
or1k_interrupt_twice (signo)
751
     int signo;
752
{
753
  /* Try everything */
754
  quit_flag = 1;
755
  or1k_stop ();
756
  signal (signo, ofunc);
757
  interrupt_query ();
758
  signal (signo, or1k_interrupt_twice);
759
}
760
 
761
/* Resume execution of the target process.  STEP says whether to single-step
762
   or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
763
   to the target, or zero for no signal.  */
764
 
765
static void
766
or1k_resume (ptid, step, siggnal)
767
     ptid_t ptid;
768
     int step;
769
     enum target_signal siggnal;
770
{
771
  unsigned int pc;
772
  unsigned int ppc;
773
  unsigned int npc;
774
  unsigned int val;
775
  unsigned int ppc_insn;
776
  unsigned int pc_insn;
777
 
778
  /* Save step value for wait function */
779
  resume_stepped = step;
780
 
781
  pc = read_pc();
782
  npc = or1k_read_spr_reg (PC_SPRNUM);
783
  ppc = or1k_read_spr_reg (PPC_SPRNUM);
784
  debug ("pc = %08x BP = %x npc = %08x ppc = %08x\n", pc, breakpoint_here_p (pc), npc, ppc);
785
  debug ("resume %i, %i, %i\n",step, siggnal, or1k_status);
786
  if (or1k_status != TARGET_STOPPED)
787
    if (or1k_status == TARGET_RUNNING)
788
      error ("Program is already running.");
789
    else
790
      error ("The program is not being run.");
791
 
792
 
793
  /* Clear reason register for later.  */
794
  or1k_write_spr_reg (DRR_SPRNUM, 0);
795
 
796
  or1k_commit_debug_registers ();
797
 
798
  /* Fetch previous insn */
799
  ppc_insn = or1k_fetch_instruction (ppc);
800
 
801
  /* Fetch next insn */
802
  pc_insn = or1k_fetch_instruction (pc);
803
 
804
  if (step)
805
    {
806
      /* HW STEP.  Set DMR1_ST.  */
807
      dmr1 |= DMR1_ST;
808
      or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
809
      dmr1 &= ~DMR1_ST;
810
 
811
      if (new_pc_set)
812
        {
813
          debug("resume: 1\n");
814
          /* If new PC was set, then just set it again to fill the pipeline */
815
 
816
          or1k_write_spr_reg (PC_SPRNUM, pc);
817
 
818
          if (is_delayed (pc_insn) && insn_modifies_gprs (pc_insn))
819
            {
820
              debug("resume: 10\n");
821
              /* We are steping across jump an link insn - save link
822
                 register, so we will be able to restore it when we will
823
                 step across delay slot insn */
824
              step_link_insn = 1;
825
              lr = or1k_read_spr_reg (REGNUM_TO_SPRNUM(9));
826
            }
827
        }
828
      else if (is_delayed (ppc_insn) && (ppc != pc))
829
        {
830
          debug("resume: 2\n");
831
          /* Steping across delay slot insn - we have to reexcute branch insn */
832
 
833
          if (breakpoint_here_p (ppc))
834
            or1k_write_mem(ppc, ppc_insn);
835
 
836
          if (insn_modifies_gprs (ppc_insn) && step_link_insn)
837
            {
838
              debug("resume: 11\n");
839
              /* If this is delay slot of jump an link insn that was
840
                 allready executed - restore link register first */
841
              or1k_write_spr_reg (REGNUM_TO_SPRNUM(9), lr);
842
              step_link_insn = 0;
843
            }
844
 
845
          or1k_write_spr_reg (PC_SPRNUM, ppc);
846
 
847
          or1k_unstall ();
848
 
849
          or1k_set_chain (SC_REGISTER);
850
          val = or1k_read_reg (JTAG_RISCOP);
851
          do {
852
            val = or1k_read_reg (JTAG_RISCOP);
853
          } while ((val & 1) == 0);
854
        }
855
      else if (hit_breakpoint && ((ppc + 4) != npc) && (pc != npc))
856
        {
857
          debug("resume: 3\n");
858
          /* Trapped on delay slot instruction. */
859
          /* Set PC to branch insn preceding delay slot. */
860
          or1k_write_spr_reg (PC_SPRNUM, ppc - 4);
861
 
862
          if (insn_modifies_gprs (or1k_fetch_instruction (ppc - 4)))
863
            {
864
              debug("resume: 12\n");
865
              /* We are steping across jump an link insn - save link
866
                 register, so we will be able to restore it when we will
867
                 step across delay slot insn */
868
              step_link_insn = 1;
869
              lr = or1k_read_spr_reg (REGNUM_TO_SPRNUM(9));
870
            }
871
 
872
          or1k_unstall ();
873
 
874
          or1k_set_chain (SC_REGISTER);
875
          val = or1k_read_reg (JTAG_RISCOP);
876
          do {
877
            val = or1k_read_reg (JTAG_RISCOP);
878
          } while ((val & 1) == 0);
879
        }
880
      else
881
        {
882
          debug("resume: 4\n");
883
          /* Steping across 'non delay slot' insn - set PC to fill the pipeline */
884
 
885
          or1k_write_spr_reg (PC_SPRNUM, pc);
886
 
887
          if (is_delayed (pc_insn) && insn_modifies_gprs (pc_insn))
888
            {
889
              debug("resume: 13\n");
890
              /* We are steping across jump an link insn - save link
891
                 register, so we will be able to restore it when we will
892
                 step across delay slot insn */
893
              step_link_insn = 1;
894
              lr = or1k_read_spr_reg (REGNUM_TO_SPRNUM(9));
895
            }
896
        }
897
    }
898
  else
899
    {
900
      dmr1 &= ~DMR1_ST;
901
      or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
902
 
903
      if (new_pc_set)
904
        {
905
          debug("resume: 5\n");
906
          /* If new PC was set, then just set it again to fill the pipeline */
907
 
908
          step_link_insn = 0;
909
          or1k_write_spr_reg (PC_SPRNUM, pc);
910
        }
911
      else if (is_delayed (ppc_insn) && !breakpoint_here_p (ppc))
912
        {
913
          debug("resume: 6\n");
914
          /* If next insn is delay slot insn - set PC to previous branch insn
915
             and continue from there to refill the pipeline */
916
 
917
          if (insn_modifies_gprs (ppc_insn) && step_link_insn)
918
            {
919
              debug("resume: 14\n");
920
              /* If this is delay slot of jump an link insn that was
921
                 allready executed - restore link register first */
922
              or1k_write_spr_reg (REGNUM_TO_SPRNUM(9), lr);
923
              step_link_insn = 0;
924
            }
925
 
926
           or1k_write_spr_reg (PC_SPRNUM, ppc);
927
        }
928
      else if (is_delayed (ppc_insn) && breakpoint_here_p (ppc))
929
        {
930
          debug("resume: 7\n");
931
          /* If next insn is delay slot insn and previous branch insn
932
             is actually BP - replace BP with original branch insn, set PC
933
             to that insn step over it, put back BP and continue */
934
 
935
          or1k_write_mem(ppc, ppc_insn);
936
 
937
          dmr1 |= DMR1_ST;
938
          or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
939
          dmr1 &= ~DMR1_ST;
940
 
941
          or1k_write_spr_reg (PC_SPRNUM, ppc);
942
 
943
          if (insn_modifies_gprs (ppc_insn) && step_link_insn)
944
            {
945
              debug("resume: 15\n");
946
              /* If this is delay slot of jump an link insn that was
947
                 allready executed - restore link register first */
948
              or1k_write_spr_reg (REGNUM_TO_SPRNUM(9), lr);
949
              step_link_insn = 0;
950
            }
951
 
952
           or1k_unstall ();
953
 
954
          or1k_set_chain (SC_REGISTER);
955
          val = or1k_read_reg (JTAG_RISCOP);
956
          do {
957
            val = or1k_read_reg (JTAG_RISCOP);
958
          } while ((val & 1) == 0);
959
 
960
          or1k_write_mem(ppc, 0x21000001);
961
 
962
          or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
963
        }
964
      else
965
        {
966
          debug("resume: 8\n");
967
          /* Continue from 'non delay slot' insn - set PC to fill the pipeline */
968
 
969
          or1k_write_spr_reg (PC_SPRNUM, pc);
970
        }
971
    }
972
 
973
  /* Now we are in normal program flow again */
974
  new_pc_set = 0;
975
 
976
  /* We can now continue normally, independent of step */
977
  or1k_unstall ();
978
  or1k_status = TARGET_RUNNING;
979
  debug ("-resume %i, %i, %i\n",step, siggnal, or1k_status);
980
}
981
 
982
/* Wait until the remote stops, and return a wait status.  */
983
 
984
static ptid_t
985
or1k_wait (remote_ptid, status)
986
     ptid_t remote_ptid;
987
     struct target_waitstatus *status;
988
{
989
  unsigned long val;
990
  unsigned long pc;
991
  unsigned long ppc;
992
  char buf[MAX_REGISTER_RAW_SIZE];
993
  int pid;
994
 
995
  pid = remote_ptid.pid;
996
  debug ("wait %i %i\n", pid, or1k_status);
997
  /* If we have not sent a single step or continue command, then the
998
     board is waiting for us to do something.  Return a status
999
     indicating that it is stopped.  */
1000
  if (or1k_status != TARGET_RUNNING)
1001
    {
1002
      if (or1k_status != TARGET_STOPPED)
1003
        error("Target in invalid state.");
1004
      status->kind = TARGET_WAITKIND_STOPPED;
1005
      status->value.sig = TARGET_SIGNAL_TRAP;
1006
      return remote_ptid;
1007
    }
1008
 
1009
  if (err)
1010
    or1k_error ("Remote failure: %s", or1k_err_name (err));
1011
 
1012
  interrupt_count = 0;
1013
 
1014
  /* Set new signal handler */
1015
  ofunc = signal (SIGINT, or1k_interrupt);
1016
 
1017
  /* Wait for risc to stop.  */
1018
  do {
1019
    or1k_set_chain (SC_REGISTER);
1020
    val = or1k_read_reg (JTAG_RISCOP);
1021
 
1022
    /* When we press Ctrl-C, interrupt count is set, but we must wait
1023
         for or1k_read_reg to finish, otherwise we would interrupt transaction.  */
1024
    if (interrupt_count)
1025
      or1k_stop ();
1026
 
1027
    usleep (10);
1028 1248 hpanther
    debug ("%d", val);
1029 1183 sfurman
  } while ((val & 1) == 0);
1030
 
1031
  /* If we had an error, wait just a while, so user can press another ^C */
1032
  if (quit_flag)
1033
    sleep(1);
1034
 
1035
  drr = or1k_read_spr_reg (DRR_SPRNUM);
1036
 
1037
  /* Restore old INT signal handler */
1038
  signal (SIGINT, ofunc);
1039
 
1040
  /* Single step does not set trap exception, so we set it manually to simplify our code */
1041
  dmr1 = or1k_read_spr_reg (DMR1_SPRNUM);
1042
  if (dmr1 & DMR1_ST)
1043
    drr |= DRR_TE;
1044
 
1045
  status->kind = TARGET_WAITKIND_STOPPED;
1046
 
1047
  debug ("epcr0 = %08x\n", or1k_read_spr_reg (EPCR0_SPRNUM));
1048
  debug ("drr = %08x\n", drr);
1049
 
1050
  registers_changed ();
1051
  pc = read_pc ();
1052
  ppc = or1k_read_spr_reg (PPC_SPRNUM);
1053
  debug ("ppc = %08x\n", ppc);
1054
 
1055
  if (drr & DRR_TE)
1056
    {
1057
      /* If single step is not set, we should correct the pc.  */
1058
      if (!(dmr1 & DMR1_ST))
1059
        /* PC has already stepped over the l.trap instruction.  */
1060
        pc = ppc;
1061
      status->value.sig = TARGET_SIGNAL_TRAP;
1062
      drr &= ~DRR_TE;
1063
    }
1064
  else if (drr & DRR_RSTE)
1065
    {
1066
      status->value.sig = TARGET_SIGNAL_REALTIME_33;
1067
      drr &= ~DRR_RSTE;
1068
    }
1069
  else if (drr & DRR_BUSEE)
1070
    {
1071
      status->value.sig = TARGET_SIGNAL_BUS;
1072
      drr &= ~DRR_BUSEE;
1073
    }
1074
  else if (drr & DRR_AE)
1075
    {
1076
      status->value.sig = TARGET_SIGNAL_REALTIME_36;
1077
      drr &= ~DRR_AE;
1078
    }
1079
  else if (drr & DRR_IIE)
1080
    {
1081
      status->value.sig = TARGET_SIGNAL_ILL;
1082
      drr &= ~DRR_IIE;
1083
    }
1084
  else if (drr & DRR_RE)
1085
    {
1086
      status->value.sig = TARGET_SIGNAL_REALTIME_39;
1087
      drr &= ~DRR_RE;
1088
    }
1089
  else if (drr & DRR_IME)
1090
    {
1091
      status->value.sig = TARGET_SIGNAL_REALTIME_38;
1092
      drr &= ~DRR_IME;
1093
    }
1094
  else if (drr & DRR_DME)
1095
    {
1096
      status->value.sig = TARGET_SIGNAL_REALTIME_37;
1097
      drr &= ~DRR_DME;
1098
    }
1099
  else if (drr & DRR_DPFE)
1100
    {
1101
      status->value.sig = TARGET_SIGNAL_REALTIME_34;
1102
      drr &= ~DRR_DPFE;
1103
    }
1104
  else if (drr & DRR_IPFE)
1105
    {
1106
      status->value.sig = TARGET_SIGNAL_REALTIME_35;
1107
      drr &= ~DRR_DPFE;
1108
    }
1109
  else if (drr & DRR_SCE)
1110
    {
1111
      status->value.sig = TARGET_SIGNAL_REALTIME_40;
1112
      drr &= ~DRR_SCE;
1113
    }
1114
  else if (drr & DRR_HPINTE)
1115
    {
1116
      status->value.sig = TARGET_SIGNAL_INT;
1117
      drr &= ~DRR_HPINTE;
1118
    }
1119
  else if (drr & DRR_LPINTE)
1120
    {
1121
      status->value.sig = TARGET_SIGNAL_INT;
1122
      drr &= ~DRR_LPINTE;
1123
    }
1124
  else
1125
    {
1126
      status->value.sig = TARGET_SIGNAL_UNKNOWN;
1127
      warning ("Invalid exception occured.");
1128
    }
1129
 
1130
  /* Update drr register */
1131
  or1k_write_spr_reg (DRR_SPRNUM, drr);
1132
 
1133
  /* Write into PC flushes the pipeline! */
1134
  /* We got the number the register holds, but gdb expects to see a
1135
     value in the target byte ordering.  */
1136
/*  write_pc (pc);
1137
*/
1138
  store_unsigned_integer (buf, REGISTER_RAW_SIZE (PC_REGNUM), pc);
1139
  supply_register (PC_REGNUM, buf);
1140
 
1141
  hit_breakpoint = breakpoint_here_p (pc);
1142
 
1143
  /*or1k_write_spr_reg (PC_SPRNUM, pc);
1144
  store_unsigned_integer (buf, REGISTER_RAW_SIZE (PC_REGNUM), pc);
1145
  supply_register (PC_REGNUM, buf);*/
1146
 
1147
  /* Log remote stop.  */
1148
  or1k_status = TARGET_STOPPED;
1149
 
1150
  /* Determine what caused trap - breakpoint or watchpoint.  */
1151
  if (status->value.sig == TARGET_SIGNAL_TRAP)
1152
    {
1153
      /* Search all active breakpoints for a match.  */
1154
      CORE_ADDR pc = read_pc ();
1155
      int breakpoint = 0;
1156
      int i;
1157
      unsigned char break_bytes[4] = BRK_INSTR_STRUCT;
1158
      unsigned long b_insn = ntohl(*((unsigned long*)break_bytes));
1159
      unsigned long value = pc;
1160
 
1161
      for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
1162
        if (dvr[i] == pc && dcr[i].dp && dcr[i].cc == CC_EQUAL
1163
            && !dcr[i].sc && dcr[i].ct == CT_FETCH)
1164
          {
1165
            breakpoint = 1;
1166
            break;
1167
          }
1168
      hit_watchpoint = !breakpoint;
1169
 
1170
      /* Cause the trap/breakpoint exception to be ignored. This is
1171
         the behavior of the simulator when the PC value is changed
1172
         by a write command. All pending exceptions are cleared and
1173
         the simulator continues at the PC value specified. We need
1174
         to do this if the instruction at the current PC has the
1175
         value BRK_INSTR_STRUCT */
1176
 
1177
      if(b_insn == or1k_read_mem((pc & 3)))
1178
        {
1179
          or1k_write_spr_reg(PC_SPRNUM,value);
1180
        }
1181
    }
1182
  else
1183
    hit_watchpoint = 0;
1184
 
1185
  /* If the stop PC is in the _exit function, assume
1186
     we hit the 'break 0x3ff' instruction in _exit, so this
1187
     is not a normal breakpoint.  */
1188
  {
1189
    char *func_name;
1190
    CORE_ADDR func_start;
1191
    CORE_ADDR pc = read_pc ();
1192
 
1193
    find_pc_partial_function (pc, &func_name, &func_start, NULL);
1194
    if (func_name != NULL && strcmp (func_name, "_exit") == 0
1195
        && func_start == pc)
1196
      status->kind = TARGET_WAITKIND_EXITED;
1197
  }
1198
 
1199
  or1k_read_trace ();
1200
  debug ("-wait %i %i\n", pid, or1k_status);
1201
  return remote_ptid;
1202
}
1203
 
1204
/* Fetch a word from the target board.  All memory accesses to the
1205
   remote board are word aligned.  */
1206
 
1207
unsigned int
1208
or1k_fetch_word (addr)
1209
     CORE_ADDR addr;
1210
{
1211
  if (addr & 3)
1212
    {
1213
      int subaddr = addr & 3;
1214
      unsigned char buf[8];
1215
      unsigned int low, high;
1216
      addr >>= 2;
1217
      low = or1k_read_mem (addr << 2);
1218
      high = or1k_read_reg ((addr + 1) << 2);
1219
      memcpy (&buf[0], &low, 4);
1220
      memcpy (&buf[4], &high, 4);
1221
      memcpy (&low, &buf[subaddr], 4);
1222
      return low;
1223
    }
1224
  else
1225
    {
1226
      return or1k_read_mem (addr);
1227
    }
1228
}
1229
 
1230
/* Store a word to the target board.  Returns errno code or zero for
1231
   success.  All memory accesses to the remote board are word aligned.  */
1232
 
1233
static int
1234
or1k_store_word (addr, val)
1235
     CORE_ADDR addr;
1236
     unsigned int val;
1237
{
1238
  if (addr & 3)
1239
    {
1240
      int subaddr = addr & 3;
1241
      unsigned char buf[8];
1242
      unsigned int low, high;
1243
      addr >>= 2;
1244
      low = or1k_read_mem (addr << 2);
1245
      high = or1k_read_mem ((addr + 1) << 2);
1246
      memcpy (&buf[0], &low, 4);
1247
      memcpy (&buf[4], &high, 4);
1248
      memcpy (&buf[subaddr], &val, 4);
1249
      memcpy (&low, &buf[0], 4);
1250
      memcpy (&high, &buf[4], 4);
1251
      or1k_write_mem (addr << 2, low);
1252
      or1k_write_mem ((addr + 1) << 2, high);
1253
    }
1254
  else
1255
    {
1256
      or1k_write_mem (addr, val);
1257
    }
1258
  return err;
1259
}
1260
 
1261
/* Fetch the remote registers.  */
1262
 
1263
void
1264
or1k_fetch_registers (regno)
1265
     int regno;
1266
{
1267
  unsigned int val;
1268
 
1269
  if (regno == -1)
1270
    {
1271
      for (regno = 0; regno < NUM_REGS; regno++)
1272
        or1k_fetch_registers (regno);
1273
      return;
1274
    }
1275
 
1276
  if (regno >= NUM_REGS)
1277
    error("Invalid register number!");
1278
 
1279
  /* Convert to SPRNUM and read.  */
1280
  val = or1k_read_spr_reg (REGNUM_TO_SPRNUM(regno));
1281
 
1282
  {
1283
    char buf[MAX_REGISTER_RAW_SIZE];
1284
 
1285
    /* We got the number the register holds, but gdb expects to see a
1286
       value in the target byte ordering.  */
1287
    store_unsigned_integer (buf, REGISTER_RAW_SIZE (regno), val);
1288
    supply_register (regno, buf);
1289
  }
1290
  if (err)
1291
    or1k_error ("Can't read register %d(%i): %s", regno,
1292
                REGNUM_TO_SPRNUM(regno), or1k_err_name (err));
1293
}
1294
 
1295
/* Fetch and return instruction from the specified location.  */
1296
 
1297
unsigned int
1298
or1k_fetch_instruction (addr)
1299
     CORE_ADDR addr;
1300
{
1301
  char buf[OR1K_INSTLEN];
1302
  int status;
1303
 
1304
  status = read_memory_nobpt (addr, buf, OR1K_INSTLEN);
1305
  if (status)
1306
    memory_error (status, addr);
1307
  return extract_unsigned_integer (buf, OR1K_INSTLEN);
1308
}
1309
 
1310
/* Currently not needed.  */
1311
 
1312
static void
1313
or1k_prepare_to_store ()
1314
{
1315
}
1316
 
1317
/* Store remote register(s).  */
1318
 
1319
static void
1320
or1k_store_registers (regno)
1321
     int regno;
1322
{
1323
  if (regno == -1)
1324
    {
1325
      for (regno = 0; regno < NUM_REGS; regno++)
1326
        or1k_store_registers (regno);
1327
      return;
1328
    }
1329
 
1330
  if (regno >= NUM_REGS)
1331
    error("Invalid register number!");
1332
 
1333
  or1k_write_spr_reg (REGNUM_TO_SPRNUM(regno), read_register (regno));
1334
  if (err)
1335
    or1k_error ("Can't write register %d(%i): %s", regno, REGNUM_TO_SPRNUM(regno), or1k_err_name (err));
1336
}
1337
 
1338
/* Read or write LEN bytes from inferior memory at MEMADDR,
1339
   transferring to or from debugger address MYADDR.  Write to inferior
1340
   if SHOULD_WRITE is nonzero.  Returns length of data written or
1341
   read; 0 for error.  Note that protocol gives us the correct value
1342
   for a longword, since it transfers values in ASCII.  We want the
1343
   byte values, so we have to swap the longword values.  */
1344
 
1345 1248 hpanther
static int or1k_load_block(CORE_ADDR addr,void* buffer,int nRegisters);
1346
 
1347 1183 sfurman
static int
1348
or1k_xfer_memory (memaddr, myaddr, len, write, ignore)
1349
     CORE_ADDR memaddr;
1350
     char *myaddr;
1351
     int len;
1352
     int write;
1353
     struct target_ops *ignore;
1354
{
1355
  register int i;
1356
  /* Round starting address down to longword boundary.  */
1357
  register CORE_ADDR addr = memaddr & ~3;
1358
  /* Round ending address up; get number of longwords that makes.  */
1359
  register int count = (((memaddr + len) - addr) + 3) / 4;
1360
  /* Allocate buffer of that many longwords.  */
1361
  register char *buffer = alloca (count * 4);
1362
  int status;
1363
 
1364
  int block_xfer_size = 256; /* CZ 21/06/01 ... number of 32 bit words */
1365
  int nBlocks = (count + block_xfer_size -1)/block_xfer_size;
1366
  int terminate = 0;  /* Terminate the printing of '*'s... */
1367
 
1368
#ifdef DEBUG_JTAG
1369
  debug ("xfer_memory %s addr=%x, len=%i, \n", write?"write":"read", memaddr, len);
1370
  fflush(stdout);
1371
#endif
1372
 
1373
#if 0
1374
  if (memaddr >= MEM_SPACE)
1375
    error("Invalid address");
1376
#endif
1377
 
1378
  /* (CZ 21/06/01 -- because upper layers which know nothing about
1379
     Or1k or JTAG call this function directly, it is always necessary
1380
     to set the chain to point to the Debug Unit. Otherwise, it may
1381
     be pointing to the Development Interface chain, in which case
1382
     we're going to get bupkiss... */
1383
 
1384
  if (write)
1385
    {
1386
      /* Fill start and end extra bytes of buffer with existing data.  */
1387
      if (addr != memaddr || len < 4)
1388
        {
1389
          /* Need part of initial word -- fetch it.  */
1390
          store_unsigned_integer (&buffer[0], 4, or1k_fetch_word (addr));
1391
        }
1392
 
1393
      if (count > 1)
1394
        {
1395
          /* Need part of last word -- fetch it.  FIXME: we do this even
1396
             if we don't need it.  */
1397
          store_unsigned_integer (&buffer[(count - 1) * 4], 4,
1398
                                  or1k_fetch_word (addr + (count - 1) * 4));
1399
        }
1400
 
1401
      /* Copy data to be written over corresponding part of buffer */
1402
      memcpy ((char *) buffer + (memaddr & 3), myaddr, len);
1403
 
1404
      /* CZ: rewrote the block transfer routines to make the code
1405
         a little more efficient for implementations that can handle
1406
         variable sized scan chains. Might be useful in the future.
1407
         Certainly makes downloads to the simulator more efficient. */
1408
      for(i=0;i<nBlocks;i++,count-=block_xfer_size,addr += block_xfer_size*4)
1409
        {
1410
          int j;
1411
          int n = count < block_xfer_size ? count : block_xfer_size;
1412
          unsigned long *__buf;
1413
 
1414
          if(!(__buf = (unsigned long*)malloc(n*sizeof(unsigned long))))
1415
            {
1416
              errno = ERR_MEM;
1417
              return 0;
1418
            }
1419
 
1420
          for(j=0;j<n;j++)
1421
            __buf[j] = (unsigned long)extract_unsigned_integer(&buffer[(i * block_xfer_size +j)*4], 4);
1422
          or1k_set_chain (SC_WISHBONE);
1423
          status = or1k_store_block(addr,__buf,n);
1424
          free(__buf);
1425
          if(n == block_xfer_size)
1426
            {
1427
              debug ("*");
1428
              gdb_flush (gdb_stdout);
1429
            }
1430
          if (status)
1431
            {
1432
              errno = status;
1433
              return 0;
1434
            }
1435
          /* FIXME: Do we want a QUIT here?  */
1436
        }
1437
      if (terminate)
1438
        debug ("\n");
1439
    }
1440
  else
1441
    {
1442
      for(i=0;i<nBlocks;i++,count-=block_xfer_size,addr += block_xfer_size*4)
1443
        {
1444
          int j;
1445
          int n = count < block_xfer_size ? count : block_xfer_size;
1446
          unsigned long *__buf;
1447
 
1448
    or1k_set_chain (SC_WISHBONE);
1449
          __buf = (unsigned long*)malloc(n*sizeof(unsigned long));
1450
          status = or1k_load_block(addr,__buf,n);
1451
          if (!status)
1452
            for(j=0;j<n;j++)
1453
              store_unsigned_integer (&buffer[(i * block_xfer_size +j)*4], 4, __buf[j]);
1454
          else
1455
            errno = status;
1456
          free(__buf);
1457
 
1458
          if(status)
1459
            return 0;
1460
        }
1461
      /* Copy appropriate bytes out of the buffer.  */
1462
      memcpy (myaddr, buffer + (memaddr & 3), len);
1463
    }
1464
  return len;
1465
}
1466
 
1467
int or1k_load_block(CORE_ADDR addr,void* buffer,int nRegisters)
1468
{
1469
  int i=0;
1470
  unsigned int regno = addr;
1471
 
1472
  if (current_or1k_target != NULL && current_or1k_target->to_read_block != NULL)
1473
    return current_or1k_target->to_read_block (regno,buffer,nRegisters);
1474
  else
1475
    for(i=0;i<nRegisters;i++)
1476
      ((unsigned long*)buffer)[i] = 0x1234;
1477
  return 0;
1478
}
1479
 
1480
int or1k_store_block(CORE_ADDR addr,void* buffer,int nRegisters)
1481
{
1482
  unsigned int regno = addr;
1483
 
1484
  if (current_or1k_target != NULL && current_or1k_target->to_write_block != NULL)
1485
    return current_or1k_target->to_write_block (regno,buffer,nRegisters);
1486
  return 0;
1487
}
1488
 
1489
/* Print info on this target.  */
1490
 
1491
static void
1492
or1k_files_info (ignore)
1493
     struct target_ops *ignore;
1494
{
1495
  char *file = "nothing";
1496
 
1497
  if (exec_bfd)
1498
    file = bfd_get_filename (exec_bfd);
1499
 
1500
  printf_filtered ("or1k_files_info: file \"%s\"\n", file);
1501
 
1502
  if (exec_bfd)
1503
    {
1504
      printf_filtered ("\tAttached to %s running program %s\n",
1505
                       target_shortname, file);
1506
    }
1507
  /* Print target info. */
1508
  printf_filtered ("Status: %s\n", status_name[or1k_status]);
1509
}
1510
 
1511
/* Tell whether we can support a hardware breakpoint.  */
1512
 
1513
static int
1514
or1k_can_use_hardware_breakpoint ()
1515
{
1516
  int i;
1517
 
1518
  /* Search for unused breakpoint.  */
1519
  return or1k_implementation.num_used_matchpoints < or1k_implementation.num_matchpoints;
1520
}
1521
 
1522
/* Insert a breakpoint.  On targets that don't have built-in breakpoint
1523
   support, we read the contents of the target location and stash it,
1524
   then overwrite it with a breakpoint instruction.  ADDR is the target
1525
   location in the target machine.  CONTENTS_CACHE is a pointer to
1526
   memory allocated for saving the target contents.  It is guaranteed
1527
   by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1528
   is accomplished via BREAKPOINT_MAX).  */
1529
 
1530 1248 hpanther
static int set_breakpoint (CORE_ADDR addr);
1531
 
1532 1183 sfurman
int
1533
or1k_insert_breakpoint (addr, contents_cache)
1534
     CORE_ADDR addr;
1535
     char *contents_cache;
1536
{
1537
  if (or1k_can_use_hardware_breakpoint())
1538
    return set_breakpoint (addr);
1539
  else
1540
    return memory_insert_breakpoint (addr, contents_cache);
1541
}
1542
 
1543
int
1544
or1k_remove_breakpoint (addr, contents_cache)
1545
     CORE_ADDR addr;
1546
     char *contents_cache;
1547
{
1548
  /* First try to remove HW breakpoint at address */
1549
  if (clear_breakpoint (addr))
1550
    return memory_remove_breakpoint (addr, contents_cache);
1551
  else
1552
    return 0;
1553
}
1554
 
1555
/* Tell whether this target can support a hardware breakpoint.  CNT
1556
   is the number of hardware breakpoints already installed.  This
1557
   implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro.
1558
   Lower bound is estimated. !!! Can we estimate better? */
1559
 
1560
int
1561
or1k_can_use_hardware_watchpoint (bp_type, cnt)
1562
     enum bptype bp_type;
1563
     int cnt;
1564
{
1565 1248 hpanther
#if 0
1566
        // We can't rely on or1k_implementation.num_matchpoints, since that is only valid
1567
        // with JTAG. This function must work with remote gdbstub too, and the default
1568
        // remote handler does not know how many matchpoints there are.
1569 1183 sfurman
  /* Are there at least two matchpoints left for watch? - estimate lower bound  */
1570
  return cnt + ((bp_type == bp_hardware_watchpoint)?(1):(0))
1571
    <= or1k_implementation.num_matchpoints;
1572 1248 hpanther
#endif
1573
        if (cnt <= OR1K_MAX_MATCHPOINTS)
1574
                return 1;
1575
        else
1576
                return -1;
1577 1183 sfurman
}
1578
 
1579
/* Moves matchpoint.  This is very tricky - we have to update
1580
   all references to matchpoint indexes.  We assume here that
1581
   matchpoint with index to is unused! */
1582
 
1583
static void
1584
move_matchpoint (int from, int to)
1585
{
1586
  int i, j, tmp, chaining;
1587
  if (matchpoint_user_count[to] != 0)
1588
    error ("Internal: Destination matchpoint still has users");
1589
  matchpoint_user_count[to] = matchpoint_user_count[from];
1590
  matchpoint_user_count[from] = 0;
1591
  debug_regs_changed = 1;
1592
 
1593
  dvr[to] = dvr[from];
1594
  dcr[to] = dcr[from];
1595
  dcr[from].dp = 0;
1596
 
1597
  /* Copy chaining bits.  */
1598
  chaining = dmr1 & (3 << (2 * from));
1599
  dmr1 &= ~(3 << (2 * to));
1600
  dmr1 |= chaining << (2 * to);
1601
  dmr1 &= ~(3 << (2 * from));
1602
 
1603
  /* Copy watchpoint bits */
1604
  tmp = dmr2 & (1 << from);
1605
  dmr2 &= 1 << to;
1606
  dmr2 |= tmp << to;
1607
  dmr2 &= 1 << from;
1608
 
1609
  /* Update hwatch table.  Here we assume that matchpoint
1610
     group is connected (it cannot be implemented in HW
1611
     otherwise), so if we move first, we will have to move
1612
     others later.  */
1613
  for (i = 0; i < num_hw_watches; i++)
1614
    if (or1k_hwatch[i].matchpoint_start == from)
1615
      or1k_hwatch[i].matchpoint_start = to;
1616
 
1617
  /* Update htrace struct.  */
1618
  tmp = or1k_htrace.trig.wp_trig & (1 << from);
1619
  or1k_htrace.trig.wp_trig &= 1 << to;
1620
  or1k_htrace.trig.wp_trig |= tmp << to;
1621
  or1k_htrace.trig.wp_trig &= 1 << from;
1622
 
1623
  tmp = or1k_htrace.qual.wp_trig & (1 << from);
1624
  or1k_htrace.qual.wp_trig &= 1 << to;
1625
  or1k_htrace.qual.wp_trig |= tmp << to;
1626
  or1k_htrace.qual.wp_trig &= 1 << from;
1627
 
1628
  tmp = or1k_htrace.stop.wp_trig & (1 << from);
1629
  or1k_htrace.stop.wp_trig &= 1 << to;
1630
  or1k_htrace.stop.wp_trig |= tmp << to;
1631
  or1k_htrace.stop.wp_trig &= 1 << from;
1632
 
1633
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1634
    {
1635
      tmp = or1k_htrace.wp_record_uses[i] & (1 << from);
1636
      or1k_htrace.wp_record_uses[i] &= 1 << to;
1637
      or1k_htrace.wp_record_uses[i] |= tmp << to;
1638
      or1k_htrace.wp_record_uses[i] &= 1 << from;
1639
    }
1640
 
1641
  /* Do we need to move other references also? */
1642
}
1643
 
1644
/* Sifts unused matchpoints to higher indexses.  */
1645
 
1646
void
1647
sift_matchpoints ()
1648
{
1649
  int i, first_free = 0;
1650
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1651
    if (dcr[i].dp)
1652
      {
1653
        /* Move references.  */
1654
        move_matchpoint (i, first_free);
1655
 
1656
        first_free++;
1657
      }
1658
 
1659
  /* Unused matchpoints should be disabled by move_matchpoint,
1660
     so we are done here.  */
1661
}
1662
 
1663
/* Translates gdb watchpoint type into one in DCR register.  */
1664
 
1665
static int
1666
translate_type (gdb_type)
1667
     int gdb_type;
1668
{
1669
  switch (gdb_type)
1670
    {
1671
    case 0:
1672
      return CT_SDATA;
1673
    case 1:
1674
      return CT_LDATA;
1675
    case 2:
1676
      return CT_ADATA;
1677
    default:
1678
      error ("Invalid type.");
1679
    }
1680
}
1681
 
1682
/* Set a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1683
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1684
   watchpoint. */
1685
 
1686
int
1687
or1k_insert_watchpoint (addr, len, type)
1688
     CORE_ADDR addr;
1689
     int len;
1690
     int type;
1691
{
1692
  int i;
1693
 
1694
  if (len < 1)
1695
    return -1;
1696
 
1697
  type = translate_type (type);
1698
 
1699
  /* Moves unused watchpoints to the top.  */
1700
  sift_matchpoints ();
1701
 
1702
  /* Place at first free matchpoint.  */
1703
  i = or1k_implementation.num_used_matchpoints;
1704
  dvr[i] = addr;
1705
  dcr[i].dp = 1;
1706
  dcr[i].cc = CC_GREATE;
1707
  dcr[i].sc = 0;
1708
  dcr[i].ct = type;
1709
 
1710
  /* Set && chaining here.  */
1711
  dmr1 &= ~(3 << (2 * i));
1712
  dmr1 |= CHAINING_AND << (2 * i);
1713
 
1714
  /* Set upper watchpoint bound.  */
1715
  i++;
1716
  dvr[i] = addr + len - 1;
1717
  dcr[i].dp = 1;
1718
  dcr[i].cc = CC_LESSE;
1719
  dcr[i].sc = 0;
1720
  dcr[i].ct = type;
1721
 
1722
  /* Matchpoints will cause breakpoints */
1723
  dmr2 |= (1 << i);
1724
  or1k_implementation.num_used_matchpoints += 2;
1725
  debug_regs_changed = 1;
1726
  return 0;
1727
}
1728
 
1729
/* Removes a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1730
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1731
   watchpoint. */
1732
 
1733
int
1734
or1k_remove_watchpoint (addr, len, type)
1735
     CORE_ADDR addr;
1736
     int len;
1737
     int type;
1738
{
1739
  int i, found = -1;
1740
 
1741
  if (len < 1)
1742
    return -1;
1743
 
1744
  type = translate_type (type);
1745
 
1746
  /* Find the right one.  */
1747
  for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
1748
    if (dvr[i] == addr && dcr[i].dp && dcr[i].cc == CC_GREATE && !dcr[i].sc && dcr[i].ct == type
1749
        && dvr[i + 1] == addr + len - 1 && dcr[i + 1].dp && dcr[i + 1].cc == CC_LESSE
1750
        && !dcr[i + 1].sc && dcr[i + 1].ct == type)
1751
      {
1752
        found = i;
1753
        break;
1754
      }
1755
 
1756
  if (found < 0)
1757
    return -1;
1758
 
1759
  dcr[found].dp = 0;
1760
  dcr[found + 1].dp = 0;
1761
 
1762
  /* Matchpoints will not cause breakpoints anymore. */
1763
  dmr2 &= ~(1 << i);
1764
  or1k_implementation.num_used_matchpoints -= 2;
1765
  debug_regs_changed = 1;
1766
  return 0;
1767
}
1768
 
1769
int
1770
or1k_stopped_by_watchpoint (void)
1771
{
1772
  /* For now, no watchpoints */
1773
  return 0;
1774
 
1775
  /* return hit_watchpoint; */
1776
}
1777
 
1778
/* Insert a breakpoint.  */
1779
 
1780
int
1781
set_breakpoint (addr)
1782
     CORE_ADDR addr;
1783
{
1784
  int i;
1785
 
1786
  /* Search for unused breakpoint.  */
1787
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1788
    if (dcr[i].dp == 0) break;
1789
  if (i >= NUM_MATCHPOINTS) return 1;
1790
  dvr[i] = addr;
1791
  dcr[i].dp = 1;
1792
  dcr[i].cc = CC_EQUAL;
1793
  dcr[i].sc = 0;
1794
  dcr[i].ct = CT_FETCH;
1795
  or1k_implementation.num_used_matchpoints++;
1796
 
1797
  /* No chaining here.  */
1798
  dmr1 &= ~(3 << (2*i));
1799
 
1800
  /* Matchpoints will cause breakpoints */
1801
  dmr2 |= (1 << i);
1802
  debug_regs_changed = 1;
1803
  return 0;
1804
}
1805
 
1806
/* Clear a breakpoint.  */
1807
 
1808
int
1809
clear_breakpoint (addr)
1810
     CORE_ADDR addr;
1811
{
1812
  int i;
1813
 
1814
  /* Search for matching breakpoint.  */
1815
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1816
    if ((dcr[i].dp == 1) && (dvr[i] == addr) && (dcr[i].cc == CC_EQUAL)
1817
        && (dcr[i].sc == 0) && (dcr[i].ct == CT_FETCH)) break;
1818
 
1819
  if (i >= NUM_MATCHPOINTS) return 1;
1820
  dcr[i].dp = 0;
1821
 
1822
  /* Matchpoints will cause breakpoints */
1823
  dmr2 &= ~(1 << i);
1824
  or1k_implementation.num_used_matchpoints--;
1825
  debug_regs_changed = 1;
1826
  return 0;
1827
}
1828
 
1829
/* Start running on the target board.  */
1830
 
1831
static void
1832
or1k_create_inferior (execfile, args, env)
1833
     char *execfile;
1834
     char *args;
1835
     char **env;
1836
{
1837
  CORE_ADDR entry_pt;
1838
 
1839
  if (args && *args)
1840
    {
1841
      warning ("Can't pass arguments to remote OR1K board; arguments ignored.");
1842
 
1843
      /* And don't try to use them on the next "run" command.  */
1844
      execute_command ("set args", 0);
1845
    }
1846
 
1847
  if (execfile == 0 || exec_bfd == 0)
1848
    error ("No executable file specified");
1849
 
1850
  or1k_kill ();
1851
  remove_breakpoints ();
1852
 
1853
  entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
1854
  init_wait_for_inferior ();
1855
 
1856
  /* FIXME: Should we set inferior_pid here?  */
1857
 
1858
  /* Needed to get correct instruction in cache */
1859
  insert_breakpoints ();
1860
  clear_proceed_status ();
1861
  or1k_status = TARGET_STOPPED;
1862
  proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
1863
}
1864
 
1865
/* Clean up after a process.  Actually nothing to do.  */
1866
 
1867
static void
1868
or1k_mourn_inferior ()
1869
{
1870
  generic_mourn_inferior ();
1871
}
1872
 
1873
static void
1874
or1k_dummy_open (name, from_tty)
1875
     char *name;
1876
     int from_tty;
1877
{
1878
  target_preopen (from_tty);
1879
  if (or1k_is_open)
1880
    unpush_target (current_ops);
1881
  current_or1k_target = &or1k_target_dummy;
1882
  or1k_open (name, from_tty);
1883
}
1884
 
1885
static void
1886
or1k_jtag_open (name, from_tty)
1887
     char *name;
1888
     int from_tty;
1889
{
1890
  target_preopen (from_tty);
1891
  if (or1k_is_open)
1892
    unpush_target (current_ops);
1893
  current_or1k_target = &or1k_target_jtag;
1894
  or1k_open (name, from_tty);
1895
}
1896
 
1897
static void
1898
or1k_sim_open (name, from_tty)
1899
     char *name;
1900
     int from_tty;
1901
{
1902
  /* target_preopen (from_tty); - do we need this ? */
1903
  if (or1k_is_open)
1904
    unpush_target (current_ops);
1905
  current_or1k_target = &or1k_target_sim;
1906
  or1k_open (name, from_tty);
1907
}
1908
 
1909
/* Executes command on the target.  */
1910
 
1911
void
1912
or1k_sim_cmd (char *args, int from_tty)
1913
{
1914
  if (current_or1k_target != NULL && current_or1k_target->to_exec_command != NULL)
1915
    current_or1k_target->to_exec_command (args, from_tty);
1916
  else
1917
    error ("Command not supported on this target. ");
1918
}
1919
 
1920
/* Displays matchpoints usage.  */
1921
 
1922
void
1923
info_matchpoints_command (char *args, int from_tty)
1924
{
1925
  int i;
1926
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1927
    {
1928
      printf_filtered ("WP%i ", i);
1929
      if (dcr[i].dp)
1930
        {
1931
          int chaining = (dmr1 << 2*i) & 3;
1932
          printf_filtered ("= %s ", ct_names[dcr[i].ct]);
1933
          if (dcr[i]. sc)
1934
            printf_filtered ("s%s %i", cc_names[dcr[i].cc], (int)dvr[i]);
1935
          else
1936
            printf_filtered ("%s %u", cc_names[dcr[i].cc], (unsigned int)dvr[i]);
1937
          if (chaining)
1938
            printf_filtered ("%s WP%i", ch_names[chaining], i - 1);
1939
        }
1940
      else
1941
        printf_filtered ("NOT USED");
1942
      if ((dmr2 >> i) & 1)
1943
        printf_filtered (", causes breakpoint");
1944
      if ((dmr2 >> (i + 11)) & 1)
1945
        printf_filtered (", increments counter");
1946
      printf_filtered ("\n");
1947
    }
1948
}
1949
 
1950
static int
1951
insn_modifies_gprs(unsigned int insn)
1952
{
1953
  /* l.jal */
1954
  if ((insn >> 26) == 0x01)
1955
    return 1;
1956
 
1957
  /* l.jalr */
1958
  if ((insn >> 26) == 0x12)
1959
    return 1;
1960
 
1961
  return 0;
1962
}
1963
 
1964
void
1965
_initialize_remote_or1k ()
1966
{
1967
  /* Initialize the fields in or1k_ops that are common to all targets.  */
1968
  or1k_dummy_ops.to_close = or1k_close;
1969
  or1k_dummy_ops.to_detach = or1k_detach;
1970
  or1k_dummy_ops.to_resume = or1k_resume;
1971
  or1k_dummy_ops.to_wait = or1k_wait;
1972
  or1k_dummy_ops.to_fetch_registers = or1k_fetch_registers;
1973
  or1k_dummy_ops.to_store_registers = or1k_store_registers;
1974
  or1k_dummy_ops.to_prepare_to_store = or1k_prepare_to_store;
1975
  or1k_dummy_ops.to_xfer_memory = or1k_xfer_memory;
1976
  or1k_dummy_ops.to_files_info = or1k_files_info;
1977
  or1k_dummy_ops.to_insert_breakpoint = or1k_insert_breakpoint;
1978
  or1k_dummy_ops.to_remove_breakpoint = or1k_remove_breakpoint;
1979 1248 hpanther
  or1k_dummy_ops.to_insert_hw_breakpoint = or1k_insert_breakpoint;
1980
  or1k_dummy_ops.to_remove_hw_breakpoint = or1k_remove_breakpoint;
1981
  or1k_dummy_ops.to_insert_watchpoint = or1k_insert_watchpoint;
1982
  or1k_dummy_ops.to_remove_watchpoint = or1k_remove_watchpoint;
1983
  or1k_dummy_ops.to_stopped_by_watchpoint = or1k_stopped_by_watchpoint;
1984 1183 sfurman
  or1k_dummy_ops.to_kill = or1k_kill;
1985
  or1k_dummy_ops.to_load = generic_load;
1986
  or1k_dummy_ops.to_create_inferior = or1k_create_inferior;
1987
  or1k_dummy_ops.to_mourn_inferior = or1k_mourn_inferior;
1988
  or1k_dummy_ops.to_stratum = process_stratum;
1989
  or1k_dummy_ops.to_stop = or1k_stop;
1990
 
1991
  /* We can access memory while program is running.  */
1992
  or1k_dummy_ops.to_has_all_memory = 0;
1993
 
1994
  or1k_dummy_ops.to_has_memory = 1;
1995
  or1k_dummy_ops.to_has_stack = 1;
1996
  or1k_dummy_ops.to_has_registers = 1;
1997
  or1k_dummy_ops.to_has_execution = 1;
1998
  or1k_dummy_ops.to_magic = OPS_MAGIC;
1999
 
2000
  /* Copy the common fields to all target vectors.  */
2001
  or1k_jtag_ops = or1k_sim_ops = or1k_dummy_ops;
2002
 
2003
  /* Initialize target-specific fields in the target vectors adn add targets.  */
2004
  or1k_jtag_ops.to_shortname = "jtag";
2005
  or1k_jtag_ops.to_longname = "Remote or1k debugging over JTAG port";
2006
  or1k_jtag_ops.to_doc = "Debug a board using the OR1K remote debugging protocol"
2007
    " over a parallel line.\nThe argument is the parallel port it is connected "
2008
    "to, or, if it is formatted\nas a URL of the form jtag://<hostname>:<port>,"
2009
    " then the argument refers to\na remote JTAG proxy server.\n";
2010
  or1k_jtag_ops.to_open = or1k_jtag_open;
2011
  add_target (&or1k_jtag_ops);
2012
 
2013
  or1k_dummy_ops.to_shortname = "dummy";
2014
  or1k_dummy_ops.to_longname = "Dummy target";
2015
  or1k_dummy_ops.to_doc = "Actually no real target attached - more like /dev/null.\n";
2016
  or1k_dummy_ops.to_open = or1k_dummy_open;
2017
  add_target (&or1k_dummy_ops);
2018
 
2019
  or1k_sim_ops.to_shortname = "sim";
2020
  or1k_sim_ops.to_longname = "Remote or1k debugging using architecture simulator";
2021
  or1k_sim_ops.to_doc = "Debug using an architecture simulator.\n";
2022
  or1k_sim_ops.to_open = or1k_sim_open;
2023
  add_target (&or1k_sim_ops);
2024
  add_info ("matchpoints", info_matchpoints_command, "Show current matchpoints allocation status.");
2025
}

powered by: WebSVN 2.1.0

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