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

Subversion Repositories or1k

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

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 "execute.h"
44 69 lampret
#include "sim-config.h"
45 103 lampret
#include "spr_defs.h"
46 518 markom
#include "sprs.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 518 markom
const char rcsrev[] = "$Revision: 1.57 $";
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 304 markom
 
325 361 markom
  srand(getpid());
326
  init_defconfig();
327
  if (parse_args(argc, argv)) {
328
    printf("Usage: %s [options] <filename>\n", argv[0]);
329
    printf("Options:\n");
330
    printf(" -v                 version and copyright note\n");
331
    printf(" -i                 enable interactive command prompt\n");
332
    printf(" -f or --file       load script file [sim.cfg]\n");
333
    printf(" --nosrv            do not launch JTAG proxy server\n"); /* (CZ) */
334
    printf(" --srv <n>          launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
335
    printf(" --profile          enable profiling\n");
336
    exit(-1);
337
  }
338 304 markom
 
339
#ifdef HAVE_LIBREADLINE
340 361 markom
  initialize_readline (); /* Bind our completer. */
341 304 markom
#endif
342
 
343
  /* Read configuration file.  */
344 361 markom
  if (!runtime.sim.script_file_specified)
345
    read_script_file ("sim.cfg");
346 424 markom
  if (!runtime.sim.script_file_specified && config.sim.verbose)
347
    fprintf (stderr, "WARNING: No config file read, assuming default configuration.\n");
348 304 markom
  print_config();
349 336 markom
  sim_init ();
350 304 markom
  signal(SIGINT, ctrl_c);
351 335 markom
 
352 361 markom
  while(1) {
353
    if (config.sim.iprompt) {
354
      if (GDB_ENABLED)
355
        {
356
          printf ("(sim) ");
357
          fflush(stdout);
358
          HandleServerSocket(true);  /* block & check_stdin = true */
359
        }
360 16 jrydberg
#ifdef HAVE_LIBREADLINE
361 361 markom
      /* Must disable readline in new mode. It isn't compatible
362
         with non blocking environments */
363
      if(!GDB_ENABLED)
364
        linestr = readline("(sim) ");
365
      else
366
        linestr = fgets(b2, sizeof b2, stdin);
367 16 jrydberg
#else
368 361 markom
      if(!GDB_ENABLED)
369
        printf ("(sim) ");
370
      linestr = fgets(b2, sizeof b2, stdin);
371 16 jrydberg
#endif
372 361 markom
    } else
373
      strcpy(linestr = b2, "run -1 hush");
374 7 jrydberg
 
375 361 markom
    if (!linestr)
376
      break;
377
    linestr = stripwhite (linestr);
378 7 jrydberg
 
379 16 jrydberg
#ifdef HAVE_LIBREADLINE
380 361 markom
    /* Readline only works in the old mode */
381
    if(!server_fd)
382
      {
383
        if (strlen(linestr) == 0) {
384
          char *l = repeat_last_command ();
385
 
386
          if (l) {
387
      free (linestr);
388
      linestr = l;
389
          }
390
        }
391
 
392
        if (*linestr) {
393
          add_history (linestr);
394
        }
395
      }
396 16 jrydberg
#endif /* HAVE_LIBREADLINE */
397 361 markom
 
398
    if (redirstr = strstr(linestr, ">")) {
399
      *redirstr = '\0';
400
      strtoken(&redirstr[1], item1, 1);
401
      freopen(item1, "w+", stdout);
402
    }
403
 
404
    if (linestr[0] == '\n')
405
      strcpy (linestr, &prev_str[0]);
406
    else
407
      strcpy (&prev_str[0], linestr);
408
 
409
    strtoken(linestr, item1, 1);
410
    if (strcmp(item1, "q") == 0) {  /* quit */
411
      printf ("\n");
412
      sim_done ();
413
    } else
414
    if (strcmp(item1, "help") == 0) /* help */
415
      help();
416
    else
417
    if (strcmp(item1, "t") == 0) {  /* trace */
418
      cont_run = 1;
419
    } else
420
    if (strcmp(item1, "dm") == 0) { /* dump memory */
421
      char item2[20];
422
      char item3[20];
423
      static int from = 0, to = 0;
424
 
425
      strtoken(linestr, item2, 2);
426
      strtoken(linestr, item3, 3);
427
 
428
      if (strlen(item2)) {
429
        if (item2[0] == '_')
430
          from = eval_label(item2);
431
        else
432
          from = strtoul(item2, NULL, 0);
433
        to = from + 0x40;
434
      }
435
      if (strlen(item3))
436
        to = strtoul(item3, NULL, 0);
437
      dumpmemory(from, to, 0, 1);
438
            printf("\n");
439
    } else
440
    if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
441
      char item2[20];
442
      char item3[20];
443
      char item4[20];
444
      static int from = 0, to = 0;
445
 
446
      strtoken(linestr, item2, 2);
447
      strtoken(linestr, item3, 3);
448
      strtoken(linestr, item4, 4);
449
 
450
      if (strlen(item2)) {
451
        if (item2[0] == '_')
452
          from = eval_label(item2);
453
        else
454
          from = strtoul(item2, NULL, 0);
455
        to = from + 0x40;
456
      }
457
      if (strlen(item3))
458
        to = strtoul(item3, NULL, 0);
459
      if (!strlen(item4))
460
        strcpy(item4, "or1k_mem");
461
      dumpverilog(item4, from, to);
462
        printf("\n");
463
    } else
464
    if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
465
      char item2[20];
466
      char item3[20];
467
      static int from = 0, to = 0;
468
 
469
      strtoken(linestr, item2, 2);
470
      strtoken(linestr, item3, 3);
471
 
472
      if (strlen(item2)) {
473
        if (item2[0] == '_')
474
          from = eval_label(item2);
475
        else
476
          from = strtoul(item2, NULL, 0);
477
        to = from + 0x40;
478
      }
479
      if (strlen(item3))
480
        to = strtoul(item3, NULL, 0);
481
      dumphex(from, to);
482
        printf("\n");
483
    } else
484
    if (strcmp(item1, "pm") == 0) { /* patch memory */
485
      char item2[20];
486
      char item3[20];
487
      static int addr = 0;
488
      int breakpoint = 0;
489 123 markom
 
490 361 markom
      strtoken(linestr, item2, 2);
491
      strtoken(linestr, item3, 3);
492
      if (strlen(item2))
493
        if (item2[0] == '_')
494
          addr = eval_label(item2);
495
        else
496
          addr = strtoul(item2, NULL, 0);
497
      set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
498
    } else
499
    if (strcmp(item1, "pr") == 0) { /* patch regs */
500
      char item2[20];
501
      char item3[20];
502
 
503
      strtoken(linestr, item2, 2);
504
      strtoken(linestr, item3, 3);
505
      set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
506
    } else
507
    if (strcmp(item1, "pc") == 0) { /* patch PC */
508
      char item2[20];
509 491 markom
 
510 361 markom
      strtoken(linestr, item2, 2);
511 491 markom
      pc = strtoul(item2, NULL, 0);
512 361 markom
    } else
513
    if (strcmp(item1, "break") == 0) {  /* set/clear breakpoint */
514
      char item2[20];
515
 
516
      strtoken(linestr, item2, 2);
517
      set_insnbrkpoint(strtoul(item2, NULL, 0));
518
    } else
519
    if (strcmp(item1, "r") == 0) {  /* dump regs */
520
      dumpreg();
521
    } else
522
    if (strcmp(item1, "de") == 0) { /* reset simulator */
523
      char item2[20];
524
      char item3[20];
525
      static int from = 0, to = 0;
526
 
527
      strtoken(linestr, item2, 2);
528
      strtoken(linestr, item3, 3);
529
 
530
      if (strlen(item2)) {
531
        if (item2[0] == '_')
532
          from = eval_label(item2);
533
        else
534
          from = strtoul(item2, NULL, 0);
535
        to = from + 0x40;
536
      }
537
      if (strlen(item3))
538
        to = strtoul(item3, NULL, 0);
539
      debugmem(from, to);
540
      printf("\n");
541
    } else
542
    if (strcmp(item1, "reset") == 0) {  /* reset simulator */
543
      uart_reset();
544
      dma_reset();
545
      eth_reset();
546 444 erez
      gpio_reset();
547 361 markom
      tick_reset();
548
      pm_reset();
549
      pic_reset();
550
      reset(); /* Old or new mode */
551
    } else
552
    if (strcmp(item1, "debug") == 0) {  /* debug mode */
553
      config.sim.debug ^= 1;
554
    } else
555
    if (strcmp(item1, "hist") == 0) { /* dump history */
556
      int i;
557
      for(i = HISTEXEC_LEN; i; i--)
558
        dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
559
      printf("\n");
560
    } else
561
    if (strcmp(item1, "run") == 0) { /* run */
562
      char item2[20];
563
      char item3[20];
564
 
565
      strtoken(linestr, item2, 2);
566
      strtoken(linestr, item3, 3);
567
      if (strcmp(item3, "hush") == 0)
568
        hush = 1;
569
      else
570
        hush = 0;
571
      cont_run = strtol(item2, NULL, 0);
572
    } else
573
    if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
574 479 markom
      set_stall_state (1);
575 361 markom
      config.sim.iprompt = 0;
576
      cont_run = -1;
577
      hush = 1;
578
    } else
579
    if (strcmp(item1, "stats") == 0) { /* stats */
580
      char item2[20];
581
      int i = 0;
582
 
583
      strtoken(linestr, item2, 2);
584
      if (strcmp(item2, "clear") == 0) {
585
        initstats();
586
        printf("Cleared.\n");
587
      } else {
588
        i = strtoul(item2, NULL, 0);
589
        printstats(i);
590
      }
591
    } else
592
    if (strcmp(item1, "info") == 0) /* configuration info */
593
      sim_info ();
594
    else
595
    if (strcmp(item1, "set") == 0) { /* configuration info */
596
      char *s = linestr;
597
      int i;
598
      extern section;
599
      extern struct section sections[];
600
      while (*s != ' ' && *s) s++;
601
      set_config_command (s);
602
    } else
603
      printf("%s: Unknown command.\n", linestr);
604 103 lampret
 
605 361 markom
    /* MM: 'run -1' means endless execution.  */
606
    while(cont_run != 0) {
607
      int debug_slowdown = DEBUG_SLOWDOWN;
608
      extern int cycle_delay;  /* Added by CZ 27/05/01. Set during exception. */
609 123 markom
 
610 479 markom
      if (cpu_stalled) {
611
        printf ("!");
612 361 markom
        if(GDB_ENABLED) {
613
          BlockJTAG();
614
          HandleServerSocket(false);
615
        } else
616
          fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
617 479 markom
        continue;
618
      }
619 127 chris
 
620 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
621 463 simons
        pic_clock();
622 304 markom
        if(cycle_delay <= 0) {
623
          if (cont_run > 0) cont_run--;
624
          if(fetch()) {
625 344 markom
            printf ("Breakpoint hit.\n");
626 304 markom
            cont_run = 0; /* memory breakpoint encountered */
627
            break;
628
          }
629 181 chris
 
630 494 markom
          decode_execute(&iqueue[0]);
631 304 markom
          update_pc();
632
          analysis();
633
          if (!hush)
634
            dumpreg();
635
        } else
636 261 markom
          cycle_delay--;
637 123 markom
 
638 261 markom
        dc_clock();
639
        ic_clock();
640 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
641 261 markom
      }
642 304 markom
 
643 261 markom
      pm_clock();
644 304 markom
      if (config.uarts_enabled) uart_clock();
645
      if (config.dmas_enabled) dma_clock();
646
      if (config.ethernets_enabled) eth_clock();
647 444 erez
      if (config.gpios_enabled) gpio_clock();
648 304 markom
      if (config.sim.exe_log) dump_exe_log();
649
      if (config.vapi.enabled) vapi_check();
650 479 markom
      if (GDB_ENABLED) {// && ((debug_slowdown--) <= 0)) {
651 261 markom
        debug_slowdown = DEBUG_SLOWDOWN;
652 361 markom
        HandleServerSocket(false); /* block & check_stdin = false */
653 479 markom
        debug (1, ".");
654 361 markom
      }
655 479 markom
      if (DEBUG_ENABLED)
656
        if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
657 361 markom
    }
658
    hush = 0;
659
    fflush(stdout);
660
    freopen("/dev/fd/0", "w+", stdout);
661 2 cvs
 
662 361 markom
    if (!config.sim.iprompt)  /* non-interactive quit */
663
      sim_done();
664 304 markom
 
665 16 jrydberg
#ifdef HAVE_LIBREADLINE
666 361 markom
    if (linestr)
667
      free (linestr);
668 16 jrydberg
#endif
669 7 jrydberg
 
670 361 markom
  }
671
  sim_done();
672 2 cvs
}
673 7 jrydberg
 
674 16 jrydberg
#ifdef HAVE_LIBREADLINE
675 7 jrydberg
char *command_generator ();
676
char **sim_completion ();
677
 
678
/* Tell the GNU readline library how to complete.  We want to try to complete
679
   on command names if this is the first word in the line, or on filenames
680
   if not. */
681
void initialize_readline ()
682
{
683
  /* Allow conditional parsing of the ~/.inputrc file. */
684
  rl_readline_name = "or1ksim";
685
 
686
  /* Tell the completer that we want a crack first. */
687
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
688
}
689
 
690
/* Attempt to complete on the contents of TEXT.  START and END bound the
691
   region of rl_line_buffer that contains the word to complete.  TEXT is
692
   the word to complete.  We can use the entire contents of rl_line_buffer
693
   in case we want to do some simple parsing.  Return the array of matches,
694
   or NULL if there aren't any. */
695
char **
696
sim_completion (text, start, end)
697
     char *text;
698
     int start, end;
699
{
700
  char **matches;
701
 
702
  matches = (char **)NULL;
703
 
704
  /* If this word is at the start of the line, then it is a command
705
     to complete.  Otherwise it is the name of a file in the current
706
     directory. */
707
  if (start == 0)
708
    matches = completion_matches (text, command_generator);
709
 
710
  return (matches);
711
}
712
 
713
/* Generator function for command completion.  STATE lets us know whether
714
   to start from scratch; without any state (i.e. STATE == 0), then we
715
   start at the top of the list. */
716
char *
717
command_generator (text, state)
718
     char *text;
719
     int state;
720
{
721
  static int list_index, len;
722
  char *name;
723
 
724
  /* If this is a new word to complete, initialize now.  This includes
725
     saving the length of TEXT for efficiency, and initializing the index
726
     variable to 0. */
727
  if (!state)
728
    {
729
      list_index = 0;
730
      len = strlen (text);
731
    }
732
 
733
  /* Return the next name which partially matches from the command list. */
734
  while (name = sim_commands[list_index])
735
    {
736
      list_index++;
737
 
738
      if (strncmp (name, text, len) == 0)
739
        return (dupstr(name));
740
    }
741
 
742
  /* If no names matched, then return NULL. */
743
  return ((char *)NULL);
744
}
745
 
746
/* Repeats the last command.  */
747
char *
748
repeat_last_command ()
749
{
750
  int offset = where_history ();
751
  HIST_ENTRY *hist;
752
 
753
  if (hist = history_get (offset))
754 306 markom
    return dupstr (hist->line);
755 7 jrydberg
  return 0;
756
}
757 16 jrydberg
 
758
#endif
759
 
760 138 markom
extern char *disassembled;
761 257 erez
void debugmem( unsigned long from, unsigned long to )
762
{
763 138 markom
  int i;
764
  printf("starting to dump mem...\n");
765 257 erez
  for(i=from; i<to; ) {
766 261 markom
    struct label_entry *entry;
767 221 markom
    unsigned int _insn;
768 261 markom
    printf("i=%x :: ", i);
769
 
770
    if (verify_memoryarea(i) && (entry = get_label(i)))
771
      printf("label: %s |", entry->name);
772 221 markom
 
773
    iqueue[0].insn = _insn = evalsim_mem32(i);
774
    iqueue[0].insn_index = insn_decode(_insn);
775
    disassemble_insn (_insn);
776
    printf("%08x %s\n", _insn, disassembled);
777 361 markom
    i += insn_len( iqueue[0].insn_index );
778 138 markom
  }
779 21 cmchen
}

powered by: WebSVN 2.1.0

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