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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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