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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [remote-or1k.c] - Blame information for rev 135

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

Line No. Rev Author Line
1 106 markom
/* Remote debugging interface for various or1k debugging protocols.
2 118 markom
   Currently supported or1k targets are: simulator, jtag, dummy.
3
 
4 106 markom
   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
 
37
#include <signal.h>
38
#include <sys/types.h>
39
#include <sys/stat.h>
40
#include <sys/ioctl.h>
41
#include <fcntl.h>
42
 
43 125 chris
/* The following prototype is necessary or the compiler will not
44
   correctly promote the data argument to ULONGEST */
45
static void or1k_write_reg (unsigned int, ULONGEST);
46
 
47 118 markom
/* JTAG or1k target ops.  */
48 106 markom
extern void jtag_init PARAMS ((char * args));
49 122 markom
extern ULONGEST jtag_read_reg PARAMS ((unsigned int regno));
50
extern void jtag_write_reg PARAMS ((unsigned int regno, ULONGEST data));
51 106 markom
extern void jtag_done PARAMS ((void));
52 113 markom
extern void jtag_set_chain PARAMS ((int chain));
53 106 markom
struct target_ops or1k_jtag_ops;
54
static struct or1k_target_ops or1k_target_jtag =
55
  {
56
    "jtag",
57
    jtag_init,
58
    jtag_done,
59
    jtag_read_reg,
60
    jtag_write_reg,
61 113 markom
    jtag_set_chain,
62 106 markom
    NULL,
63
    &or1k_jtag_ops,
64
    OPS_MAGIC
65
  };
66
 
67 118 markom
/* simulator or1k target ops.  */
68 106 markom
struct target_ops or1k_sim_ops;
69
static struct or1k_target_ops or1k_target_sim =
70
  {
71
    "simulator",
72
    NULL,
73
    NULL,
74
    NULL,
75
    NULL,
76
    NULL,
77
    NULL,
78
    &or1k_sim_ops,
79
    OPS_MAGIC
80
  };
81
 
82 118 markom
/* dummy or1k target ops.  */
83 106 markom
struct target_ops or1k_dummy_ops;
84
static struct or1k_target_ops or1k_target_dummy =
85
  {
86
    "dummy",
87
    NULL,
88
    NULL,
89
    NULL,
90
    NULL,
91
    NULL,
92
    NULL,
93
    &or1k_dummy_ops,
94
    OPS_MAGIC
95
  };
96
 
97
const char *str_err[] =
98
  {
99
    "None", "CRC error"
100
  };
101
 
102
const char *status_name[] =
103
  {
104
    "UNDEFINED", "CONNECTING", "DISCONNECTING", "RUNNING", "STOPPED"
105
  };
106
 
107 113 markom
/* Names for matchpoint related stuff.  */
108
static char *ct_names[] =
109
  {
110
    "DIS", "IFEA", "LEA", "SEA", "AEA", "LDATA", "SDATA", "ADATA"
111
  };
112
 
113
static char *cc_names[] =
114
  {
115
    "&", "==", "<", "<=", ">", ">=", "!=", "ERR"
116
  };
117
 
118
static char *ch_names[] =
119
  {
120
    "ERR", "&", "|", "ERR"
121
  };
122
 
123 106 markom
/* Implementation specific information.  Set by or1k_initialize.  */
124
struct struct_or1k_implementation or1k_implementation;
125
 
126
/* Current target status.  */
127
static enum target_status or1k_status = TARGET_UNDEFINED;
128
 
129
/* The target vector.  */
130
struct target_ops or1k_dummy_ops, or1k_jtag_ops, or1k_sim_ops;
131
 
132
/* Currently active target description (if or1k_is_open == 1) */
133
static struct target_ops *current_ops;
134
 
135
/* Currently active or1k target operations.  */
136
static struct or1k_target_ops *current_or1k_target = NULL;
137
 
138
/* Set to 1 if the target is open.  */
139
static int or1k_is_open = 0;
140
 
141
/* Error last occured, zero = ok.  */
142 118 markom
int err = 0;
143 106 markom
 
144 118 markom
/* Nonzero, if we changed something.  */
145
int debug_regs_changed;
146
 
147 106 markom
/* Number of interrupts while waiting for process.  */
148
static int interrupt_count = 0;
149
 
150 113 markom
/* Reason of last stop.  */
151
static int hit_watchpoint = 0;
152
 
153 106 markom
/* Current register values.  */
154 118 markom
unsigned int dmr1 = 0;
155
unsigned int dmr2 = 0;
156
unsigned int dsr = 0;
157
unsigned int drr = 0;
158 106 markom
 
159 118 markom
/* Current matchpoints.  */
160
unsigned int dvr[MAX_MATCHPOINTS];
161
struct dcr_struct dcr[MAX_MATCHPOINTS];
162 106 markom
 
163 118 markom
int matchpoint_user_count[MAX_MATCHPOINTS] = {0};
164
 
165 106 markom
/* Handle low-level error that we can't recover from.  Note that just
166
   error()ing out from target_wait or some such low-level place will cause
167
   all hell to break loose--the rest of GDB will tend to get left in an
168
   inconsistent state.  */
169
 
170
static NORETURN void
171
or1k_error (char *string,...)
172
{
173
  va_list args;
174
 
175
  va_start (args, string);
176
 
177
  target_terminal_ours ();
178
  wrap_here ("");               /* Force out any buffered output */
179
  gdb_flush (gdb_stdout);
180
  if (error_pre_print)
181
    fprintf_filtered (gdb_stderr, error_pre_print);
182
  vfprintf_filtered (gdb_stderr, string, args);
183
  fprintf_filtered (gdb_stderr, "\n");
184
  va_end (args);
185
  gdb_flush (gdb_stderr);
186
 
187
  /* Clean up in such a way that or1k_close won't try to talk to the
188
     board (it almost surely won't work since we weren't able to talk to
189
     it).  */
190
  or1k_is_open = 0;
191
 
192
  printf_unfiltered ("Ending remote or1k debugging.\n");
193
  target_mourn_inferior ();
194
 
195
  return_to_top_level (RETURN_ERROR);
196
}
197
 
198
const char *
199
or1k_err_name (e)
200
     int e;
201
{
202
  return str_err[e];
203
}
204
 
205
/* putc_readable - print a character, displaying non-printable chars in
206
   ^x notation or in hex.  */
207
 
208
static void
209
fputc_readable (ch, file)
210
     int ch;
211
     struct ui_file *file;
212
{
213
  if (ch == '\n')
214
    fputc_unfiltered ('\n', file);
215
  else if (ch == '\r')
216
    fprintf_unfiltered (file, "\\r");
217
  else if (ch < 0x20)           /* ASCII control character */
218
    fprintf_unfiltered (file, "^%c", ch + '@');
219
  else if (ch >= 0x7f)          /* non-ASCII characters (rubout or greater) */
220
    fprintf_unfiltered (file, "[%02x]", ch & 0xff);
221
  else
222
    fputc_unfiltered (ch, file);
223
}
224
 
225
 
226
/* puts_readable - print a string, displaying non-printable chars in
227
   ^x notation or in hex.  */
228
 
229
static void
230
fputs_readable (string, file)
231
     char *string;
232
     struct ui_file *file;
233
{
234
  int c;
235
 
236
  while ((c = *string++) != '\0')
237
    fputc_readable (c, file);
238
}
239
 
240 113 markom
/* Sets scan chain.  */
241
 
242
static void
243
or1k_set_chain (chain)
244
     int chain;
245
{
246
  if (current_or1k_target != NULL && current_or1k_target->to_set_chain != NULL)
247
    current_or1k_target->to_set_chain (chain);
248
}
249
 
250 106 markom
/* Sets register/memory regno to data.  */
251
 
252 113 markom
static void
253 106 markom
or1k_write_reg (regno, data)
254
     unsigned int regno;
255 122 markom
     ULONGEST data;
256 106 markom
{
257 113 markom
  if (current_or1k_target != NULL && current_or1k_target->to_write_reg != NULL)
258
    current_or1k_target->to_write_reg (regno, data);
259 106 markom
}
260
 
261
/* Reads register/memory from regno.  */
262
 
263 122 markom
static ULONGEST
264 106 markom
or1k_read_reg (regno)
265
     unsigned int regno;
266
{
267 113 markom
  if (current_or1k_target != NULL && current_or1k_target->to_read_reg != NULL)
268
    return current_or1k_target->to_read_reg (regno);
269 106 markom
  else
270
    return 0x1234;
271
}
272
 
273 113 markom
/* Sets SPR register regno to data.  */
274
 
275
void
276
or1k_write_spr_reg (regno, data)
277
     unsigned int regno;
278
     unsigned int data;
279
{
280
  or1k_set_chain (SC_RISC_DEBUG);
281
  or1k_write_reg (regno + REG_SPACE, data);
282
}
283
 
284
/* Reads register SPR from regno.  */
285
 
286
unsigned int
287
or1k_read_spr_reg (regno)
288
     unsigned int regno;
289
{
290
  or1k_set_chain (SC_RISC_DEBUG);
291
  return or1k_read_reg (regno + REG_SPACE);
292
}
293
 
294 106 markom
/* Stalls the CPU.  */
295
 
296
static void
297
or1k_stall ()
298
{
299 113 markom
  int val;
300
  or1k_set_chain (SC_REGISTER);
301
  val = or1k_read_reg (JTAG_RISCOP);
302
  or1k_write_reg (JTAG_RISCOP, val | 1);
303 118 markom
 
304
  /* Be cautious - disable trace.  */
305
  val = or1k_read_reg (JTAG_MODER);
306
  or1k_write_reg (JTAG_MODER, val & ~2);
307 113 markom
  or1k_flush_pipeline ();
308 106 markom
}
309
 
310
/* Unstalls the CPU.  */
311
 
312
static void
313
or1k_unstall ()
314
{
315 113 markom
  unsigned int val;
316
  or1k_set_chain (SC_REGISTER);
317
  val = or1k_read_reg (JTAG_RISCOP);
318
  or1k_write_reg (JTAG_RISCOP, val & ~1);
319 106 markom
}
320
 
321 113 markom
/* Resets the CPU and stalls it.  */
322 118 markom
 
323 106 markom
static void
324 113 markom
or1k_reset ()
325
{
326
  unsigned int val;
327
  or1k_set_chain (SC_REGISTER);
328 118 markom
 
329
  /* Be cautious - disable trace.  */
330
  val = or1k_read_reg (JTAG_MODER);
331
  or1k_write_reg (JTAG_MODER, val & ~2);
332
 
333 113 markom
  val = or1k_read_reg (JTAG_RISCOP);
334
  val &= ~3;
335 118 markom
  /* Assert reset signal.  */
336
  or1k_write_reg (JTAG_RISCOP, val | 3);
337
 
338
  /* give it some time */
339
  usleep (1000);
340 113 markom
  or1k_flush_pipeline ();
341 125 chris
 
342
  or1k_set_chain (SC_REGISTER);  /* CZ: Changed 16/06/01...must reset
343
                                    scan chain after flush_pipeline() */
344 118 markom
  /* Release reset signal, but keep in stall state.  */
345
  or1k_write_reg (JTAG_RISCOP, val | 1);
346 113 markom
  or1k_flush_pipeline ();
347
}
348
 
349 118 markom
/* Synchronizes debug registers in memory with those on target,
350
   if there is any change.  */
351
 
352 113 markom
static void
353 118 markom
or1k_commit_debug_registers ()
354
{
355
  int i;
356
  unsigned int u;
357
  if (!debug_regs_changed)
358
    return;
359
 
360
  /* Matchpoints (breakpoints, watchpoints).  */
361
  for (i = 0; i < NUM_MATCHPOINTS; i++)
362
    {
363
      unsigned int u;
364
      or1k_write_spr_reg (DVR0_SPRNUM + i, dvr[i]);
365
      memcpy (&u, &dcr[i], sizeof(dcr[i]));
366
      or1k_write_spr_reg (DCR0_SPRNUM + i, u);
367
    }
368
  or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
369
  or1k_write_spr_reg (DMR2_SPRNUM, dmr2);
370
 
371
  /* Trace dependent.  */
372
  or1k_set_chain (SC_REGISTER);
373
  memcpy (&u, &or1k_htrace.trig, sizeof(or1k_htrace.trig));
374
  or1k_write_reg (JTAG_TSEL, u);
375
  memcpy (&u, &or1k_htrace.qual, sizeof(or1k_htrace.qual));
376
  or1k_write_reg (JTAG_QSEL, u);
377
  memcpy (&u, &or1k_htrace.stop, sizeof(or1k_htrace.stop));
378
  or1k_write_reg (JTAG_SSEL, u);
379
  debug_regs_changed = 0;
380
  for (i = 0; i < NUM_RECORDS; i++)
381
    {
382
      memcpy (&u, &or1k_htrace.recwp[i], sizeof(or1k_htrace.recwp[i]));
383
      or1k_write_reg (JTAG_RECWP0 + i, u);
384
    }
385
  memcpy (&u, &or1k_htrace.recbp, sizeof(or1k_htrace.recbp));
386
  or1k_write_reg (JTAG_RECBP0, u);
387
  memcpy (&u, &or1k_htrace.moder, sizeof(or1k_htrace.moder));
388
  or1k_write_reg (JTAG_MODER, u);
389
}
390
 
391
static void
392 106 markom
or1k_set_undefined_cleanups (arg)
393
     PTR arg;
394
{
395
  or1k_status = TARGET_UNDEFINED;
396
}
397
 
398
/* Initialize a new connection to the or1k board, and make sure we are
399
   really connected.  */
400
 
401
static void
402
or1k_init (args)
403
     char *args;
404
{
405
  struct cleanup *old_cleanups = make_cleanup (or1k_set_undefined_cleanups, NULL);
406
  int i;
407 115 markom
  unsigned int tmp;
408 118 markom
  FILE *f;
409 106 markom
 
410
  /* What is this code doing here?  I don't see any way it can happen, and
411
     it might mean or1k_initializing didn't get cleared properly.
412
     So I'll make it a warning.  */
413
 
414
  if (or1k_status == TARGET_CONNECTING)
415
    {
416
      warning ("internal error: or1k_initialize called twice");
417
      return;
418
    }
419
 
420
  or1k_status = TARGET_CONNECTING;
421
  if (current_or1k_target != NULL && current_or1k_target->to_init != NULL)
422
    current_or1k_target->to_init (args);
423 122 markom
 
424
  or1k_reset ();
425 106 markom
 
426
  /* Determine implementation configuration.  */
427 113 markom
  or1k_implementation.VR = or1k_read_spr_reg (VR_SPRNUM);
428
  or1k_implementation.UPR = or1k_read_spr_reg (UPR_SPRNUM);
429 118 markom
 
430 115 markom
  /* Determine number of gpr_regs.  */
431
  tmp = or1k_read_spr_reg (CPUCFGR_SPRNUM);
432
  or1k_implementation.num_gpr_regs = ((tmp >> 4) & 1)?(16):(32);
433 118 markom
 
434 115 markom
  /* Is any vector or floating point support present? */
435
  or1k_implementation.vf_present = ((tmp >> 7) & 7) != 0;
436
  or1k_implementation.num_vfpr_regs = (or1k_implementation.vf_present)?(32):(0);
437 106 markom
 
438 115 markom
  /* Determine max number of supported matchpoints.  */
439
  tmp = or1k_read_spr_reg (DCFGR_SPRNUM);
440
  or1k_implementation.num_matchpoints = tmp & 7;
441 113 markom
  or1k_implementation.num_used_matchpoints = 0;
442 115 markom
  or1k_implementation.has_counters = tmp & 4 == 1;
443 106 markom
 
444
  /* Is implementation supported? */
445
 
446
  /* First we should have system and debug groups implemented. */
447
  if (or1k_implementation.VR & (1 << SPR_SYSTEM_GROUP) == 0)
448
    error ("System group should be available in the or1k implementation.");
449
  if (or1k_implementation.VR & (1 << SPR_DEBUG_GROUP) == 0)
450
    error ("Debug group should be available in the or1k implementation.");
451 115 markom
  if (or1k_implementation.has_counters)
452
    warning ("Counters not supported.");
453 106 markom
 
454
  /* Delete break, watch, catch points.  */
455
  for(i = 0; i < NUM_MATCHPOINTS; i++)
456 118 markom
    {
457
      memset (&dcr[i], 0, sizeof (dcr[i]));
458
      matchpoint_user_count[i] = 0;
459
    }
460 106 markom
 
461
  dmr1 = 0;
462
  dmr2 = 0;
463 118 markom
  memset (&or1k_htrace, 0, sizeof (or1k_htrace));
464
 
465
  /* RECSELDEPEND = 0 does not match our trace scheme. */
466
  or1k_htrace.moder.rec_sel_dep = 1;
467
 
468
  debug_regs_changed = 1;
469
  or1k_commit_debug_registers ();
470
 
471 106 markom
  if (err != 0)
472
    error ("Cannot connect.");
473
 
474
  /* Stop when breakpoint occurs.  */
475 113 markom
  or1k_write_spr_reg (DSR_SPRNUM, 0x1000);
476 106 markom
 
477
  do_cleanups (old_cleanups);
478
 
479
  /* This should cause an error if not connected.  */
480
  or1k_fetch_registers (-1);
481
 
482
  set_current_frame (create_new_frame (read_fp (), read_pc ()));
483
  select_frame (get_current_frame (), 0);
484 118 markom
 
485
  /* Just empty it.  */
486
  if ((f = fopen (TRACE_FILENAME, "wb+")) == NULL)
487
    error ("Cannot open trace file.");
488
  fclose (f);
489
  trace_size = 0;
490 106 markom
}
491
 
492
/* Kill the process running on the board.  */
493
 
494
void
495
or1k_kill ()
496
{
497
  if (or1k_status != TARGET_RUNNING)
498
    return;
499
  or1k_status = TARGET_UNDEFINED;
500 113 markom
  or1k_reset();
501
  or1k_status = TARGET_STOPPED;
502 106 markom
 
503
  inferior_pid = 0;
504
}
505
 
506
/* Open a connection to the remote board.  */
507
 
508
static void
509
or1k_open (name, from_tty)
510
     char *name;
511
     int from_tty;
512
{
513
  or1k_init (name);
514
 
515
  /* Switch to using remote target now.  */
516
  current_ops = current_or1k_target->gdb_ops;
517
  or1k_is_open = 1;
518
  push_target (current_ops);
519
 
520
  /* FIXME: Should we call start_remote here?  */
521
 
522
/* This is really the job of start_remote however, that makes an assumption
523
   that the target is about to print out a status message of some sort.  That
524
   doesn't happen here (in fact, it may not be possible to get the monitor to
525
   send the appropriate packet).  */
526
 
527
  flush_cached_frames ();
528
  registers_changed ();
529
  stop_pc = read_pc ();
530
  set_current_frame (create_new_frame (read_fp (), stop_pc));
531
  select_frame (get_current_frame (), 0);
532
  print_stack_frame (selected_frame, -1, 1);
533
}
534
 
535
/* Close a connection to the remote board.  */
536
 
537
static void
538
or1k_close (quitting)
539
     int quitting;
540
{
541
  if (or1k_is_open)
542
    {
543
      or1k_kill ();
544
      if (current_or1k_target != NULL && current_or1k_target->to_done != NULL)
545
        current_or1k_target->to_done ();
546
      current_or1k_target = NULL;
547
    }
548
  generic_mourn_inferior ();
549
}
550
 
551
/* Detach from the remote board.  */
552
 
553
static void
554
or1k_detach (args, from_tty)
555
     char *args;
556
     int from_tty;
557
{
558
  if (args)
559
    error ("Argument given to \"detach\" when remotely debugging.");
560
 
561
  pop_target ();
562
 
563
  or1k_close (1);
564
 
565
  if (from_tty)
566
    printf_unfiltered ("Ending remote or1k debugging.\n");
567
}
568
 
569 118 markom
/* Appends trace data to the trace file.  */
570
 
571
static void
572
or1k_read_trace ()
573
{
574
  struct htrace_data_struct data;
575 122 markom
  ULONGEST tmp;
576 118 markom
  int first = 1;
577
  FILE *fd;
578
  if ((fd = fopen (TRACE_FILENAME, "ab")) == NULL)
579
    {
580
      warning ("Cannot append to trace file.");
581
      return;
582
    }
583
 
584
  or1k_set_chain (SC_TRACE);
585
  while (1)
586
    {
587
      tmp = or1k_read_reg (0);
588
      memcpy (&data, &tmp, sizeof (data));
589
 
590
      /* Last record reached. */
591
      if (!data.valid)
592
        break;
593
      data.valid = first;
594
      first = 0;
595
      if (!fwrite (&data, sizeof (data), 1, fd))
596
        {
597
          warning ("Cannot write trace data");
598
          break;
599
        }
600
    }
601
  fclose (fd);
602
}
603
 
604 106 markom
/* Resume execution of the target process.  STEP says whether to single-step
605
   or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
606
   to the target, or zero for no signal.  */
607
 
608
static void
609
or1k_resume (pid, step, siggnal)
610
     int pid, step;
611
     enum target_signal siggnal;
612
{
613
  if (or1k_status != TARGET_STOPPED)
614
    if (or1k_status == TARGET_RUNNING)
615
      error ("Program is already running.");
616
    else
617
      error ("The program is not being run.");
618
 
619
  /* Clear reason register for later.  */
620 113 markom
  or1k_write_spr_reg (DRR_SPRNUM, 0);
621 106 markom
 
622
  if (step)
623
    {
624
      /* HW STEP.  Set DMR1_ST.  */
625
      dmr1 |= DMR1_ST;
626 113 markom
      or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
627 106 markom
      dmr1 &= ~DMR1_ST;
628
    }
629
 
630 118 markom
  or1k_commit_debug_registers ();
631 106 markom
  /* Run the target. */
632
  or1k_unstall ();
633
  or1k_status = TARGET_RUNNING;
634
}
635
 
636
/* Wait until the remote stops, and return a wait status.  */
637
 
638
static int
639
or1k_wait (pid, status)
640
     int pid;
641
     struct target_waitstatus *status;
642
{
643
  interrupt_count = 0;
644
 
645
  /* If we have not sent a single step or continue command, then the
646
     board is waiting for us to do something.  Return a status
647
     indicating that it is stopped.  */
648
  if (or1k_status != TARGET_RUNNING)
649
    {
650
      if (or1k_status != TARGET_STOPPED)
651
        error("Target in invalid state.");
652
      status->kind = TARGET_WAITKIND_STOPPED;
653
      status->value.sig = TARGET_SIGNAL_TRAP;
654
      return 0;
655
    }
656
 
657
  if (err)
658
    or1k_error ("Remote failure: %s", or1k_err_name (err));
659
 
660
  /* Wait for or1k DRR register to be nonzero.  */
661
  do
662
    {
663 113 markom
      drr = or1k_read_spr_reg (DRR_SPRNUM);
664 106 markom
      usleep (10);
665
    }
666
  while (drr == 0);
667
 
668
  status->kind = TARGET_WAITKIND_STOPPED;
669 113 markom
  or1k_flush_pipeline ();
670 106 markom
 
671
  if (drr & DRR_RSTE)
672
    status->value.sig = TARGET_SIGNAL_REALTIME_33;
673
  else if (drr & DRR_BUSEE)
674
    status->value.sig = TARGET_SIGNAL_BUS;
675
  else if (drr & DRR_DPFE)
676
    status->value.sig = TARGET_SIGNAL_REALTIME_34;
677
  else if (drr & DRR_IPFE)
678
    status->value.sig = TARGET_SIGNAL_REALTIME_35;
679
  else if (drr & DRR_LPINTE)
680
    status->value.sig = TARGET_SIGNAL_INT;
681
  else if (drr & DRR_AE)
682
    status->value.sig = TARGET_SIGNAL_REALTIME_36;
683
  else if (drr & DRR_IIE)
684
    status->value.sig = TARGET_SIGNAL_ILL;
685
  else if (drr & DRR_HPINTE)
686
    status->value.sig = TARGET_SIGNAL_INT;
687
  else if (drr & DRR_DME)
688
    status->value.sig = TARGET_SIGNAL_REALTIME_37;
689
  else if (drr & DRR_IME)
690
    status->value.sig = TARGET_SIGNAL_REALTIME_38;
691
  else if (drr & DRR_RE)
692
    status->value.sig = TARGET_SIGNAL_REALTIME_39;
693
  else if (drr & DRR_SCE)
694
    status->value.sig = TARGET_SIGNAL_REALTIME_40;
695
  else if (drr & DRR_BE)
696
    status->value.sig = TARGET_SIGNAL_TRAP;
697
  else
698
    {
699
      status->value.sig = TARGET_SIGNAL_UNKNOWN;
700
      warning ("Invalid exception occured.");
701
    }
702
 
703 113 markom
  /* Log remote stop.  */
704 106 markom
  or1k_status = TARGET_STOPPED;
705 113 markom
 
706
  /* Determine what caused trap - breakpoint or watchpoint.  */
707
  if (status->value.sig == TARGET_SIGNAL_TRAP)
708
    {
709
      /* Search all active breakpoints for a match.  */
710
      CORE_ADDR pc = read_pc ();
711
      int breakpoint = 0;
712
      int i;
713
      for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
714 118 markom
        if (dvr[i] == pc && dcr[i].dp && dcr[i].cc == CC_EQUAL
715
            && !dcr[i].sc && dcr[i].ct == CT_FETCH)
716 113 markom
          {
717
            breakpoint = 1;
718
            break;
719
          }
720
      hit_watchpoint = !breakpoint;
721
    }
722
  else
723
    hit_watchpoint = 0;
724 106 markom
 
725
  /* If the stop PC is in the _exit function, assume
726
     we hit the 'break 0x3ff' instruction in _exit, so this
727
     is not a normal breakpoint.  */
728
  {
729
    char *func_name;
730
    CORE_ADDR func_start;
731
    CORE_ADDR pc = read_pc ();
732
 
733
    find_pc_partial_function (pc, &func_name, &func_start, NULL);
734
    if (func_name != NULL && strcmp (func_name, "_exit") == 0
735
        && func_start == pc)
736
      status->kind = TARGET_WAITKIND_EXITED;
737
  }
738 118 markom
 
739
  or1k_read_trace ();
740 106 markom
  return 0;
741
}
742
 
743 113 markom
/* Fetch a word from the target board.  All memory accesses to the
744
   remote board are word aligned.  */
745 106 markom
 
746 118 markom
unsigned int
747 106 markom
or1k_fetch_word (addr)
748
     CORE_ADDR addr;
749
{
750 113 markom
  if (addr & 3)
751
    {
752
      int subaddr = addr & 3;
753
      unsigned char buf[8];
754
      unsigned int low, high;
755
      addr >>= 2;
756
      low = or1k_read_reg (addr + MEM_SPACE);
757
      high = or1k_read_reg (addr + 1 + MEM_SPACE);
758
      memcpy (&buf[0], &low, 4);
759
      memcpy (&buf[4], &high, 4);
760
      memcpy (&low, &buf[subaddr], 4);
761
      return low;
762
    }
763
  else
764
    {
765
      addr >>= 2;
766
      return or1k_read_reg (addr + MEM_SPACE);
767
    }
768 106 markom
}
769
 
770
/* Store a word to the target board.  Returns errno code or zero for
771 113 markom
   success.  All memory accesses to the remote board are word aligned.  */
772 118 markom
 
773 106 markom
static int
774
or1k_store_word (addr, val)
775
     CORE_ADDR addr;
776
     unsigned int val;
777
{
778 113 markom
  if (addr & 3)
779
    {
780
      int subaddr = addr & 3;
781
      unsigned char buf[8];
782
      unsigned int low, high;
783
      addr >>= 2;
784
      low = or1k_read_reg (addr + MEM_SPACE);
785
      high = or1k_read_reg (addr + 1 + MEM_SPACE);
786
      memcpy (&buf[0], &low, 4);
787
      memcpy (&buf[4], &high, 4);
788
      memcpy (&buf[subaddr], &val, 4);
789
      memcpy (&low, &buf[0], 4);
790
      memcpy (&high, &buf[4], 4);
791
      or1k_write_reg (addr + MEM_SPACE, low);
792
      or1k_write_reg (addr + 1 + MEM_SPACE, high);
793
    }
794
  else
795
    {
796
      addr >>= 2;
797
      or1k_write_reg (addr + MEM_SPACE, val);
798
    }
799 106 markom
  return err;
800
}
801
 
802
/* Fetch the remote registers.  */
803
 
804
void
805
or1k_fetch_registers (regno)
806
     int regno;
807
{
808
  unsigned int val;
809
 
810
  if (regno == -1)
811
    {
812
      for (regno = 0; regno < NUM_REGS; regno++)
813
        or1k_fetch_registers (regno);
814
      return;
815
    }
816
 
817
  if (regno >= NUM_REGS)
818
    error("Invalid register number!");
819
 
820
  /* Convert to SPRNUM and read.  */
821 113 markom
  val = or1k_read_spr_reg (REGNUM_TO_SPRNUM(regno));
822 106 markom
 
823
  {
824
    char buf[MAX_REGISTER_RAW_SIZE];
825
 
826
    /* We got the number the register holds, but gdb expects to see a
827
       value in the target byte ordering.  */
828
    store_unsigned_integer (buf, REGISTER_RAW_SIZE (regno), val);
829
    supply_register (regno, buf);
830
  }
831
  if (err)
832 118 markom
    or1k_error ("Can't read register %d(%i): %s", regno,
833
                REGNUM_TO_SPRNUM(regno) + REG_SPACE, or1k_err_name (err));
834 106 markom
}
835
 
836
/* Fetch and return instruction from the specified location.  */
837
 
838
unsigned int
839
or1k_fetch_instruction (addr)
840
     CORE_ADDR addr;
841
{
842
  char buf[OR1K_INSTLEN];
843
  int status;
844
 
845
  status = read_memory_nobpt (addr, buf, OR1K_INSTLEN);
846
  if (status)
847
    memory_error (status, addr);
848
  return extract_unsigned_integer (buf, OR1K_INSTLEN);
849
}
850
 
851 113 markom
/* Currently not needed.  */
852
 
853 106 markom
static void
854
or1k_prepare_to_store ()
855
{
856
}
857
 
858
/* Store remote register(s).  */
859
 
860
static void
861
or1k_store_registers (regno)
862
     int regno;
863
{
864
  if (regno == -1)
865
    {
866
      for (regno = 0; regno < NUM_REGS; regno++)
867
        or1k_store_registers (regno);
868
      return;
869
    }
870
 
871
  if (regno >= NUM_REGS)
872
    error("Invalid register number!");
873
 
874 113 markom
  or1k_write_spr_reg (REGNUM_TO_SPRNUM(regno), or1k_read_spr_reg (REGNUM_TO_SPRNUM(regno)));
875 106 markom
  if (err)
876 113 markom
    or1k_error ("Can't write register %d(%i): %s", regno, REGNUM_TO_SPRNUM(regno), or1k_err_name (err));
877 106 markom
}
878
 
879
/* Read or write LEN bytes from inferior memory at MEMADDR,
880
   transferring to or from debugger address MYADDR.  Write to inferior
881
   if SHOULD_WRITE is nonzero.  Returns length of data written or
882
   read; 0 for error.  Note that protocol gives us the correct value
883
   for a longword, since it transfers values in ASCII.  We want the
884
   byte values, so we have to swap the longword values.  */
885
 
886
static int
887
or1k_xfer_memory (memaddr, myaddr, len, write, ignore)
888
     CORE_ADDR memaddr;
889
     char *myaddr;
890
     int len;
891
     int write;
892
     struct target_ops *ignore;
893
{
894
  register int i;
895
  /* Round starting address down to longword boundary.  */
896
  register CORE_ADDR addr = memaddr & ~3;
897
  /* Round ending address up; get number of longwords that makes.  */
898
  register int count = (((memaddr + len) - addr) + 3) / 4;
899
  /* Allocate buffer of that many longwords.  */
900
  register char *buffer = alloca (count * 4);
901
 
902
  int status;
903
 
904
  if (memaddr >= MEM_SPACE)
905
    error("Invalid address");
906
 
907 135 chris
  /* (CZ 21/06/01 -- because upper layers which know nothing about
908
     Or1k or JTAG call this function directly, it is always necessary
909
     to set the chain to point to the Debug Unit. Otherwise, it may
910
     be pointint to the Development Interface chain, in which case
911
     we're going to get bupkiss... */
912
 
913
  or1k_set_chain (SC_RISC_DEBUG);
914
 
915 106 markom
  if (write)
916
    {
917
      /* Fill start and end extra bytes of buffer with existing data.  */
918
      if (addr != memaddr || len < 4)
919
        {
920
          /* Need part of initial word -- fetch it.  */
921
          store_unsigned_integer (&buffer[0], 4, or1k_fetch_word (addr));
922
        }
923
 
924
      if (count > 1)
925
        {
926
          /* Need part of last word -- fetch it.  FIXME: we do this even
927
             if we don't need it.  */
928
          store_unsigned_integer (&buffer[(count - 1) * 4], 4,
929
                                  or1k_fetch_word (addr + (count - 1) * 4));
930
        }
931
 
932
      /* Copy data to be written over corresponding part of buffer */
933
      memcpy ((char *) buffer + (memaddr & 3), myaddr, len);
934
 
935
      /* Write the entire buffer.  */
936
      for (i = 0; i < count; i++, addr += 4)
937
        {
938
          status = or1k_store_word (addr,
939 135 chris
                               (unsigned long)extract_unsigned_integer (&buffer[i * 4], 4));
940 106 markom
          /* Report each kilobyte (we download 32-bit words at a time) */
941
          if (i % 256 == 255)
942
            {
943
              printf_unfiltered ("*");
944
              gdb_flush (gdb_stdout);
945
            }
946
          if (status)
947
            {
948
              errno = status;
949
              return 0;
950
            }
951
          /* FIXME: Do we want a QUIT here?  */
952
        }
953
      if (count >= 256)
954
        printf_unfiltered ("\n");
955
    }
956
  else
957
    {
958
      /* Read all the longwords */
959
      for (i = 0; i < count; i++, addr += 4)
960
        {
961
          store_unsigned_integer (&buffer[i * 4], 4, or1k_fetch_word (addr));
962
          QUIT;
963
        }
964
 
965
      /* Copy appropriate bytes out of the buffer.  */
966
      memcpy (myaddr, buffer + (memaddr & 3), len);
967
    }
968
  return len;
969
}
970
 
971 113 markom
/* Flushes pipeline. May not be needed by all implementations, but
972
   it doen't hurt to do it. This function should be called every time
973
   or1k stops.
974
   When or1k stops it still has instructions in pipeline.
975
   We do this by inserting nop instructions.
976
   IF cycle remains unaffacted by writing to DIR, and it still holds
977
   instruction, that caused break or watchpoint. */
978
 
979
void
980
or1k_flush_pipeline ()
981
{
982
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
983
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
984
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
985
}
986
 
987 106 markom
/* Print info on this target.  */
988
 
989
static void
990
or1k_files_info (ignore)
991
     struct target_ops *ignore;
992
{
993
  char *file = "nothing";
994
 
995
  if (exec_bfd)
996
    file = bfd_get_filename (exec_bfd);
997
 
998
  printf_filtered ("or1k_files_info: file \"%s\"\n", file);
999
 
1000
  if (exec_bfd)
1001
    {
1002
      printf_filtered ("\tAttached to %s running program %s\n",
1003
                       target_shortname, file);
1004
    }
1005
  /* Print target info. */
1006
  printf_filtered ("Status: %s\n", status_name[or1k_status]);
1007
}
1008
 
1009
/* Tell whether we can support a hardware breakpoint.  */
1010 118 markom
 
1011 106 markom
static int
1012
or1k_can_use_hardware_breakpoint ()
1013
{
1014
  int i;
1015 118 markom
 
1016 106 markom
  /* Search for unused breakpoint.  */
1017 113 markom
  return or1k_implementation.num_used_matchpoints < or1k_implementation.num_matchpoints;
1018 106 markom
}
1019
 
1020
/* Insert a breakpoint.  On targets that don't have built-in breakpoint
1021
   support, we read the contents of the target location and stash it,
1022
   then overwrite it with a breakpoint instruction.  ADDR is the target
1023
   location in the target machine.  CONTENTS_CACHE is a pointer to
1024
   memory allocated for saving the target contents.  It is guaranteed
1025
   by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1026
   is accomplished via BREAKPOINT_MAX).  */
1027
 
1028 113 markom
int
1029 106 markom
or1k_insert_breakpoint (addr, contents_cache)
1030
     CORE_ADDR addr;
1031
     char *contents_cache;
1032
{
1033
  if (or1k_can_use_hardware_breakpoint())
1034
    return set_breakpoint (addr);
1035
  else
1036
    return memory_insert_breakpoint (addr, contents_cache);
1037
}
1038
 
1039 113 markom
int
1040 106 markom
or1k_remove_breakpoint (addr, contents_cache)
1041
     CORE_ADDR addr;
1042
     char *contents_cache;
1043
{
1044
  /* First try to remove HW breakpoint at address */
1045
  if (clear_breakpoint (addr))
1046
    return memory_remove_breakpoint (addr, contents_cache);
1047
  else
1048
    return 0;
1049
}
1050
 
1051 113 markom
/* Tell whether this target can support a hardware breakpoint.  CNT
1052
   is the number of hardware breakpoints already installed.  This
1053
   implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro.
1054
   Lower bound is estimated. !!! Can we estimate better? */
1055
 
1056
int
1057
or1k_can_use_hardware_watchpoint (bp_type, cnt)
1058
     enum bptype bp_type;
1059
     int cnt;
1060
{
1061
  /* Are there at least two matchpoints left for watch? - estimate lower bound  */
1062
  return cnt + ((bp_type == bp_hardware_watchpoint)?(1):(0))
1063
    <= or1k_implementation.num_matchpoints;
1064
}
1065
 
1066 118 markom
/* Moves matchpoint.  This is very tricky - we have to update
1067
   all references to matchpoint indexes.  We assume here that
1068
   matchpoint with index to is unused! */
1069
 
1070
static void
1071
move_matchpoint (int from, int to)
1072
{
1073
  int i, j, tmp, chaining;
1074
  if (matchpoint_user_count[to] != 0)
1075
    error ("Internal: Destination matchpoint still has users");
1076
  matchpoint_user_count[to] = matchpoint_user_count[from];
1077
  matchpoint_user_count[from] = 0;
1078
  debug_regs_changed = 1;
1079
 
1080
  dvr[to] = dvr[from];
1081
  dcr[to] = dcr[from];
1082
  dcr[from].dp = 0;
1083
 
1084
  /* Copy chaining bits.  */
1085
  chaining = dmr1 & (3 << (2 * from));
1086
  dmr1 &= ~(3 << (2 * to));
1087
  dmr1 |= chaining << (2 * to);
1088
  dmr1 &= ~(3 << (2 * from));
1089
 
1090
  /* Copy watchpoint bits */
1091
  tmp = dmr2 & (1 << from);
1092
  dmr2 &= 1 << to;
1093
  dmr2 |= tmp << to;
1094
  dmr2 &= 1 << from;
1095
 
1096
  /* Update hwatch table.  Here we assume that matchpoint
1097
     group is connected (it cannot be implemented in HW
1098
     otherwise), so if we move first, we will have to move
1099
     others later.  */
1100
  for (i = 0; i < num_hw_watches; i++)
1101
    if (or1k_hwatch[i].matchpoint_start == from)
1102
      or1k_hwatch[i].matchpoint_start = to;
1103
 
1104
  /* Update htrace struct.  */
1105
  tmp = or1k_htrace.trig.wp_trig & (1 << from);
1106
  or1k_htrace.trig.wp_trig &= 1 << to;
1107
  or1k_htrace.trig.wp_trig |= tmp << to;
1108
  or1k_htrace.trig.wp_trig &= 1 << from;
1109
 
1110
  tmp = or1k_htrace.qual.wp_trig & (1 << from);
1111
  or1k_htrace.qual.wp_trig &= 1 << to;
1112
  or1k_htrace.qual.wp_trig |= tmp << to;
1113
  or1k_htrace.qual.wp_trig &= 1 << from;
1114
 
1115
  tmp = or1k_htrace.stop.wp_trig & (1 << from);
1116
  or1k_htrace.stop.wp_trig &= 1 << to;
1117
  or1k_htrace.stop.wp_trig |= tmp << to;
1118
  or1k_htrace.stop.wp_trig &= 1 << from;
1119
 
1120
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1121
    {
1122
      tmp = or1k_htrace.wp_record_uses[i] & (1 << from);
1123
      or1k_htrace.wp_record_uses[i] &= 1 << to;
1124
      or1k_htrace.wp_record_uses[i] |= tmp << to;
1125
      or1k_htrace.wp_record_uses[i] &= 1 << from;
1126
    }
1127
 
1128
  /* Do we need to move other references also? */
1129
}
1130
 
1131 113 markom
/* Sifts unused matchpoints to higher indexses.  */
1132
 
1133 118 markom
void
1134 113 markom
sift_matchpoints ()
1135
{
1136
  int i, first_free = 0;
1137
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1138
    if (dcr[i].dp)
1139
      {
1140 118 markom
        /* Move references.  */
1141
        move_matchpoint (i, first_free);
1142
 
1143 113 markom
        first_free++;
1144
      }
1145 118 markom
 
1146
  /* Unused matchpoints should be disabled by move_matchpoint,
1147
     so we are done here.  */
1148 113 markom
}
1149
 
1150
/* Translates gdb watchpoint type into one in DCR register.  */
1151
 
1152
static int
1153
translate_type (gdb_type)
1154
     int gdb_type;
1155
{
1156
  switch (gdb_type)
1157
    {
1158
    case 0:
1159
      return CT_SDATA;
1160
    case 1:
1161
      return CT_LDATA;
1162
    case 2:
1163
      return CT_ADATA;
1164
    default:
1165
      error ("Invalid type.");
1166
    }
1167
}
1168
 
1169
/* Set a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1170
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1171
   watchpoint. */
1172
 
1173
int
1174
or1k_insert_watchpoint (addr, len, type)
1175
     CORE_ADDR addr;
1176
     int len;
1177
     int type;
1178
{
1179
  int i;
1180 118 markom
 
1181 113 markom
  if (len < 1)
1182
    return -1;
1183
 
1184
  type = translate_type (type);
1185
 
1186
  /* Moves unused watchpoints to the top.  */
1187
  sift_matchpoints ();
1188 118 markom
 
1189 113 markom
  /* Place at first free matchpoint.  */
1190
  i = or1k_implementation.num_used_matchpoints;
1191
  dvr[i] = addr;
1192
  dcr[i].dp = 1;
1193
  dcr[i].cc = CC_GREATE;
1194
  dcr[i].sc = 0;
1195
  dcr[i].ct = type;
1196 118 markom
 
1197 113 markom
  /* Set && chaining here.  */
1198
  dmr1 &= ~(3 << (2 * i));
1199 118 markom
  dmr1 |= CHAINING_AND << (2 * i);
1200
 
1201 113 markom
  /* Set upper watchpoint bound.  */
1202
  i++;
1203
  dvr[i] = addr + len - 1;
1204
  dcr[i].dp = 1;
1205
  dcr[i].cc = CC_LESSE;
1206
  dcr[i].sc = 0;
1207
  dcr[i].ct = type;
1208 118 markom
 
1209 113 markom
  /* Matchpoints will cause breakpoints */
1210 118 markom
  dmr2 |= (1 << i);
1211 113 markom
  or1k_implementation.num_used_matchpoints += 2;
1212 118 markom
  debug_regs_changed = 1;
1213 113 markom
  return 0;
1214
}
1215
 
1216
/* Removes a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1217
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1218
   watchpoint. */
1219 118 markom
 
1220 113 markom
int
1221
or1k_remove_watchpoint (addr, len, type)
1222
     CORE_ADDR addr;
1223
     int len;
1224
     int type;
1225
{
1226
  int i, found = -1;
1227 118 markom
 
1228 113 markom
  if (len < 1)
1229
    return -1;
1230
 
1231
  type = translate_type (type);
1232
 
1233
  /* Find the right one.  */
1234
  for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
1235
    if (dvr[i] == addr && dcr[i].dp && dcr[i].cc == CC_GREATE && !dcr[i].sc && dcr[i].ct == type
1236
        && dvr[i + 1] == addr + len - 1 && dcr[i + 1].dp && dcr[i + 1].cc == CC_LESSE
1237
        && !dcr[i + 1].sc && dcr[i + 1].ct == type)
1238
      {
1239
        found = i;
1240
        break;
1241
      }
1242
 
1243
  if (found < 0)
1244
    return -1;
1245
 
1246
  dcr[found].dp = 0;
1247
  dcr[found + 1].dp = 0;
1248
 
1249
  /* Matchpoints will not cause breakpoints anymore. */
1250 118 markom
  dmr2 &= ~(1 << i);
1251 113 markom
  or1k_implementation.num_used_matchpoints -= 2;
1252 118 markom
  debug_regs_changed = 1;
1253 113 markom
  return 0;
1254
}
1255
 
1256
int
1257
or1k_stopped_by_watchpoint (void)
1258
{
1259
  return hit_watchpoint;
1260
}
1261
 
1262 106 markom
/* Insert a breakpoint.  */
1263
 
1264
int
1265
set_breakpoint (addr)
1266
     CORE_ADDR addr;
1267
{
1268
  int i;
1269 118 markom
 
1270 106 markom
  /* Search for unused breakpoint.  */
1271
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1272
    if (dcr[i].dp == 0) break;
1273
  if (i >= NUM_MATCHPOINTS) return 1;
1274
  dvr[i] = addr;
1275
  dcr[i].dp = 1;
1276
  dcr[i].cc = CC_EQUAL;
1277
  dcr[i].sc = 0;
1278
  dcr[i].ct = CT_FETCH;
1279 113 markom
  or1k_implementation.num_used_matchpoints++;
1280
 
1281
  /* No chaining here.  */
1282
  dmr1 &= ~(3 << (2*i));
1283 118 markom
 
1284 113 markom
  /* Matchpoints will cause breakpoints */
1285 118 markom
  dmr2 |= (1 << i);
1286
  debug_regs_changed = 1;
1287 106 markom
  return 0;
1288
}
1289
 
1290
/* Clear a breakpoint.  */
1291
 
1292
int
1293
clear_breakpoint (addr)
1294
     CORE_ADDR addr;
1295
{
1296
  int i;
1297 118 markom
 
1298 106 markom
  /* Search for matching breakpoint.  */
1299
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1300
    if ((dcr[i].dp == 1) && (dvr[i] == addr) && (dcr[i].cc == CC_EQUAL)
1301
        && (dcr[i].sc == 0) && (dcr[i].ct == CT_FETCH)) break;
1302
 
1303
  if (i >= NUM_MATCHPOINTS) return 1;
1304
  dcr[i].dp = 0;
1305 118 markom
 
1306 113 markom
  /* Matchpoints will cause breakpoints */
1307 118 markom
  dmr2 &= ~(1 << i);
1308 113 markom
  or1k_implementation.num_used_matchpoints--;
1309 118 markom
  debug_regs_changed = 1;
1310 106 markom
  return 0;
1311
}
1312
 
1313
/* Start running on the target board.  */
1314
 
1315
static void
1316
or1k_create_inferior (execfile, args, env)
1317
     char *execfile;
1318
     char *args;
1319
     char **env;
1320
{
1321
  CORE_ADDR entry_pt;
1322
 
1323
  if (args && *args)
1324
    {
1325 118 markom
      warning ("Can't pass arguments to remote OR1K board; arguments ignored.");
1326
 
1327 106 markom
      /* And don't try to use them on the next "run" command.  */
1328
      execute_command ("set args", 0);
1329
    }
1330
 
1331
  if (execfile == 0 || exec_bfd == 0)
1332
    error ("No executable file specified");
1333
 
1334
  or1k_kill ();
1335
  remove_breakpoints ();
1336
 
1337
  entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
1338
  init_wait_for_inferior ();
1339
 
1340
  /* FIXME: Should we set inferior_pid here?  */
1341 113 markom
 
1342 118 markom
  /* Needed to get correct instruction in cache */
1343
  insert_breakpoints ();
1344 106 markom
  clear_proceed_status ();
1345
  or1k_status = TARGET_STOPPED;
1346
  proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
1347
}
1348
 
1349
/* Clean up after a process.  Actually nothing to do.  */
1350
 
1351
static void
1352
or1k_mourn_inferior ()
1353
{
1354
  generic_mourn_inferior ();
1355
}
1356
 
1357
static void
1358
or1k_dummy_open (name, from_tty)
1359
     char *name;
1360
     int from_tty;
1361
{
1362
  target_preopen (from_tty);
1363
  if (or1k_is_open)
1364
    unpush_target (current_ops);
1365
  current_or1k_target = &or1k_target_dummy;
1366
  or1k_open (name, from_tty);
1367
}
1368
 
1369
static void
1370
or1k_jtag_open (name, from_tty)
1371
     char *name;
1372
     int from_tty;
1373
{
1374
  target_preopen (from_tty);
1375
  if (or1k_is_open)
1376
    unpush_target (current_ops);
1377
  current_or1k_target = &or1k_target_jtag;
1378
  or1k_open (name, from_tty);
1379
}
1380
 
1381
static void
1382
or1k_sim_open (name, from_tty)
1383
     char *name;
1384
     int from_tty;
1385
{
1386
  /* target_preopen (from_tty); - do we need this ? */
1387
  if (or1k_is_open)
1388
    unpush_target (current_ops);
1389
  current_or1k_target = &or1k_target_sim;
1390
  or1k_open (name, from_tty);
1391
}
1392
 
1393
/* Executes command on the target.  */
1394
 
1395
void
1396
or1k_sim_cmd (char *args, int from_tty)
1397
{
1398
  if (current_or1k_target != NULL && current_or1k_target->to_exec_command != NULL)
1399
    current_or1k_target->to_exec_command (args, from_tty);
1400
  else
1401
    error ("Command not supported on this target. ");
1402
}
1403
 
1404 113 markom
/* Displays matchpoints usage.  */
1405
 
1406 106 markom
void
1407 113 markom
info_matchpoints_command (char *args, int from_tty)
1408
{
1409
  int i;
1410
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1411
    {
1412
      printf_filtered ("WP%i ", i);
1413
      if (dcr[i].dp)
1414
        {
1415
          int chaining = (dmr1 << 2*i) & 3;
1416
          printf_filtered ("= %s ", ct_names[dcr[i].ct]);
1417
          if (dcr[i]. sc)
1418
            printf_filtered ("s%s %i", cc_names[dcr[i].cc], (int)dvr[i]);
1419
          else
1420
            printf_filtered ("%s %u", cc_names[dcr[i].cc], (unsigned int)dvr[i]);
1421
          if (chaining)
1422
            printf_filtered ("%s WP%i", ch_names[chaining], i - 1);
1423
        }
1424
      else
1425
        printf_filtered ("NOT USED");
1426
      if ((dmr2 >> i) & 1)
1427
        printf_filtered (", causes breakpoint");
1428
      if ((dmr2 >> (i + 11)) & 1)
1429
        printf_filtered (", increments counter");
1430
      printf_filtered ("\n");
1431
    }
1432
}
1433
 
1434
void
1435 106 markom
_initialize_remote_or1k ()
1436
{
1437
  /* Initialize the fields in or1k_ops that are common to all targets.  */
1438
  or1k_dummy_ops.to_close = or1k_close;
1439
  or1k_dummy_ops.to_detach = or1k_detach;
1440
  or1k_dummy_ops.to_resume = or1k_resume;
1441
  or1k_dummy_ops.to_wait = or1k_wait;
1442
  or1k_dummy_ops.to_fetch_registers = or1k_fetch_registers;
1443
  or1k_dummy_ops.to_store_registers = or1k_store_registers;
1444
  or1k_dummy_ops.to_prepare_to_store = or1k_prepare_to_store;
1445
  or1k_dummy_ops.to_xfer_memory = or1k_xfer_memory;
1446
  or1k_dummy_ops.to_files_info = or1k_files_info;
1447
  or1k_dummy_ops.to_insert_breakpoint = or1k_insert_breakpoint;
1448
  or1k_dummy_ops.to_remove_breakpoint = or1k_remove_breakpoint;
1449
  or1k_dummy_ops.to_kill = or1k_kill;
1450
  or1k_dummy_ops.to_load = generic_load;
1451
  or1k_dummy_ops.to_create_inferior = or1k_create_inferior;
1452
  or1k_dummy_ops.to_mourn_inferior = or1k_mourn_inferior;
1453
  or1k_dummy_ops.to_stratum = process_stratum;
1454 118 markom
 
1455
  /* We can access memory while program is running.  */
1456
  or1k_dummy_ops.to_has_all_memory = 0;
1457
 
1458 106 markom
  or1k_dummy_ops.to_has_memory = 1;
1459
  or1k_dummy_ops.to_has_stack = 1;
1460
  or1k_dummy_ops.to_has_registers = 1;
1461
  or1k_dummy_ops.to_has_execution = 1;
1462
  or1k_dummy_ops.to_magic = OPS_MAGIC;
1463
 
1464
  /* Copy the common fields to all target vectors.  */
1465
  or1k_jtag_ops = or1k_sim_ops = or1k_dummy_ops;
1466
 
1467
  /* Initialize target-specific fields in the target vectors adn add targets.  */
1468
  or1k_jtag_ops.to_shortname = "jtag";
1469
  or1k_jtag_ops.to_longname = "Remote or1k debugging over JTAG port";
1470 125 chris
  or1k_jtag_ops.to_doc = "Debug a board using the OR1K remote debugging protocol"
1471
    " over a parallel line.\nThe argument is the parallel port it is connected "
1472
    "to, or, if it is formatted\nas a URL of the form jtag://<hostname>:<port>,"
1473
    " then the argument refers to\na remote JTAG proxy server.\n";
1474 106 markom
  or1k_jtag_ops.to_open = or1k_jtag_open;
1475
  add_target (&or1k_jtag_ops);
1476
 
1477
  or1k_dummy_ops.to_shortname = "dummy";
1478
  or1k_dummy_ops.to_longname = "Dummy target";
1479
  or1k_dummy_ops.to_doc = "Actually no real target attached - more like /dev/null.\n";
1480
  or1k_dummy_ops.to_open = or1k_dummy_open;
1481
  add_target (&or1k_dummy_ops);
1482
 
1483
  or1k_sim_ops.to_shortname = "sim";
1484
  or1k_sim_ops.to_longname = "Remote or1k debugging using architecture simulator";
1485
  or1k_sim_ops.to_doc = "Debug using an architecture simulator.\n";
1486
  or1k_sim_ops.to_open = or1k_sim_open;
1487
  add_target (&or1k_sim_ops);
1488 113 markom
  add_info ("matchpoints", info_matchpoints_command, "Show current matchpoints allocation status.");
1489 106 markom
}

powered by: WebSVN 2.1.0

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