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

Subversion Repositories or1k

[/] [or1k/] [tags/] [tn_m001/] [or1ksim/] [toplevel.c] - Blame information for rev 664

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

powered by: WebSVN 2.1.0

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