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

Subversion Repositories or1k

[/] [or1k/] [tags/] [tn_m001/] [or1ksim/] [toplevel.c] - Blame information for rev 550

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

powered by: WebSVN 2.1.0

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