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 593

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

powered by: WebSVN 2.1.0

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