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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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