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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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