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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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