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

Subversion Repositories or1k

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

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 554 markom
const char rcsrev[] = "$Revision: 1.67 $";
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
  reset();
171
}
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
      set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
548
    } 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
      uart_reset();
586
      dma_reset();
587
      eth_reset();
588 444 erez
      gpio_reset();
589 361 markom
      tick_reset();
590
      pm_reset();
591
      pic_reset();
592
      reset(); /* Old or new mode */
593
    } else
594 551 markom
#if !FAST_SIM
595 361 markom
    if (strcmp(item1, "debug") == 0) {  /* debug mode */
596
      config.sim.debug ^= 1;
597
    } else
598 551 markom
#endif
599 361 markom
    if (strcmp(item1, "hist") == 0) { /* dump history */
600
      int i;
601
      for(i = HISTEXEC_LEN; i; i--)
602
        dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
603
      printf("\n");
604
    } else
605
    if (strcmp(item1, "run") == 0) { /* run */
606
      char item2[20];
607
      char item3[20];
608
 
609
      strtoken(linestr, item2, 2);
610
      strtoken(linestr, item3, 3);
611
      if (strcmp(item3, "hush") == 0)
612
        hush = 1;
613
      else
614
        hush = 0;
615
      cont_run = strtol(item2, NULL, 0);
616
    } else
617
    if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
618 479 markom
      set_stall_state (1);
619 551 markom
      runtime.sim.iprompt = 0;
620 361 markom
      cont_run = -1;
621
      hush = 1;
622
    } else
623
    if (strcmp(item1, "stats") == 0) { /* stats */
624
      char item2[20];
625
      int i = 0;
626
 
627
      strtoken(linestr, item2, 2);
628
      if (strcmp(item2, "clear") == 0) {
629
        initstats();
630
        printf("Cleared.\n");
631
      } else {
632
        i = strtoul(item2, NULL, 0);
633
        printstats(i);
634
      }
635
    } else
636
    if (strcmp(item1, "info") == 0) /* configuration info */
637
      sim_info ();
638
    else
639 551 markom
#if !FAST_SIM
640 361 markom
    if (strcmp(item1, "set") == 0) { /* configuration info */
641
      char *s = linestr;
642
      int i;
643
      extern section;
644
      extern struct section sections[];
645
      while (*s != ' ' && *s) s++;
646
      set_config_command (s);
647
    } else
648 551 markom
#endif /* !FAST_SIM */
649 361 markom
      printf("%s: Unknown command.\n", linestr);
650 103 lampret
 
651 361 markom
    /* MM: 'run -1' means endless execution.  */
652
    while(cont_run != 0) {
653 537 markom
      extern int mem_cycles;
654 123 markom
 
655 479 markom
      if (cpu_stalled) {
656
        printf ("!");
657 550 markom
        if(config.debug.gdb_enabled) {
658 361 markom
          BlockJTAG();
659
          HandleServerSocket(false);
660
        } else
661
          fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
662 479 markom
        continue;
663
      }
664 127 chris
 
665 537 markom
      /* Each cycle has counter of mem_cycles; this value is joined with cycles
666
         at the end of the cycle; no sim originated memory accesses should be
667
         performed inbetween. */
668
      mem_cycles = 0;
669 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
670 463 simons
        pic_clock();
671 535 markom
        if (cont_run > 0) cont_run--;
672
        if(fetch()) {
673
          printf ("Breakpoint hit.\n");
674
          cont_run = 0; /* memory breakpoint encountered */
675
          break;
676
        }
677
        decode_execute(&iqueue[0]);
678
        update_pc();
679
        analysis();
680 261 markom
        dc_clock();
681
        ic_clock();
682 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
683 261 markom
      }
684 304 markom
 
685 261 markom
      pm_clock();
686 549 markom
      if (config.uarts) uart_clock();
687
      if (config.dmas) dma_clock();
688
      if (config.ethernets) eth_clock();
689
      if (config.ngpios) gpio_clock();
690 551 markom
      if (config.vapi.enabled && runtime.vapi.enabled) vapi_check();
691
      if (config.debug.gdb_enabled) {
692 361 markom
        HandleServerSocket(false); /* block & check_stdin = false */
693 479 markom
        debug (1, ".");
694 361 markom
      }
695 550 markom
      if (config.debug.enabled)
696 479 markom
        if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
697 537 markom
      cycles += mem_cycles;
698
      if (!hush) dumpreg();
699
      if (config.sim.exe_log) dump_exe_log();
700 361 markom
    }
701
    hush = 0;
702
    fflush(stdout);
703
    freopen("/dev/fd/0", "w+", stdout);
704 2 cvs
 
705 551 markom
    if (!runtime.sim.iprompt)  /* non-interactive quit */
706 361 markom
      sim_done();
707 304 markom
 
708 16 jrydberg
#ifdef HAVE_LIBREADLINE
709 361 markom
    if (linestr)
710
      free (linestr);
711 16 jrydberg
#endif
712 7 jrydberg
 
713 361 markom
  }
714
  sim_done();
715 2 cvs
}
716 7 jrydberg
 
717 16 jrydberg
#ifdef HAVE_LIBREADLINE
718 7 jrydberg
char *command_generator ();
719
char **sim_completion ();
720
 
721
/* Tell the GNU readline library how to complete.  We want to try to complete
722
   on command names if this is the first word in the line, or on filenames
723
   if not. */
724
void initialize_readline ()
725
{
726
  /* Allow conditional parsing of the ~/.inputrc file. */
727
  rl_readline_name = "or1ksim";
728
 
729
  /* Tell the completer that we want a crack first. */
730
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
731
}
732
 
733
/* Attempt to complete on the contents of TEXT.  START and END bound the
734
   region of rl_line_buffer that contains the word to complete.  TEXT is
735
   the word to complete.  We can use the entire contents of rl_line_buffer
736
   in case we want to do some simple parsing.  Return the array of matches,
737
   or NULL if there aren't any. */
738
char **
739
sim_completion (text, start, end)
740
     char *text;
741
     int start, end;
742
{
743
  char **matches;
744
 
745
  matches = (char **)NULL;
746
 
747
  /* If this word is at the start of the line, then it is a command
748
     to complete.  Otherwise it is the name of a file in the current
749
     directory. */
750
  if (start == 0)
751
    matches = completion_matches (text, command_generator);
752
 
753
  return (matches);
754
}
755
 
756
/* Generator function for command completion.  STATE lets us know whether
757
   to start from scratch; without any state (i.e. STATE == 0), then we
758
   start at the top of the list. */
759
char *
760
command_generator (text, state)
761
     char *text;
762
     int state;
763
{
764
  static int list_index, len;
765
  char *name;
766
 
767
  /* If this is a new word to complete, initialize now.  This includes
768
     saving the length of TEXT for efficiency, and initializing the index
769
     variable to 0. */
770
  if (!state)
771
    {
772
      list_index = 0;
773
      len = strlen (text);
774
    }
775
 
776
  /* Return the next name which partially matches from the command list. */
777
  while (name = sim_commands[list_index])
778
    {
779
      list_index++;
780
 
781
      if (strncmp (name, text, len) == 0)
782
        return (dupstr(name));
783
    }
784
 
785
  /* If no names matched, then return NULL. */
786
  return ((char *)NULL);
787
}
788
 
789
/* Repeats the last command.  */
790
char *
791
repeat_last_command ()
792
{
793
  int offset = where_history ();
794
  HIST_ENTRY *hist;
795
 
796
  if (hist = history_get (offset))
797 306 markom
    return dupstr (hist->line);
798 7 jrydberg
  return 0;
799
}
800 16 jrydberg
 
801
#endif
802
 
803 138 markom
extern char *disassembled;
804 257 erez
void debugmem( unsigned long from, unsigned long to )
805
{
806 138 markom
  int i;
807
  printf("starting to dump mem...\n");
808 257 erez
  for(i=from; i<to; ) {
809 261 markom
    struct label_entry *entry;
810 221 markom
    unsigned int _insn;
811 261 markom
    printf("i=%x :: ", i);
812
 
813
    if (verify_memoryarea(i) && (entry = get_label(i)))
814
      printf("label: %s |", entry->name);
815 221 markom
 
816
    iqueue[0].insn = _insn = evalsim_mem32(i);
817
    iqueue[0].insn_index = insn_decode(_insn);
818
    disassemble_insn (_insn);
819
    printf("%08x %s\n", _insn, disassembled);
820 361 markom
    i += insn_len( iqueue[0].insn_index );
821 138 markom
  }
822 21 cmchen
}

powered by: WebSVN 2.1.0

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