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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_73/] [or1ksim/] [toplevel.c] - Blame information for rev 883

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

powered by: WebSVN 2.1.0

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