*/
#include "config.h"
-
#include <signal.h>
#include <string.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <stdio.h>
+#include <time.h>
+#include <sys/fcntl.h>
#include "sis.h"
#include <dis-asm.h>
+#include "sim-config.h"
#ifndef fprintf
extern fprintf();
#endif
-#define VAL(x) strtol(x,(char *)NULL,0)
+#define VAL(x) strtol(x,(char **)NULL,0)
+
+/* Structures and functions from readline library */
+
+typedef struct {
+ char *line;
+ char *data;
+} HIST_ENTRY;
+
+extern char * readline PARAMS ((char *prompt));
+extern void using_history PARAMS ((void));
+extern void add_history PARAMS ((char *string));
+extern HIST_ENTRY *remove_history PARAMS ((int which));
+
-extern char *readline(char *prompt); /* GNU readline function */
/* Command history buffer length - MUST be binary */
#define HIST_LEN 64
extern int ctrl_c;
extern int nfp;
+extern int ift;
+extern int wrp;
+extern int rom8;
+extern int uben;
extern int sis_verbose;
extern char *sis_version;
extern struct estate ebase;
extern struct evcell evbuf[];
extern struct irqcell irqarr[];
extern int irqpend, ext_irl;
+extern int termsave;
+extern int sparclite;
+extern int dumbio;
extern char uart_dev1[];
extern char uart_dev2[];
+extern uint32 last_load_addr;
-#ifdef IUREV0
-extern int iurev0;
-#endif
-
-#ifdef MECREV0
-extern int mecrev0;
+#ifdef ERA
+extern int era;
#endif
-run_sim(sregs, go, icount, dis)
+int
+run_sim(sregs, icount, dis)
struct pstate *sregs;
- int go;
unsigned int icount;
int dis;
{
- int mexc, ws;
+ int irq, mexc, deb, asi;
sregs->starttime = time(NULL);
- while (!sregs->err_mode & (go || (icount > 0))) {
- if (sregs->bptnum && check_bpt(sregs))
- return (BPT_HIT);
- sregs->bphit = 0;
- sregs->fhold = 0;
- sregs->hold = 0;
- sregs->icnt = 0;
-
- sregs->asi = 9 - ((sregs->psr & 0x080) >> 7);
-
-#ifdef IUREV0
- if (iurev0 && sregs->rett_err) {
- sregs->asi &= ~0x1;
- sregs->asi |= ((sregs->psr & 0x040) >> 6);
- }
-#endif
-
- mexc = memory_read(sregs->asi, sregs->pc, &sregs->inst, &sregs->hold);
+ init_stdio();
+ if (sregs->err_mode) icount = 0;
+ deb = dis || sregs->histlen || sregs->bptnum;
+ irq = 0;
+ while (icount > 0) {
+ if (sregs->psr & 0x080)
+ asi = 9;
+ else
+ asi = 8;
+ mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold);
+ sregs->icnt = 1;
if (sregs->annul) {
sregs->annul = 0;
- sregs->icnt = 1;
sregs->pc = sregs->npc;
sregs->npc = sregs->npc + 4;
- mexc = 0; /* Traps ignored during annul */
} else {
- check_interrupts(sregs);
- if (sregs->trap) {
- sregs->err_mode = execute_trap(sregs);
- } else {
+ sregs->fhold = 0;
+ if (ext_irl) irq = check_interrupts(sregs);
+ if (!irq) {
if (mexc) {
sregs->trap = I_ACC_EXC;
} else {
- if (sregs->histlen) {
- sregs->histbuf[sregs->histind].addr = sregs->pc;
- sregs->histbuf[sregs->histind].time = ebase.simtime;
- sregs->histind++;
- if (sregs->histind >= sregs->histlen)
- sregs->histind = 0;
- }
- if (dis) {
- printf(" %8u ", ebase.simtime);
- dis_mem(sregs->pc, 1, &dinfo);
+ if (deb) {
+ if ((sregs->bphit = check_bpt(sregs)) != 0) {
+ restore_stdio();
+ return (BPT_HIT);
+ }
+ if (sregs->histlen) {
+ sregs->histbuf[sregs->histind].addr = sregs->pc;
+ sregs->histbuf[sregs->histind].time = ebase.simtime;
+ sregs->histind++;
+ if (sregs->histind >= sregs->histlen)
+ sregs->histind = 0;
+ }
+ if (dis) {
+ printf(" %8u ", ebase.simtime);
+ dis_mem(sregs->pc, 1, &dinfo);
+ }
}
dispatch_instruction(sregs);
+ icount--;
}
- icount--;
}
if (sregs->trap) {
+ irq = 0;
sregs->err_mode = execute_trap(sregs);
+ if (sregs->err_mode) {
+ error_mode(sregs->pc);
+ icount = 0;
+ }
}
}
advance_time(sregs);
- if (ctrl_c) {
- go = icount = 0;
+ if (ctrl_c || (sregs->tlimit <= ebase.simtime)) {
+ icount = 0;
+ if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1;
}
}
sregs->tottime += time(NULL) - sregs->starttime;
- if (sregs->err_mode)
- error_mode(sregs->pc);
+ restore_stdio();
if (sregs->err_mode)
return (ERROR);
if (ctrl_c) {
return (TIME_OUT);
}
+int
main(argc, argv)
int argc;
char **argv;
int freq = 14;
int copt = 0;
- char lastcmd[128] = "reg";
- char *cmd, *cfile, *bacmd;
+ char *cfile, *bacmd;
char *cmdq[HIST_LEN];
int cmdi = 0;
int i;
+ cfile = 0;
for (i = 0; i < 64; i++)
cmdq[i] = 0;
printf("\n SIS - SPARC intruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version);
}
} else if (strcmp(argv[stat], "-nfp") == 0)
nfp = 1;
-#ifdef IUREV0
- else if (strcmp(argv[stat], "-iurev0") == 0)
- iurev0 = 1;
-#endif
-#ifdef MECREV0
- else if (strcmp(argv[stat], "-mecrev0") == 0)
- mecrev0 = 1;
-#endif
+ else if (strcmp(argv[stat], "-ift") == 0)
+ ift = 1;
+ else if (strcmp(argv[stat], "-wrp") == 0)
+ wrp = 1;
+ else if (strcmp(argv[stat], "-rom8") == 0)
+ rom8 = 1;
+ else if (strcmp(argv[stat], "-uben") == 0)
+ uben = 1;
else if (strcmp(argv[stat], "-uart1") == 0) {
if ((stat + 1) < argc)
strcpy(uart_dev1, argv[++stat]);
} else if (strcmp(argv[stat], "-freq") == 0) {
if ((stat + 1) < argc)
freq = VAL(argv[++stat]);
+ } else if (strcmp(argv[stat], "-sparclite") == 0) {
+ sparclite = 1;
+#ifdef ERA
+ } else if (strcmp(argv[stat], "-era") == 0) {
+ era = 1;
+#endif
+ } else if (strcmp(argv[stat], "-dumbio") == 0) {
+ dumbio = 1;
} else {
printf("unknown option %s\n", argv[stat]);
usage();
exit(1);
}
} else {
- bfd_load(argv[stat]);
+ last_load_addr = bfd_load(argv[stat]);
}
stat++;
}
-#ifdef IUREV0
- if (iurev0)
- printf(" simulating IU rev.0 jmpl/restore bug\n");
-#endif
-#ifdef MECREV0
- if (iurev0)
- printf(" simulating MEC rev.0 timer and uart interrupt bug\n");
-#endif
if (nfp)
printf("FPU disabled\n");
+#ifdef ERA
+ if (era)
+ printf("ERA ECC emulation enabled\n");
+#endif
sregs.freq = freq;
INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf);
+ dinfo.endian = BFD_ENDIAN_BIG;
+ termsave = fcntl(0, F_GETFL, 0);
using_history();
init_signals();
ebase.simtime = 0;
while (cont) {
if (cmdq[cmdi] != 0) {
+#if 0
remove_history(cmdq[cmdi]);
+#else
+ remove_history(cmdi);
+#endif
free(cmdq[cmdi]);
cmdq[cmdi] = 0;
}
case CTRL_C:
printf("\b\bInterrupt!\n");
case TIME_OUT:
- printf(" Stopped at time %d\n", ebase.simtime);
+ printf(" Stopped at time %d (%.3f ms)\n", ebase.simtime,
+ ((double) ebase.simtime / (double) sregs.freq) / 1000.0);
break;
case BPT_HIT:
printf("breakpoint at 0x%08x reached\n", sregs.pc);
cmdi = (cmdi + 1) & (HIST_LEN - 1);
}
+ return 0;
}
+