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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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