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 613

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

powered by: WebSVN 2.1.0

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