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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [sim/] [erc32/] [sis.c] - Diff between revs 827 and 840

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 827 Rev 840
/*
/*
 * This file is part of SIS.
 * This file is part of SIS.
 *
 *
 * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European
 * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European
 * Space Agency
 * Space Agency
 *
 *
 * This program is free software; you can redistribute it and/or modify it under
 * 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
 * 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)
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * any later version.
 *
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * more details.
 *
 *
 * You should have received a copy of the GNU General Public License along with
 * 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
 * this program; if not, write to the Free Software Foundation, Inc., 675
 * Mass Ave, Cambridge, MA 02139, USA.
 * Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 */
 */
 
 
#include "config.h"
#include "config.h"
#include <signal.h>
#include <signal.h>
#include <string.h>
#include <string.h>
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
#include <stdio.h>
#include <stdio.h>
#include <time.h>
#include <time.h>
#include <sys/fcntl.h>
#include <sys/fcntl.h>
#include "sis.h"
#include "sis.h"
#include <dis-asm.h>
#include <dis-asm.h>
#include "sim-config.h"
#include "sim-config.h"
 
 
#define VAL(x)  strtol(x,(char **)NULL,0)
#define VAL(x)  strtol(x,(char **)NULL,0)
 
 
/* Structures and functions from readline library */
/* Structures and functions from readline library */
 
 
typedef struct {
typedef struct {
  char *line;
  char *line;
  char *data;
  char *data;
} HIST_ENTRY;
} HIST_ENTRY;
 
 
extern char *   readline PARAMS ((char *prompt));
extern char *   readline PARAMS ((char *prompt));
extern void     using_history PARAMS ((void));
extern void     using_history PARAMS ((void));
extern void     add_history PARAMS ((char *string));
extern void     add_history PARAMS ((char *string));
extern HIST_ENTRY *remove_history PARAMS ((int which));
extern HIST_ENTRY *remove_history PARAMS ((int which));
 
 
 
 
 
 
/* Command history buffer length - MUST be binary */
/* Command history buffer length - MUST be binary */
#define HIST_LEN        64
#define HIST_LEN        64
 
 
extern struct disassemble_info dinfo;
extern struct disassemble_info dinfo;
extern struct pstate sregs;
extern struct pstate sregs;
extern struct estate ebase;
extern struct estate ebase;
 
 
extern int      ctrl_c;
extern int      ctrl_c;
extern int      nfp;
extern int      nfp;
extern int      ift;
extern int      ift;
extern int      wrp;
extern int      wrp;
extern int      rom8;
extern int      rom8;
extern int      uben;
extern int      uben;
extern int      sis_verbose;
extern int      sis_verbose;
extern char    *sis_version;
extern char    *sis_version;
extern struct estate ebase;
extern struct estate ebase;
extern struct evcell evbuf[];
extern struct evcell evbuf[];
extern struct irqcell irqarr[];
extern struct irqcell irqarr[];
extern int      irqpend, ext_irl;
extern int      irqpend, ext_irl;
extern int      termsave;
extern int      termsave;
extern int      sparclite;
extern int      sparclite;
extern int      dumbio;
extern int      dumbio;
extern char     uart_dev1[];
extern char     uart_dev1[];
extern char     uart_dev2[];
extern char     uart_dev2[];
extern uint32   last_load_addr;
extern uint32   last_load_addr;
 
 
#ifdef ERA
#ifdef ERA
extern int era;
extern int era;
#endif
#endif
 
 
int
int
run_sim(sregs, icount, dis)
run_sim(sregs, icount, dis)
    struct pstate  *sregs;
    struct pstate  *sregs;
    unsigned int    icount;
    unsigned int    icount;
    int             dis;
    int             dis;
{
{
    int             irq, mexc, deb, asi;
    int             irq, mexc, deb, asi;
 
 
    sregs->starttime = time(NULL);
    sregs->starttime = time(NULL);
    init_stdio();
    init_stdio();
    if (sregs->err_mode) icount = 0;
    if (sregs->err_mode) icount = 0;
    deb = dis || sregs->histlen || sregs->bptnum;
    deb = dis || sregs->histlen || sregs->bptnum;
    irq = 0;
    irq = 0;
    while (icount > 0) {
    while (icount > 0) {
 
 
        if (sregs->psr & 0x080)
        if (sregs->psr & 0x080)
            asi = 9;
            asi = 9;
        else
        else
            asi = 8;
            asi = 8;
        mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold);
        mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold);
        sregs->icnt = 1;
        sregs->icnt = 1;
        if (sregs->annul) {
        if (sregs->annul) {
            sregs->annul = 0;
            sregs->annul = 0;
            sregs->pc = sregs->npc;
            sregs->pc = sregs->npc;
            sregs->npc = sregs->npc + 4;
            sregs->npc = sregs->npc + 4;
        } else {
        } else {
            sregs->fhold = 0;
            sregs->fhold = 0;
            if (ext_irl) irq = check_interrupts(sregs);
            if (ext_irl) irq = check_interrupts(sregs);
            if (!irq) {
            if (!irq) {
                if (mexc) {
                if (mexc) {
                    sregs->trap = I_ACC_EXC;
                    sregs->trap = I_ACC_EXC;
                } else {
                } else {
                    if (deb) {
                    if (deb) {
                        if ((sregs->bphit = check_bpt(sregs)) != 0) {
                        if ((sregs->bphit = check_bpt(sregs)) != 0) {
                            restore_stdio();
                            restore_stdio();
                            return (BPT_HIT);
                            return (BPT_HIT);
                        }
                        }
                        if (sregs->histlen) {
                        if (sregs->histlen) {
                            sregs->histbuf[sregs->histind].addr = sregs->pc;
                            sregs->histbuf[sregs->histind].addr = sregs->pc;
                            sregs->histbuf[sregs->histind].time = ebase.simtime;
                            sregs->histbuf[sregs->histind].time = ebase.simtime;
                            sregs->histind++;
                            sregs->histind++;
                            if (sregs->histind >= sregs->histlen)
                            if (sregs->histind >= sregs->histlen)
                                sregs->histind = 0;
                                sregs->histind = 0;
                        }
                        }
                        if (dis) {
                        if (dis) {
                            printf(" %8u ", ebase.simtime);
                            printf(" %8u ", ebase.simtime);
                            dis_mem(sregs->pc, 1, &dinfo);
                            dis_mem(sregs->pc, 1, &dinfo);
                        }
                        }
                    }
                    }
                    dispatch_instruction(sregs);
                    dispatch_instruction(sregs);
                    icount--;
                    icount--;
                }
                }
            }
            }
            if (sregs->trap) {
            if (sregs->trap) {
                irq = 0;
                irq = 0;
                sregs->err_mode = execute_trap(sregs);
                sregs->err_mode = execute_trap(sregs);
                if (sregs->err_mode) {
                if (sregs->err_mode) {
                    error_mode(sregs->pc);
                    error_mode(sregs->pc);
                    icount = 0;
                    icount = 0;
                }
                }
            }
            }
        }
        }
        advance_time(sregs);
        advance_time(sregs);
        if (ctrl_c || (sregs->tlimit <= ebase.simtime)) {
        if (ctrl_c || (sregs->tlimit <= ebase.simtime)) {
            icount = 0;
            icount = 0;
            if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1;
            if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1;
        }
        }
    }
    }
    sregs->tottime += time(NULL) - sregs->starttime;
    sregs->tottime += time(NULL) - sregs->starttime;
    restore_stdio();
    restore_stdio();
    if (sregs->err_mode)
    if (sregs->err_mode)
        return (ERROR);
        return (ERROR);
    if (ctrl_c) {
    if (ctrl_c) {
        ctrl_c = 0;
        ctrl_c = 0;
        return (CTRL_C);
        return (CTRL_C);
    }
    }
    return (TIME_OUT);
    return (TIME_OUT);
}
}
 
 
int
int
main(argc, argv)
main(argc, argv)
    int             argc;
    int             argc;
    char          **argv;
    char          **argv;
{
{
 
 
    int             cont = 1;
    int             cont = 1;
    int             stat = 1;
    int             stat = 1;
    int             freq = 14;
    int             freq = 14;
    int             copt = 0;
    int             copt = 0;
 
 
    char           *cfile, *bacmd;
    char           *cfile, *bacmd;
    char           *cmdq[HIST_LEN];
    char           *cmdq[HIST_LEN];
    int             cmdi = 0;
    int             cmdi = 0;
    int             i;
    int             i;
 
 
    cfile = 0;
    cfile = 0;
    for (i = 0; i < 64; i++)
    for (i = 0; i < 64; i++)
        cmdq[i] = 0;
        cmdq[i] = 0;
    printf("\n SIS - SPARC intruction simulator %s,  copyright Jiri Gaisler 1995\n", sis_version);
    printf("\n SIS - SPARC intruction simulator %s,  copyright Jiri Gaisler 1995\n", sis_version);
    printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
    printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
    while (stat < argc) {
    while (stat < argc) {
        if (argv[stat][0] == '-') {
        if (argv[stat][0] == '-') {
            if (strcmp(argv[stat], "-v") == 0) {
            if (strcmp(argv[stat], "-v") == 0) {
                sis_verbose = 1;
                sis_verbose = 1;
            } else if (strcmp(argv[stat], "-c") == 0) {
            } else if (strcmp(argv[stat], "-c") == 0) {
                if ((stat + 1) < argc) {
                if ((stat + 1) < argc) {
                    copt = 1;
                    copt = 1;
                    cfile = argv[++stat];
                    cfile = argv[++stat];
                }
                }
            } else if (strcmp(argv[stat], "-nfp") == 0)
            } else if (strcmp(argv[stat], "-nfp") == 0)
                nfp = 1;
                nfp = 1;
            else if (strcmp(argv[stat], "-ift") == 0)
            else if (strcmp(argv[stat], "-ift") == 0)
                ift = 1;
                ift = 1;
            else if (strcmp(argv[stat], "-wrp") == 0)
            else if (strcmp(argv[stat], "-wrp") == 0)
                wrp = 1;
                wrp = 1;
            else if (strcmp(argv[stat], "-rom8") == 0)
            else if (strcmp(argv[stat], "-rom8") == 0)
                rom8 = 1;
                rom8 = 1;
            else if (strcmp(argv[stat], "-uben") == 0)
            else if (strcmp(argv[stat], "-uben") == 0)
                uben = 1;
                uben = 1;
            else if (strcmp(argv[stat], "-uart1") == 0) {
            else if (strcmp(argv[stat], "-uart1") == 0) {
                if ((stat + 1) < argc)
                if ((stat + 1) < argc)
                    strcpy(uart_dev1, argv[++stat]);
                    strcpy(uart_dev1, argv[++stat]);
            } else if (strcmp(argv[stat], "-uart2") == 0) {
            } else if (strcmp(argv[stat], "-uart2") == 0) {
                if ((stat + 1) < argc)
                if ((stat + 1) < argc)
                    strcpy(uart_dev2, argv[++stat]);
                    strcpy(uart_dev2, argv[++stat]);
            } else if (strcmp(argv[stat], "-freq") == 0) {
            } else if (strcmp(argv[stat], "-freq") == 0) {
                if ((stat + 1) < argc)
                if ((stat + 1) < argc)
                    freq = VAL(argv[++stat]);
                    freq = VAL(argv[++stat]);
            } else if (strcmp(argv[stat], "-sparclite") == 0) {
            } else if (strcmp(argv[stat], "-sparclite") == 0) {
                sparclite = 1;
                sparclite = 1;
#ifdef ERA
#ifdef ERA
            } else if (strcmp(argv[stat], "-era") == 0) {
            } else if (strcmp(argv[stat], "-era") == 0) {
                era = 1;
                era = 1;
#endif
#endif
            } else if (strcmp(argv[stat], "-dumbio") == 0) {
            } else if (strcmp(argv[stat], "-dumbio") == 0) {
                dumbio = 1;
                dumbio = 1;
            } else {
            } else {
                printf("unknown option %s\n", argv[stat]);
                printf("unknown option %s\n", argv[stat]);
                usage();
                usage();
                exit(1);
                exit(1);
            }
            }
        } else {
        } else {
            last_load_addr = bfd_load(argv[stat]);
            last_load_addr = bfd_load(argv[stat]);
        }
        }
        stat++;
        stat++;
    }
    }
    if (nfp)
    if (nfp)
        printf("FPU disabled\n");
        printf("FPU disabled\n");
#ifdef ERA
#ifdef ERA
    if (era)
    if (era)
        printf("ERA ECC emulation enabled\n");
        printf("ERA ECC emulation enabled\n");
#endif
#endif
    sregs.freq = freq;
    sregs.freq = freq;
 
 
    INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf);
    INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf);
    dinfo.endian = BFD_ENDIAN_BIG;
    dinfo.endian = BFD_ENDIAN_BIG;
 
 
    termsave = fcntl(0, F_GETFL, 0);
    termsave = fcntl(0, F_GETFL, 0);
    using_history();
    using_history();
    init_signals();
    init_signals();
    ebase.simtime = 0;
    ebase.simtime = 0;
    reset_all();
    reset_all();
    init_bpt(&sregs);
    init_bpt(&sregs);
    init_sim();
    init_sim();
#ifdef STAT
#ifdef STAT
    reset_stat(&sregs);
    reset_stat(&sregs);
#endif
#endif
 
 
    if (copt) {
    if (copt) {
        bacmd = (char *) malloc(256);
        bacmd = (char *) malloc(256);
        strcpy(bacmd, "batch ");
        strcpy(bacmd, "batch ");
        strcat(bacmd, cfile);
        strcat(bacmd, cfile);
        exec_cmd(&sregs, bacmd);
        exec_cmd(&sregs, bacmd);
    }
    }
    while (cont) {
    while (cont) {
 
 
        if (cmdq[cmdi] != 0) {
        if (cmdq[cmdi] != 0) {
#if 0
#if 0
            remove_history(cmdq[cmdi]);
            remove_history(cmdq[cmdi]);
#else
#else
            remove_history(cmdi);
            remove_history(cmdi);
#endif
#endif
            free(cmdq[cmdi]);
            free(cmdq[cmdi]);
            cmdq[cmdi] = 0;
            cmdq[cmdi] = 0;
        }
        }
        cmdq[cmdi] = readline("sis> ");
        cmdq[cmdi] = readline("sis> ");
        if (cmdq[cmdi] && *cmdq[cmdi])
        if (cmdq[cmdi] && *cmdq[cmdi])
            add_history(cmdq[cmdi]);
            add_history(cmdq[cmdi]);
        if (cmdq[cmdi])
        if (cmdq[cmdi])
            stat = exec_cmd(&sregs, cmdq[cmdi]);
            stat = exec_cmd(&sregs, cmdq[cmdi]);
        else {
        else {
            puts("\n");
            puts("\n");
            exit(0);
            exit(0);
        }
        }
        switch (stat) {
        switch (stat) {
        case OK:
        case OK:
            break;
            break;
        case CTRL_C:
        case CTRL_C:
            printf("\b\bInterrupt!\n");
            printf("\b\bInterrupt!\n");
        case TIME_OUT:
        case TIME_OUT:
            printf(" Stopped at time %d (%.3f ms)\n", ebase.simtime,
            printf(" Stopped at time %d (%.3f ms)\n", ebase.simtime,
              ((double) ebase.simtime / (double) sregs.freq) / 1000.0);
              ((double) ebase.simtime / (double) sregs.freq) / 1000.0);
            break;
            break;
        case BPT_HIT:
        case BPT_HIT:
            printf("breakpoint at 0x%08x reached\n", sregs.pc);
            printf("breakpoint at 0x%08x reached\n", sregs.pc);
            sregs.bphit = 1;
            sregs.bphit = 1;
            break;
            break;
        case ERROR:
        case ERROR:
            printf("IU in error mode (%d)\n", sregs.trap);
            printf("IU in error mode (%d)\n", sregs.trap);
            stat = 0;
            stat = 0;
            printf(" %8d ", ebase.simtime);
            printf(" %8d ", ebase.simtime);
            dis_mem(sregs.pc, 1, &dinfo);
            dis_mem(sregs.pc, 1, &dinfo);
            break;
            break;
        default:
        default:
            break;
            break;
        }
        }
        ctrl_c = 0;
        ctrl_c = 0;
        stat = OK;
        stat = OK;
 
 
        cmdi = (cmdi + 1) & (HIST_LEN - 1);
        cmdi = (cmdi + 1) & (HIST_LEN - 1);
 
 
    }
    }
    return 0;
    return 0;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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