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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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