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

Subversion Repositories or1k

[/] [or1k/] [tags/] [or1k-1_0/] [or1ksim/] [toplevel.c] - Blame information for rev 1765

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
#include <stdio.h>
24
#include <ctype.h>
25
#include <string.h>
26
#include <stdlib.h>
27
#include <signal.h>
28
#include <stdarg.h>
29
 
30
#include "arch.h"
31
#include "parse.h"
32
#include "abstract.h"
33
#include "trace.h"
34
#include "execute.h"
35
 
36
/* CVS revision number. */
37
static const char rcsrev[] = "$Revision: 1.1.1.1 $";
38
 
39
/* Continuos run versus single step tracing switch. */
40
int cont_run;
41
 
42
/* History of execution */
43
int histexec[HISTEXEC_LEN];
44
 
45
void debug(const char *format, ...)
46
{
47
#if DEBUG
48
        char *p;
49
        va_list ap;
50
 
51
        if ((p = malloc(1000)) == NULL)
52
                return;
53
        va_start(ap, format);
54
        (void) vsnprintf(p, 1000, format, ap);
55
        va_end(ap);
56
        printf("%s\n", p);
57
        fflush(stdout);
58
        free(p);
59
#endif
60
        return;
61
}
62
 
63
void ctrl_c(int signum)
64
{
65
        cont_run = 1;
66
        signal(SIGINT, ctrl_c);
67
}
68
 
69
void version()
70
{
71
        printf("\n");
72
        printf("OpenRISC 1000 Architectural Simulator, revision %s\n", rcsrev);
73
        printf("Copyright (C) 1999  Damjan Lampret, lampret@opencores.org\n");
74
        printf("Visit http://www.opencores.org for more information about ");
75
        printf("OpenRISC 1000 and\nother open source cores.\n\n");
76
        printf("This software comes with ABSOLUTELY NO WARRANTY; for ");
77
        printf("details see COPYING.\nThis is free software, and you ");
78
        printf("are welcome to redistribute it under certain\nconditions; ");
79
        printf("for details see COPYING.\n");
80
}
81
 
82
void help()
83
{
84
        printf("q                        - quit simulator\n");
85
        printf("r                        - display all registers\n");
86
        printf("t                        - execute next instruction\n");
87
        printf("run <cycles> [<hush>]    - execute <cycles> instructions, no reg dump if hush\n");
88
        printf("pr <r> <value>           - patch register <r> with <value>\n");
89
        printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
90
        printf("pm <addr> <value>        - patch memory location <addr> with <value>\n");
91
        printf("pc <value>               - patch PC register with <value>\n");
92
        printf("brk <addr>               - toggle breakpoint at address <addr>\n");
93
        printf("hist                     - execution history\n");
94
        printf("<cmd> > <filename>       - redirect simulator stdout to <filename> (and not emulated printf)\n");
95
        printf("help                     - available commands (this list)\n");
96
}
97
 
98
int main(int argc, char *argv[])
99
{
100
        char linestr[500];
101
        char item1[500];
102
        char *redirstr;
103
        int hush;
104
 
105
        if (argc != 2) {
106
                printf("Usage: %s <filename>\n", argv[0]);
107
                exit(-1);
108
        }
109
 
110
        version();
111
        signal(SIGINT, ctrl_c);
112
        initstats();
113
        loadcode(argv[1]);
114
        reset();
115
        while(1) {
116
                printf("\n# ");
117
                fgets(linestr, sizeof(linestr), stdin);
118
 
119
                if (redirstr = strstr(linestr, ">")) {
120
                        *redirstr = '\0';
121
                        strtoken(&redirstr[1], item1, 1);
122
                        freopen(item1, "w+", stdout);
123
                }
124
 
125
                strtoken(linestr, item1, 1);
126
                if (strcmp(item1, "q") == 0)     /* quit */
127
                        exit(0);
128
                else
129
                if (strcmp(item1, "help") == 0)  /* help */
130
                        help();
131
                else
132
                if (strcmp(item1, "t") == 0) {   /* trace */
133
                        cont_run = 1;
134
                } else
135
                if (strcmp(item1, "dm") == 0) {  /* dump memory */
136
                        char item2[20];
137
                        char item3[20];
138
                        static int from = 0, to = 0;
139
 
140
                        strtoken(linestr, item2, 2);
141
                        strtoken(linestr, item3, 3);
142
 
143
                        if (strlen(item2)) {
144
                                if (item2[0] == '_')
145
                                        from = eval_label(item2);
146
                                else
147
                                        from = strtoul(item2, NULL, 0);
148
                                to = from + 0x40;
149
                        }
150
                        if (strlen(item3))
151
                                to = strtoul(item3, NULL, 0);
152
                        dumpmemory(from, to);
153
                } else
154
                if (strcmp(item1, "pm") == 0) {  /* patch memory */
155
                        char item2[20];
156
                        char item3[20];
157
                        static int addr = 0;
158
 
159
                        strtoken(linestr, item2, 2);
160
                        strtoken(linestr, item3, 3);
161
                        if (strlen(item2))
162
                                if (item2[0] == '_')
163
                                        addr = eval_label(item2);
164
                                else
165
                                        addr = strtoul(item2, NULL, 0);
166
                        set_mem32(addr, strtoul(item3, NULL, 0));
167
                } else
168
                if (strcmp(item1, "pr") == 0) {  /* patch regs */
169
                        char item2[20];
170
                        char item3[20];
171
 
172
                        strtoken(linestr, item2, 2);
173
                        strtoken(linestr, item3, 3);
174
                        set_reg32(item2, strtoul(item3, NULL, 0));
175
                } else
176
                if (strcmp(item1, "pc") == 0) {  /* patch PC */
177
                        char item2[20];
178
 
179
                        strtoken(linestr, item2, 2);
180
                        pctemp = strtoul(item2, NULL, 0);
181
                } else
182
                if (strcmp(item1, "brk") == 0) { /* set/clear breakpoint */
183
                        char item2[20];
184
 
185
                        strtoken(linestr, item2, 2);
186
                        set_insnbrkpoint(strtoul(item2, NULL, 0));
187
                } else
188
                if (strcmp(item1, "r") == 0) {   /* dump regs */
189
                        dumpreg();
190
                } else
191
                if (strcmp(item1, "hist") == 0) {        /* dump history */
192
                        int i;
193
                        for(i = HISTEXEC_LEN; i; i--)
194
                                dumpmemory(histexec[i - 1], histexec[i - 1] + 4);
195
                } else
196
                if (strcmp(item1, "run") == 0) { /* run */
197
                        char item2[20];
198
                        char item3[20];
199
 
200
                        strtoken(linestr, item2, 2);
201
                        strtoken(linestr, item3, 3);
202
                        if (strcmp(item3, "hush") == 0)
203
                                hush = 1;
204
                        else
205
                                hush = 0;
206
                        cont_run = strtoul(item2, NULL, 0);
207
                } else
208
                if (strcmp(item1, "stats") == 0) { /* stats */
209
                        printstats();
210
                }
211
 
212
                while(cont_run) {
213
                        cont_run--;
214
                        fetch();
215
                        decode(&iqueue[0]);
216
                        execute();
217
                        if (!hush)
218
                                dumpreg();
219
                }
220
 
221
                hush = 0;
222
                fflush(stdout);
223
                freopen("/dev/fd/0", "w+", stdout);
224
 
225
        }
226
        exit(0);
227
}

powered by: WebSVN 2.1.0

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