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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_59/] [or1ksim/] [toplevel.c] - Blame information for rev 868

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 868 markom
const char rcsrev[] = "$Revision: 1.85 $";
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 868 markom
  mp_help ();
161
  prof_help ();
162 551 markom
#endif
163 361 markom
  printf("help       - available commands (this list)\n");
164 2 cvs
}
165
 
166 479 markom
void debugmem (unsigned long from, unsigned long to );
167 21 cmchen
 
168 479 markom
/* Resets all subunits */
169
void sim_reset ()
170
{
171 728 markom
  SCHED_INIT();
172 479 markom
  uart_reset();
173
  dma_reset();
174
  eth_reset();
175
  gpio_reset();
176 645 markom
  vga_reset ();
177
  fb_reset ();
178 664 markom
  kbd_reset ();
179 479 markom
  tick_reset();
180
  pm_reset();
181
  pic_reset();
182
  mc_reset();
183
  du_reset ();
184 557 markom
  cpu_reset();
185 479 markom
}
186
 
187 304 markom
/* Initalizes all devices and sim */
188
void sim_init ()
189 2 cvs
{
190 424 markom
  init_memory_table ();
191 269 markom
  init_labels();
192
  init_breakpoints();
193 361 markom
  initstats();
194
  build_automata();
195
 
196 305 markom
  if (config.sim.profile) {
197 361 markom
    runtime.sim.fprof = fopen(config.sim.prof_fn, "wt+");
198
    if(!runtime.sim.fprof) {
199 551 markom
      fprintf(stderr, "ERROR: Problems opening profile file.\n");
200
      exit (1);
201 173 markom
    } else
202 632 ivang
      fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF total\n");
203 173 markom
  }
204 294 markom
 
205 547 markom
  if (config.sim.mprofile) {
206
    runtime.sim.fmprof = fopen(config.sim.mprof_fn, "wb+");
207
    if(!runtime.sim.fmprof) {
208 551 markom
      fprintf(stderr, "ERROR: Problems opening memory profile file.\n");
209
      exit (1);
210 547 markom
    }
211
  }
212
 
213 294 markom
  if (config.sim.exe_log) {
214 361 markom
    runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
215
    if(!runtime.sim.fexe_log) {
216 551 markom
      printf("ERROR: Problems opening exe_log file.\n");
217
      exit (1);
218 294 markom
    }
219
  }
220 263 markom
 
221 624 ivang
  if (config.sim.spr_log) {
222
    printf("OPENING SPRLOG\n");
223
    runtime.sim.fspr_log = fopen(config.sim.spr_log_fn, "wt+");
224
    if (!runtime.sim.fspr_log) {
225
      printf("ERROR: Problems opening spr_log file.\n");
226
      exit(1);
227
    }
228
  }
229
 
230 262 markom
  /* Initialize memory */
231
  {
232 361 markom
    extern struct dev_memarea *dev_list;
233 554 markom
    struct dev_memarea *area;
234 361 markom
    int i;
235
    if (config.memory.type == MT_RANDOM) {
236
      unsigned int val = 0;
237 123 markom
 
238 262 markom
      if (config.memory.random_seed == -1) {
239 551 markom
        runtime.memory.random_seed = time(NULL);
240 262 markom
        /* Print out the seed just in case we ever need to debug */
241 361 markom
        printf("Seeding random generator with value %d\n", config.memory.random_seed);
242 551 markom
      } else
243
        runtime.memory.random_seed = config.memory.random_seed;
244
      srandom(runtime.memory.random_seed);
245 262 markom
 
246 554 markom
      for (area = dev_list; area; area = area->next)
247
        for(i = 0; i < area->size; i++) {
248 221 markom
          val = random();
249 554 markom
          setsim_mem8(i + area->addr_compare, val & 0xFF);
250 221 markom
        }
251 262 markom
    } else if(config.memory.type == MT_PATTERN) {
252 554 markom
      for (area = dev_list; area; area = area->next)
253
        for(i = 0; i < area->size; i++)
254
          setsim_mem8(i + area->addr_compare, config.memory.pattern);
255 269 markom
    } else if (config.memory.type != MT_UNKNOWN) {
256 262 markom
      fprintf(stderr, "Invalid memory configuration type.\n");
257 361 markom
      exit(1);
258 221 markom
    }
259 242 markom
  }
260 262 markom
 
261 361 markom
  if(runtime.sim.filename) {
262
    unsigned long endaddr = 0xFFFFFFFF;
263
    endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero.  */
264
    if (endaddr == -1) {
265
      fprintf(stderr, "Problems loading boot code.\n");
266
      exit(1);
267
    }
268
  }
269 551 markom
 
270
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
271 361 markom
  /* Disable gdb debugging, if debug module is not available.  */
272
  if (config.debug.gdb_enabled && !config.debug.enabled) {
273
    config.debug.gdb_enabled = 0;
274
    if (config.sim.verbose)
275
      fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
276
  }
277 551 markom
#endif
278
 
279 550 markom
  if (config.debug.gdb_enabled)
280 479 markom
    gdbcomm_init ();
281 551 markom
 
282
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
283 361 markom
  /* Enable dependency stats, if we want to do history analisis */
284 394 markom
  if (config.sim.history && !config.cpu.dependstats) {
285
    config.cpu.dependstats = 1;
286 361 markom
    if (config.sim.verbose)
287 394 markom
      fprintf (stderr, "WARNING: dependstats stats must be enabled to do history analisis.\n");
288 361 markom
  }
289 551 markom
#endif
290
 
291
#if !FAST_SIM /* We assume we have valid configuration with fsim*/  
292 361 markom
  /* Debug forces verbose */
293
  if (config.sim.debug && !config.sim.verbose) {
294
    config.sim.verbose = 1;
295
    fprintf (stderr, "WARNING: verbose turned on.\n");
296
  }
297 551 markom
#endif
298 361 markom
 
299
  /* Start VAPI before device initialization.  */
300
  if (config.vapi.enabled) {
301 551 markom
    runtime.vapi.enabled = 1;
302 361 markom
    vapi_init ();
303
    if (config.sim.verbose)
304
      printf ("VAPI started, waiting for clients.\n");
305
  }
306 538 markom
 
307 479 markom
  sim_reset ();
308 424 markom
 
309 543 simons
  lock_memory_table ();
310
 
311 361 markom
  /* Wait till all test are connected.  */
312 551 markom
  if (runtime.vapi.enabled) {
313 361 markom
    int numu = vapi_num_unconnected (0);
314
    if (numu) {
315
      printf ("\nWaiting for VAPI tests with ids:\n");
316
      vapi_num_unconnected (1);
317
      printf ("\n");
318
      while (numu = vapi_num_unconnected (0)) {
319
        vapi_check ();
320
        printf ("\rStill waiting for %i VAPI test(s) to connect.       ", numu);
321
        usleep (100);
322
      }
323
      printf ("\n");
324
    }
325
    printf ("All devices connected                         \n");
326
  }
327
  /* simulator is initialized */
328
  runtime.sim.init = 0;
329 304 markom
}
330 7 jrydberg
 
331 304 markom
/* Display info about various modules */
332
void sim_info () {
333 427 markom
  sprs_status();
334 535 markom
  printf ("\n");
335 427 markom
  memory_table_status ();
336 535 markom
  if (config.immu.enabled) itlb_status(-1);
337
  if (config.dmmu.enabled) dtlb_status(-1);
338
  if (config.ic.enabled) ic_info();
339
  if (config.dc.enabled) dc_info();
340 361 markom
 
341 541 markom
  if (config.bpb.enabled) bpb_info();
342
  if (config.bpb.btic) btic_info();
343 535 markom
 
344 741 ivang
  if (config.mc.enabled) mc_status();
345 549 markom
  if (config.nuarts) uart_status();
346
  if (config.ndmas) dma_status();
347
  if (config.nethernets) eth_status();
348
  if (config.ngpios) gpio_status();
349 683 lampret
  kbd_info();
350 304 markom
}
351
 
352
/* Cleanup */
353
void sim_done ()
354
{
355
  if (config.sim.profile) {
356
    extern int cycles;
357 361 markom
    fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
358
    fclose(runtime.sim.fprof);
359 304 markom
  }
360 547 markom
 
361 847 markom
  if (config.sim.mprofile) fclose(runtime.sim.fmprof);
362 361 markom
  if (config.sim.exe_log)   fclose(runtime.sim.fexe_log);
363 551 markom
  if (runtime.vapi.enabled)  vapi_done ();
364 426 markom
  done_memory_table ();
365 304 markom
  exit(0);
366
}
367
 
368 728 markom
/* Executes jobs in time queue */
369
static inline void do_scheduler ()
370
{
371
  void (*func)(int);
372
  int param;
373 632 ivang
 
374 728 markom
  /* Execute all jobs till now */
375
  do {
376
    func = SCHED_PEEK().func;
377
    param = SCHED_PEEK().param;
378
    SCHED_REMOVE();
379
    func (param);
380
  } while (cycles >= SCHED_PEEK().time);
381
}
382 632 ivang
 
383 728 markom
/* Main function */
384 304 markom
int main(argc, argv)
385
     int argc;
386
     char *argv[];
387
{
388 361 markom
  char *linestr;
389
  char item1[500], b2[500], prev_str[500] = "";
390
  char *redirstr;
391
  int hush = 0;
392
  int first_prompt = 1;
393 304 markom
 
394 361 markom
  srand(getpid());
395
  init_defconfig();
396
  if (parse_args(argc, argv)) {
397
    printf("Usage: %s [options] <filename>\n", argv[0]);
398
    printf("Options:\n");
399 632 ivang
    printf(" -v                   version and copyright note\n");
400
    printf(" -i                   enable interactive command prompt\n");
401
    printf(" --nosrv              do not launch JTAG proxy server\n"); /* (CZ) */
402
    printf(" --srv <n>            launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
403 551 markom
#if !FAST_SIM
404 632 ivang
    printf(" -f or --file         load script file [sim.cfg]\n");
405 847 markom
    printf(" --enable-profile     enable profiling.\n");
406
    printf(" --enable-mprofile    enable memory profiling.\n");
407 551 markom
#endif
408 847 markom
    printf(" --output-cfg         prints C structure of current\n");
409
    printf("                      configuration to standard output\n");
410
    printf("\nor   : %s ", argv[0]);
411
    mp_help ();
412
    printf("\nor   : %s ", argv[0]);
413
    prof_help ();
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 848 markom
    if (strcmp (item1, "profiler") == 0) { /* run profiler utility */
677
      char *argv[10];
678
      int argc = tokenize_line (linestr, argv, 10);
679
      main_profiler (argc, argv);
680 847 markom
    } else
681 848 markom
    if (strcmp (item1, "mprofiler") == 0) { /* run mprofiler utility */
682
      char *argv[10];
683
      int argc = tokenize_line (linestr, argv, 10);
684
      main_mprofiler (argc, argv);
685
    } else
686 551 markom
#if !FAST_SIM
687 361 markom
    if (strcmp(item1, "set") == 0) { /* configuration info */
688
      char *s = linestr;
689
      int i;
690
      extern section;
691
      extern struct section sections[];
692
      while (*s != ' ' && *s) s++;
693
      set_config_command (s);
694
    } else
695 551 markom
#endif /* !FAST_SIM */
696 361 markom
      printf("%s: Unknown command.\n", linestr);
697 713 markom
 
698 714 markom
    { /* Needed by execution */
699
      extern int do_stats;
700
      do_stats = config.cpu.dependstats || config.cpu.superscalar || config.cpu.dependstats
701
              || config.sim.history || config.sim.exe_log;
702
    }
703
 
704 361 markom
    /* MM: 'run -1' means endless execution.  */
705 713 markom
    while(cont_run) {
706 537 markom
      extern int mem_cycles;
707 123 markom
 
708 557 markom
      IFF (config.debug.enabled) {
709
        if (cpu_stalled) {
710
          if(config.debug.gdb_enabled) {
711
            BlockJTAG();
712
            HandleServerSocket(false);
713 605 markom
          } else {
714
            fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
715
            cont_run = 0;
716
          }
717 557 markom
          continue;
718
        }
719 479 markom
      }
720 127 chris
 
721 537 markom
      /* Each cycle has counter of mem_cycles; this value is joined with cycles
722
         at the end of the cycle; no sim originated memory accesses should be
723
         performed inbetween. */
724
      mem_cycles = 0;
725 557 markom
      if (!config.pm.enabled || !testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
726 535 markom
        if (cont_run > 0) cont_run--;
727 599 simons
        pic_clock ();
728
        if (cpu_clock ()) break;
729
        if (config.dc.enabled) dc_clock();
730
        if (config.ic.enabled) ic_clock();
731 261 markom
      }
732 304 markom
 
733 549 markom
      if (config.dmas) dma_clock();
734
      if (config.ethernets) eth_clock();
735
      if (config.ngpios) gpio_clock();
736 551 markom
      if (config.vapi.enabled && runtime.vapi.enabled) vapi_check();
737 557 markom
      if (config.debug.gdb_enabled) HandleServerSocket(false); /* block & check_stdin = false */
738
      IFF(config.debug.enabled)
739 479 markom
        if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
740 557 markom
 
741 537 markom
      cycles += mem_cycles;
742 728 markom
      if (cycles >= SCHED_PEEK().time) do_scheduler ();
743 537 markom
      if (!hush) dumpreg();
744 361 markom
    }
745
    hush = 0;
746
    fflush(stdout);
747
    freopen("/dev/fd/0", "w+", stdout);
748 2 cvs
 
749 551 markom
    if (!runtime.sim.iprompt)  /* non-interactive quit */
750 361 markom
      sim_done();
751 304 markom
 
752 16 jrydberg
#ifdef HAVE_LIBREADLINE
753 361 markom
    if (linestr)
754
      free (linestr);
755 16 jrydberg
#endif
756 7 jrydberg
 
757 361 markom
  }
758
  sim_done();
759 2 cvs
}
760 7 jrydberg
 
761 16 jrydberg
#ifdef HAVE_LIBREADLINE
762 7 jrydberg
char *command_generator ();
763
char **sim_completion ();
764
 
765
/* Tell the GNU readline library how to complete.  We want to try to complete
766
   on command names if this is the first word in the line, or on filenames
767
   if not. */
768
void initialize_readline ()
769
{
770
  /* Allow conditional parsing of the ~/.inputrc file. */
771
  rl_readline_name = "or1ksim";
772
 
773
  /* Tell the completer that we want a crack first. */
774
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
775
}
776
 
777
/* Attempt to complete on the contents of TEXT.  START and END bound the
778
   region of rl_line_buffer that contains the word to complete.  TEXT is
779
   the word to complete.  We can use the entire contents of rl_line_buffer
780
   in case we want to do some simple parsing.  Return the array of matches,
781
   or NULL if there aren't any. */
782
char **
783
sim_completion (text, start, end)
784
     char *text;
785
     int start, end;
786
{
787
  char **matches;
788
 
789
  matches = (char **)NULL;
790
 
791
  /* If this word is at the start of the line, then it is a command
792
     to complete.  Otherwise it is the name of a file in the current
793
     directory. */
794
  if (start == 0)
795
    matches = completion_matches (text, command_generator);
796
 
797
  return (matches);
798
}
799
 
800
/* Generator function for command completion.  STATE lets us know whether
801
   to start from scratch; without any state (i.e. STATE == 0), then we
802
   start at the top of the list. */
803
char *
804
command_generator (text, state)
805
     char *text;
806
     int state;
807
{
808
  static int list_index, len;
809
  char *name;
810
 
811
  /* If this is a new word to complete, initialize now.  This includes
812
     saving the length of TEXT for efficiency, and initializing the index
813
     variable to 0. */
814
  if (!state)
815
    {
816
      list_index = 0;
817
      len = strlen (text);
818
    }
819
 
820
  /* Return the next name which partially matches from the command list. */
821
  while (name = sim_commands[list_index])
822
    {
823
      list_index++;
824
 
825
      if (strncmp (name, text, len) == 0)
826
        return (dupstr(name));
827
    }
828
 
829
  /* If no names matched, then return NULL. */
830
  return ((char *)NULL);
831
}
832
 
833
/* Repeats the last command.  */
834
char *
835
repeat_last_command ()
836
{
837
  int offset = where_history ();
838
  HIST_ENTRY *hist;
839
 
840
  if (hist = history_get (offset))
841 306 markom
    return dupstr (hist->line);
842 7 jrydberg
  return 0;
843
}
844 16 jrydberg
 
845
#endif
846
 
847 138 markom
extern char *disassembled;
848 257 erez
void debugmem( unsigned long from, unsigned long to )
849
{
850 138 markom
  int i;
851
  printf("starting to dump mem...\n");
852 257 erez
  for(i=from; i<to; ) {
853 261 markom
    struct label_entry *entry;
854 221 markom
    unsigned int _insn;
855 261 markom
    printf("i=%x :: ", i);
856
 
857
    if (verify_memoryarea(i) && (entry = get_label(i)))
858
      printf("label: %s |", entry->name);
859 221 markom
 
860
    iqueue[0].insn = _insn = evalsim_mem32(i);
861
    iqueue[0].insn_index = insn_decode(_insn);
862
    disassemble_insn (_insn);
863
    printf("%08x %s\n", _insn, disassembled);
864 361 markom
    i += insn_len( iqueue[0].insn_index );
865 138 markom
  }
866 21 cmchen
}

powered by: WebSVN 2.1.0

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