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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_66/] [or1ksim/] [toplevel.c] - Blame information for rev 1352

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

powered by: WebSVN 2.1.0

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