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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [remote-or1k.c] - Blame information for rev 1765

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

powered by: WebSVN 2.1.0

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