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

Subversion Repositories or1k

[/] [or1k/] [tags/] [final_interface/] [gdb-5.0/] [sim/] [erc32/] [sis.c] - Blame information for rev 114

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/*
2
 * This file is part of SIS.
3
 *
4
 * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European
5
 * Space Agency
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License as published by the Free
9
 * Software Foundation; either version 2 of the License, or (at your option)
10
 * any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful, but WITHOUT
13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
 * more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with
18
 * this program; if not, write to the Free Software Foundation, Inc., 675
19
 * Mass Ave, Cambridge, MA 02139, USA.
20
 *
21
 */
22
 
23
#include "config.h"
24
#include <signal.h>
25
#include <string.h>
26
#ifdef HAVE_STDLIB_H
27
#include <stdlib.h>
28
#endif
29
#include <stdio.h>
30
#include <time.h>
31
#include <sys/fcntl.h>
32
#include "sis.h"
33
#include <dis-asm.h>
34
#include "sim-config.h"
35
 
36
#ifndef fprintf
37
extern          fprintf();
38
#endif
39
 
40
#define VAL(x)  strtol(x,(char **)NULL,0)
41
 
42
/* Structures and functions from readline library */
43
 
44
typedef struct {
45
  char *line;
46
  char *data;
47
} HIST_ENTRY;
48
 
49
extern char *   readline PARAMS ((char *prompt));
50
extern void     using_history PARAMS ((void));
51
extern void     add_history PARAMS ((char *string));
52
extern HIST_ENTRY *remove_history PARAMS ((int which));
53
 
54
 
55
 
56
/* Command history buffer length - MUST be binary */
57
#define HIST_LEN        64
58
 
59
extern struct disassemble_info dinfo;
60
extern struct pstate sregs;
61
extern struct estate ebase;
62
 
63
extern int      ctrl_c;
64
extern int      nfp;
65
extern int      ift;
66
extern int      wrp;
67
extern int      rom8;
68
extern int      uben;
69
extern int      sis_verbose;
70
extern char    *sis_version;
71
extern struct estate ebase;
72
extern struct evcell evbuf[];
73
extern struct irqcell irqarr[];
74
extern int      irqpend, ext_irl;
75
extern int      termsave;
76
extern int      sparclite;
77
extern int      dumbio;
78
extern char     uart_dev1[];
79
extern char     uart_dev2[];
80
extern uint32   last_load_addr;
81
 
82
#ifdef ERA
83
extern int era;
84
#endif
85
 
86
int
87
run_sim(sregs, icount, dis)
88
    struct pstate  *sregs;
89
    unsigned int    icount;
90
    int             dis;
91
{
92
    int             irq, mexc, deb, asi;
93
 
94
    sregs->starttime = time(NULL);
95
    init_stdio();
96
    if (sregs->err_mode) icount = 0;
97
    deb = dis || sregs->histlen || sregs->bptnum;
98
    irq = 0;
99
    while (icount > 0) {
100
 
101
        if (sregs->psr & 0x080)
102
            asi = 9;
103
        else
104
            asi = 8;
105
        mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold);
106
        sregs->icnt = 1;
107
        if (sregs->annul) {
108
            sregs->annul = 0;
109
            sregs->pc = sregs->npc;
110
            sregs->npc = sregs->npc + 4;
111
        } else {
112
            sregs->fhold = 0;
113
            if (ext_irl) irq = check_interrupts(sregs);
114
            if (!irq) {
115
                if (mexc) {
116
                    sregs->trap = I_ACC_EXC;
117
                } else {
118
                    if (deb) {
119
                        if ((sregs->bphit = check_bpt(sregs)) != 0) {
120
                            restore_stdio();
121
                            return (BPT_HIT);
122
                        }
123
                        if (sregs->histlen) {
124
                            sregs->histbuf[sregs->histind].addr = sregs->pc;
125
                            sregs->histbuf[sregs->histind].time = ebase.simtime;
126
                            sregs->histind++;
127
                            if (sregs->histind >= sregs->histlen)
128
                                sregs->histind = 0;
129
                        }
130
                        if (dis) {
131
                            printf(" %8u ", ebase.simtime);
132
                            dis_mem(sregs->pc, 1, &dinfo);
133
                        }
134
                    }
135
                    dispatch_instruction(sregs);
136
                    icount--;
137
                }
138
            }
139
            if (sregs->trap) {
140
                irq = 0;
141
                sregs->err_mode = execute_trap(sregs);
142
                if (sregs->err_mode) {
143
                    error_mode(sregs->pc);
144
                    icount = 0;
145
                }
146
            }
147
        }
148
        advance_time(sregs);
149
        if (ctrl_c || (sregs->tlimit <= ebase.simtime)) {
150
            icount = 0;
151
            if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1;
152
        }
153
    }
154
    sregs->tottime += time(NULL) - sregs->starttime;
155
    restore_stdio();
156
    if (sregs->err_mode)
157
        return (ERROR);
158
    if (ctrl_c) {
159
        ctrl_c = 0;
160
        return (CTRL_C);
161
    }
162
    return (TIME_OUT);
163
}
164
 
165
int
166
main(argc, argv)
167
    int             argc;
168
    char          **argv;
169
{
170
 
171
    int             cont = 1;
172
    int             stat = 1;
173
    int             freq = 14;
174
    int             copt = 0;
175
 
176
    char           *cfile, *bacmd;
177
    char           *cmdq[HIST_LEN];
178
    int             cmdi = 0;
179
    int             i;
180
 
181
    cfile = 0;
182
    for (i = 0; i < 64; i++)
183
        cmdq[i] = 0;
184
    printf("\n SIS - SPARC intruction simulator %s,  copyright Jiri Gaisler 1995\n", sis_version);
185
    printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
186
    while (stat < argc) {
187
        if (argv[stat][0] == '-') {
188
            if (strcmp(argv[stat], "-v") == 0) {
189
                sis_verbose = 1;
190
            } else if (strcmp(argv[stat], "-c") == 0) {
191
                if ((stat + 1) < argc) {
192
                    copt = 1;
193
                    cfile = argv[++stat];
194
                }
195
            } else if (strcmp(argv[stat], "-nfp") == 0)
196
                nfp = 1;
197
            else if (strcmp(argv[stat], "-ift") == 0)
198
                ift = 1;
199
            else if (strcmp(argv[stat], "-wrp") == 0)
200
                wrp = 1;
201
            else if (strcmp(argv[stat], "-rom8") == 0)
202
                rom8 = 1;
203
            else if (strcmp(argv[stat], "-uben") == 0)
204
                uben = 1;
205
            else if (strcmp(argv[stat], "-uart1") == 0) {
206
                if ((stat + 1) < argc)
207
                    strcpy(uart_dev1, argv[++stat]);
208
            } else if (strcmp(argv[stat], "-uart2") == 0) {
209
                if ((stat + 1) < argc)
210
                    strcpy(uart_dev2, argv[++stat]);
211
            } else if (strcmp(argv[stat], "-freq") == 0) {
212
                if ((stat + 1) < argc)
213
                    freq = VAL(argv[++stat]);
214
            } else if (strcmp(argv[stat], "-sparclite") == 0) {
215
                sparclite = 1;
216
#ifdef ERA
217
            } else if (strcmp(argv[stat], "-era") == 0) {
218
                era = 1;
219
#endif
220
            } else if (strcmp(argv[stat], "-dumbio") == 0) {
221
                dumbio = 1;
222
            } else {
223
                printf("unknown option %s\n", argv[stat]);
224
                usage();
225
                exit(1);
226
            }
227
        } else {
228
            last_load_addr = bfd_load(argv[stat]);
229
        }
230
        stat++;
231
    }
232
    if (nfp)
233
        printf("FPU disabled\n");
234
#ifdef ERA
235
    if (era)
236
        printf("ERA ECC emulation enabled\n");
237
#endif
238
    sregs.freq = freq;
239
 
240
    INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf);
241
    dinfo.endian = BFD_ENDIAN_BIG;
242
 
243
    termsave = fcntl(0, F_GETFL, 0);
244
    using_history();
245
    init_signals();
246
    ebase.simtime = 0;
247
    reset_all();
248
    init_bpt(&sregs);
249
    init_sim();
250
#ifdef STAT
251
    reset_stat(&sregs);
252
#endif
253
 
254
    if (copt) {
255
        bacmd = (char *) malloc(256);
256
        strcpy(bacmd, "batch ");
257
        strcat(bacmd, cfile);
258
        exec_cmd(&sregs, bacmd);
259
    }
260
    while (cont) {
261
 
262
        if (cmdq[cmdi] != 0) {
263
#if 0
264
            remove_history(cmdq[cmdi]);
265
#else
266
            remove_history(cmdi);
267
#endif
268
            free(cmdq[cmdi]);
269
            cmdq[cmdi] = 0;
270
        }
271
        cmdq[cmdi] = readline("sis> ");
272
        if (cmdq[cmdi] && *cmdq[cmdi])
273
            add_history(cmdq[cmdi]);
274
        if (cmdq[cmdi])
275
            stat = exec_cmd(&sregs, cmdq[cmdi]);
276
        else {
277
            puts("\n");
278
            exit(0);
279
        }
280
        switch (stat) {
281
        case OK:
282
            break;
283
        case CTRL_C:
284
            printf("\b\bInterrupt!\n");
285
        case TIME_OUT:
286
            printf(" Stopped at time %d (%.3f ms)\n", ebase.simtime,
287
              ((double) ebase.simtime / (double) sregs.freq) / 1000.0);
288
            break;
289
        case BPT_HIT:
290
            printf("breakpoint at 0x%08x reached\n", sregs.pc);
291
            sregs.bphit = 1;
292
            break;
293
        case ERROR:
294
            printf("IU in error mode (%d)\n", sregs.trap);
295
            stat = 0;
296
            printf(" %8d ", ebase.simtime);
297
            dis_mem(sregs.pc, 1, &dinfo);
298
            break;
299
        default:
300
            break;
301
        }
302
        ctrl_c = 0;
303
        stat = OK;
304
 
305
        cmdi = (cmdi + 1) & (HIST_LEN - 1);
306
 
307
    }
308
    return 0;
309
}
310
 

powered by: WebSVN 2.1.0

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