X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Ferc32%2Fsis.c;h=c52a90a34393c5b494ff895aa1e98a1112085d61;hb=3922b302645fda04da42a5279399578ae2f6206c;hp=5834e5aca2591adbb30bea3cfabc3c31066e6d28;hpb=e98fe4f7b54cbdf29aef9287bbb1bea8801dd05a;p=deliverable%2Fbinutils-gdb.git diff --git a/sim/erc32/sis.c b/sim/erc32/sis.c index 5834e5aca2..c52a90a343 100644 --- a/sim/erc32/sis.c +++ b/sim/erc32/sis.c @@ -1,43 +1,40 @@ -/* - * This file is part of SIS. - * - * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European - * Space Agency - * - * 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. - * - */ +/* This file is part of SIS (SPARC instruction simulator) -#include "config.h" + Copyright (C) 1995-2020 Free Software Foundation, Inc. + Contributed by Jiri Gaisler, European Space Agency + + 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 3 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, see . */ +#include "config.h" #include #include #ifdef HAVE_STDLIB_H #include #endif #include +#include #include "sis.h" #include +#include "sim-config.h" +#include -#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 */ -extern char *readline(char *prompt); /* GNU readline function */ +#include "readline/readline.h" +#include "readline/history.h" /* Command history buffer length - MUST be binary */ #define HIST_LEN 64 @@ -48,101 +45,103 @@ extern struct estate ebase; 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; + uint64 icount; int dis; { - int mexc, ws; - - 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; + int irq, mexc, deb; - 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); + sregs->starttime = get_time(); + init_stdio(); + if (sregs->err_mode) icount = 0; + deb = dis || sregs->histlen || sregs->bptnum; + irq = 0; + while (icount > 0) { + mexc = memory_iread (sregs->pc, &sregs->inst, &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(" %8" PRIu64 " ", 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); + sregs->tottime += get_time() - sregs->starttime; + restore_stdio(); if (sregs->err_mode) - return (ERROR); + return ERROR; if (ctrl_c) { ctrl_c = 0; - return (CTRL_C); + return CTRL_C; } - return (TIME_OUT); + return TIME_OUT; } +int main(argc, argv) int argc; char **argv; @@ -153,20 +152,21 @@ main(argc, 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; + int lfile = 0; + 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); + printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version); printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n"); while (stat < argc) { if (argv[stat][0] == '-') { if (strcmp(argv[stat], "-v") == 0) { - sis_verbose = 1; + sis_verbose += 1; } else if (strcmp(argv[stat], "-c") == 0) { if ((stat + 1) < argc) { copt = 1; @@ -174,14 +174,14 @@ main(argc, argv) } } 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]); @@ -191,36 +191,48 @@ main(argc, argv) } 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]); + lfile = 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); +#ifdef HOST_LITTLE_ENDIAN + dinfo.endian = BFD_ENDIAN_LITTLE; +#else + dinfo.endian = BFD_ENDIAN_BIG; +#endif + termsave = fcntl(0, F_GETFL, 0); using_history(); init_signals(); ebase.simtime = 0; reset_all(); init_bpt(&sregs); init_sim(); + if (lfile) + last_load_addr = bfd_load(argv[lfile]); #ifdef STAT reset_stat(&sregs); #endif @@ -234,7 +246,11 @@ main(argc, argv) while (cont) { if (cmdq[cmdi] != 0) { +#if 0 remove_history(cmdq[cmdi]); +#else + remove_history(cmdi); +#endif free(cmdq[cmdi]); cmdq[cmdi] = 0; } @@ -253,7 +269,8 @@ main(argc, argv) case CTRL_C: printf("\b\bInterrupt!\n"); case TIME_OUT: - printf(" Stopped at time %d\n", ebase.simtime); + printf(" Stopped at time %" PRIu64 " (%.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); @@ -262,7 +279,7 @@ main(argc, argv) case ERROR: printf("IU in error mode (%d)\n", sregs.trap); stat = 0; - printf(" %8d ", ebase.simtime); + printf(" %8" PRIu64 " ", ebase.simtime); dis_mem(sregs.pc, 1, &dinfo); break; default: @@ -274,4 +291,6 @@ main(argc, argv) cmdi = (cmdi + 1) & (HIST_LEN - 1); } + return 0; } +