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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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