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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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