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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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