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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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