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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [toplevel.c] - Blame information for rev 547

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

powered by: WebSVN 2.1.0

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