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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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