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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [toplevel.c] - Blame information for rev 6

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
#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 6 lampret
static const char rcsrev[] = "$Revision: 1.2 $";
38 2 cvs
 
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 6 lampret
        printf("stats <num|clear>        - execution statistics num or clear it.\n");
95
        printf("info                     - configuration info (caches etc.)\n");
96 2 cvs
        printf("<cmd> > <filename>       - redirect simulator stdout to <filename> (and not emulated printf)\n");
97
        printf("help                     - available commands (this list)\n");
98
}
99
 
100
int main(int argc, char *argv[])
101
{
102
        char linestr[500];
103
        char item1[500];
104
        char *redirstr;
105
        int hush;
106
 
107
        if (argc != 2) {
108
                printf("Usage: %s <filename>\n", argv[0]);
109
                exit(-1);
110
        }
111
 
112
        version();
113 6 lampret
        init_defconfig();
114 2 cvs
        signal(SIGINT, ctrl_c);
115
        initstats();
116
        loadcode(argv[1]);
117
        reset();
118
        while(1) {
119
                printf("\n# ");
120
                fgets(linestr, sizeof(linestr), stdin);
121
 
122
                if (redirstr = strstr(linestr, ">")) {
123
                        *redirstr = '\0';
124
                        strtoken(&redirstr[1], item1, 1);
125
                        freopen(item1, "w+", stdout);
126
                }
127
 
128
                strtoken(linestr, item1, 1);
129
                if (strcmp(item1, "q") == 0)     /* quit */
130
                        exit(0);
131
                else
132
                if (strcmp(item1, "help") == 0)  /* help */
133
                        help();
134
                else
135
                if (strcmp(item1, "t") == 0) {   /* trace */
136
                        cont_run = 1;
137
                } else
138
                if (strcmp(item1, "dm") == 0) {  /* dump memory */
139
                        char item2[20];
140
                        char item3[20];
141
                        static int from = 0, to = 0;
142
 
143
                        strtoken(linestr, item2, 2);
144
                        strtoken(linestr, item3, 3);
145
 
146
                        if (strlen(item2)) {
147
                                if (item2[0] == '_')
148
                                        from = eval_label(item2);
149
                                else
150
                                        from = strtoul(item2, NULL, 0);
151
                                to = from + 0x40;
152
                        }
153
                        if (strlen(item3))
154
                                to = strtoul(item3, NULL, 0);
155
                        dumpmemory(from, to);
156
                } else
157
                if (strcmp(item1, "pm") == 0) {  /* patch memory */
158
                        char item2[20];
159
                        char item3[20];
160
                        static int addr = 0;
161
 
162
                        strtoken(linestr, item2, 2);
163
                        strtoken(linestr, item3, 3);
164
                        if (strlen(item2))
165
                                if (item2[0] == '_')
166
                                        addr = eval_label(item2);
167
                                else
168
                                        addr = strtoul(item2, NULL, 0);
169
                        set_mem32(addr, strtoul(item3, NULL, 0));
170
                } else
171
                if (strcmp(item1, "pr") == 0) {  /* patch regs */
172
                        char item2[20];
173
                        char item3[20];
174
 
175
                        strtoken(linestr, item2, 2);
176
                        strtoken(linestr, item3, 3);
177
                        set_reg32(item2, strtoul(item3, NULL, 0));
178
                } else
179
                if (strcmp(item1, "pc") == 0) {  /* patch PC */
180
                        char item2[20];
181
 
182
                        strtoken(linestr, item2, 2);
183
                        pctemp = strtoul(item2, NULL, 0);
184
                } else
185
                if (strcmp(item1, "brk") == 0) { /* set/clear breakpoint */
186
                        char item2[20];
187
 
188
                        strtoken(linestr, item2, 2);
189
                        set_insnbrkpoint(strtoul(item2, NULL, 0));
190
                } else
191
                if (strcmp(item1, "r") == 0) {   /* dump regs */
192
                        dumpreg();
193
                } else
194
                if (strcmp(item1, "hist") == 0) {        /* dump history */
195
                        int i;
196
                        for(i = HISTEXEC_LEN; i; i--)
197
                                dumpmemory(histexec[i - 1], histexec[i - 1] + 4);
198
                } else
199
                if (strcmp(item1, "run") == 0) { /* run */
200
                        char item2[20];
201
                        char item3[20];
202
 
203
                        strtoken(linestr, item2, 2);
204
                        strtoken(linestr, item3, 3);
205
                        if (strcmp(item3, "hush") == 0)
206
                                hush = 1;
207
                        else
208
                                hush = 0;
209
                        cont_run = strtoul(item2, NULL, 0);
210
                } else
211
                if (strcmp(item1, "stats") == 0) { /* stats */
212 6 lampret
                        char item2[20];
213
                        int i = 0;
214
 
215
                        strtoken(linestr, item2, 2);
216
                        if (strcmp(item2, "clear") == 0) {
217
                                initstats();
218
                                printf("Cleared.\n");
219
                        } else {
220
                                i = strtoul(item2, NULL, 0);
221
                                printstats(i);
222
                        }
223
                } else
224
                if (strcmp(item1, "info") == 0) { /* configuration info */
225
                        bpb_info();
226
                        btic_info();
227
                        ic_info();
228
                        dc_info();
229 2 cvs
                }
230
 
231
                while(cont_run) {
232
                        cont_run--;
233
                        fetch();
234
                        decode(&iqueue[0]);
235
                        execute();
236
                        if (!hush)
237
                                dumpreg();
238
                }
239
 
240
                hush = 0;
241
                fflush(stdout);
242
                freopen("/dev/fd/0", "w+", stdout);
243
 
244
        }
245
        exit(0);
246
}

powered by: WebSVN 2.1.0

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