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 118

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

powered by: WebSVN 2.1.0

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