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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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