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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_63/] [or1ksim/] [toplevel.c] - Blame information for rev 847

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

powered by: WebSVN 2.1.0

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