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 125

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
  if (write)
908
    {
909
      /* Fill start and end extra bytes of buffer with existing data.  */
910
      if (addr != memaddr || len < 4)
911
        {
912
          /* Need part of initial word -- fetch it.  */
913
          store_unsigned_integer (&buffer[0], 4, or1k_fetch_word (addr));
914
        }
915
 
916
      if (count > 1)
917
        {
918
          /* Need part of last word -- fetch it.  FIXME: we do this even
919
             if we don't need it.  */
920
          store_unsigned_integer (&buffer[(count - 1) * 4], 4,
921
                                  or1k_fetch_word (addr + (count - 1) * 4));
922
        }
923
 
924
      /* Copy data to be written over corresponding part of buffer */
925
      memcpy ((char *) buffer + (memaddr & 3), myaddr, len);
926
 
927
      /* Write the entire buffer.  */
928
      for (i = 0; i < count; i++, addr += 4)
929
        {
930
          status = or1k_store_word (addr,
931
                               extract_unsigned_integer (&buffer[i * 4], 4));
932
          /* Report each kilobyte (we download 32-bit words at a time) */
933
          if (i % 256 == 255)
934
            {
935
              printf_unfiltered ("*");
936
              gdb_flush (gdb_stdout);
937
            }
938
          if (status)
939
            {
940
              errno = status;
941
              return 0;
942
            }
943
          /* FIXME: Do we want a QUIT here?  */
944
        }
945
      if (count >= 256)
946
        printf_unfiltered ("\n");
947
    }
948
  else
949
    {
950
      /* Read all the longwords */
951
      for (i = 0; i < count; i++, addr += 4)
952
        {
953
          store_unsigned_integer (&buffer[i * 4], 4, or1k_fetch_word (addr));
954
          QUIT;
955
        }
956
 
957
      /* Copy appropriate bytes out of the buffer.  */
958
      memcpy (myaddr, buffer + (memaddr & 3), len);
959
    }
960
  return len;
961
}
962
 
963 113 markom
/* Flushes pipeline. May not be needed by all implementations, but
964
   it doen't hurt to do it. This function should be called every time
965
   or1k stops.
966
   When or1k stops it still has instructions in pipeline.
967
   We do this by inserting nop instructions.
968
   IF cycle remains unaffacted by writing to DIR, and it still holds
969
   instruction, that caused break or watchpoint. */
970
 
971
void
972
or1k_flush_pipeline ()
973
{
974
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
975
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
976
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
977
}
978
 
979 106 markom
/* Print info on this target.  */
980
 
981
static void
982
or1k_files_info (ignore)
983
     struct target_ops *ignore;
984
{
985
  char *file = "nothing";
986
 
987
  if (exec_bfd)
988
    file = bfd_get_filename (exec_bfd);
989
 
990
  printf_filtered ("or1k_files_info: file \"%s\"\n", file);
991
 
992
  if (exec_bfd)
993
    {
994
      printf_filtered ("\tAttached to %s running program %s\n",
995
                       target_shortname, file);
996
    }
997
  /* Print target info. */
998
  printf_filtered ("Status: %s\n", status_name[or1k_status]);
999
}
1000
 
1001
/* Tell whether we can support a hardware breakpoint.  */
1002 118 markom
 
1003 106 markom
static int
1004
or1k_can_use_hardware_breakpoint ()
1005
{
1006
  int i;
1007 118 markom
 
1008 106 markom
  /* Search for unused breakpoint.  */
1009 113 markom
  return or1k_implementation.num_used_matchpoints < or1k_implementation.num_matchpoints;
1010 106 markom
}
1011
 
1012
/* Insert a breakpoint.  On targets that don't have built-in breakpoint
1013
   support, we read the contents of the target location and stash it,
1014
   then overwrite it with a breakpoint instruction.  ADDR is the target
1015
   location in the target machine.  CONTENTS_CACHE is a pointer to
1016
   memory allocated for saving the target contents.  It is guaranteed
1017
   by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1018
   is accomplished via BREAKPOINT_MAX).  */
1019
 
1020 113 markom
int
1021 106 markom
or1k_insert_breakpoint (addr, contents_cache)
1022
     CORE_ADDR addr;
1023
     char *contents_cache;
1024
{
1025
  if (or1k_can_use_hardware_breakpoint())
1026
    return set_breakpoint (addr);
1027
  else
1028
    return memory_insert_breakpoint (addr, contents_cache);
1029
}
1030
 
1031 113 markom
int
1032 106 markom
or1k_remove_breakpoint (addr, contents_cache)
1033
     CORE_ADDR addr;
1034
     char *contents_cache;
1035
{
1036
  /* First try to remove HW breakpoint at address */
1037
  if (clear_breakpoint (addr))
1038
    return memory_remove_breakpoint (addr, contents_cache);
1039
  else
1040
    return 0;
1041
}
1042
 
1043 113 markom
/* Tell whether this target can support a hardware breakpoint.  CNT
1044
   is the number of hardware breakpoints already installed.  This
1045
   implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro.
1046
   Lower bound is estimated. !!! Can we estimate better? */
1047
 
1048
int
1049
or1k_can_use_hardware_watchpoint (bp_type, cnt)
1050
     enum bptype bp_type;
1051
     int cnt;
1052
{
1053
  /* Are there at least two matchpoints left for watch? - estimate lower bound  */
1054
  return cnt + ((bp_type == bp_hardware_watchpoint)?(1):(0))
1055
    <= or1k_implementation.num_matchpoints;
1056
}
1057
 
1058 118 markom
/* Moves matchpoint.  This is very tricky - we have to update
1059
   all references to matchpoint indexes.  We assume here that
1060
   matchpoint with index to is unused! */
1061
 
1062
static void
1063
move_matchpoint (int from, int to)
1064
{
1065
  int i, j, tmp, chaining;
1066
  if (matchpoint_user_count[to] != 0)
1067
    error ("Internal: Destination matchpoint still has users");
1068
  matchpoint_user_count[to] = matchpoint_user_count[from];
1069
  matchpoint_user_count[from] = 0;
1070
  debug_regs_changed = 1;
1071
 
1072
  dvr[to] = dvr[from];
1073
  dcr[to] = dcr[from];
1074
  dcr[from].dp = 0;
1075
 
1076
  /* Copy chaining bits.  */
1077
  chaining = dmr1 & (3 << (2 * from));
1078
  dmr1 &= ~(3 << (2 * to));
1079
  dmr1 |= chaining << (2 * to);
1080
  dmr1 &= ~(3 << (2 * from));
1081
 
1082
  /* Copy watchpoint bits */
1083
  tmp = dmr2 & (1 << from);
1084
  dmr2 &= 1 << to;
1085
  dmr2 |= tmp << to;
1086
  dmr2 &= 1 << from;
1087
 
1088
  /* Update hwatch table.  Here we assume that matchpoint
1089
     group is connected (it cannot be implemented in HW
1090
     otherwise), so if we move first, we will have to move
1091
     others later.  */
1092
  for (i = 0; i < num_hw_watches; i++)
1093
    if (or1k_hwatch[i].matchpoint_start == from)
1094
      or1k_hwatch[i].matchpoint_start = to;
1095
 
1096
  /* Update htrace struct.  */
1097
  tmp = or1k_htrace.trig.wp_trig & (1 << from);
1098
  or1k_htrace.trig.wp_trig &= 1 << to;
1099
  or1k_htrace.trig.wp_trig |= tmp << to;
1100
  or1k_htrace.trig.wp_trig &= 1 << from;
1101
 
1102
  tmp = or1k_htrace.qual.wp_trig & (1 << from);
1103
  or1k_htrace.qual.wp_trig &= 1 << to;
1104
  or1k_htrace.qual.wp_trig |= tmp << to;
1105
  or1k_htrace.qual.wp_trig &= 1 << from;
1106
 
1107
  tmp = or1k_htrace.stop.wp_trig & (1 << from);
1108
  or1k_htrace.stop.wp_trig &= 1 << to;
1109
  or1k_htrace.stop.wp_trig |= tmp << to;
1110
  or1k_htrace.stop.wp_trig &= 1 << from;
1111
 
1112
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1113
    {
1114
      tmp = or1k_htrace.wp_record_uses[i] & (1 << from);
1115
      or1k_htrace.wp_record_uses[i] &= 1 << to;
1116
      or1k_htrace.wp_record_uses[i] |= tmp << to;
1117
      or1k_htrace.wp_record_uses[i] &= 1 << from;
1118
    }
1119
 
1120
  /* Do we need to move other references also? */
1121
}
1122
 
1123 113 markom
/* Sifts unused matchpoints to higher indexses.  */
1124
 
1125 118 markom
void
1126 113 markom
sift_matchpoints ()
1127
{
1128
  int i, first_free = 0;
1129
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1130
    if (dcr[i].dp)
1131
      {
1132 118 markom
        /* Move references.  */
1133
        move_matchpoint (i, first_free);
1134
 
1135 113 markom
        first_free++;
1136
      }
1137 118 markom
 
1138
  /* Unused matchpoints should be disabled by move_matchpoint,
1139
     so we are done here.  */
1140 113 markom
}
1141
 
1142
/* Translates gdb watchpoint type into one in DCR register.  */
1143
 
1144
static int
1145
translate_type (gdb_type)
1146
     int gdb_type;
1147
{
1148
  switch (gdb_type)
1149
    {
1150
    case 0:
1151
      return CT_SDATA;
1152
    case 1:
1153
      return CT_LDATA;
1154
    case 2:
1155
      return CT_ADATA;
1156
    default:
1157
      error ("Invalid type.");
1158
    }
1159
}
1160
 
1161
/* Set a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1162
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1163
   watchpoint. */
1164
 
1165
int
1166
or1k_insert_watchpoint (addr, len, type)
1167
     CORE_ADDR addr;
1168
     int len;
1169
     int type;
1170
{
1171
  int i;
1172 118 markom
 
1173 113 markom
  if (len < 1)
1174
    return -1;
1175
 
1176
  type = translate_type (type);
1177
 
1178
  /* Moves unused watchpoints to the top.  */
1179
  sift_matchpoints ();
1180 118 markom
 
1181 113 markom
  /* Place at first free matchpoint.  */
1182
  i = or1k_implementation.num_used_matchpoints;
1183
  dvr[i] = addr;
1184
  dcr[i].dp = 1;
1185
  dcr[i].cc = CC_GREATE;
1186
  dcr[i].sc = 0;
1187
  dcr[i].ct = type;
1188 118 markom
 
1189 113 markom
  /* Set && chaining here.  */
1190
  dmr1 &= ~(3 << (2 * i));
1191 118 markom
  dmr1 |= CHAINING_AND << (2 * i);
1192
 
1193 113 markom
  /* Set upper watchpoint bound.  */
1194
  i++;
1195
  dvr[i] = addr + len - 1;
1196
  dcr[i].dp = 1;
1197
  dcr[i].cc = CC_LESSE;
1198
  dcr[i].sc = 0;
1199
  dcr[i].ct = type;
1200 118 markom
 
1201 113 markom
  /* Matchpoints will cause breakpoints */
1202 118 markom
  dmr2 |= (1 << i);
1203 113 markom
  or1k_implementation.num_used_matchpoints += 2;
1204 118 markom
  debug_regs_changed = 1;
1205 113 markom
  return 0;
1206
}
1207
 
1208
/* Removes a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1209
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1210
   watchpoint. */
1211 118 markom
 
1212 113 markom
int
1213
or1k_remove_watchpoint (addr, len, type)
1214
     CORE_ADDR addr;
1215
     int len;
1216
     int type;
1217
{
1218
  int i, found = -1;
1219 118 markom
 
1220 113 markom
  if (len < 1)
1221
    return -1;
1222
 
1223
  type = translate_type (type);
1224
 
1225
  /* Find the right one.  */
1226
  for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
1227
    if (dvr[i] == addr && dcr[i].dp && dcr[i].cc == CC_GREATE && !dcr[i].sc && dcr[i].ct == type
1228
        && dvr[i + 1] == addr + len - 1 && dcr[i + 1].dp && dcr[i + 1].cc == CC_LESSE
1229
        && !dcr[i + 1].sc && dcr[i + 1].ct == type)
1230
      {
1231
        found = i;
1232
        break;
1233
      }
1234
 
1235
  if (found < 0)
1236
    return -1;
1237
 
1238
  dcr[found].dp = 0;
1239
  dcr[found + 1].dp = 0;
1240
 
1241
  /* Matchpoints will not cause breakpoints anymore. */
1242 118 markom
  dmr2 &= ~(1 << i);
1243 113 markom
  or1k_implementation.num_used_matchpoints -= 2;
1244 118 markom
  debug_regs_changed = 1;
1245 113 markom
  return 0;
1246
}
1247
 
1248
int
1249
or1k_stopped_by_watchpoint (void)
1250
{
1251
  return hit_watchpoint;
1252
}
1253
 
1254 106 markom
/* Insert a breakpoint.  */
1255
 
1256
int
1257
set_breakpoint (addr)
1258
     CORE_ADDR addr;
1259
{
1260
  int i;
1261 118 markom
 
1262 106 markom
  /* Search for unused breakpoint.  */
1263
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1264
    if (dcr[i].dp == 0) break;
1265
  if (i >= NUM_MATCHPOINTS) return 1;
1266
  dvr[i] = addr;
1267
  dcr[i].dp = 1;
1268
  dcr[i].cc = CC_EQUAL;
1269
  dcr[i].sc = 0;
1270
  dcr[i].ct = CT_FETCH;
1271 113 markom
  or1k_implementation.num_used_matchpoints++;
1272
 
1273
  /* No chaining here.  */
1274
  dmr1 &= ~(3 << (2*i));
1275 118 markom
 
1276 113 markom
  /* Matchpoints will cause breakpoints */
1277 118 markom
  dmr2 |= (1 << i);
1278
  debug_regs_changed = 1;
1279 106 markom
  return 0;
1280
}
1281
 
1282
/* Clear a breakpoint.  */
1283
 
1284
int
1285
clear_breakpoint (addr)
1286
     CORE_ADDR addr;
1287
{
1288
  int i;
1289 118 markom
 
1290 106 markom
  /* Search for matching breakpoint.  */
1291
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1292
    if ((dcr[i].dp == 1) && (dvr[i] == addr) && (dcr[i].cc == CC_EQUAL)
1293
        && (dcr[i].sc == 0) && (dcr[i].ct == CT_FETCH)) break;
1294
 
1295
  if (i >= NUM_MATCHPOINTS) return 1;
1296
  dcr[i].dp = 0;
1297 118 markom
 
1298 113 markom
  /* Matchpoints will cause breakpoints */
1299 118 markom
  dmr2 &= ~(1 << i);
1300 113 markom
  or1k_implementation.num_used_matchpoints--;
1301 118 markom
  debug_regs_changed = 1;
1302 106 markom
  return 0;
1303
}
1304
 
1305
/* Start running on the target board.  */
1306
 
1307
static void
1308
or1k_create_inferior (execfile, args, env)
1309
     char *execfile;
1310
     char *args;
1311
     char **env;
1312
{
1313
  CORE_ADDR entry_pt;
1314
 
1315
  if (args && *args)
1316
    {
1317 118 markom
      warning ("Can't pass arguments to remote OR1K board; arguments ignored.");
1318
 
1319 106 markom
      /* And don't try to use them on the next "run" command.  */
1320
      execute_command ("set args", 0);
1321
    }
1322
 
1323
  if (execfile == 0 || exec_bfd == 0)
1324
    error ("No executable file specified");
1325
 
1326
  or1k_kill ();
1327
  remove_breakpoints ();
1328
 
1329
  entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
1330
  init_wait_for_inferior ();
1331
 
1332
  /* FIXME: Should we set inferior_pid here?  */
1333 113 markom
 
1334 118 markom
  /* Needed to get correct instruction in cache */
1335
  insert_breakpoints ();
1336 106 markom
  clear_proceed_status ();
1337
  or1k_status = TARGET_STOPPED;
1338
  proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
1339
}
1340
 
1341
/* Clean up after a process.  Actually nothing to do.  */
1342
 
1343
static void
1344
or1k_mourn_inferior ()
1345
{
1346
  generic_mourn_inferior ();
1347
}
1348
 
1349
static void
1350
or1k_dummy_open (name, from_tty)
1351
     char *name;
1352
     int from_tty;
1353
{
1354
  target_preopen (from_tty);
1355
  if (or1k_is_open)
1356
    unpush_target (current_ops);
1357
  current_or1k_target = &or1k_target_dummy;
1358
  or1k_open (name, from_tty);
1359
}
1360
 
1361
static void
1362
or1k_jtag_open (name, from_tty)
1363
     char *name;
1364
     int from_tty;
1365
{
1366
  target_preopen (from_tty);
1367
  if (or1k_is_open)
1368
    unpush_target (current_ops);
1369
  current_or1k_target = &or1k_target_jtag;
1370
  or1k_open (name, from_tty);
1371
}
1372
 
1373
static void
1374
or1k_sim_open (name, from_tty)
1375
     char *name;
1376
     int from_tty;
1377
{
1378
  /* target_preopen (from_tty); - do we need this ? */
1379
  if (or1k_is_open)
1380
    unpush_target (current_ops);
1381
  current_or1k_target = &or1k_target_sim;
1382
  or1k_open (name, from_tty);
1383
}
1384
 
1385
/* Executes command on the target.  */
1386
 
1387
void
1388
or1k_sim_cmd (char *args, int from_tty)
1389
{
1390
  if (current_or1k_target != NULL && current_or1k_target->to_exec_command != NULL)
1391
    current_or1k_target->to_exec_command (args, from_tty);
1392
  else
1393
    error ("Command not supported on this target. ");
1394
}
1395
 
1396 113 markom
/* Displays matchpoints usage.  */
1397
 
1398 106 markom
void
1399 113 markom
info_matchpoints_command (char *args, int from_tty)
1400
{
1401
  int i;
1402
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1403
    {
1404
      printf_filtered ("WP%i ", i);
1405
      if (dcr[i].dp)
1406
        {
1407
          int chaining = (dmr1 << 2*i) & 3;
1408
          printf_filtered ("= %s ", ct_names[dcr[i].ct]);
1409
          if (dcr[i]. sc)
1410
            printf_filtered ("s%s %i", cc_names[dcr[i].cc], (int)dvr[i]);
1411
          else
1412
            printf_filtered ("%s %u", cc_names[dcr[i].cc], (unsigned int)dvr[i]);
1413
          if (chaining)
1414
            printf_filtered ("%s WP%i", ch_names[chaining], i - 1);
1415
        }
1416
      else
1417
        printf_filtered ("NOT USED");
1418
      if ((dmr2 >> i) & 1)
1419
        printf_filtered (", causes breakpoint");
1420
      if ((dmr2 >> (i + 11)) & 1)
1421
        printf_filtered (", increments counter");
1422
      printf_filtered ("\n");
1423
    }
1424
}
1425
 
1426
void
1427 106 markom
_initialize_remote_or1k ()
1428
{
1429
  /* Initialize the fields in or1k_ops that are common to all targets.  */
1430
  or1k_dummy_ops.to_close = or1k_close;
1431
  or1k_dummy_ops.to_detach = or1k_detach;
1432
  or1k_dummy_ops.to_resume = or1k_resume;
1433
  or1k_dummy_ops.to_wait = or1k_wait;
1434
  or1k_dummy_ops.to_fetch_registers = or1k_fetch_registers;
1435
  or1k_dummy_ops.to_store_registers = or1k_store_registers;
1436
  or1k_dummy_ops.to_prepare_to_store = or1k_prepare_to_store;
1437
  or1k_dummy_ops.to_xfer_memory = or1k_xfer_memory;
1438
  or1k_dummy_ops.to_files_info = or1k_files_info;
1439
  or1k_dummy_ops.to_insert_breakpoint = or1k_insert_breakpoint;
1440
  or1k_dummy_ops.to_remove_breakpoint = or1k_remove_breakpoint;
1441
  or1k_dummy_ops.to_kill = or1k_kill;
1442
  or1k_dummy_ops.to_load = generic_load;
1443
  or1k_dummy_ops.to_create_inferior = or1k_create_inferior;
1444
  or1k_dummy_ops.to_mourn_inferior = or1k_mourn_inferior;
1445
  or1k_dummy_ops.to_stratum = process_stratum;
1446 118 markom
 
1447
  /* We can access memory while program is running.  */
1448
  or1k_dummy_ops.to_has_all_memory = 0;
1449
 
1450 106 markom
  or1k_dummy_ops.to_has_memory = 1;
1451
  or1k_dummy_ops.to_has_stack = 1;
1452
  or1k_dummy_ops.to_has_registers = 1;
1453
  or1k_dummy_ops.to_has_execution = 1;
1454
  or1k_dummy_ops.to_magic = OPS_MAGIC;
1455
 
1456
  /* Copy the common fields to all target vectors.  */
1457
  or1k_jtag_ops = or1k_sim_ops = or1k_dummy_ops;
1458
 
1459
  /* Initialize target-specific fields in the target vectors adn add targets.  */
1460
  or1k_jtag_ops.to_shortname = "jtag";
1461
  or1k_jtag_ops.to_longname = "Remote or1k debugging over JTAG port";
1462 125 chris
  or1k_jtag_ops.to_doc = "Debug a board using the OR1K remote debugging protocol"
1463
    " over a parallel line.\nThe argument is the parallel port it is connected "
1464
    "to, or, if it is formatted\nas a URL of the form jtag://<hostname>:<port>,"
1465
    " then the argument refers to\na remote JTAG proxy server.\n";
1466 106 markom
  or1k_jtag_ops.to_open = or1k_jtag_open;
1467
  add_target (&or1k_jtag_ops);
1468
 
1469
  or1k_dummy_ops.to_shortname = "dummy";
1470
  or1k_dummy_ops.to_longname = "Dummy target";
1471
  or1k_dummy_ops.to_doc = "Actually no real target attached - more like /dev/null.\n";
1472
  or1k_dummy_ops.to_open = or1k_dummy_open;
1473
  add_target (&or1k_dummy_ops);
1474
 
1475
  or1k_sim_ops.to_shortname = "sim";
1476
  or1k_sim_ops.to_longname = "Remote or1k debugging using architecture simulator";
1477
  or1k_sim_ops.to_doc = "Debug using an architecture simulator.\n";
1478
  or1k_sim_ops.to_open = or1k_sim_open;
1479
  add_target (&or1k_sim_ops);
1480 113 markom
  add_info ("matchpoints", info_matchpoints_command, "Show current matchpoints allocation status.");
1481 106 markom
}

powered by: WebSVN 2.1.0

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