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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_42/] [or1ksim/] [toplevel.c] - Blame information for rev 1049

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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