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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [toplevel.c] - Blame information for rev 1061

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

powered by: WebSVN 2.1.0

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