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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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