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

Subversion Repositories or1k

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

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 551 markom
const char rcsrev[] = "$Revision: 1.66 $";
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
    int i;
211
    if (config.memory.type == MT_RANDOM) {
212
      unsigned int val = 0;
213 123 markom
 
214 262 markom
      if (config.memory.random_seed == -1) {
215 551 markom
        runtime.memory.random_seed = time(NULL);
216 262 markom
        /* Print out the seed just in case we ever need to debug */
217 361 markom
        printf("Seeding random generator with value %d\n", config.memory.random_seed);
218 551 markom
      } else
219
        runtime.memory.random_seed = config.memory.random_seed;
220
      srandom(runtime.memory.random_seed);
221 262 markom
 
222 361 markom
      for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
223 221 markom
        for(i = 0; i < cur_area->size; i++) {
224
          val = random();
225 262 markom
          setsim_mem8(i + cur_area->addr_compare, val & 0xFF);
226 221 markom
        }
227 262 markom
    } else if(config.memory.type == MT_PATTERN) {
228 361 markom
      for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
229 221 markom
        for(i = 0; i < cur_area->size; i++)
230 262 markom
          setsim_mem8(i + cur_area->addr_compare, config.memory.pattern);
231 269 markom
    } else if (config.memory.type != MT_UNKNOWN) {
232 262 markom
      fprintf(stderr, "Invalid memory configuration type.\n");
233 361 markom
      exit(1);
234 221 markom
    }
235 242 markom
  }
236 262 markom
 
237 361 markom
  if(runtime.sim.filename) {
238
    unsigned long endaddr = 0xFFFFFFFF;
239
    endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero.  */
240
    if (endaddr == -1) {
241
      fprintf(stderr, "Problems loading boot code.\n");
242
      exit(1);
243
    }
244
  }
245 551 markom
 
246
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
247 361 markom
  /* Disable gdb debugging, if debug module is not available.  */
248
  if (config.debug.gdb_enabled && !config.debug.enabled) {
249
    config.debug.gdb_enabled = 0;
250
    if (config.sim.verbose)
251
      fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
252
  }
253 551 markom
#endif
254
 
255 550 markom
  if (config.debug.gdb_enabled)
256 479 markom
    gdbcomm_init ();
257 551 markom
 
258
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
259 361 markom
  /* Enable dependency stats, if we want to do history analisis */
260 394 markom
  if (config.sim.history && !config.cpu.dependstats) {
261
    config.cpu.dependstats = 1;
262 361 markom
    if (config.sim.verbose)
263 394 markom
      fprintf (stderr, "WARNING: dependstats stats must be enabled to do history analisis.\n");
264 361 markom
  }
265 551 markom
#endif
266
 
267
#if !FAST_SIM /* We assume we have valid configuration with fsim*/  
268 361 markom
  /* Debug forces verbose */
269
  if (config.sim.debug && !config.sim.verbose) {
270
    config.sim.verbose = 1;
271
    fprintf (stderr, "WARNING: verbose turned on.\n");
272
  }
273 551 markom
#endif
274 361 markom
 
275
  /* Start VAPI before device initialization.  */
276
  if (config.vapi.enabled) {
277 551 markom
    runtime.vapi.enabled = 1;
278 361 markom
    vapi_init ();
279
    if (config.sim.verbose)
280
      printf ("VAPI started, waiting for clients.\n");
281
  }
282 538 markom
 
283 479 markom
  sim_reset ();
284 424 markom
 
285 543 simons
  lock_memory_table ();
286
 
287 361 markom
  /* Wait till all test are connected.  */
288 551 markom
  if (runtime.vapi.enabled) {
289 361 markom
    int numu = vapi_num_unconnected (0);
290
    if (numu) {
291
      printf ("\nWaiting for VAPI tests with ids:\n");
292
      vapi_num_unconnected (1);
293
      printf ("\n");
294
      while (numu = vapi_num_unconnected (0)) {
295
        vapi_check ();
296
        printf ("\rStill waiting for %i VAPI test(s) to connect.       ", numu);
297
        usleep (100);
298
      }
299
      printf ("\n");
300
    }
301
    printf ("All devices connected                         \n");
302
  }
303
  /* simulator is initialized */
304
  runtime.sim.init = 0;
305 304 markom
}
306 7 jrydberg
 
307 304 markom
/* Display info about various modules */
308
void sim_info () {
309 427 markom
  sprs_status();
310 535 markom
  printf ("\n");
311 427 markom
  memory_table_status ();
312 535 markom
  if (config.immu.enabled) itlb_status(-1);
313
  if (config.dmmu.enabled) dtlb_status(-1);
314
  if (config.ic.enabled) ic_info();
315
  if (config.dc.enabled) dc_info();
316 361 markom
 
317 541 markom
  if (config.bpb.enabled) bpb_info();
318
  if (config.bpb.btic) btic_info();
319 535 markom
 
320 549 markom
  if (config.nuarts) uart_status();
321
  if (config.ndmas) dma_status();
322
  if (config.nethernets) eth_status();
323
  if (config.ngpios) gpio_status();
324 304 markom
}
325
 
326
/* Cleanup */
327
void sim_done ()
328
{
329
  if (config.sim.profile) {
330
    extern int cycles;
331 361 markom
    fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
332
    fclose(runtime.sim.fprof);
333 304 markom
  }
334 547 markom
 
335
  if (config.sim.mprofile)
336
    fclose(runtime.sim.fmprof);
337
 
338 361 markom
  if (config.sim.exe_log)   fclose(runtime.sim.fexe_log);
339 551 markom
  if (runtime.vapi.enabled)  vapi_done ();
340 426 markom
  done_memory_table ();
341 304 markom
  exit(0);
342
}
343
 
344
int main(argc, argv)
345
     int argc;
346
     char *argv[];
347
{
348 361 markom
  char *linestr;
349
  char item1[500], b2[500], prev_str[500] = "";
350
  char *redirstr;
351
  int hush = 0;
352
  int first_prompt = 1;
353 304 markom
 
354 361 markom
  srand(getpid());
355
  init_defconfig();
356
  if (parse_args(argc, argv)) {
357
    printf("Usage: %s [options] <filename>\n", argv[0]);
358
    printf("Options:\n");
359
    printf(" -v                 version and copyright note\n");
360
    printf(" -i                 enable interactive command prompt\n");
361
    printf(" --nosrv            do not launch JTAG proxy server\n"); /* (CZ) */
362
    printf(" --srv <n>          launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
363 551 markom
#if !FAST_SIM
364
    printf(" -f or --file       load script file [sim.cfg]\n");
365 361 markom
    printf(" --profile          enable profiling\n");
366 547 markom
    printf(" --mprofile         enable memory profiling\n");
367 551 markom
#endif
368 549 markom
    printf(" --output-cfg       prints C structure of current configuration to standard output\n");
369 361 markom
    exit(-1);
370
  }
371 304 markom
 
372
#ifdef HAVE_LIBREADLINE
373 361 markom
  initialize_readline (); /* Bind our completer. */
374 304 markom
#endif
375
 
376 551 markom
#if !FAST_SIM
377 304 markom
  /* Read configuration file.  */
378 361 markom
  if (!runtime.sim.script_file_specified)
379
    read_script_file ("sim.cfg");
380 424 markom
  if (!runtime.sim.script_file_specified && config.sim.verbose)
381
    fprintf (stderr, "WARNING: No config file read, assuming default configuration.\n");
382 551 markom
#else
383
  printf ("\n\tNOTE: running fast sim with fixed configuration!\n\n");
384
#endif
385 549 markom
  if (runtime.sim.output_cfg) {
386
    output_cfg (stdout);
387
    exit (0);
388
  }
389 304 markom
  print_config();
390 336 markom
  sim_init ();
391 304 markom
  signal(SIGINT, ctrl_c);
392 335 markom
 
393 361 markom
  while(1) {
394 551 markom
    if (runtime.sim.iprompt) {
395 550 markom
      if (config.debug.gdb_enabled)
396 361 markom
        {
397
          printf ("(sim) ");
398
          fflush(stdout);
399
          HandleServerSocket(true);  /* block & check_stdin = true */
400
        }
401 16 jrydberg
#ifdef HAVE_LIBREADLINE
402 361 markom
      /* Must disable readline in new mode. It isn't compatible
403
         with non blocking environments */
404 550 markom
      if(!config.debug.gdb_enabled)
405 361 markom
        linestr = readline("(sim) ");
406
      else
407
        linestr = fgets(b2, sizeof b2, stdin);
408 16 jrydberg
#else
409 550 markom
      if(!config.debug.gdb_enabled)
410 361 markom
        printf ("(sim) ");
411
      linestr = fgets(b2, sizeof b2, stdin);
412 16 jrydberg
#endif
413 361 markom
    } else
414
      strcpy(linestr = b2, "run -1 hush");
415 7 jrydberg
 
416 361 markom
    if (!linestr)
417
      break;
418
    linestr = stripwhite (linestr);
419 7 jrydberg
 
420 16 jrydberg
#ifdef HAVE_LIBREADLINE
421 361 markom
    /* Readline only works in the old mode */
422
    if(!server_fd)
423
      {
424
        if (strlen(linestr) == 0) {
425
          char *l = repeat_last_command ();
426
 
427
          if (l) {
428
      free (linestr);
429
      linestr = l;
430
          }
431
        }
432
 
433
        if (*linestr) {
434
          add_history (linestr);
435
        }
436
      }
437 16 jrydberg
#endif /* HAVE_LIBREADLINE */
438 361 markom
 
439
    if (redirstr = strstr(linestr, ">")) {
440
      *redirstr = '\0';
441
      strtoken(&redirstr[1], item1, 1);
442
      freopen(item1, "w+", stdout);
443
    }
444
 
445
    if (linestr[0] == '\n')
446
      strcpy (linestr, &prev_str[0]);
447
    else
448
      strcpy (&prev_str[0], linestr);
449
 
450
    strtoken(linestr, item1, 1);
451
    if (strcmp(item1, "q") == 0) {  /* quit */
452
      printf ("\n");
453
      sim_done ();
454
    } else
455
    if (strcmp(item1, "help") == 0) /* help */
456
      help();
457
    else
458
    if (strcmp(item1, "t") == 0) {  /* trace */
459
      cont_run = 1;
460
    } else
461
    if (strcmp(item1, "dm") == 0) { /* dump memory */
462
      char item2[20];
463
      char item3[20];
464
      static int from = 0, to = 0;
465
 
466
      strtoken(linestr, item2, 2);
467
      strtoken(linestr, item3, 3);
468
 
469
      if (strlen(item2)) {
470
        if (item2[0] == '_')
471
          from = eval_label(item2);
472
        else
473
          from = strtoul(item2, NULL, 0);
474
        to = from + 0x40;
475
      }
476
      if (strlen(item3))
477
        to = strtoul(item3, NULL, 0);
478
      dumpmemory(from, to, 0, 1);
479
            printf("\n");
480
    } else
481
    if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
482
      char item2[20];
483
      char item3[20];
484
      char item4[20];
485
      static int from = 0, to = 0;
486
 
487
      strtoken(linestr, item2, 2);
488
      strtoken(linestr, item3, 3);
489
      strtoken(linestr, item4, 4);
490
 
491
      if (strlen(item2)) {
492
        if (item2[0] == '_')
493
          from = eval_label(item2);
494
        else
495
          from = strtoul(item2, NULL, 0);
496
        to = from + 0x40;
497
      }
498
      if (strlen(item3))
499
        to = strtoul(item3, NULL, 0);
500
      if (!strlen(item4))
501
        strcpy(item4, "or1k_mem");
502
      dumpverilog(item4, from, to);
503
        printf("\n");
504
    } else
505
    if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
506
      char item2[20];
507
      char item3[20];
508
      static int from = 0, to = 0;
509
 
510
      strtoken(linestr, item2, 2);
511
      strtoken(linestr, item3, 3);
512
 
513
      if (strlen(item2)) {
514
        if (item2[0] == '_')
515
          from = eval_label(item2);
516
        else
517
          from = strtoul(item2, NULL, 0);
518
        to = from + 0x40;
519
      }
520
      if (strlen(item3))
521
        to = strtoul(item3, NULL, 0);
522
      dumphex(from, to);
523
        printf("\n");
524
    } else
525
    if (strcmp(item1, "pm") == 0) { /* patch memory */
526
      char item2[20];
527
      char item3[20];
528
      static int addr = 0;
529
      int breakpoint = 0;
530 123 markom
 
531 361 markom
      strtoken(linestr, item2, 2);
532
      strtoken(linestr, item3, 3);
533
      if (strlen(item2))
534
        if (item2[0] == '_')
535
          addr = eval_label(item2);
536
        else
537
          addr = strtoul(item2, NULL, 0);
538
      set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
539
    } else
540
    if (strcmp(item1, "pr") == 0) { /* patch regs */
541
      char item2[20];
542
      char item3[20];
543
 
544
      strtoken(linestr, item2, 2);
545
      strtoken(linestr, item3, 3);
546
      set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
547
    } else
548
    if (strcmp(item1, "pc") == 0) { /* patch PC */
549
      char item2[20];
550 491 markom
 
551 361 markom
      strtoken(linestr, item2, 2);
552 491 markom
      pc = strtoul(item2, NULL, 0);
553 361 markom
    } else
554
    if (strcmp(item1, "break") == 0) {  /* set/clear breakpoint */
555
      char item2[20];
556
 
557
      strtoken(linestr, item2, 2);
558
      set_insnbrkpoint(strtoul(item2, NULL, 0));
559
    } else
560
    if (strcmp(item1, "r") == 0) {  /* dump regs */
561
      dumpreg();
562
    } else
563
    if (strcmp(item1, "de") == 0) { /* reset simulator */
564
      char item2[20];
565
      char item3[20];
566
      static int from = 0, to = 0;
567
 
568
      strtoken(linestr, item2, 2);
569
      strtoken(linestr, item3, 3);
570
 
571
      if (strlen(item2)) {
572
        if (item2[0] == '_')
573
          from = eval_label(item2);
574
        else
575
          from = strtoul(item2, NULL, 0);
576
        to = from + 0x40;
577
      }
578
      if (strlen(item3))
579
        to = strtoul(item3, NULL, 0);
580
      debugmem(from, to);
581
      printf("\n");
582
    } else
583
    if (strcmp(item1, "reset") == 0) {  /* reset simulator */
584
      uart_reset();
585
      dma_reset();
586
      eth_reset();
587 444 erez
      gpio_reset();
588 361 markom
      tick_reset();
589
      pm_reset();
590
      pic_reset();
591
      reset(); /* Old or new mode */
592
    } else
593 551 markom
#if !FAST_SIM
594 361 markom
    if (strcmp(item1, "debug") == 0) {  /* debug mode */
595
      config.sim.debug ^= 1;
596
    } else
597 551 markom
#endif
598 361 markom
    if (strcmp(item1, "hist") == 0) { /* dump history */
599
      int i;
600
      for(i = HISTEXEC_LEN; i; i--)
601
        dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
602
      printf("\n");
603
    } else
604
    if (strcmp(item1, "run") == 0) { /* run */
605
      char item2[20];
606
      char item3[20];
607
 
608
      strtoken(linestr, item2, 2);
609
      strtoken(linestr, item3, 3);
610
      if (strcmp(item3, "hush") == 0)
611
        hush = 1;
612
      else
613
        hush = 0;
614
      cont_run = strtol(item2, NULL, 0);
615
    } else
616
    if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
617 479 markom
      set_stall_state (1);
618 551 markom
      runtime.sim.iprompt = 0;
619 361 markom
      cont_run = -1;
620
      hush = 1;
621
    } else
622
    if (strcmp(item1, "stats") == 0) { /* stats */
623
      char item2[20];
624
      int i = 0;
625
 
626
      strtoken(linestr, item2, 2);
627
      if (strcmp(item2, "clear") == 0) {
628
        initstats();
629
        printf("Cleared.\n");
630
      } else {
631
        i = strtoul(item2, NULL, 0);
632
        printstats(i);
633
      }
634
    } else
635
    if (strcmp(item1, "info") == 0) /* configuration info */
636
      sim_info ();
637
    else
638 551 markom
#if !FAST_SIM
639 361 markom
    if (strcmp(item1, "set") == 0) { /* configuration info */
640
      char *s = linestr;
641
      int i;
642
      extern section;
643
      extern struct section sections[];
644
      while (*s != ' ' && *s) s++;
645
      set_config_command (s);
646
    } else
647 551 markom
#endif /* !FAST_SIM */
648 361 markom
      printf("%s: Unknown command.\n", linestr);
649 103 lampret
 
650 361 markom
    /* MM: 'run -1' means endless execution.  */
651
    while(cont_run != 0) {
652 537 markom
      extern int mem_cycles;
653 123 markom
 
654 479 markom
      if (cpu_stalled) {
655
        printf ("!");
656 550 markom
        if(config.debug.gdb_enabled) {
657 361 markom
          BlockJTAG();
658
          HandleServerSocket(false);
659
        } else
660
          fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
661 479 markom
        continue;
662
      }
663 127 chris
 
664 537 markom
      /* Each cycle has counter of mem_cycles; this value is joined with cycles
665
         at the end of the cycle; no sim originated memory accesses should be
666
         performed inbetween. */
667
      mem_cycles = 0;
668 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
669 463 simons
        pic_clock();
670 535 markom
        if (cont_run > 0) cont_run--;
671
        if(fetch()) {
672
          printf ("Breakpoint hit.\n");
673
          cont_run = 0; /* memory breakpoint encountered */
674
          break;
675
        }
676
        decode_execute(&iqueue[0]);
677
        update_pc();
678
        analysis();
679 261 markom
        dc_clock();
680
        ic_clock();
681 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
682 261 markom
      }
683 304 markom
 
684 261 markom
      pm_clock();
685 549 markom
      if (config.uarts) uart_clock();
686
      if (config.dmas) dma_clock();
687
      if (config.ethernets) eth_clock();
688
      if (config.ngpios) gpio_clock();
689 551 markom
      if (config.vapi.enabled && runtime.vapi.enabled) vapi_check();
690
      if (config.debug.gdb_enabled) {
691 361 markom
        HandleServerSocket(false); /* block & check_stdin = false */
692 479 markom
        debug (1, ".");
693 361 markom
      }
694 550 markom
      if (config.debug.enabled)
695 479 markom
        if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
696 537 markom
      cycles += mem_cycles;
697
      if (!hush) dumpreg();
698
      if (config.sim.exe_log) dump_exe_log();
699 361 markom
    }
700
    hush = 0;
701
    fflush(stdout);
702
    freopen("/dev/fd/0", "w+", stdout);
703 2 cvs
 
704 551 markom
    if (!runtime.sim.iprompt)  /* non-interactive quit */
705 361 markom
      sim_done();
706 304 markom
 
707 16 jrydberg
#ifdef HAVE_LIBREADLINE
708 361 markom
    if (linestr)
709
      free (linestr);
710 16 jrydberg
#endif
711 7 jrydberg
 
712 361 markom
  }
713
  sim_done();
714 2 cvs
}
715 7 jrydberg
 
716 16 jrydberg
#ifdef HAVE_LIBREADLINE
717 7 jrydberg
char *command_generator ();
718
char **sim_completion ();
719
 
720
/* Tell the GNU readline library how to complete.  We want to try to complete
721
   on command names if this is the first word in the line, or on filenames
722
   if not. */
723
void initialize_readline ()
724
{
725
  /* Allow conditional parsing of the ~/.inputrc file. */
726
  rl_readline_name = "or1ksim";
727
 
728
  /* Tell the completer that we want a crack first. */
729
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
730
}
731
 
732
/* Attempt to complete on the contents of TEXT.  START and END bound the
733
   region of rl_line_buffer that contains the word to complete.  TEXT is
734
   the word to complete.  We can use the entire contents of rl_line_buffer
735
   in case we want to do some simple parsing.  Return the array of matches,
736
   or NULL if there aren't any. */
737
char **
738
sim_completion (text, start, end)
739
     char *text;
740
     int start, end;
741
{
742
  char **matches;
743
 
744
  matches = (char **)NULL;
745
 
746
  /* If this word is at the start of the line, then it is a command
747
     to complete.  Otherwise it is the name of a file in the current
748
     directory. */
749
  if (start == 0)
750
    matches = completion_matches (text, command_generator);
751
 
752
  return (matches);
753
}
754
 
755
/* Generator function for command completion.  STATE lets us know whether
756
   to start from scratch; without any state (i.e. STATE == 0), then we
757
   start at the top of the list. */
758
char *
759
command_generator (text, state)
760
     char *text;
761
     int state;
762
{
763
  static int list_index, len;
764
  char *name;
765
 
766
  /* If this is a new word to complete, initialize now.  This includes
767
     saving the length of TEXT for efficiency, and initializing the index
768
     variable to 0. */
769
  if (!state)
770
    {
771
      list_index = 0;
772
      len = strlen (text);
773
    }
774
 
775
  /* Return the next name which partially matches from the command list. */
776
  while (name = sim_commands[list_index])
777
    {
778
      list_index++;
779
 
780
      if (strncmp (name, text, len) == 0)
781
        return (dupstr(name));
782
    }
783
 
784
  /* If no names matched, then return NULL. */
785
  return ((char *)NULL);
786
}
787
 
788
/* Repeats the last command.  */
789
char *
790
repeat_last_command ()
791
{
792
  int offset = where_history ();
793
  HIST_ENTRY *hist;
794
 
795
  if (hist = history_get (offset))
796 306 markom
    return dupstr (hist->line);
797 7 jrydberg
  return 0;
798
}
799 16 jrydberg
 
800
#endif
801
 
802 138 markom
extern char *disassembled;
803 257 erez
void debugmem( unsigned long from, unsigned long to )
804
{
805 138 markom
  int i;
806
  printf("starting to dump mem...\n");
807 257 erez
  for(i=from; i<to; ) {
808 261 markom
    struct label_entry *entry;
809 221 markom
    unsigned int _insn;
810 261 markom
    printf("i=%x :: ", i);
811
 
812
    if (verify_memoryarea(i) && (entry = get_label(i)))
813
      printf("label: %s |", entry->name);
814 221 markom
 
815
    iqueue[0].insn = _insn = evalsim_mem32(i);
816
    iqueue[0].insn_index = insn_decode(_insn);
817
    disassemble_insn (_insn);
818
    printf("%08x %s\n", _insn, disassembled);
819 361 markom
    i += insn_len( iqueue[0].insn_index );
820 138 markom
  }
821 21 cmchen
}

powered by: WebSVN 2.1.0

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