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 607

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

powered by: WebSVN 2.1.0

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