URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [branches/] [oc/] [or1ksim/] [toplevel.c] - Rev 1773
Go to most recent revision | Compare with Previous | Blame | View Log
/* toplevel.c -- Top level simulator source file Copyright (C) 1999 Damjan Lampret, lampret@opencores.org This file is part of OpenRISC 1000 Architectural Simulator. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Simulator commands. Help and version output. SIGINT processing. Stdout redirection is specific to linux (I need to fix this). */ #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include <signal.h> #include <stdarg.h> #include "arch.h" #include "parse.h" #include "abstract.h" #include "trace.h" #include "execute.h" /* CVS revision number. */ static const char rcsrev[] = "$Revision: 1.1.1.1 $"; /* Continuos run versus single step tracing switch. */ int cont_run; /* History of execution */ int histexec[HISTEXEC_LEN]; void debug(const char *format, ...) { #if DEBUG char *p; va_list ap; if ((p = malloc(1000)) == NULL) return; va_start(ap, format); (void) vsnprintf(p, 1000, format, ap); va_end(ap); printf("%s\n", p); fflush(stdout); free(p); #endif return; } void ctrl_c(int signum) { cont_run = 1; signal(SIGINT, ctrl_c); } void version() { printf("\n"); printf("OpenRISC 1000 Architectural Simulator, revision %s\n", rcsrev); printf("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n"); printf("Visit http://www.opencores.org for more information about "); printf("OpenRISC 1000 and\nother open source cores.\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY; for "); printf("details see COPYING.\nThis is free software, and you "); printf("are welcome to redistribute it under certain\nconditions; "); printf("for details see COPYING.\n"); } void help() { printf("q - quit simulator\n"); printf("r - display all registers\n"); printf("t - execute next instruction\n"); printf("run <cycles> [<hush>] - execute <cycles> instructions, no reg dump if hush\n"); printf("pr <r> <value> - patch register <r> with <value>\n"); printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n"); printf("pm <addr> <value> - patch memory location <addr> with <value>\n"); printf("pc <value> - patch PC register with <value>\n"); printf("brk <addr> - toggle breakpoint at address <addr>\n"); printf("hist - execution history\n"); printf("<cmd> > <filename> - redirect simulator stdout to <filename> (and not emulated printf)\n"); printf("help - available commands (this list)\n"); } int main(int argc, char *argv[]) { char linestr[500]; char item1[500]; char *redirstr; int hush; if (argc != 2) { printf("Usage: %s <filename>\n", argv[0]); exit(-1); } version(); signal(SIGINT, ctrl_c); initstats(); loadcode(argv[1]); reset(); while(1) { printf("\n# "); fgets(linestr, sizeof(linestr), stdin); if (redirstr = strstr(linestr, ">")) { *redirstr = '\0'; strtoken(&redirstr[1], item1, 1); freopen(item1, "w+", stdout); } strtoken(linestr, item1, 1); if (strcmp(item1, "q") == 0) /* quit */ exit(0); else if (strcmp(item1, "help") == 0) /* help */ help(); else if (strcmp(item1, "t") == 0) { /* trace */ cont_run = 1; } else if (strcmp(item1, "dm") == 0) { /* dump memory */ char item2[20]; char item3[20]; static int from = 0, to = 0; strtoken(linestr, item2, 2); strtoken(linestr, item3, 3); if (strlen(item2)) { if (item2[0] == '_') from = eval_label(item2); else from = strtoul(item2, NULL, 0); to = from + 0x40; } if (strlen(item3)) to = strtoul(item3, NULL, 0); dumpmemory(from, to); } else if (strcmp(item1, "pm") == 0) { /* patch memory */ char item2[20]; char item3[20]; static int addr = 0; strtoken(linestr, item2, 2); strtoken(linestr, item3, 3); if (strlen(item2)) if (item2[0] == '_') addr = eval_label(item2); else addr = strtoul(item2, NULL, 0); set_mem32(addr, strtoul(item3, NULL, 0)); } else if (strcmp(item1, "pr") == 0) { /* patch regs */ char item2[20]; char item3[20]; strtoken(linestr, item2, 2); strtoken(linestr, item3, 3); set_reg32(item2, strtoul(item3, NULL, 0)); } else if (strcmp(item1, "pc") == 0) { /* patch PC */ char item2[20]; strtoken(linestr, item2, 2); pctemp = strtoul(item2, NULL, 0); } else if (strcmp(item1, "brk") == 0) { /* set/clear breakpoint */ char item2[20]; strtoken(linestr, item2, 2); set_insnbrkpoint(strtoul(item2, NULL, 0)); } else if (strcmp(item1, "r") == 0) { /* dump regs */ dumpreg(); } else if (strcmp(item1, "hist") == 0) { /* dump history */ int i; for(i = HISTEXEC_LEN; i; i--) dumpmemory(histexec[i - 1], histexec[i - 1] + 4); } else if (strcmp(item1, "run") == 0) { /* run */ char item2[20]; char item3[20]; strtoken(linestr, item2, 2); strtoken(linestr, item3, 3); if (strcmp(item3, "hush") == 0) hush = 1; else hush = 0; cont_run = strtoul(item2, NULL, 0); } else if (strcmp(item1, "stats") == 0) { /* stats */ printstats(); } while(cont_run) { cont_run--; fetch(); decode(&iqueue[0]); execute(); if (!hush) dumpreg(); } hush = 0; fflush(stdout); freopen("/dev/fd/0", "w+", stdout); } exit(0); }
Go to most recent revision | Compare with Previous | Blame | View Log