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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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