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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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