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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [toplevel.c] - Blame information for rev 879

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

powered by: WebSVN 2.1.0

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