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 122

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 122 markom
extern ULONGEST jtag_read_reg PARAMS ((unsigned int regno));
46
extern void jtag_write_reg PARAMS ((unsigned int regno, ULONGEST 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 122 markom
     ULONGEST 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 122 markom
static ULONGEST
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
  if (current_or1k_target != NULL && current_or1k_target->to_init != NULL)
415
    current_or1k_target->to_init (args);
416 122 markom
 
417
  or1k_reset ();
418 106 markom
 
419
  /* Determine implementation configuration.  */
420 113 markom
  or1k_implementation.VR = or1k_read_spr_reg (VR_SPRNUM);
421
  or1k_implementation.UPR = or1k_read_spr_reg (UPR_SPRNUM);
422 118 markom
 
423 115 markom
  /* Determine number of gpr_regs.  */
424
  tmp = or1k_read_spr_reg (CPUCFGR_SPRNUM);
425
  or1k_implementation.num_gpr_regs = ((tmp >> 4) & 1)?(16):(32);
426 118 markom
 
427 115 markom
  /* Is any vector or floating point support present? */
428
  or1k_implementation.vf_present = ((tmp >> 7) & 7) != 0;
429
  or1k_implementation.num_vfpr_regs = (or1k_implementation.vf_present)?(32):(0);
430 106 markom
 
431 115 markom
  /* Determine max number of supported matchpoints.  */
432
  tmp = or1k_read_spr_reg (DCFGR_SPRNUM);
433
  or1k_implementation.num_matchpoints = tmp & 7;
434 113 markom
  or1k_implementation.num_used_matchpoints = 0;
435 115 markom
  or1k_implementation.has_counters = tmp & 4 == 1;
436 106 markom
 
437
  /* Is implementation supported? */
438
 
439
  /* First we should have system and debug groups implemented. */
440
  if (or1k_implementation.VR & (1 << SPR_SYSTEM_GROUP) == 0)
441
    error ("System group should be available in the or1k implementation.");
442
  if (or1k_implementation.VR & (1 << SPR_DEBUG_GROUP) == 0)
443
    error ("Debug group should be available in the or1k implementation.");
444 115 markom
  if (or1k_implementation.has_counters)
445
    warning ("Counters not supported.");
446 106 markom
 
447
  /* Delete break, watch, catch points.  */
448
  for(i = 0; i < NUM_MATCHPOINTS; i++)
449 118 markom
    {
450
      memset (&dcr[i], 0, sizeof (dcr[i]));
451
      matchpoint_user_count[i] = 0;
452
    }
453 106 markom
 
454
  dmr1 = 0;
455
  dmr2 = 0;
456 118 markom
  memset (&or1k_htrace, 0, sizeof (or1k_htrace));
457
 
458
  /* RECSELDEPEND = 0 does not match our trace scheme. */
459
  or1k_htrace.moder.rec_sel_dep = 1;
460
 
461
  debug_regs_changed = 1;
462
  or1k_commit_debug_registers ();
463
 
464 106 markom
  if (err != 0)
465
    error ("Cannot connect.");
466
 
467
  /* Stop when breakpoint occurs.  */
468 113 markom
  or1k_write_spr_reg (DSR_SPRNUM, 0x1000);
469 106 markom
 
470
  do_cleanups (old_cleanups);
471
 
472
  /* This should cause an error if not connected.  */
473
  or1k_fetch_registers (-1);
474
 
475
  set_current_frame (create_new_frame (read_fp (), read_pc ()));
476
  select_frame (get_current_frame (), 0);
477 118 markom
 
478
  /* Just empty it.  */
479
  if ((f = fopen (TRACE_FILENAME, "wb+")) == NULL)
480
    error ("Cannot open trace file.");
481
  fclose (f);
482
  trace_size = 0;
483 106 markom
}
484
 
485
/* Kill the process running on the board.  */
486
 
487
void
488
or1k_kill ()
489
{
490
  if (or1k_status != TARGET_RUNNING)
491
    return;
492
  or1k_status = TARGET_UNDEFINED;
493 113 markom
  or1k_reset();
494
  or1k_status = TARGET_STOPPED;
495 106 markom
 
496
  inferior_pid = 0;
497
}
498
 
499
/* Open a connection to the remote board.  */
500
 
501
static void
502
or1k_open (name, from_tty)
503
     char *name;
504
     int from_tty;
505
{
506
  or1k_init (name);
507
 
508
  /* Switch to using remote target now.  */
509
  current_ops = current_or1k_target->gdb_ops;
510
  or1k_is_open = 1;
511
  push_target (current_ops);
512
 
513
  /* FIXME: Should we call start_remote here?  */
514
 
515
/* This is really the job of start_remote however, that makes an assumption
516
   that the target is about to print out a status message of some sort.  That
517
   doesn't happen here (in fact, it may not be possible to get the monitor to
518
   send the appropriate packet).  */
519
 
520
  flush_cached_frames ();
521
  registers_changed ();
522
  stop_pc = read_pc ();
523
  set_current_frame (create_new_frame (read_fp (), stop_pc));
524
  select_frame (get_current_frame (), 0);
525
  print_stack_frame (selected_frame, -1, 1);
526
}
527
 
528
/* Close a connection to the remote board.  */
529
 
530
static void
531
or1k_close (quitting)
532
     int quitting;
533
{
534
  if (or1k_is_open)
535
    {
536
      or1k_kill ();
537
      if (current_or1k_target != NULL && current_or1k_target->to_done != NULL)
538
        current_or1k_target->to_done ();
539
      current_or1k_target = NULL;
540
    }
541
  generic_mourn_inferior ();
542
}
543
 
544
/* Detach from the remote board.  */
545
 
546
static void
547
or1k_detach (args, from_tty)
548
     char *args;
549
     int from_tty;
550
{
551
  if (args)
552
    error ("Argument given to \"detach\" when remotely debugging.");
553
 
554
  pop_target ();
555
 
556
  or1k_close (1);
557
 
558
  if (from_tty)
559
    printf_unfiltered ("Ending remote or1k debugging.\n");
560
}
561
 
562 118 markom
/* Appends trace data to the trace file.  */
563
 
564
static void
565
or1k_read_trace ()
566
{
567
  struct htrace_data_struct data;
568 122 markom
  ULONGEST tmp;
569 118 markom
  int first = 1;
570
  FILE *fd;
571
  if ((fd = fopen (TRACE_FILENAME, "ab")) == NULL)
572
    {
573
      warning ("Cannot append to trace file.");
574
      return;
575
    }
576
 
577
  or1k_set_chain (SC_TRACE);
578
  while (1)
579
    {
580
      tmp = or1k_read_reg (0);
581
      memcpy (&data, &tmp, sizeof (data));
582
 
583
      /* Last record reached. */
584
      if (!data.valid)
585
        break;
586
      data.valid = first;
587
      first = 0;
588
      if (!fwrite (&data, sizeof (data), 1, fd))
589
        {
590
          warning ("Cannot write trace data");
591
          break;
592
        }
593
    }
594
  fclose (fd);
595
}
596
 
597 106 markom
/* Resume execution of the target process.  STEP says whether to single-step
598
   or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
599
   to the target, or zero for no signal.  */
600
 
601
static void
602
or1k_resume (pid, step, siggnal)
603
     int pid, step;
604
     enum target_signal siggnal;
605
{
606
  if (or1k_status != TARGET_STOPPED)
607
    if (or1k_status == TARGET_RUNNING)
608
      error ("Program is already running.");
609
    else
610
      error ("The program is not being run.");
611
 
612
  /* Clear reason register for later.  */
613 113 markom
  or1k_write_spr_reg (DRR_SPRNUM, 0);
614 106 markom
 
615
  if (step)
616
    {
617
      /* HW STEP.  Set DMR1_ST.  */
618
      dmr1 |= DMR1_ST;
619 113 markom
      or1k_write_spr_reg (DMR1_SPRNUM, dmr1);
620 106 markom
      dmr1 &= ~DMR1_ST;
621
    }
622
 
623 118 markom
  or1k_commit_debug_registers ();
624 106 markom
  /* Run the target. */
625
  or1k_unstall ();
626
  or1k_status = TARGET_RUNNING;
627
}
628
 
629
/* Wait until the remote stops, and return a wait status.  */
630
 
631
static int
632
or1k_wait (pid, status)
633
     int pid;
634
     struct target_waitstatus *status;
635
{
636
  interrupt_count = 0;
637
 
638
  /* If we have not sent a single step or continue command, then the
639
     board is waiting for us to do something.  Return a status
640
     indicating that it is stopped.  */
641
  if (or1k_status != TARGET_RUNNING)
642
    {
643
      if (or1k_status != TARGET_STOPPED)
644
        error("Target in invalid state.");
645
      status->kind = TARGET_WAITKIND_STOPPED;
646
      status->value.sig = TARGET_SIGNAL_TRAP;
647
      return 0;
648
    }
649
 
650
  if (err)
651
    or1k_error ("Remote failure: %s", or1k_err_name (err));
652
 
653
  /* Wait for or1k DRR register to be nonzero.  */
654
  do
655
    {
656 113 markom
      drr = or1k_read_spr_reg (DRR_SPRNUM);
657 106 markom
      usleep (10);
658
    }
659
  while (drr == 0);
660
 
661
  status->kind = TARGET_WAITKIND_STOPPED;
662 113 markom
  or1k_flush_pipeline ();
663 106 markom
 
664
  if (drr & DRR_RSTE)
665
    status->value.sig = TARGET_SIGNAL_REALTIME_33;
666
  else if (drr & DRR_BUSEE)
667
    status->value.sig = TARGET_SIGNAL_BUS;
668
  else if (drr & DRR_DPFE)
669
    status->value.sig = TARGET_SIGNAL_REALTIME_34;
670
  else if (drr & DRR_IPFE)
671
    status->value.sig = TARGET_SIGNAL_REALTIME_35;
672
  else if (drr & DRR_LPINTE)
673
    status->value.sig = TARGET_SIGNAL_INT;
674
  else if (drr & DRR_AE)
675
    status->value.sig = TARGET_SIGNAL_REALTIME_36;
676
  else if (drr & DRR_IIE)
677
    status->value.sig = TARGET_SIGNAL_ILL;
678
  else if (drr & DRR_HPINTE)
679
    status->value.sig = TARGET_SIGNAL_INT;
680
  else if (drr & DRR_DME)
681
    status->value.sig = TARGET_SIGNAL_REALTIME_37;
682
  else if (drr & DRR_IME)
683
    status->value.sig = TARGET_SIGNAL_REALTIME_38;
684
  else if (drr & DRR_RE)
685
    status->value.sig = TARGET_SIGNAL_REALTIME_39;
686
  else if (drr & DRR_SCE)
687
    status->value.sig = TARGET_SIGNAL_REALTIME_40;
688
  else if (drr & DRR_BE)
689
    status->value.sig = TARGET_SIGNAL_TRAP;
690
  else
691
    {
692
      status->value.sig = TARGET_SIGNAL_UNKNOWN;
693
      warning ("Invalid exception occured.");
694
    }
695
 
696 113 markom
  /* Log remote stop.  */
697 106 markom
  or1k_status = TARGET_STOPPED;
698 113 markom
 
699
  /* Determine what caused trap - breakpoint or watchpoint.  */
700
  if (status->value.sig == TARGET_SIGNAL_TRAP)
701
    {
702
      /* Search all active breakpoints for a match.  */
703
      CORE_ADDR pc = read_pc ();
704
      int breakpoint = 0;
705
      int i;
706
      for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
707 118 markom
        if (dvr[i] == pc && dcr[i].dp && dcr[i].cc == CC_EQUAL
708
            && !dcr[i].sc && dcr[i].ct == CT_FETCH)
709 113 markom
          {
710
            breakpoint = 1;
711
            break;
712
          }
713
      hit_watchpoint = !breakpoint;
714
    }
715
  else
716
    hit_watchpoint = 0;
717 106 markom
 
718
  /* If the stop PC is in the _exit function, assume
719
     we hit the 'break 0x3ff' instruction in _exit, so this
720
     is not a normal breakpoint.  */
721
  {
722
    char *func_name;
723
    CORE_ADDR func_start;
724
    CORE_ADDR pc = read_pc ();
725
 
726
    find_pc_partial_function (pc, &func_name, &func_start, NULL);
727
    if (func_name != NULL && strcmp (func_name, "_exit") == 0
728
        && func_start == pc)
729
      status->kind = TARGET_WAITKIND_EXITED;
730
  }
731 118 markom
 
732
  or1k_read_trace ();
733 106 markom
  return 0;
734
}
735
 
736 113 markom
/* Fetch a word from the target board.  All memory accesses to the
737
   remote board are word aligned.  */
738 106 markom
 
739 118 markom
unsigned int
740 106 markom
or1k_fetch_word (addr)
741
     CORE_ADDR addr;
742
{
743 113 markom
  if (addr & 3)
744
    {
745
      int subaddr = addr & 3;
746
      unsigned char buf[8];
747
      unsigned int low, high;
748
      addr >>= 2;
749
      low = or1k_read_reg (addr + MEM_SPACE);
750
      high = or1k_read_reg (addr + 1 + MEM_SPACE);
751
      memcpy (&buf[0], &low, 4);
752
      memcpy (&buf[4], &high, 4);
753
      memcpy (&low, &buf[subaddr], 4);
754
      return low;
755
    }
756
  else
757
    {
758
      addr >>= 2;
759
      return or1k_read_reg (addr + MEM_SPACE);
760
    }
761 106 markom
}
762
 
763
/* Store a word to the target board.  Returns errno code or zero for
764 113 markom
   success.  All memory accesses to the remote board are word aligned.  */
765 118 markom
 
766 106 markom
static int
767
or1k_store_word (addr, val)
768
     CORE_ADDR addr;
769
     unsigned int val;
770
{
771 113 markom
  if (addr & 3)
772
    {
773
      int subaddr = addr & 3;
774
      unsigned char buf[8];
775
      unsigned int low, high;
776
      addr >>= 2;
777
      low = or1k_read_reg (addr + MEM_SPACE);
778
      high = or1k_read_reg (addr + 1 + MEM_SPACE);
779
      memcpy (&buf[0], &low, 4);
780
      memcpy (&buf[4], &high, 4);
781
      memcpy (&buf[subaddr], &val, 4);
782
      memcpy (&low, &buf[0], 4);
783
      memcpy (&high, &buf[4], 4);
784
      or1k_write_reg (addr + MEM_SPACE, low);
785
      or1k_write_reg (addr + 1 + MEM_SPACE, high);
786
    }
787
  else
788
    {
789
      addr >>= 2;
790
      or1k_write_reg (addr + MEM_SPACE, val);
791
    }
792 106 markom
  return err;
793
}
794
 
795
/* Fetch the remote registers.  */
796
 
797
void
798
or1k_fetch_registers (regno)
799
     int regno;
800
{
801
  unsigned int val;
802
 
803
  if (regno == -1)
804
    {
805
      for (regno = 0; regno < NUM_REGS; regno++)
806
        or1k_fetch_registers (regno);
807
      return;
808
    }
809
 
810
  if (regno >= NUM_REGS)
811
    error("Invalid register number!");
812
 
813
  /* Convert to SPRNUM and read.  */
814 113 markom
  val = or1k_read_spr_reg (REGNUM_TO_SPRNUM(regno));
815 106 markom
 
816
  {
817
    char buf[MAX_REGISTER_RAW_SIZE];
818
 
819
    /* We got the number the register holds, but gdb expects to see a
820
       value in the target byte ordering.  */
821
    store_unsigned_integer (buf, REGISTER_RAW_SIZE (regno), val);
822
    supply_register (regno, buf);
823
  }
824
  if (err)
825 118 markom
    or1k_error ("Can't read register %d(%i): %s", regno,
826
                REGNUM_TO_SPRNUM(regno) + REG_SPACE, or1k_err_name (err));
827 106 markom
}
828
 
829
/* Fetch and return instruction from the specified location.  */
830
 
831
unsigned int
832
or1k_fetch_instruction (addr)
833
     CORE_ADDR addr;
834
{
835
  char buf[OR1K_INSTLEN];
836
  int status;
837
 
838
  status = read_memory_nobpt (addr, buf, OR1K_INSTLEN);
839
  if (status)
840
    memory_error (status, addr);
841
  return extract_unsigned_integer (buf, OR1K_INSTLEN);
842
}
843
 
844 113 markom
/* Currently not needed.  */
845
 
846 106 markom
static void
847
or1k_prepare_to_store ()
848
{
849
}
850
 
851
/* Store remote register(s).  */
852
 
853
static void
854
or1k_store_registers (regno)
855
     int regno;
856
{
857
  if (regno == -1)
858
    {
859
      for (regno = 0; regno < NUM_REGS; regno++)
860
        or1k_store_registers (regno);
861
      return;
862
    }
863
 
864
  if (regno >= NUM_REGS)
865
    error("Invalid register number!");
866
 
867 113 markom
  or1k_write_spr_reg (REGNUM_TO_SPRNUM(regno), or1k_read_spr_reg (REGNUM_TO_SPRNUM(regno)));
868 106 markom
  if (err)
869 113 markom
    or1k_error ("Can't write register %d(%i): %s", regno, REGNUM_TO_SPRNUM(regno), or1k_err_name (err));
870 106 markom
}
871
 
872
/* Read or write LEN bytes from inferior memory at MEMADDR,
873
   transferring to or from debugger address MYADDR.  Write to inferior
874
   if SHOULD_WRITE is nonzero.  Returns length of data written or
875
   read; 0 for error.  Note that protocol gives us the correct value
876
   for a longword, since it transfers values in ASCII.  We want the
877
   byte values, so we have to swap the longword values.  */
878
 
879
static int
880
or1k_xfer_memory (memaddr, myaddr, len, write, ignore)
881
     CORE_ADDR memaddr;
882
     char *myaddr;
883
     int len;
884
     int write;
885
     struct target_ops *ignore;
886
{
887
  register int i;
888
  /* Round starting address down to longword boundary.  */
889
  register CORE_ADDR addr = memaddr & ~3;
890
  /* Round ending address up; get number of longwords that makes.  */
891
  register int count = (((memaddr + len) - addr) + 3) / 4;
892
  /* Allocate buffer of that many longwords.  */
893
  register char *buffer = alloca (count * 4);
894
 
895
  int status;
896
 
897
  if (memaddr >= MEM_SPACE)
898
    error("Invalid address");
899
 
900
  if (write)
901
    {
902
      /* Fill start and end extra bytes of buffer with existing data.  */
903
      if (addr != memaddr || len < 4)
904
        {
905
          /* Need part of initial word -- fetch it.  */
906
          store_unsigned_integer (&buffer[0], 4, or1k_fetch_word (addr));
907
        }
908
 
909
      if (count > 1)
910
        {
911
          /* Need part of last word -- fetch it.  FIXME: we do this even
912
             if we don't need it.  */
913
          store_unsigned_integer (&buffer[(count - 1) * 4], 4,
914
                                  or1k_fetch_word (addr + (count - 1) * 4));
915
        }
916
 
917
      /* Copy data to be written over corresponding part of buffer */
918
      memcpy ((char *) buffer + (memaddr & 3), myaddr, len);
919
 
920
      /* Write the entire buffer.  */
921
      for (i = 0; i < count; i++, addr += 4)
922
        {
923
          status = or1k_store_word (addr,
924
                               extract_unsigned_integer (&buffer[i * 4], 4));
925
          /* Report each kilobyte (we download 32-bit words at a time) */
926
          if (i % 256 == 255)
927
            {
928
              printf_unfiltered ("*");
929
              gdb_flush (gdb_stdout);
930
            }
931
          if (status)
932
            {
933
              errno = status;
934
              return 0;
935
            }
936
          /* FIXME: Do we want a QUIT here?  */
937
        }
938
      if (count >= 256)
939
        printf_unfiltered ("\n");
940
    }
941
  else
942
    {
943
      /* Read all the longwords */
944
      for (i = 0; i < count; i++, addr += 4)
945
        {
946
          store_unsigned_integer (&buffer[i * 4], 4, or1k_fetch_word (addr));
947
          QUIT;
948
        }
949
 
950
      /* Copy appropriate bytes out of the buffer.  */
951
      memcpy (myaddr, buffer + (memaddr & 3), len);
952
    }
953
  return len;
954
}
955
 
956 113 markom
/* Flushes pipeline. May not be needed by all implementations, but
957
   it doen't hurt to do it. This function should be called every time
958
   or1k stops.
959
   When or1k stops it still has instructions in pipeline.
960
   We do this by inserting nop instructions.
961
   IF cycle remains unaffacted by writing to DIR, and it still holds
962
   instruction, that caused break or watchpoint. */
963
 
964
void
965
or1k_flush_pipeline ()
966
{
967
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
968
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
969
  or1k_write_spr_reg (DIR_SPRNUM, NOP_INSTR);
970
}
971
 
972 106 markom
/* Print info on this target.  */
973
 
974
static void
975
or1k_files_info (ignore)
976
     struct target_ops *ignore;
977
{
978
  char *file = "nothing";
979
 
980
  if (exec_bfd)
981
    file = bfd_get_filename (exec_bfd);
982
 
983
  printf_filtered ("or1k_files_info: file \"%s\"\n", file);
984
 
985
  if (exec_bfd)
986
    {
987
      printf_filtered ("\tAttached to %s running program %s\n",
988
                       target_shortname, file);
989
    }
990
  /* Print target info. */
991
  printf_filtered ("Status: %s\n", status_name[or1k_status]);
992
}
993
 
994
/* Tell whether we can support a hardware breakpoint.  */
995 118 markom
 
996 106 markom
static int
997
or1k_can_use_hardware_breakpoint ()
998
{
999
  int i;
1000 118 markom
 
1001 106 markom
  /* Search for unused breakpoint.  */
1002 113 markom
  return or1k_implementation.num_used_matchpoints < or1k_implementation.num_matchpoints;
1003 106 markom
}
1004
 
1005
/* Insert a breakpoint.  On targets that don't have built-in breakpoint
1006
   support, we read the contents of the target location and stash it,
1007
   then overwrite it with a breakpoint instruction.  ADDR is the target
1008
   location in the target machine.  CONTENTS_CACHE is a pointer to
1009
   memory allocated for saving the target contents.  It is guaranteed
1010
   by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1011
   is accomplished via BREAKPOINT_MAX).  */
1012
 
1013 113 markom
int
1014 106 markom
or1k_insert_breakpoint (addr, contents_cache)
1015
     CORE_ADDR addr;
1016
     char *contents_cache;
1017
{
1018
  if (or1k_can_use_hardware_breakpoint())
1019
    return set_breakpoint (addr);
1020
  else
1021
    return memory_insert_breakpoint (addr, contents_cache);
1022
}
1023
 
1024 113 markom
int
1025 106 markom
or1k_remove_breakpoint (addr, contents_cache)
1026
     CORE_ADDR addr;
1027
     char *contents_cache;
1028
{
1029
  /* First try to remove HW breakpoint at address */
1030
  if (clear_breakpoint (addr))
1031
    return memory_remove_breakpoint (addr, contents_cache);
1032
  else
1033
    return 0;
1034
}
1035
 
1036 113 markom
/* Tell whether this target can support a hardware breakpoint.  CNT
1037
   is the number of hardware breakpoints already installed.  This
1038
   implements the TARGET_CAN_USE_HARDWARE_WATCHPOINT macro.
1039
   Lower bound is estimated. !!! Can we estimate better? */
1040
 
1041
int
1042
or1k_can_use_hardware_watchpoint (bp_type, cnt)
1043
     enum bptype bp_type;
1044
     int cnt;
1045
{
1046
  /* Are there at least two matchpoints left for watch? - estimate lower bound  */
1047
  return cnt + ((bp_type == bp_hardware_watchpoint)?(1):(0))
1048
    <= or1k_implementation.num_matchpoints;
1049
}
1050
 
1051 118 markom
/* Moves matchpoint.  This is very tricky - we have to update
1052
   all references to matchpoint indexes.  We assume here that
1053
   matchpoint with index to is unused! */
1054
 
1055
static void
1056
move_matchpoint (int from, int to)
1057
{
1058
  int i, j, tmp, chaining;
1059
  if (matchpoint_user_count[to] != 0)
1060
    error ("Internal: Destination matchpoint still has users");
1061
  matchpoint_user_count[to] = matchpoint_user_count[from];
1062
  matchpoint_user_count[from] = 0;
1063
  debug_regs_changed = 1;
1064
 
1065
  dvr[to] = dvr[from];
1066
  dcr[to] = dcr[from];
1067
  dcr[from].dp = 0;
1068
 
1069
  /* Copy chaining bits.  */
1070
  chaining = dmr1 & (3 << (2 * from));
1071
  dmr1 &= ~(3 << (2 * to));
1072
  dmr1 |= chaining << (2 * to);
1073
  dmr1 &= ~(3 << (2 * from));
1074
 
1075
  /* Copy watchpoint bits */
1076
  tmp = dmr2 & (1 << from);
1077
  dmr2 &= 1 << to;
1078
  dmr2 |= tmp << to;
1079
  dmr2 &= 1 << from;
1080
 
1081
  /* Update hwatch table.  Here we assume that matchpoint
1082
     group is connected (it cannot be implemented in HW
1083
     otherwise), so if we move first, we will have to move
1084
     others later.  */
1085
  for (i = 0; i < num_hw_watches; i++)
1086
    if (or1k_hwatch[i].matchpoint_start == from)
1087
      or1k_hwatch[i].matchpoint_start = to;
1088
 
1089
  /* Update htrace struct.  */
1090
  tmp = or1k_htrace.trig.wp_trig & (1 << from);
1091
  or1k_htrace.trig.wp_trig &= 1 << to;
1092
  or1k_htrace.trig.wp_trig |= tmp << to;
1093
  or1k_htrace.trig.wp_trig &= 1 << from;
1094
 
1095
  tmp = or1k_htrace.qual.wp_trig & (1 << from);
1096
  or1k_htrace.qual.wp_trig &= 1 << to;
1097
  or1k_htrace.qual.wp_trig |= tmp << to;
1098
  or1k_htrace.qual.wp_trig &= 1 << from;
1099
 
1100
  tmp = or1k_htrace.stop.wp_trig & (1 << from);
1101
  or1k_htrace.stop.wp_trig &= 1 << to;
1102
  or1k_htrace.stop.wp_trig |= tmp << to;
1103
  or1k_htrace.stop.wp_trig &= 1 << from;
1104
 
1105
  for (i = 0; i < MAX_MATCHPOINTS; i++)
1106
    {
1107
      tmp = or1k_htrace.wp_record_uses[i] & (1 << from);
1108
      or1k_htrace.wp_record_uses[i] &= 1 << to;
1109
      or1k_htrace.wp_record_uses[i] |= tmp << to;
1110
      or1k_htrace.wp_record_uses[i] &= 1 << from;
1111
    }
1112
 
1113
  /* Do we need to move other references also? */
1114
}
1115
 
1116 113 markom
/* Sifts unused matchpoints to higher indexses.  */
1117
 
1118 118 markom
void
1119 113 markom
sift_matchpoints ()
1120
{
1121
  int i, first_free = 0;
1122
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1123
    if (dcr[i].dp)
1124
      {
1125 118 markom
        /* Move references.  */
1126
        move_matchpoint (i, first_free);
1127
 
1128 113 markom
        first_free++;
1129
      }
1130 118 markom
 
1131
  /* Unused matchpoints should be disabled by move_matchpoint,
1132
     so we are done here.  */
1133 113 markom
}
1134
 
1135
/* Translates gdb watchpoint type into one in DCR register.  */
1136
 
1137
static int
1138
translate_type (gdb_type)
1139
     int gdb_type;
1140
{
1141
  switch (gdb_type)
1142
    {
1143
    case 0:
1144
      return CT_SDATA;
1145
    case 1:
1146
      return CT_LDATA;
1147
    case 2:
1148
      return CT_ADATA;
1149
    default:
1150
      error ("Invalid type.");
1151
    }
1152
}
1153
 
1154
/* Set a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1155
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1156
   watchpoint. */
1157
 
1158
int
1159
or1k_insert_watchpoint (addr, len, type)
1160
     CORE_ADDR addr;
1161
     int len;
1162
     int type;
1163
{
1164
  int i;
1165 118 markom
 
1166 113 markom
  if (len < 1)
1167
    return -1;
1168
 
1169
  type = translate_type (type);
1170
 
1171
  /* Moves unused watchpoints to the top.  */
1172
  sift_matchpoints ();
1173 118 markom
 
1174 113 markom
  /* Place at first free matchpoint.  */
1175
  i = or1k_implementation.num_used_matchpoints;
1176
  dvr[i] = addr;
1177
  dcr[i].dp = 1;
1178
  dcr[i].cc = CC_GREATE;
1179
  dcr[i].sc = 0;
1180
  dcr[i].ct = type;
1181 118 markom
 
1182 113 markom
  /* Set && chaining here.  */
1183
  dmr1 &= ~(3 << (2 * i));
1184 118 markom
  dmr1 |= CHAINING_AND << (2 * i);
1185
 
1186 113 markom
  /* Set upper watchpoint bound.  */
1187
  i++;
1188
  dvr[i] = addr + len - 1;
1189
  dcr[i].dp = 1;
1190
  dcr[i].cc = CC_LESSE;
1191
  dcr[i].sc = 0;
1192
  dcr[i].ct = type;
1193 118 markom
 
1194 113 markom
  /* Matchpoints will cause breakpoints */
1195 118 markom
  dmr2 |= (1 << i);
1196 113 markom
  or1k_implementation.num_used_matchpoints += 2;
1197 118 markom
  debug_regs_changed = 1;
1198 113 markom
  return 0;
1199
}
1200
 
1201
/* Removes a data watchpoint.  ADDR and LEN should be obvious.  TYPE is 0
1202
   for a write watchpoint, 1 for a read watchpoint, or 2 for a read/write
1203
   watchpoint. */
1204 118 markom
 
1205 113 markom
int
1206
or1k_remove_watchpoint (addr, len, type)
1207
     CORE_ADDR addr;
1208
     int len;
1209
     int type;
1210
{
1211
  int i, found = -1;
1212 118 markom
 
1213 113 markom
  if (len < 1)
1214
    return -1;
1215
 
1216
  type = translate_type (type);
1217
 
1218
  /* Find the right one.  */
1219
  for (i = 0; i < or1k_implementation.num_used_matchpoints; i++)
1220
    if (dvr[i] == addr && dcr[i].dp && dcr[i].cc == CC_GREATE && !dcr[i].sc && dcr[i].ct == type
1221
        && dvr[i + 1] == addr + len - 1 && dcr[i + 1].dp && dcr[i + 1].cc == CC_LESSE
1222
        && !dcr[i + 1].sc && dcr[i + 1].ct == type)
1223
      {
1224
        found = i;
1225
        break;
1226
      }
1227
 
1228
  if (found < 0)
1229
    return -1;
1230
 
1231
  dcr[found].dp = 0;
1232
  dcr[found + 1].dp = 0;
1233
 
1234
  /* Matchpoints will not cause breakpoints anymore. */
1235 118 markom
  dmr2 &= ~(1 << i);
1236 113 markom
  or1k_implementation.num_used_matchpoints -= 2;
1237 118 markom
  debug_regs_changed = 1;
1238 113 markom
  return 0;
1239
}
1240
 
1241
int
1242
or1k_stopped_by_watchpoint (void)
1243
{
1244
  return hit_watchpoint;
1245
}
1246
 
1247 106 markom
/* Insert a breakpoint.  */
1248
 
1249
int
1250
set_breakpoint (addr)
1251
     CORE_ADDR addr;
1252
{
1253
  int i;
1254 118 markom
 
1255 106 markom
  /* Search for unused breakpoint.  */
1256
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1257
    if (dcr[i].dp == 0) break;
1258
  if (i >= NUM_MATCHPOINTS) return 1;
1259
  dvr[i] = addr;
1260
  dcr[i].dp = 1;
1261
  dcr[i].cc = CC_EQUAL;
1262
  dcr[i].sc = 0;
1263
  dcr[i].ct = CT_FETCH;
1264 113 markom
  or1k_implementation.num_used_matchpoints++;
1265
 
1266
  /* No chaining here.  */
1267
  dmr1 &= ~(3 << (2*i));
1268 118 markom
 
1269 113 markom
  /* Matchpoints will cause breakpoints */
1270 118 markom
  dmr2 |= (1 << i);
1271
  debug_regs_changed = 1;
1272 106 markom
  return 0;
1273
}
1274
 
1275
/* Clear a breakpoint.  */
1276
 
1277
int
1278
clear_breakpoint (addr)
1279
     CORE_ADDR addr;
1280
{
1281
  int i;
1282 118 markom
 
1283 106 markom
  /* Search for matching breakpoint.  */
1284
  for (i = 0; i < NUM_MATCHPOINTS; i++)
1285
    if ((dcr[i].dp == 1) && (dvr[i] == addr) && (dcr[i].cc == CC_EQUAL)
1286
        && (dcr[i].sc == 0) && (dcr[i].ct == CT_FETCH)) break;
1287
 
1288
  if (i >= NUM_MATCHPOINTS) return 1;
1289
  dcr[i].dp = 0;
1290 118 markom
 
1291 113 markom
  /* Matchpoints will cause breakpoints */
1292 118 markom
  dmr2 &= ~(1 << i);
1293 113 markom
  or1k_implementation.num_used_matchpoints--;
1294 118 markom
  debug_regs_changed = 1;
1295 106 markom
  return 0;
1296
}
1297
 
1298
/* Start running on the target board.  */
1299
 
1300
static void
1301
or1k_create_inferior (execfile, args, env)
1302
     char *execfile;
1303
     char *args;
1304
     char **env;
1305
{
1306
  CORE_ADDR entry_pt;
1307
 
1308
  if (args && *args)
1309
    {
1310 118 markom
      warning ("Can't pass arguments to remote OR1K board; arguments ignored.");
1311
 
1312 106 markom
      /* And don't try to use them on the next "run" command.  */
1313
      execute_command ("set args", 0);
1314
    }
1315
 
1316
  if (execfile == 0 || exec_bfd == 0)
1317
    error ("No executable file specified");
1318
 
1319
  or1k_kill ();
1320
  remove_breakpoints ();
1321
 
1322
  entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
1323
  init_wait_for_inferior ();
1324
 
1325
  /* FIXME: Should we set inferior_pid here?  */
1326 113 markom
 
1327 118 markom
  /* Needed to get correct instruction in cache */
1328
  insert_breakpoints ();
1329 106 markom
  clear_proceed_status ();
1330
  or1k_status = TARGET_STOPPED;
1331
  proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
1332
}
1333
 
1334
/* Clean up after a process.  Actually nothing to do.  */
1335
 
1336
static void
1337
or1k_mourn_inferior ()
1338
{
1339
  generic_mourn_inferior ();
1340
}
1341
 
1342
static void
1343
or1k_dummy_open (name, from_tty)
1344
     char *name;
1345
     int from_tty;
1346
{
1347
  target_preopen (from_tty);
1348
  if (or1k_is_open)
1349
    unpush_target (current_ops);
1350
  current_or1k_target = &or1k_target_dummy;
1351
  or1k_open (name, from_tty);
1352
}
1353
 
1354
static void
1355
or1k_jtag_open (name, from_tty)
1356
     char *name;
1357
     int from_tty;
1358
{
1359
  target_preopen (from_tty);
1360
  if (or1k_is_open)
1361
    unpush_target (current_ops);
1362
  current_or1k_target = &or1k_target_jtag;
1363
  or1k_open (name, from_tty);
1364
}
1365
 
1366
static void
1367
or1k_sim_open (name, from_tty)
1368
     char *name;
1369
     int from_tty;
1370
{
1371
  /* target_preopen (from_tty); - do we need this ? */
1372
  if (or1k_is_open)
1373
    unpush_target (current_ops);
1374
  current_or1k_target = &or1k_target_sim;
1375
  or1k_open (name, from_tty);
1376
}
1377
 
1378
/* Executes command on the target.  */
1379
 
1380
void
1381
or1k_sim_cmd (char *args, int from_tty)
1382
{
1383
  if (current_or1k_target != NULL && current_or1k_target->to_exec_command != NULL)
1384
    current_or1k_target->to_exec_command (args, from_tty);
1385
  else
1386
    error ("Command not supported on this target. ");
1387
}
1388
 
1389 113 markom
/* Displays matchpoints usage.  */
1390
 
1391 106 markom
void
1392 113 markom
info_matchpoints_command (char *args, int from_tty)
1393
{
1394
  int i;
1395
  for (i = 0; i < or1k_implementation.num_matchpoints; i++)
1396
    {
1397
      printf_filtered ("WP%i ", i);
1398
      if (dcr[i].dp)
1399
        {
1400
          int chaining = (dmr1 << 2*i) & 3;
1401
          printf_filtered ("= %s ", ct_names[dcr[i].ct]);
1402
          if (dcr[i]. sc)
1403
            printf_filtered ("s%s %i", cc_names[dcr[i].cc], (int)dvr[i]);
1404
          else
1405
            printf_filtered ("%s %u", cc_names[dcr[i].cc], (unsigned int)dvr[i]);
1406
          if (chaining)
1407
            printf_filtered ("%s WP%i", ch_names[chaining], i - 1);
1408
        }
1409
      else
1410
        printf_filtered ("NOT USED");
1411
      if ((dmr2 >> i) & 1)
1412
        printf_filtered (", causes breakpoint");
1413
      if ((dmr2 >> (i + 11)) & 1)
1414
        printf_filtered (", increments counter");
1415
      printf_filtered ("\n");
1416
    }
1417
}
1418
 
1419
void
1420 106 markom
_initialize_remote_or1k ()
1421
{
1422
  /* Initialize the fields in or1k_ops that are common to all targets.  */
1423
  or1k_dummy_ops.to_close = or1k_close;
1424
  or1k_dummy_ops.to_detach = or1k_detach;
1425
  or1k_dummy_ops.to_resume = or1k_resume;
1426
  or1k_dummy_ops.to_wait = or1k_wait;
1427
  or1k_dummy_ops.to_fetch_registers = or1k_fetch_registers;
1428
  or1k_dummy_ops.to_store_registers = or1k_store_registers;
1429
  or1k_dummy_ops.to_prepare_to_store = or1k_prepare_to_store;
1430
  or1k_dummy_ops.to_xfer_memory = or1k_xfer_memory;
1431
  or1k_dummy_ops.to_files_info = or1k_files_info;
1432
  or1k_dummy_ops.to_insert_breakpoint = or1k_insert_breakpoint;
1433
  or1k_dummy_ops.to_remove_breakpoint = or1k_remove_breakpoint;
1434
  or1k_dummy_ops.to_kill = or1k_kill;
1435
  or1k_dummy_ops.to_load = generic_load;
1436
  or1k_dummy_ops.to_create_inferior = or1k_create_inferior;
1437
  or1k_dummy_ops.to_mourn_inferior = or1k_mourn_inferior;
1438
  or1k_dummy_ops.to_stratum = process_stratum;
1439 118 markom
 
1440
  /* We can access memory while program is running.  */
1441
  or1k_dummy_ops.to_has_all_memory = 0;
1442
 
1443 106 markom
  or1k_dummy_ops.to_has_memory = 1;
1444
  or1k_dummy_ops.to_has_stack = 1;
1445
  or1k_dummy_ops.to_has_registers = 1;
1446
  or1k_dummy_ops.to_has_execution = 1;
1447
  or1k_dummy_ops.to_magic = OPS_MAGIC;
1448
 
1449
  /* Copy the common fields to all target vectors.  */
1450
  or1k_jtag_ops = or1k_sim_ops = or1k_dummy_ops;
1451
 
1452
  /* Initialize target-specific fields in the target vectors adn add targets.  */
1453
  or1k_jtag_ops.to_shortname = "jtag";
1454
  or1k_jtag_ops.to_longname = "Remote or1k debugging over JTAG port";
1455
  or1k_jtag_ops.to_doc = "\
1456
Debug a board using the OR1K remote debugging protocol over a parallel line.\n\
1457
The argument is the device it is connected to or, if it contains a colon,\n";
1458
  or1k_jtag_ops.to_open = or1k_jtag_open;
1459
  add_target (&or1k_jtag_ops);
1460
 
1461
  or1k_dummy_ops.to_shortname = "dummy";
1462
  or1k_dummy_ops.to_longname = "Dummy target";
1463
  or1k_dummy_ops.to_doc = "Actually no real target attached - more like /dev/null.\n";
1464
  or1k_dummy_ops.to_open = or1k_dummy_open;
1465
  add_target (&or1k_dummy_ops);
1466
 
1467
  or1k_sim_ops.to_shortname = "sim";
1468
  or1k_sim_ops.to_longname = "Remote or1k debugging using architecture simulator";
1469
  or1k_sim_ops.to_doc = "Debug using an architecture simulator.\n";
1470
  or1k_sim_ops.to_open = or1k_sim_open;
1471
  add_target (&or1k_sim_ops);
1472 113 markom
  add_info ("matchpoints", info_matchpoints_command, "Show current matchpoints allocation status.");
1473 106 markom
}

powered by: WebSVN 2.1.0

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