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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [toplevel.c] - Blame information for rev 876

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

powered by: WebSVN 2.1.0

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