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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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