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

Subversion Repositories or1k

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

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 344 markom
const char rcsrev[] = "$Revision: 1.45 $";
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
  "q",
65
  "t",
66
  "help",
67 21 cmchen
  "de",
68 7 jrydberg
  "dm",
69
  "run",
70
  "pr",
71
  "pm",
72
  "pc",
73 18 lampret
  "reset",
74
  "break",
75 7 jrydberg
  "hist",
76
  "stats",
77 181 chris
  "stall"
78 7 jrydberg
  "info",
79
  "r",
80 54 lampret
  "dv",
81 7 jrydberg
 
82
};
83
 
84 344 markom
inline void debug(int level, const char *format, ...)
85 2 cvs
{
86 7 jrydberg
  char *p;
87
  va_list ap;
88 2 cvs
 
89 344 markom
  if (config.sim.debug >= level) {
90 69 lampret
    if ((p = malloc(1000)) == NULL)
91
      return;
92
    va_start(ap, format);
93
    (void) vsnprintf(p, 1000, format, ap);
94
    va_end(ap);
95 344 markom
    printf("%s", p);
96 69 lampret
    fflush(stdout);
97
    free(p);
98
  } else {
99
#if DEBUG
100 7 jrydberg
  if ((p = malloc(1000)) == NULL)
101
    return;
102
  va_start(ap, format);
103
  (void) vsnprintf(p, 1000, format, ap);
104
  va_end(ap);
105
  printf("%s\n", p);
106
  fflush(stdout);
107
  free(p);
108 2 cvs
#endif
109 69 lampret
  }
110 2 cvs
}
111
 
112 304 markom
void ctrl_c(signum)
113 7 jrydberg
     int signum;
114 2 cvs
{
115 181 chris
  extern int cpu_stalled;  /* CZ from debug_interface */
116
  cont_run = cpu_stalled ? 0 : 1;
117 264 markom
  config.sim.iprompt = 1;
118 181 chris
  cpu_stalled = 0;
119 7 jrydberg
  signal(SIGINT, ctrl_c);
120 2 cvs
}
121
 
122 304 markom
void version()
123 2 cvs
{
124 7 jrydberg
        printf ("\n");
125 18 lampret
        printf ("OpenRISC 1000 (OR16+OR32) Architectural Simulator, %s\n", rcsrev);
126
        printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
127
        printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
128 21 cmchen
        printf ("                   Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
129 18 lampret
        printf ("                   Johan Rydberg, johan.rydberg@insight.se\n");
130 264 markom
        printf ("                   Marko Mlinar, markom@opencores.org\n");
131
  printf ("Copyright (C) 2001 Simon Srot, simons@opencores.org\n");
132
  printf ("                   Marko Mlinar, markom@opencores.org\n");
133 7 jrydberg
        printf ("Visit http://www.opencores.org for more information about ");
134
        printf ("OpenRISC 1000 and\nother open source cores.\n\n");
135
        printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
136
        printf ("details see COPYING.\nThis is free software, and you ");
137
        printf ("are welcome to redistribute it under certain\nconditions; ");
138
        printf ("for details see COPYING.\n");
139 2 cvs
}
140
 
141 7 jrydberg
void
142
help()
143 2 cvs
{
144
        printf("q                        - quit simulator\n");
145
        printf("r                        - display all registers\n");
146
        printf("t                        - execute next instruction\n");
147
        printf("run <cycles> [<hush>]    - execute <cycles> instructions, no reg dump if hush\n");
148
        printf("pr <r> <value>           - patch register <r> with <value>\n");
149
        printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
150 257 erez
        printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
151 2 cvs
        printf("pm <addr> <value>        - patch memory location <addr> with <value>\n");
152
        printf("pc <value>               - patch PC register with <value>\n");
153 18 lampret
        printf("break <addr>             - toggle breakpoint at address <addr>\n");
154
        printf("reset                    - simulator reset\n");
155 2 cvs
        printf("hist                     - execution history\n");
156 181 chris
        printf("stall                    - stalls the processor and gives control to the debugger\n");
157 6 lampret
        printf("stats <num|clear>        - execution statistics num or clear it.\n");
158
        printf("info                     - configuration info (caches etc.)\n");
159 54 lampret
        printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
160 86 lampret
        printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
161 2 cvs
        printf("<cmd> > <filename>       - redirect simulator stdout to <filename> (and not emulated printf)\n");
162 69 lampret
        printf("debug                    - toggles simulator debug mode\n");
163 2 cvs
        printf("help                     - available commands (this list)\n");
164
}
165
 
166 257 erez
void debugmem( unsigned long from, unsigned long to );
167 21 cmchen
 
168 304 markom
/* Initalizes all devices and sim */
169
void sim_init ()
170 2 cvs
{
171 269 markom
  init_labels();
172
  init_breakpoints();
173
        initstats();
174
        build_automata();
175
 
176 306 markom
  if (GDB_ENABLED)
177
    gdbcomm_init ();
178
 
179 305 markom
  if (config.sim.profile) {
180 294 markom
    config.sim.fprof = fopen(config.sim.prof_fn, "wt+");
181 264 markom
    if(!config.sim.fprof) {
182
      config.sim.profile = 0;
183 294 markom
      fprintf(stderr, "WARNING: Problems opening profile file. Profiling disabled. \n");
184 173 markom
    } else
185 264 markom
      fprintf(config.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF main\n");
186 173 markom
  }
187 294 markom
 
188
  if (config.sim.exe_log) {
189
    config.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
190
    if(!config.sim.fexe_log) {
191
      config.sim.exe_log = 0;
192
      printf("WARNING: Problems opening exe_log file. Execution logging disabled. \n");
193
    }
194
  }
195 263 markom
 
196 262 markom
  /* Initialize memory */
197
  {
198 221 markom
          extern struct dev_memarea *dev_list;
199
          int i;
200 269 markom
          if (config.memory.type == MT_RANDOM) {
201 221 markom
                  unsigned int val = 0;
202 123 markom
 
203 262 markom
      if (config.memory.random_seed == -1) {
204
        config.memory.random_seed = time(NULL);
205
        /* Print out the seed just in case we ever need to debug */
206
                    printf("Seeding random generator with value %d\n", config.memory.random_seed);
207
                  }
208
                  srandom(config.memory.random_seed);
209
 
210 221 markom
                  for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
211
        for(i = 0; i < cur_area->size; i++) {
212
          val = random();
213 262 markom
          setsim_mem8(i + cur_area->addr_compare, val & 0xFF);
214 221 markom
        }
215 262 markom
    } else if(config.memory.type == MT_PATTERN) {
216 221 markom
                  for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
217
        for(i = 0; i < cur_area->size; i++)
218 262 markom
          setsim_mem8(i + cur_area->addr_compare, config.memory.pattern);
219 269 markom
    } else if (config.memory.type != MT_UNKNOWN) {
220 262 markom
      fprintf(stderr, "Invalid memory configuration type.\n");
221
            exit(1);
222 221 markom
    }
223 242 markom
  }
224 262 markom
 
225
        if(config.filename) {
226 304 markom
          unsigned long endaddr = 0xFFFFFFFF;
227 262 markom
          endaddr = loadcode(config.filename, 0, 0); /* MM170901 always load at address zero.  */
228
          if (endaddr == -1) {
229
            fprintf(stderr, "Problems loading boot code.\n");
230
            exit(1);
231
          }
232
        }
233 269 markom
 
234
        /* Disable gdb debugging, if debug module is not available.  */
235 335 markom
        if (config.debug.gdb_enabled && !config.debug.enabled) {
236 269 markom
          config.debug.gdb_enabled = 0;
237 331 markom
          if (config.sim.verbose)
238
            fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
239
        }
240 305 markom
 
241 331 markom
        /* Enable dependency stats, if we want to do history analisis */
242
        if (config.cpu.history && !config.cpu.dependency) {
243
          config.cpu.dependency = 1;
244
          if (config.sim.verbose)
245
            fprintf (stderr, "WARNING: dependency stats must be enabled to do history analisis.\n");
246
        }
247
 
248 341 markom
        /* 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 305 markom
        /* 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 341 markom
 
261 30 lampret
        uart_reset();
262 212 erez
        dma_reset();
263 257 erez
        eth_reset();
264 92 lampret
        tick_reset();
265 103 lampret
        pm_reset();
266 242 markom
        pic_reset();
267 261 markom
        mc_reset();
268 2 cvs
        reset();
269 305 markom
 
270
        /* Wait till all test are connected.  */
271 336 markom
        if (config.vapi.enabled) {
272
          int numu = vapi_num_unconnected (0);
273 305 markom
          if (numu) {
274 336 markom
            printf ("\nWaiting for VAPI tests with ids:\n");
275
            vapi_num_unconnected (1);
276 305 markom
            printf ("\n");
277 336 markom
            while (numu = vapi_num_unconnected (0)) {
278
              vapi_check ();
279
            printf ("\rStill waiting for %i VAPI test(s) to connect.       ", numu);
280 305 markom
            usleep (100);
281
            }
282 336 markom
            printf ("\n");
283 305 markom
          }
284
          printf ("All devices connected                         \n");
285
        }
286 304 markom
}
287 7 jrydberg
 
288 304 markom
/* Display info about various modules */
289
void sim_info () {
290
  itlb_status(-1);
291
        dtlb_status(-1);
292
        ic_info();
293
        dc_info();
294
        sprs_status();
295
 
296
        if (config.cpu.bpb) bpb_info();
297
        if (config.cpu.btic) btic_info();
298
        if (config.uarts_enabled) uart_status();
299
        if (config.dmas_enabled) dma_status();
300
        if (config.ethernets_enabled) eth_status();
301
}
302
 
303
/* Cleanup */
304
void sim_done ()
305
{
306
  if (config.sim.profile) {
307
    extern int cycles;
308
    fprintf(config.sim.fprof,"-%08X FFFFFFFF\n", cycles);
309
    fclose(config.sim.fprof);
310
  }
311
  if (config.sim.exe_log)   fclose(config.sim.fexe_log);
312
  if (config.vapi.enabled)  vapi_done ();
313
  exit(0);
314
}
315
 
316
int main(argc, argv)
317
     int argc;
318
     char *argv[];
319
{
320
        char *linestr;
321
        char item1[500], b2[500], prev_str[500] = "";
322
        char *redirstr;
323
        int hush = 0;
324
        int first_prompt = 1;
325
        int trace_fd = 0;
326
 
327
        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       change 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
 
341
#ifdef HAVE_LIBREADLINE
342
  initialize_readline ();       /* Bind our completer. */
343
#endif
344
 
345
  /* Read configuration file.  */
346 335 markom
  read_script_file (config.script_file);
347 304 markom
  print_config();
348 336 markom
  sim_init ();
349 304 markom
  signal(SIGINT, ctrl_c);
350 335 markom
 
351 103 lampret
        while(1) {
352 264 markom
                if (config.sim.iprompt) {
353 306 markom
                  if (GDB_ENABLED)
354 123 markom
                    {
355
                      printf ("(sim) ");
356
                      fflush(stdout);
357
                      HandleServerSocket(true);  /* block & check_stdin = true */
358
                    }
359 16 jrydberg
#ifdef HAVE_LIBREADLINE
360 123 markom
                  /* Must disable readline in new mode. It isn't compatible
361
                     with non blocking environments */
362 306 markom
                  if(!GDB_ENABLED)
363 123 markom
                    linestr = readline("(sim) ");
364
                  else
365
                    linestr = fgets(b2, sizeof b2, stdin);
366 16 jrydberg
#else
367 306 markom
                  if(!GDB_ENABLED)
368 123 markom
                    printf ("(sim) ");
369
                  linestr = fgets(b2, sizeof b2, stdin);
370 16 jrydberg
#endif
371 103 lampret
                } else
372 173 markom
                        strcpy(linestr = b2, "run -1 hush");
373 7 jrydberg
 
374 103 lampret
                if (!linestr)
375
                        break;
376
                linestr = stripwhite (linestr);
377 7 jrydberg
 
378 16 jrydberg
#ifdef HAVE_LIBREADLINE
379 123 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 2 cvs
 
397 103 lampret
                if (redirstr = strstr(linestr, ">")) {
398
                        *redirstr = '\0';
399
                        strtoken(&redirstr[1], item1, 1);
400
                        freopen(item1, "w+", stdout);
401
                }
402 2 cvs
 
403 167 markom
                if (linestr[0] == '\n')
404
                  strcpy (linestr, &prev_str[0]);
405
                else
406
                  strcpy (&prev_str[0], linestr);
407
 
408 2 cvs
                strtoken(linestr, item1, 1);
409 167 markom
                if (strcmp(item1, "q") == 0) {   /* quit */
410
                  printf ("\n");
411 304 markom
                  sim_done ();
412 167 markom
                } else
413 2 cvs
                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 306 markom
                        dumpmemory(from, to, 0, 1);
437 54 lampret
                        printf("\n");
438 2 cvs
                } else
439 54 lampret
                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 86 lampret
                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 2 cvs
                if (strcmp(item1, "pm") == 0) {  /* patch memory */
484
                        char item2[20];
485
                        char item3[20];
486
                        static int addr = 0;
487 123 markom
                        int breakpoint = 0;
488
 
489 2 cvs
                        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 123 markom
                        set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
497 2 cvs
                } 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 138 markom
                        set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
505 2 cvs
                } else
506
                if (strcmp(item1, "pc") == 0) {  /* patch PC */
507
                        char item2[20];
508
 
509
                        strtoken(linestr, item2, 2);
510 86 lampret
                        pcnext = strtoul(item2, NULL, 0);
511 2 cvs
                } else
512 7 jrydberg
                if (strcmp(item1, "break") == 0) {       /* set/clear breakpoint */
513 2 cvs
                        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 21 cmchen
                if (strcmp(item1, "de") == 0) {  /* reset simulator */
522 257 erez
                        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 21 cmchen
                } else
541 18 lampret
                if (strcmp(item1, "reset") == 0) {       /* reset simulator */
542 30 lampret
                        uart_reset();
543 212 erez
                        dma_reset();
544 257 erez
                        eth_reset();
545 92 lampret
                        tick_reset();
546 103 lampret
                        pm_reset();
547
                        pic_reset();
548 123 markom
                        reset(); /* Old or new mode */
549 18 lampret
                } else
550 69 lampret
                if (strcmp(item1, "debug") == 0) {       /* debug mode */
551 264 markom
                        config.sim.debug ^= 1;
552 69 lampret
                } else
553 2 cvs
                if (strcmp(item1, "hist") == 0) {        /* dump history */
554
                        int i;
555
                        for(i = HISTEXEC_LEN; i; i--)
556 306 markom
                                dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
557 46 lampret
                        printf("\n");
558 2 cvs
                } else
559
                if (strcmp(item1, "run") == 0) { /* run */
560
                        char item2[20];
561
                        char item3[20];
562
 
563
                        strtoken(linestr, item2, 2);
564
                        strtoken(linestr, item3, 3);
565
                        if (strcmp(item3, "hush") == 0)
566
                                hush = 1;
567
                        else
568
                                hush = 0;
569 173 markom
                        cont_run = strtol(item2, NULL, 0);
570 2 cvs
                } else
571 181 chris
                if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
572
                  extern int cpu_stalled;  /* CZ from debug_interface */
573
                  cpu_stalled = 1;
574 264 markom
                  config.sim.iprompt = 0;
575 181 chris
                  cont_run = -1;
576
                  hush = 1;
577
                } else
578
                if (!strcmp(item1, "trace")) { /* Added by CZ 210801 */
579
                  char item2[256];
580 221 markom
 
581 181 chris
                  strtoken(linestr, item2, 2);
582
                  if(trace_fd)
583
                    {
584
                      close(trace_fd);
585
                      trace_fd = 0;
586
                    }
587
                  if(strcmp(item2,"off")) /* if we're not being turned off */
588
                    {
589
                      if(item2[0])
590
                        trace_fd = open(item2,O_CREAT | O_NOCTTY |
591
                                        O_TRUNC | O_WRONLY, 0644);
592
                      else
593
                        trace_fd = dup(1);
594
                      if(trace_fd < 0)
595
                        {
596
                          perror(item2[0]?item2:"stdout");
597
                          trace_fd = 0;
598
                        }
599
                    }
600
                } else
601 2 cvs
                if (strcmp(item1, "stats") == 0) { /* stats */
602 6 lampret
                        char item2[20];
603
                        int i = 0;
604
 
605
                        strtoken(linestr, item2, 2);
606
                        if (strcmp(item2, "clear") == 0) {
607
                                initstats();
608
                                printf("Cleared.\n");
609
                        } else {
610
                                i = strtoul(item2, NULL, 0);
611
                                printstats(i);
612
                        }
613
                } else
614 304 markom
                if (strcmp(item1, "info") == 0) /* configuration info */
615
                        sim_info ();
616
                else
617 103 lampret
                        printf("%s: Unknown command.\n", linestr);
618
 
619 304 markom
 
620 138 markom
                /* MM: 'run -1' means endless execution.  */
621
                while(cont_run != 0) {
622 261 markom
                  int debug_slowdown = DEBUG_SLOWDOWN;
623 123 markom
                  extern int cycle_delay;  /* Added by CZ 27/05/01. Set during exception. */
624 127 chris
                  extern int cpu_stalled;  /* CZ from debug_interface */
625 123 markom
 
626 294 markom
      if (cpu_stalled)
627
                    if(GDB_ENABLED) {
628
                BlockJTAG();
629
                HandleServerSocket(false);
630
                continue;
631
              } else
632
                fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
633 127 chris
 
634 261 markom
      if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
635 304 markom
        if(cycle_delay <= 0) {
636
          unsigned int addr;
637
          if (cont_run > 0) cont_run--;
638
          if(fetch()) {
639 344 markom
            printf ("Breakpoint hit.\n");
640 304 markom
            cont_run = 0; /* memory breakpoint encountered */
641
            break;
642
          }
643
          addr = iqueue[0].insn_addr;
644
 
645
          /* If trace_fd is non zero, we want
646
             to make sure that disassemble is called */
647 181 chris
 
648 304 markom
          decode_execute(&iqueue[0],trace_fd);
649
          if(trace_fd) {
650
            char sTemp[256];
651
            char sTemp2[256];
652
            unsigned long value;
653
            extern char *disassembled;
654
            extern unsigned long reg[];
655 181 chris
 
656 304 markom
            /* The objects passed to the
657
               trace command should not be
658
               hardcoded like this...instead
659
               what to dump should be passed
660
               on the command line.
661 181 chris
 
662 304 markom
               FIX THIS LATER...
663
            */
664
            value = (evalsim_mem8(0x306bc) << 24) +
665
              (evalsim_mem8(0x306bd) << 16) +
666
              (evalsim_mem8(0x306be) << 8)
667
              + evalsim_mem8(0x306bf);
668 221 markom
 
669 304 markom
            sprintf(sTemp,"0x%06x: %s",addr,disassembled);
670
            memset(sTemp2,' ',sizeof(sTemp2));
671
            strncpy(sTemp2,sTemp,strlen(sTemp));
672
            sprintf(&sTemp2[40],"<0x%08x,0x%08x> [0x%08x]\n",
673
                    reg[3],reg[4],value);
674
            write(trace_fd,sTemp2,strlen(sTemp2));
675 261 markom
          }
676 304 markom
          update_pc();
677
          analysis();
678
          if (!hush)
679
            dumpreg();
680
        } else
681 261 markom
          cycle_delay--;
682 123 markom
 
683 261 markom
        pic_clock();
684
        dc_clock();
685
        ic_clock();
686 304 markom
        if (!testsprbits(SPR_PMR, SPR_PMR_SME)) tick_clock();
687 261 markom
      }
688 304 markom
 
689 261 markom
      pm_clock();
690 304 markom
      if (config.uarts_enabled) uart_clock();
691
      if (config.dmas_enabled) dma_clock();
692
      if (config.ethernets_enabled) eth_clock();
693
      if (config.sim.exe_log) dump_exe_log();
694
      if (config.vapi.enabled) vapi_check();
695 269 markom
      if (GDB_ENABLED && debug_slowdown-- == 0) {
696 261 markom
        debug_slowdown = DEBUG_SLOWDOWN;
697
                          HandleServerSocket(false); /* block & check_stdin = false */
698 103 lampret
                        }
699 2 cvs
                }
700
                hush = 0;
701
                fflush(stdout);
702
                freopen("/dev/fd/0", "w+", stdout);
703
 
704 304 markom
                if (!config.sim.iprompt)        /* non-interactive quit */
705
                  sim_done();
706
 
707 16 jrydberg
#ifdef HAVE_LIBREADLINE
708 103 lampret
                if (linestr)
709
                        free (linestr);
710 16 jrydberg
#endif
711 7 jrydberg
 
712 2 cvs
        }
713 304 markom
        sim_done();
714 2 cvs
}
715 7 jrydberg
 
716 16 jrydberg
#ifdef HAVE_LIBREADLINE
717 7 jrydberg
char *command_generator ();
718
char **sim_completion ();
719
 
720
/* Tell the GNU readline library how to complete.  We want to try to complete
721
   on command names if this is the first word in the line, or on filenames
722
   if not. */
723
void initialize_readline ()
724
{
725
  /* Allow conditional parsing of the ~/.inputrc file. */
726
  rl_readline_name = "or1ksim";
727
 
728
  /* Tell the completer that we want a crack first. */
729
  rl_attempted_completion_function = (CPPFunction *)sim_completion;
730
}
731
 
732
/* Attempt to complete on the contents of TEXT.  START and END bound the
733
   region of rl_line_buffer that contains the word to complete.  TEXT is
734
   the word to complete.  We can use the entire contents of rl_line_buffer
735
   in case we want to do some simple parsing.  Return the array of matches,
736
   or NULL if there aren't any. */
737
char **
738
sim_completion (text, start, end)
739
     char *text;
740
     int start, end;
741
{
742
  char **matches;
743
 
744
  matches = (char **)NULL;
745
 
746
  /* If this word is at the start of the line, then it is a command
747
     to complete.  Otherwise it is the name of a file in the current
748
     directory. */
749
  if (start == 0)
750
    matches = completion_matches (text, command_generator);
751
 
752
  return (matches);
753
}
754
 
755
/* Generator function for command completion.  STATE lets us know whether
756
   to start from scratch; without any state (i.e. STATE == 0), then we
757
   start at the top of the list. */
758
char *
759
command_generator (text, state)
760
     char *text;
761
     int state;
762
{
763
  static int list_index, len;
764
  char *name;
765
 
766
  /* If this is a new word to complete, initialize now.  This includes
767
     saving the length of TEXT for efficiency, and initializing the index
768
     variable to 0. */
769
  if (!state)
770
    {
771
      list_index = 0;
772
      len = strlen (text);
773
    }
774
 
775
  /* Return the next name which partially matches from the command list. */
776
  while (name = sim_commands[list_index])
777
    {
778
      list_index++;
779
 
780
      if (strncmp (name, text, len) == 0)
781
        return (dupstr(name));
782
    }
783
 
784
  /* If no names matched, then return NULL. */
785
  return ((char *)NULL);
786
}
787
 
788
/* Repeats the last command.  */
789
char *
790
repeat_last_command ()
791
{
792
  int offset = where_history ();
793
  HIST_ENTRY *hist;
794
 
795
  if (hist = history_get (offset))
796 306 markom
    return dupstr (hist->line);
797 7 jrydberg
  return 0;
798
}
799 16 jrydberg
 
800
#endif
801
 
802 138 markom
extern char *disassembled;
803 257 erez
void debugmem( unsigned long from, unsigned long to )
804
{
805 138 markom
  int i;
806
  printf("starting to dump mem...\n");
807 257 erez
  for(i=from; i<to; ) {
808 261 markom
    struct label_entry *entry;
809 221 markom
    unsigned int _insn;
810 261 markom
    printf("i=%x :: ", i);
811
 
812
    if (verify_memoryarea(i) && (entry = get_label(i)))
813
      printf("label: %s |", entry->name);
814 221 markom
 
815
    iqueue[0].insn = _insn = evalsim_mem32(i);
816
    iqueue[0].insn_index = insn_decode(_insn);
817
    disassemble_insn (_insn);
818
    printf("%08x %s\n", _insn, disassembled);
819 257 erez
                i += insn_len( iqueue[0].insn_index );
820 138 markom
  }
821 21 cmchen
}

powered by: WebSVN 2.1.0

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