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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [toplevel.c] - Blame information for rev 426

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 426 markom
const char rcsrev[] = "$Revision: 1.50 $";
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
  tick_reset();
253
  pm_reset();
254
  pic_reset();
255
  mc_reset();
256
  reset();
257 424 markom
 
258 361 markom
  /* Wait till all test are connected.  */
259
  if (config.vapi.enabled) {
260
    int numu = vapi_num_unconnected (0);
261
    if (numu) {
262
      printf ("\nWaiting for VAPI tests with ids:\n");
263
      vapi_num_unconnected (1);
264
      printf ("\n");
265
      while (numu = vapi_num_unconnected (0)) {
266
        vapi_check ();
267
        printf ("\rStill waiting for %i VAPI test(s) to connect.       ", numu);
268
        usleep (100);
269
      }
270
      printf ("\n");
271
    }
272
    printf ("All devices connected                         \n");
273
  }
274
  /* simulator is initialized */
275
  runtime.sim.init = 0;
276 304 markom
}
277 7 jrydberg
 
278 304 markom
/* Display info about various modules */
279
void sim_info () {
280
  itlb_status(-1);
281 361 markom
  dtlb_status(-1);
282
  ic_info();
283
  dc_info();
284
  sprs_status();
285
 
286
  if (config.cpu.bpb) bpb_info();
287
  if (config.cpu.btic) btic_info();
288
  if (config.uarts_enabled) uart_status();
289
  if (config.dmas_enabled) dma_status();
290
  if (config.ethernets_enabled) eth_status();
291 304 markom
}
292
 
293
/* Cleanup */
294
void sim_done ()
295
{
296
  if (config.sim.profile) {
297
    extern int cycles;
298 361 markom
    fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
299
    fclose(runtime.sim.fprof);
300 304 markom
  }
301 361 markom
  if (config.sim.exe_log)   fclose(runtime.sim.fexe_log);
302 304 markom
  if (config.vapi.enabled)  vapi_done ();
303 426 markom
  done_memory_table ();
304 304 markom
  exit(0);
305
}
306
 
307
int main(argc, argv)
308
     int argc;
309
     char *argv[];
310
{
311 361 markom
  char *linestr;
312
  char item1[500], b2[500], prev_str[500] = "";
313
  char *redirstr;
314
  int hush = 0;
315
  int first_prompt = 1;
316
  int trace_fd = 0;
317 304 markom
 
318 361 markom
  srand(getpid());
319
  init_defconfig();
320
  if (parse_args(argc, argv)) {
321
    printf("Usage: %s [options] <filename>\n", argv[0]);
322
    printf("Options:\n");
323
    printf(" -v                 version and copyright note\n");
324
    printf(" -i                 enable interactive command prompt\n");
325
    printf(" -f or --file       load script file [sim.cfg]\n");
326
    printf(" --nosrv            do not launch JTAG proxy server\n"); /* (CZ) */
327
    printf(" --srv <n>          launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
328
    printf(" --profile          enable profiling\n");
329
    exit(-1);
330
  }
331 304 markom
 
332
#ifdef HAVE_LIBREADLINE
333 361 markom
  initialize_readline (); /* Bind our completer. */
334 304 markom
#endif
335
 
336
  /* Read configuration file.  */
337 361 markom
  if (!runtime.sim.script_file_specified)
338
    read_script_file ("sim.cfg");
339 424 markom
  if (!runtime.sim.script_file_specified && config.sim.verbose)
340
    fprintf (stderr, "WARNING: No config file read, assuming default configuration.\n");
341 304 markom
  print_config();
342 336 markom
  sim_init ();
343 304 markom
  signal(SIGINT, ctrl_c);
344 335 markom
 
345 361 markom
  while(1) {
346
    if (config.sim.iprompt) {
347
      if (GDB_ENABLED)
348
        {
349
          printf ("(sim) ");
350
          fflush(stdout);
351
          HandleServerSocket(true);  /* block & check_stdin = true */
352
        }
353 16 jrydberg
#ifdef HAVE_LIBREADLINE
354 361 markom
      /* Must disable readline in new mode. It isn't compatible
355
         with non blocking environments */
356
      if(!GDB_ENABLED)
357
        linestr = readline("(sim) ");
358
      else
359
        linestr = fgets(b2, sizeof b2, stdin);
360 16 jrydberg
#else
361 361 markom
      if(!GDB_ENABLED)
362
        printf ("(sim) ");
363
      linestr = fgets(b2, sizeof b2, stdin);
364 16 jrydberg
#endif
365 361 markom
    } else
366
      strcpy(linestr = b2, "run -1 hush");
367 7 jrydberg
 
368 361 markom
    if (!linestr)
369
      break;
370
    linestr = stripwhite (linestr);
371 7 jrydberg
 
372 16 jrydberg
#ifdef HAVE_LIBREADLINE
373 361 markom
    /* Readline only works in the old mode */
374
    if(!server_fd)
375
      {
376
        if (strlen(linestr) == 0) {
377
          char *l = repeat_last_command ();
378
 
379
          if (l) {
380
      free (linestr);
381
      linestr = l;
382
          }
383
        }
384
 
385
        if (*linestr) {
386
          add_history (linestr);
387
        }
388
      }
389 16 jrydberg
#endif /* HAVE_LIBREADLINE */
390 361 markom
 
391
    if (redirstr = strstr(linestr, ">")) {
392
      *redirstr = '\0';
393
      strtoken(&redirstr[1], item1, 1);
394
      freopen(item1, "w+", stdout);
395
    }
396
 
397
    if (linestr[0] == '\n')
398
      strcpy (linestr, &prev_str[0]);
399
    else
400
      strcpy (&prev_str[0], linestr);
401
 
402
    strtoken(linestr, item1, 1);
403
    if (strcmp(item1, "q") == 0) {  /* quit */
404
      printf ("\n");
405
      sim_done ();
406
    } else
407
    if (strcmp(item1, "help") == 0) /* help */
408
      help();
409
    else
410
    if (strcmp(item1, "t") == 0) {  /* trace */
411
      cont_run = 1;
412
    } else
413
    if (strcmp(item1, "dm") == 0) { /* dump memory */
414
      char item2[20];
415
      char item3[20];
416
      static int from = 0, to = 0;
417
 
418
      strtoken(linestr, item2, 2);
419
      strtoken(linestr, item3, 3);
420
 
421
      if (strlen(item2)) {
422
        if (item2[0] == '_')
423
          from = eval_label(item2);
424
        else
425
          from = strtoul(item2, NULL, 0);
426
        to = from + 0x40;
427
      }
428
      if (strlen(item3))
429
        to = strtoul(item3, NULL, 0);
430
      dumpmemory(from, to, 0, 1);
431
            printf("\n");
432
    } else
433
    if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
434
      char item2[20];
435
      char item3[20];
436
      char item4[20];
437
      static int from = 0, to = 0;
438
 
439
      strtoken(linestr, item2, 2);
440
      strtoken(linestr, item3, 3);
441
      strtoken(linestr, item4, 4);
442
 
443
      if (strlen(item2)) {
444
        if (item2[0] == '_')
445
          from = eval_label(item2);
446
        else
447
          from = strtoul(item2, NULL, 0);
448
        to = from + 0x40;
449
      }
450
      if (strlen(item3))
451
        to = strtoul(item3, NULL, 0);
452
      if (!strlen(item4))
453
        strcpy(item4, "or1k_mem");
454
      dumpverilog(item4, from, to);
455
        printf("\n");
456
    } else
457
    if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
458
      char item2[20];
459
      char item3[20];
460
      static int from = 0, to = 0;
461
 
462
      strtoken(linestr, item2, 2);
463
      strtoken(linestr, item3, 3);
464
 
465
      if (strlen(item2)) {
466
        if (item2[0] == '_')
467
          from = eval_label(item2);
468
        else
469
          from = strtoul(item2, NULL, 0);
470
        to = from + 0x40;
471
      }
472
      if (strlen(item3))
473
        to = strtoul(item3, NULL, 0);
474
      dumphex(from, to);
475
        printf("\n");
476
    } else
477
    if (strcmp(item1, "pm") == 0) { /* patch memory */
478
      char item2[20];
479
      char item3[20];
480
      static int addr = 0;
481
      int breakpoint = 0;
482 123 markom
 
483 361 markom
      strtoken(linestr, item2, 2);
484
      strtoken(linestr, item3, 3);
485
      if (strlen(item2))
486
        if (item2[0] == '_')
487
          addr = eval_label(item2);
488
        else
489
          addr = strtoul(item2, NULL, 0);
490
      set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
491
    } else
492
    if (strcmp(item1, "pr") == 0) { /* patch regs */
493
      char item2[20];
494
      char item3[20];
495
 
496
      strtoken(linestr, item2, 2);
497
      strtoken(linestr, item3, 3);
498
      set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
499
    } else
500
    if (strcmp(item1, "pc") == 0) { /* patch PC */
501
      char item2[20];
502
 
503
      strtoken(linestr, item2, 2);
504
      pcnext = strtoul(item2, NULL, 0);
505
    } else
506
    if (strcmp(item1, "break") == 0) {  /* set/clear breakpoint */
507
      char item2[20];
508
 
509
      strtoken(linestr, item2, 2);
510
      set_insnbrkpoint(strtoul(item2, NULL, 0));
511
    } else
512
    if (strcmp(item1, "r") == 0) {  /* dump regs */
513
      dumpreg();
514
    } else
515
    if (strcmp(item1, "de") == 0) { /* reset simulator */
516
      char item2[20];
517
      char item3[20];
518
      static int from = 0, to = 0;
519
 
520
      strtoken(linestr, item2, 2);
521
      strtoken(linestr, item3, 3);
522
 
523
      if (strlen(item2)) {
524
        if (item2[0] == '_')
525
          from = eval_label(item2);
526
        else
527
          from = strtoul(item2, NULL, 0);
528
        to = from + 0x40;
529
      }
530
      if (strlen(item3))
531
        to = strtoul(item3, NULL, 0);
532
      debugmem(from, to);
533
      printf("\n");
534
    } else
535
    if (strcmp(item1, "reset") == 0) {  /* reset simulator */
536
      uart_reset();
537
      dma_reset();
538
      eth_reset();
539
      tick_reset();
540
      pm_reset();
541
      pic_reset();
542
      reset(); /* Old or new mode */
543
    } else
544
    if (strcmp(item1, "debug") == 0) {  /* debug mode */
545
      config.sim.debug ^= 1;
546
    } else
547
    if (strcmp(item1, "hist") == 0) { /* dump history */
548
      int i;
549
      for(i = HISTEXEC_LEN; i; i--)
550
        dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
551
      printf("\n");
552
    } else
553
    if (strcmp(item1, "run") == 0) { /* run */
554
      char item2[20];
555
      char item3[20];
556
 
557
      strtoken(linestr, item2, 2);
558
      strtoken(linestr, item3, 3);
559
      if (strcmp(item3, "hush") == 0)
560
        hush = 1;
561
      else
562
        hush = 0;
563
      cont_run = strtol(item2, NULL, 0);
564
    } else
565
    if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
566
      extern int cpu_stalled;  /* CZ from debug_interface */
567
      cpu_stalled = 1;
568
      config.sim.iprompt = 0;
569
      cont_run = -1;
570
      hush = 1;
571
    } else
572
    if (!strcmp(item1, "trace")) { /* Added by CZ 210801 */
573
      char item2[256];
574
 
575
      strtoken(linestr, item2, 2);
576
      if(trace_fd) {
577
        close(trace_fd);
578
        trace_fd = 0;
579
      }
580
      if(strcmp(item2,"off")) /* if we're not being turned off */
581
        {
582
          if(item2[0])
583
            trace_fd = open(item2,O_CREAT | O_NOCTTY |
584
          O_TRUNC | O_WRONLY, 0644);
585
          else
586
            trace_fd = dup(1);
587
          if(trace_fd < 0) {
588
            perror(item2[0]?item2:"stdout");
589
            trace_fd = 0;
590
          }
591
        }
592
    } else
593
    if (strcmp(item1, "stats") == 0) { /* stats */
594
      char item2[20];
595
      int i = 0;
596
 
597
      strtoken(linestr, item2, 2);
598
      if (strcmp(item2, "clear") == 0) {
599
        initstats();
600
        printf("Cleared.\n");
601
      } else {
602
        i = strtoul(item2, NULL, 0);
603
        printstats(i);
604
      }
605
    } else
606
    if (strcmp(item1, "info") == 0) /* configuration info */
607
      sim_info ();
608
    else
609
    if (strcmp(item1, "set") == 0) { /* configuration info */
610
      char *s = linestr;
611
      int i;
612
      extern section;
613
      extern struct section sections[];
614
      while (*s != ' ' && *s) s++;
615
      set_config_command (s);
616
    } else
617
      printf("%s: Unknown command.\n", linestr);
618 103 lampret
 
619 304 markom
 
620 361 markom
    /* MM: 'run -1' means endless execution.  */
621
    while(cont_run != 0) {
622
      int debug_slowdown = DEBUG_SLOWDOWN;
623
      extern int cycle_delay;  /* Added by CZ 27/05/01. Set during exception. */
624
      extern int cpu_stalled;  /* CZ from debug_interface */
625 123 markom
 
626 294 markom
      if (cpu_stalled)
627 361 markom
        if(GDB_ENABLED) {
628
          BlockJTAG();
629
          HandleServerSocket(false);
630
          continue;
631
        } else
632
          fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
633 127 chris
 
634 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
635 304 markom
        if(cycle_delay <= 0) {
636
          unsigned int addr;
637
          if (cont_run > 0) cont_run--;
638
          if(fetch()) {
639 344 markom
            printf ("Breakpoint hit.\n");
640 304 markom
            cont_run = 0; /* memory breakpoint encountered */
641
            break;
642
          }
643
          addr = iqueue[0].insn_addr;
644
 
645
          /* If trace_fd is non zero, we want
646
             to make sure that disassemble is called */
647 181 chris
 
648 304 markom
          decode_execute(&iqueue[0],trace_fd);
649
          if(trace_fd) {
650
            char sTemp[256];
651
            char sTemp2[256];
652
            unsigned long value;
653
            extern char *disassembled;
654
            extern unsigned long reg[];
655 181 chris
 
656 304 markom
            /* The objects passed to the
657
               trace command should not be
658
               hardcoded like this...instead
659
               what to dump should be passed
660
               on the command line.
661 181 chris
 
662 304 markom
               FIX THIS LATER...
663
            */
664
            value = (evalsim_mem8(0x306bc) << 24) +
665
              (evalsim_mem8(0x306bd) << 16) +
666
              (evalsim_mem8(0x306be) << 8)
667
              + evalsim_mem8(0x306bf);
668 221 markom
 
669 304 markom
            sprintf(sTemp,"0x%06x: %s",addr,disassembled);
670
            memset(sTemp2,' ',sizeof(sTemp2));
671
            strncpy(sTemp2,sTemp,strlen(sTemp));
672
            sprintf(&sTemp2[40],"<0x%08x,0x%08x> [0x%08x]\n",
673
                    reg[3],reg[4],value);
674
            write(trace_fd,sTemp2,strlen(sTemp2));
675 261 markom
          }
676 304 markom
          update_pc();
677
          analysis();
678
          if (!hush)
679
            dumpreg();
680
        } else
681 261 markom
          cycle_delay--;
682 123 markom
 
683 261 markom
        pic_clock();
684
        dc_clock();
685
        ic_clock();
686 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
687 261 markom
      }
688 304 markom
 
689 261 markom
      pm_clock();
690 304 markom
      if (config.uarts_enabled) uart_clock();
691
      if (config.dmas_enabled) dma_clock();
692
      if (config.ethernets_enabled) eth_clock();
693
      if (config.sim.exe_log) dump_exe_log();
694
      if (config.vapi.enabled) vapi_check();
695 269 markom
      if (GDB_ENABLED && debug_slowdown-- == 0) {
696 261 markom
        debug_slowdown = DEBUG_SLOWDOWN;
697 361 markom
        HandleServerSocket(false); /* block & check_stdin = false */
698
      }
699
    }
700
    hush = 0;
701
    fflush(stdout);
702
    freopen("/dev/fd/0", "w+", stdout);
703 2 cvs
 
704 361 markom
    if (!config.sim.iprompt)  /* non-interactive quit */
705
      sim_done();
706 304 markom
 
707 16 jrydberg
#ifdef HAVE_LIBREADLINE
708 361 markom
    if (linestr)
709
      free (linestr);
710 16 jrydberg
#endif
711 7 jrydberg
 
712 361 markom
  }
713
  sim_done();
714 2 cvs
}
715 7 jrydberg
 
716 16 jrydberg
#ifdef HAVE_LIBREADLINE
717 7 jrydberg
char *command_generator ();
718
char **sim_completion ();
719
 
720
/* Tell the GNU readline library how to complete.  We want to try to complete
721
   on command names if this is the first word in the line, or on filenames
722
   if not. */
723
void initialize_readline ()
724
{
725
  /* Allow conditional parsing of the ~/.inputrc file. */
726
  rl_readline_name = "or1ksim";
727
 
728
  /* Tell the completer that we want a crack first. */
729
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
730
}
731
 
732
/* Attempt to complete on the contents of TEXT.  START and END bound the
733
   region of rl_line_buffer that contains the word to complete.  TEXT is
734
   the word to complete.  We can use the entire contents of rl_line_buffer
735
   in case we want to do some simple parsing.  Return the array of matches,
736
   or NULL if there aren't any. */
737
char **
738
sim_completion (text, start, end)
739
     char *text;
740
     int start, end;
741
{
742
  char **matches;
743
 
744
  matches = (char **)NULL;
745
 
746
  /* If this word is at the start of the line, then it is a command
747
     to complete.  Otherwise it is the name of a file in the current
748
     directory. */
749
  if (start == 0)
750
    matches = completion_matches (text, command_generator);
751
 
752
  return (matches);
753
}
754
 
755
/* Generator function for command completion.  STATE lets us know whether
756
   to start from scratch; without any state (i.e. STATE == 0), then we
757
   start at the top of the list. */
758
char *
759
command_generator (text, state)
760
     char *text;
761
     int state;
762
{
763
  static int list_index, len;
764
  char *name;
765
 
766
  /* If this is a new word to complete, initialize now.  This includes
767
     saving the length of TEXT for efficiency, and initializing the index
768
     variable to 0. */
769
  if (!state)
770
    {
771
      list_index = 0;
772
      len = strlen (text);
773
    }
774
 
775
  /* Return the next name which partially matches from the command list. */
776
  while (name = sim_commands[list_index])
777
    {
778
      list_index++;
779
 
780
      if (strncmp (name, text, len) == 0)
781
        return (dupstr(name));
782
    }
783
 
784
  /* If no names matched, then return NULL. */
785
  return ((char *)NULL);
786
}
787
 
788
/* Repeats the last command.  */
789
char *
790
repeat_last_command ()
791
{
792
  int offset = where_history ();
793
  HIST_ENTRY *hist;
794
 
795
  if (hist = history_get (offset))
796 306 markom
    return dupstr (hist->line);
797 7 jrydberg
  return 0;
798
}
799 16 jrydberg
 
800
#endif
801
 
802 138 markom
extern char *disassembled;
803 257 erez
void debugmem( unsigned long from, unsigned long to )
804
{
805 138 markom
  int i;
806
  printf("starting to dump mem...\n");
807 257 erez
  for(i=from; i<to; ) {
808 261 markom
    struct label_entry *entry;
809 221 markom
    unsigned int _insn;
810 261 markom
    printf("i=%x :: ", i);
811
 
812
    if (verify_memoryarea(i) && (entry = get_label(i)))
813
      printf("label: %s |", entry->name);
814 221 markom
 
815
    iqueue[0].insn = _insn = evalsim_mem32(i);
816
    iqueue[0].insn_index = insn_decode(_insn);
817
    disassemble_insn (_insn);
818
    printf("%08x %s\n", _insn, disassembled);
819 361 markom
    i += insn_len( iqueue[0].insn_index );
820 138 markom
  }
821 21 cmchen
}

powered by: WebSVN 2.1.0

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