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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc3/] [or1ksim/] [toplevel.c] - Blame information for rev 848

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

powered by: WebSVN 2.1.0

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