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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [toplevel.c] - Blame information for rev 361

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cvs
/* toplevel.c -- Top level simulator source file
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Simulator commands. Help and version output. SIGINT processing.
21
Stdout redirection is specific to linux (I need to fix this). */
22
 
23 16 jrydberg
#include "config.h"
24
 
25 2 cvs
#include <stdio.h>
26
#include <ctype.h>
27
#include <string.h>
28
#include <stdlib.h>
29 46 lampret
#include <unistd.h>
30 2 cvs
#include <signal.h>
31
#include <stdarg.h>
32 123 markom
#include <fcntl.h>
33 2 cvs
 
34 16 jrydberg
#ifdef HAVE_LIBREADLINE
35 7 jrydberg
#include <readline/readline.h>
36
#include <readline/history.h>
37 16 jrydberg
#endif /* HAVE_LIBREADLINE */
38 7 jrydberg
 
39 2 cvs
#include "arch.h"
40
#include "parse.h"
41
#include "abstract.h"
42 261 markom
#include "labels.h"
43 2 cvs
#include "trace.h"
44
#include "execute.h"
45 69 lampret
#include "sim-config.h"
46 103 lampret
#include "spr_defs.h"
47 212 erez
#include "dma.h"
48 304 markom
#include "vapi.h"
49 2 cvs
 
50 28 lampret
#include "coff.h"
51
 
52 304 markom
#include "gdbcomm.h"
53 127 chris
 
54 2 cvs
/* CVS revision number. */
55 361 markom
const char rcsrev[] = "$Revision: 1.46 $";
56 2 cvs
 
57
/* Continuos run versus single step tracing switch. */
58
int cont_run;
59
 
60
/* History of execution */
61
int histexec[HISTEXEC_LEN];
62
 
63 7 jrydberg
char *sim_commands [] = {
64 361 markom
  "q", "t", "help", "de", "dm", "run", "pr", "pm", "pc",
65
  "reset", "break", "hist", "stats", "stall" "info",
66
  "r", "dv", "set", 0
67 7 jrydberg
};
68
 
69 344 markom
inline void debug(int level, const char *format, ...)
70 2 cvs
{
71 7 jrydberg
  char *p;
72
  va_list ap;
73 2 cvs
 
74 344 markom
  if (config.sim.debug >= level) {
75 69 lampret
    if ((p = malloc(1000)) == NULL)
76
      return;
77
    va_start(ap, format);
78
    (void) vsnprintf(p, 1000, format, ap);
79
    va_end(ap);
80 344 markom
    printf("%s", p);
81 69 lampret
    fflush(stdout);
82
    free(p);
83
  } else {
84
#if DEBUG
85 7 jrydberg
  if ((p = malloc(1000)) == NULL)
86
    return;
87
  va_start(ap, format);
88
  (void) vsnprintf(p, 1000, format, ap);
89
  va_end(ap);
90
  printf("%s\n", p);
91
  fflush(stdout);
92
  free(p);
93 2 cvs
#endif
94 69 lampret
  }
95 2 cvs
}
96
 
97 304 markom
void ctrl_c(signum)
98 7 jrydberg
     int signum;
99 2 cvs
{
100 181 chris
  extern int cpu_stalled;  /* CZ from debug_interface */
101
  cont_run = cpu_stalled ? 0 : 1;
102 264 markom
  config.sim.iprompt = 1;
103 181 chris
  cpu_stalled = 0;
104 7 jrydberg
  signal(SIGINT, ctrl_c);
105 2 cvs
}
106
 
107 304 markom
void version()
108 2 cvs
{
109 361 markom
  printf ("\n");
110
  printf ("OpenRISC 1000 (OR16+OR32) Architectural Simulator, %s\n", rcsrev);
111
  printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
112
  printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
113
  printf ("                   Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
114
  printf ("                   Johan Rydberg, johan.rydberg@insight.se\n");
115
  printf ("                   Marko Mlinar, markom@opencores.org\n");
116 264 markom
  printf ("Copyright (C) 2001 Simon Srot, simons@opencores.org\n");
117
  printf ("                   Marko Mlinar, markom@opencores.org\n");
118 361 markom
  printf ("Visit http://www.opencores.org for more information about ");
119
  printf ("OpenRISC 1000 and\nother open source cores.\n\n");
120
  printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
121
  printf ("details see COPYING.\nThis is free software, and you ");
122
  printf ("are welcome to redistribute it under certain\nconditions; ");
123
  printf ("for details see COPYING.\n");
124 2 cvs
}
125
 
126 7 jrydberg
void
127
help()
128 2 cvs
{
129 361 markom
  printf("q      - quit simulator\n");
130
  printf("r      - display all registers\n");
131
  printf("t      - execute next instruction\n");
132
  printf("run <cycles> [<hush>]  - execute <cycles> instructions, no reg dump if hush\n");
133
  printf("pr <r> <value>     - patch register <r> with <value>\n");
134
  printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
135
  printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
136
  printf("pm <addr> <value>  - patch memory location <addr> with <value>\n");
137
  printf("pc <value>     - patch PC register with <value>\n");
138
  printf("break <addr>     - toggle breakpoint at address <addr>\n");
139
  printf("reset      - simulator reset\n");
140
  printf("hist       - execution history\n");
141
  printf("stall                    - stalls the processor and gives control to the debugger\n");
142
  printf("stats <num|clear>    - execution statistics num or clear it.\n");
143
  printf("info       - configuration info (caches etc.)\n");
144
  printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
145
  printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
146
  printf("set <section> <item> = <param>  - set configuration.  See sim.cfg for more information.\n");
147
  printf("<cmd> > <filename>   - redirect simulator stdout to <filename> (and not emulated printf)\n");
148
  printf("debug      - toggles simulator debug mode\n");
149
  printf("help       - available commands (this list)\n");
150 2 cvs
}
151
 
152 257 erez
void debugmem( unsigned long from, unsigned long to );
153 21 cmchen
 
154 304 markom
/* Initalizes all devices and sim */
155
void sim_init ()
156 2 cvs
{
157 269 markom
  init_labels();
158
  init_breakpoints();
159 361 markom
  initstats();
160
  build_automata();
161
 
162 306 markom
  if (GDB_ENABLED)
163
    gdbcomm_init ();
164
 
165 305 markom
  if (config.sim.profile) {
166 361 markom
    runtime.sim.fprof = fopen(config.sim.prof_fn, "wt+");
167
    if(!runtime.sim.fprof) {
168 264 markom
      config.sim.profile = 0;
169 294 markom
      fprintf(stderr, "WARNING: Problems opening profile file. Profiling disabled. \n");
170 173 markom
    } else
171 361 markom
      fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF main\n");
172 173 markom
  }
173 294 markom
 
174
  if (config.sim.exe_log) {
175 361 markom
    runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
176
    if(!runtime.sim.fexe_log) {
177 294 markom
      config.sim.exe_log = 0;
178
      printf("WARNING: Problems opening exe_log file. Execution logging disabled. \n");
179
    }
180
  }
181 263 markom
 
182 262 markom
  /* Initialize memory */
183
  {
184 361 markom
    extern struct dev_memarea *dev_list;
185
    int i;
186
    if (config.memory.type == MT_RANDOM) {
187
      unsigned int val = 0;
188 123 markom
 
189 262 markom
      if (config.memory.random_seed == -1) {
190
        config.memory.random_seed = time(NULL);
191
        /* Print out the seed just in case we ever need to debug */
192 361 markom
        printf("Seeding random generator with value %d\n", config.memory.random_seed);
193
      }
194
      srandom(config.memory.random_seed);
195 262 markom
 
196 361 markom
      for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
197 221 markom
        for(i = 0; i < cur_area->size; i++) {
198
          val = random();
199 262 markom
          setsim_mem8(i + cur_area->addr_compare, val & 0xFF);
200 221 markom
        }
201 262 markom
    } else if(config.memory.type == MT_PATTERN) {
202 361 markom
      for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
203 221 markom
        for(i = 0; i < cur_area->size; i++)
204 262 markom
          setsim_mem8(i + cur_area->addr_compare, config.memory.pattern);
205 269 markom
    } else if (config.memory.type != MT_UNKNOWN) {
206 262 markom
      fprintf(stderr, "Invalid memory configuration type.\n");
207 361 markom
      exit(1);
208 221 markom
    }
209 242 markom
  }
210 262 markom
 
211 361 markom
  if(runtime.sim.filename) {
212
    unsigned long endaddr = 0xFFFFFFFF;
213
    endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero.  */
214
    if (endaddr == -1) {
215
      fprintf(stderr, "Problems loading boot code.\n");
216
      exit(1);
217
    }
218
  }
219
 
220
  /* Disable gdb debugging, if debug module is not available.  */
221
  if (config.debug.gdb_enabled && !config.debug.enabled) {
222
    config.debug.gdb_enabled = 0;
223
    if (config.sim.verbose)
224
      fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
225
  }
226
 
227
  /* Enable dependency stats, if we want to do history analisis */
228
  if (config.cpu.history && !config.cpu.dependency) {
229
    config.cpu.dependency = 1;
230
    if (config.sim.verbose)
231
      fprintf (stderr, "WARNING: dependency stats must be enabled to do history analisis.\n");
232
  }
233
 
234
  /* Debug forces verbose */
235
  if (config.sim.debug && !config.sim.verbose) {
236
    config.sim.verbose = 1;
237
    fprintf (stderr, "WARNING: verbose turned on.\n");
238
  }
239
 
240
  /* Start VAPI before device initialization.  */
241
  if (config.vapi.enabled) {
242
    vapi_init ();
243
    if (config.sim.verbose)
244
      printf ("VAPI started, waiting for clients.\n");
245
  }
246
 
247
  uart_reset();
248
  dma_reset();
249
  eth_reset();
250
  tick_reset();
251
  pm_reset();
252
  pic_reset();
253
  mc_reset();
254
  reset();
255
 
256
  /* Wait till all test are connected.  */
257
  if (config.vapi.enabled) {
258
    int numu = vapi_num_unconnected (0);
259
    if (numu) {
260
      printf ("\nWaiting for VAPI tests with ids:\n");
261
      vapi_num_unconnected (1);
262
      printf ("\n");
263
      while (numu = vapi_num_unconnected (0)) {
264
        vapi_check ();
265
        printf ("\rStill waiting for %i VAPI test(s) to connect.       ", numu);
266
        usleep (100);
267
      }
268
      printf ("\n");
269
    }
270
    printf ("All devices connected                         \n");
271
  }
272
  /* simulator is initialized */
273
  runtime.sim.init = 0;
274 304 markom
}
275 7 jrydberg
 
276 304 markom
/* Display info about various modules */
277
void sim_info () {
278
  itlb_status(-1);
279 361 markom
  dtlb_status(-1);
280
  ic_info();
281
  dc_info();
282
  sprs_status();
283
 
284
  if (config.cpu.bpb) bpb_info();
285
  if (config.cpu.btic) btic_info();
286
  if (config.uarts_enabled) uart_status();
287
  if (config.dmas_enabled) dma_status();
288
  if (config.ethernets_enabled) eth_status();
289 304 markom
}
290
 
291
/* Cleanup */
292
void sim_done ()
293
{
294
  if (config.sim.profile) {
295
    extern int cycles;
296 361 markom
    fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
297
    fclose(runtime.sim.fprof);
298 304 markom
  }
299 361 markom
  if (config.sim.exe_log)   fclose(runtime.sim.fexe_log);
300 304 markom
  if (config.vapi.enabled)  vapi_done ();
301
  exit(0);
302
}
303
 
304
int main(argc, argv)
305
     int argc;
306
     char *argv[];
307
{
308 361 markom
  char *linestr;
309
  char item1[500], b2[500], prev_str[500] = "";
310
  char *redirstr;
311
  int hush = 0;
312
  int first_prompt = 1;
313
  int trace_fd = 0;
314 304 markom
 
315 361 markom
  srand(getpid());
316
  init_defconfig();
317
  if (parse_args(argc, argv)) {
318
    printf("Usage: %s [options] <filename>\n", argv[0]);
319
    printf("Options:\n");
320
    printf(" -v                 version and copyright note\n");
321
    printf(" -i                 enable interactive command prompt\n");
322
    printf(" -f or --file       load script file [sim.cfg]\n");
323
    printf(" --nosrv            do not launch JTAG proxy server\n"); /* (CZ) */
324
    printf(" --srv <n>          launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
325
    printf(" --profile          enable profiling\n");
326
    exit(-1);
327
  }
328 304 markom
 
329
#ifdef HAVE_LIBREADLINE
330 361 markom
  initialize_readline (); /* Bind our completer. */
331 304 markom
#endif
332
 
333
  /* Read configuration file.  */
334 361 markom
  if (!runtime.sim.script_file_specified)
335
    read_script_file ("sim.cfg");
336 304 markom
  print_config();
337 336 markom
  sim_init ();
338 304 markom
  signal(SIGINT, ctrl_c);
339 335 markom
 
340 361 markom
  while(1) {
341
    if (config.sim.iprompt) {
342
      if (GDB_ENABLED)
343
        {
344
          printf ("(sim) ");
345
          fflush(stdout);
346
          HandleServerSocket(true);  /* block & check_stdin = true */
347
        }
348 16 jrydberg
#ifdef HAVE_LIBREADLINE
349 361 markom
      /* Must disable readline in new mode. It isn't compatible
350
         with non blocking environments */
351
      if(!GDB_ENABLED)
352
        linestr = readline("(sim) ");
353
      else
354
        linestr = fgets(b2, sizeof b2, stdin);
355 16 jrydberg
#else
356 361 markom
      if(!GDB_ENABLED)
357
        printf ("(sim) ");
358
      linestr = fgets(b2, sizeof b2, stdin);
359 16 jrydberg
#endif
360 361 markom
    } else
361
      strcpy(linestr = b2, "run -1 hush");
362 7 jrydberg
 
363 361 markom
    if (!linestr)
364
      break;
365
    linestr = stripwhite (linestr);
366 7 jrydberg
 
367 16 jrydberg
#ifdef HAVE_LIBREADLINE
368 361 markom
    /* Readline only works in the old mode */
369
    if(!server_fd)
370
      {
371
        if (strlen(linestr) == 0) {
372
          char *l = repeat_last_command ();
373
 
374
          if (l) {
375
      free (linestr);
376
      linestr = l;
377
          }
378
        }
379
 
380
        if (*linestr) {
381
          add_history (linestr);
382
        }
383
      }
384 16 jrydberg
#endif /* HAVE_LIBREADLINE */
385 361 markom
 
386
    if (redirstr = strstr(linestr, ">")) {
387
      *redirstr = '\0';
388
      strtoken(&redirstr[1], item1, 1);
389
      freopen(item1, "w+", stdout);
390
    }
391
 
392
    if (linestr[0] == '\n')
393
      strcpy (linestr, &prev_str[0]);
394
    else
395
      strcpy (&prev_str[0], linestr);
396
 
397
    strtoken(linestr, item1, 1);
398
    if (strcmp(item1, "q") == 0) {  /* quit */
399
      printf ("\n");
400
      sim_done ();
401
    } else
402
    if (strcmp(item1, "help") == 0) /* help */
403
      help();
404
    else
405
    if (strcmp(item1, "t") == 0) {  /* trace */
406
      cont_run = 1;
407
    } else
408
    if (strcmp(item1, "dm") == 0) { /* dump memory */
409
      char item2[20];
410
      char item3[20];
411
      static int from = 0, to = 0;
412
 
413
      strtoken(linestr, item2, 2);
414
      strtoken(linestr, item3, 3);
415
 
416
      if (strlen(item2)) {
417
        if (item2[0] == '_')
418
          from = eval_label(item2);
419
        else
420
          from = strtoul(item2, NULL, 0);
421
        to = from + 0x40;
422
      }
423
      if (strlen(item3))
424
        to = strtoul(item3, NULL, 0);
425
      dumpmemory(from, to, 0, 1);
426
            printf("\n");
427
    } else
428
    if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
429
      char item2[20];
430
      char item3[20];
431
      char item4[20];
432
      static int from = 0, to = 0;
433
 
434
      strtoken(linestr, item2, 2);
435
      strtoken(linestr, item3, 3);
436
      strtoken(linestr, item4, 4);
437
 
438
      if (strlen(item2)) {
439
        if (item2[0] == '_')
440
          from = eval_label(item2);
441
        else
442
          from = strtoul(item2, NULL, 0);
443
        to = from + 0x40;
444
      }
445
      if (strlen(item3))
446
        to = strtoul(item3, NULL, 0);
447
      if (!strlen(item4))
448
        strcpy(item4, "or1k_mem");
449
      dumpverilog(item4, from, to);
450
        printf("\n");
451
    } else
452
    if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
453
      char item2[20];
454
      char item3[20];
455
      static int from = 0, to = 0;
456
 
457
      strtoken(linestr, item2, 2);
458
      strtoken(linestr, item3, 3);
459
 
460
      if (strlen(item2)) {
461
        if (item2[0] == '_')
462
          from = eval_label(item2);
463
        else
464
          from = strtoul(item2, NULL, 0);
465
        to = from + 0x40;
466
      }
467
      if (strlen(item3))
468
        to = strtoul(item3, NULL, 0);
469
      dumphex(from, to);
470
        printf("\n");
471
    } else
472
    if (strcmp(item1, "pm") == 0) { /* patch memory */
473
      char item2[20];
474
      char item3[20];
475
      static int addr = 0;
476
      int breakpoint = 0;
477 123 markom
 
478 361 markom
      strtoken(linestr, item2, 2);
479
      strtoken(linestr, item3, 3);
480
      if (strlen(item2))
481
        if (item2[0] == '_')
482
          addr = eval_label(item2);
483
        else
484
          addr = strtoul(item2, NULL, 0);
485
      set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
486
    } else
487
    if (strcmp(item1, "pr") == 0) { /* patch regs */
488
      char item2[20];
489
      char item3[20];
490
 
491
      strtoken(linestr, item2, 2);
492
      strtoken(linestr, item3, 3);
493
      set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
494
    } else
495
    if (strcmp(item1, "pc") == 0) { /* patch PC */
496
      char item2[20];
497
 
498
      strtoken(linestr, item2, 2);
499
      pcnext = strtoul(item2, NULL, 0);
500
    } else
501
    if (strcmp(item1, "break") == 0) {  /* set/clear breakpoint */
502
      char item2[20];
503
 
504
      strtoken(linestr, item2, 2);
505
      set_insnbrkpoint(strtoul(item2, NULL, 0));
506
    } else
507
    if (strcmp(item1, "r") == 0) {  /* dump regs */
508
      dumpreg();
509
    } else
510
    if (strcmp(item1, "de") == 0) { /* reset simulator */
511
      char item2[20];
512
      char item3[20];
513
      static int from = 0, to = 0;
514
 
515
      strtoken(linestr, item2, 2);
516
      strtoken(linestr, item3, 3);
517
 
518
      if (strlen(item2)) {
519
        if (item2[0] == '_')
520
          from = eval_label(item2);
521
        else
522
          from = strtoul(item2, NULL, 0);
523
        to = from + 0x40;
524
      }
525
      if (strlen(item3))
526
        to = strtoul(item3, NULL, 0);
527
      debugmem(from, to);
528
      printf("\n");
529
    } else
530
    if (strcmp(item1, "reset") == 0) {  /* reset simulator */
531
      uart_reset();
532
      dma_reset();
533
      eth_reset();
534
      tick_reset();
535
      pm_reset();
536
      pic_reset();
537
      reset(); /* Old or new mode */
538
    } else
539
    if (strcmp(item1, "debug") == 0) {  /* debug mode */
540
      config.sim.debug ^= 1;
541
    } else
542
    if (strcmp(item1, "hist") == 0) { /* dump history */
543
      int i;
544
      for(i = HISTEXEC_LEN; i; i--)
545
        dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
546
      printf("\n");
547
    } else
548
    if (strcmp(item1, "run") == 0) { /* run */
549
      char item2[20];
550
      char item3[20];
551
 
552
      strtoken(linestr, item2, 2);
553
      strtoken(linestr, item3, 3);
554
      if (strcmp(item3, "hush") == 0)
555
        hush = 1;
556
      else
557
        hush = 0;
558
      cont_run = strtol(item2, NULL, 0);
559
    } else
560
    if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
561
      extern int cpu_stalled;  /* CZ from debug_interface */
562
      cpu_stalled = 1;
563
      config.sim.iprompt = 0;
564
      cont_run = -1;
565
      hush = 1;
566
    } else
567
    if (!strcmp(item1, "trace")) { /* Added by CZ 210801 */
568
      char item2[256];
569
 
570
      strtoken(linestr, item2, 2);
571
      if(trace_fd) {
572
        close(trace_fd);
573
        trace_fd = 0;
574
      }
575
      if(strcmp(item2,"off")) /* if we're not being turned off */
576
        {
577
          if(item2[0])
578
            trace_fd = open(item2,O_CREAT | O_NOCTTY |
579
          O_TRUNC | O_WRONLY, 0644);
580
          else
581
            trace_fd = dup(1);
582
          if(trace_fd < 0) {
583
            perror(item2[0]?item2:"stdout");
584
            trace_fd = 0;
585
          }
586
        }
587
    } else
588
    if (strcmp(item1, "stats") == 0) { /* stats */
589
      char item2[20];
590
      int i = 0;
591
 
592
      strtoken(linestr, item2, 2);
593
      if (strcmp(item2, "clear") == 0) {
594
        initstats();
595
        printf("Cleared.\n");
596
      } else {
597
        i = strtoul(item2, NULL, 0);
598
        printstats(i);
599
      }
600
    } else
601
    if (strcmp(item1, "info") == 0) /* configuration info */
602
      sim_info ();
603
    else
604
    if (strcmp(item1, "set") == 0) { /* configuration info */
605
      char *s = linestr;
606
      int i;
607
      extern section;
608
      extern struct section sections[];
609
      while (*s != ' ' && *s) s++;
610
      set_config_command (s);
611
    } else
612
      printf("%s: Unknown command.\n", linestr);
613 103 lampret
 
614 304 markom
 
615 361 markom
    /* MM: 'run -1' means endless execution.  */
616
    while(cont_run != 0) {
617
      int debug_slowdown = DEBUG_SLOWDOWN;
618
      extern int cycle_delay;  /* Added by CZ 27/05/01. Set during exception. */
619
      extern int cpu_stalled;  /* CZ from debug_interface */
620 123 markom
 
621 294 markom
      if (cpu_stalled)
622 361 markom
        if(GDB_ENABLED) {
623
          BlockJTAG();
624
          HandleServerSocket(false);
625
          continue;
626
        } else
627
          fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
628 127 chris
 
629 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
630 304 markom
        if(cycle_delay <= 0) {
631
          unsigned int addr;
632
          if (cont_run > 0) cont_run--;
633
          if(fetch()) {
634 344 markom
            printf ("Breakpoint hit.\n");
635 304 markom
            cont_run = 0; /* memory breakpoint encountered */
636
            break;
637
          }
638
          addr = iqueue[0].insn_addr;
639
 
640
          /* If trace_fd is non zero, we want
641
             to make sure that disassemble is called */
642 181 chris
 
643 304 markom
          decode_execute(&iqueue[0],trace_fd);
644
          if(trace_fd) {
645
            char sTemp[256];
646
            char sTemp2[256];
647
            unsigned long value;
648
            extern char *disassembled;
649
            extern unsigned long reg[];
650 181 chris
 
651 304 markom
            /* The objects passed to the
652
               trace command should not be
653
               hardcoded like this...instead
654
               what to dump should be passed
655
               on the command line.
656 181 chris
 
657 304 markom
               FIX THIS LATER...
658
            */
659
            value = (evalsim_mem8(0x306bc) << 24) +
660
              (evalsim_mem8(0x306bd) << 16) +
661
              (evalsim_mem8(0x306be) << 8)
662
              + evalsim_mem8(0x306bf);
663 221 markom
 
664 304 markom
            sprintf(sTemp,"0x%06x: %s",addr,disassembled);
665
            memset(sTemp2,' ',sizeof(sTemp2));
666
            strncpy(sTemp2,sTemp,strlen(sTemp));
667
            sprintf(&sTemp2[40],"<0x%08x,0x%08x> [0x%08x]\n",
668
                    reg[3],reg[4],value);
669
            write(trace_fd,sTemp2,strlen(sTemp2));
670 261 markom
          }
671 304 markom
          update_pc();
672
          analysis();
673
          if (!hush)
674
            dumpreg();
675
        } else
676 261 markom
          cycle_delay--;
677 123 markom
 
678 261 markom
        pic_clock();
679
        dc_clock();
680
        ic_clock();
681 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
682 261 markom
      }
683 304 markom
 
684 261 markom
      pm_clock();
685 304 markom
      if (config.uarts_enabled) uart_clock();
686
      if (config.dmas_enabled) dma_clock();
687
      if (config.ethernets_enabled) eth_clock();
688
      if (config.sim.exe_log) dump_exe_log();
689
      if (config.vapi.enabled) vapi_check();
690 269 markom
      if (GDB_ENABLED && debug_slowdown-- == 0) {
691 261 markom
        debug_slowdown = DEBUG_SLOWDOWN;
692 361 markom
        HandleServerSocket(false); /* block & check_stdin = false */
693
      }
694
    }
695
    hush = 0;
696
    fflush(stdout);
697
    freopen("/dev/fd/0", "w+", stdout);
698 2 cvs
 
699 361 markom
    if (!config.sim.iprompt)  /* non-interactive quit */
700
      sim_done();
701 304 markom
 
702 16 jrydberg
#ifdef HAVE_LIBREADLINE
703 361 markom
    if (linestr)
704
      free (linestr);
705 16 jrydberg
#endif
706 7 jrydberg
 
707 361 markom
  }
708
  sim_done();
709 2 cvs
}
710 7 jrydberg
 
711 16 jrydberg
#ifdef HAVE_LIBREADLINE
712 7 jrydberg
char *command_generator ();
713
char **sim_completion ();
714
 
715
/* Tell the GNU readline library how to complete.  We want to try to complete
716
   on command names if this is the first word in the line, or on filenames
717
   if not. */
718
void initialize_readline ()
719
{
720
  /* Allow conditional parsing of the ~/.inputrc file. */
721
  rl_readline_name = "or1ksim";
722
 
723
  /* Tell the completer that we want a crack first. */
724
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
725
}
726
 
727
/* Attempt to complete on the contents of TEXT.  START and END bound the
728
   region of rl_line_buffer that contains the word to complete.  TEXT is
729
   the word to complete.  We can use the entire contents of rl_line_buffer
730
   in case we want to do some simple parsing.  Return the array of matches,
731
   or NULL if there aren't any. */
732
char **
733
sim_completion (text, start, end)
734
     char *text;
735
     int start, end;
736
{
737
  char **matches;
738
 
739
  matches = (char **)NULL;
740
 
741
  /* If this word is at the start of the line, then it is a command
742
     to complete.  Otherwise it is the name of a file in the current
743
     directory. */
744
  if (start == 0)
745
    matches = completion_matches (text, command_generator);
746
 
747
  return (matches);
748
}
749
 
750
/* Generator function for command completion.  STATE lets us know whether
751
   to start from scratch; without any state (i.e. STATE == 0), then we
752
   start at the top of the list. */
753
char *
754
command_generator (text, state)
755
     char *text;
756
     int state;
757
{
758
  static int list_index, len;
759
  char *name;
760
 
761
  /* If this is a new word to complete, initialize now.  This includes
762
     saving the length of TEXT for efficiency, and initializing the index
763
     variable to 0. */
764
  if (!state)
765
    {
766
      list_index = 0;
767
      len = strlen (text);
768
    }
769
 
770
  /* Return the next name which partially matches from the command list. */
771
  while (name = sim_commands[list_index])
772
    {
773
      list_index++;
774
 
775
      if (strncmp (name, text, len) == 0)
776
        return (dupstr(name));
777
    }
778
 
779
  /* If no names matched, then return NULL. */
780
  return ((char *)NULL);
781
}
782
 
783
/* Repeats the last command.  */
784
char *
785
repeat_last_command ()
786
{
787
  int offset = where_history ();
788
  HIST_ENTRY *hist;
789
 
790
  if (hist = history_get (offset))
791 306 markom
    return dupstr (hist->line);
792 7 jrydberg
  return 0;
793
}
794 16 jrydberg
 
795
#endif
796
 
797 138 markom
extern char *disassembled;
798 257 erez
void debugmem( unsigned long from, unsigned long to )
799
{
800 138 markom
  int i;
801
  printf("starting to dump mem...\n");
802 257 erez
  for(i=from; i<to; ) {
803 261 markom
    struct label_entry *entry;
804 221 markom
    unsigned int _insn;
805 261 markom
    printf("i=%x :: ", i);
806
 
807
    if (verify_memoryarea(i) && (entry = get_label(i)))
808
      printf("label: %s |", entry->name);
809 221 markom
 
810
    iqueue[0].insn = _insn = evalsim_mem32(i);
811
    iqueue[0].insn_index = insn_decode(_insn);
812
    disassemble_insn (_insn);
813
    printf("%08x %s\n", _insn, disassembled);
814 361 markom
    i += insn_len( iqueue[0].insn_index );
815 138 markom
  }
816 21 cmchen
}

powered by: WebSVN 2.1.0

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