/* Copyright (c) 1996-1997 Swiss Federal Institute of Technology, Computer Engineering and Networks Laboratory. All rights reserved. MIPS Simulator for a R3000 based machine. For details, have a look at the hardware documentation of the Integrated Device Technology ID79R3052E processor and the evaluation board 7RS385. Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without written agreement is hereby granted, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE SWISS FEDERAL INSTITUTE OF TECHNOLOGY, COMPUTER ENGINEERING AND NETWORKS LABORATORY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE SWISS FEDERAL INSTITUTE OF TECHNOLOGY, COMPUTER ENGINEERING AND NETWORKS LABORATORY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE SWISS FEDERAL INSTITUTE OF TECHNOLOGY, COMPUTER ENGINEERING AND NETWORKS LABORATORY, SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE SWISS FEDERAL INSTITUTE OF TECHNOLOGY, COMPUTER ENGINEERING AND NETWORKS LABORATORY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. File: $Source: /usr/drwho/vault/cvs/topsy/MipsSim/Simulator.java,v $ Author(s): G. Fankhauser Affiliation: ETH Zuerich, TIK Version: $Revision: 1.8 $ Creation Date: December 1996 Last Date of Change: $Date: 2000/05/08 18:47:51 $ by: $Author: gfa $ $Log: Simulator.java,v $ Revision 1.8 2000/05/08 18:47:51 gfa new playstation stuff... Revision 1.7 2000/04/05 14:33:15 gfa *** empty log message *** Revision 1.6 1999/09/22 12:15:29 gfa *** empty log message *** Revision 1.5 1999/09/21 20:42:17 gfa *** empty log message *** Revision 1.4 1999/09/21 19:53:16 gfa threading option Revision 1.3 1999/09/08 14:19:06 gfa defaults to big endian now Revision 1.2 1999/08/09 09:17:13 gfa bug hunt with gcj 2.95... Revision 1.1.1.1 1999/07/22 17:35:23 gfa cvs move Revision 1.2 1998/04/23 15:43:22 gfa chnage for trace # Revision 1.1 97/05/09 14:33:46 gfa # Initial revision # # Revision 1.2 1997/04/06 12:59:41 gfa # adapted for the applet interface, processor runs also as a thread... # # Revision 1.1 1997/02/04 10:42:01 topsy # Initial revision # */ import java.lang.*; import java.io.*; import java.util.*; import Processor; import KernelLoader; import KernelLoaderException; public final class Simulator extends Object { static Processor proc; static Tracer tracer; public static boolean traceMode = false; public static boolean verboseMode = false; public static boolean bigEndian = true; public static boolean gdb = false; public static boolean psxMode = false; public static int ethertapPort = 4000; public static void main(String argv[]) { String bootFilename = "topsy.srec"; // default kernel name String traceFilename = "topsy.trace"; String symbolsFilename = "topsy.symbols"; // default kernel symbols name boolean symbolicTraceMode = false; RandomAccessFile kernelFile; for (int i = 0; i < argv.length; i++) { if (argv[i].charAt(0) == '-') { if (argv[i].charAt(1) == 't') { traceMode = true; i++; traceFilename = argv[i]; // no check is made... continue; } else if (argv[i].charAt(1) == 's') { symbolicTraceMode=true; i++; symbolsFilename = argv[i]; // no check is made... continue; } else if (argv[i].charAt(1) == 'v') verboseMode = true; else if (argv[i].charAt(1) == 'b') bigEndian = true; else if (argv[i].charAt(1) == 'l') bigEndian = false; else if (argv[i].charAt(1) == 'g') gdb = true; else if (argv[i].charAt(1) == 'P') psxMode = true; } else { bootFilename = argv[i]; } } if (psxMode) { bigEndian = false; } // print some nice message and open kernel file System.out.print("\nMIPS R3000 (" + (bigEndian ? "big endian" : "little endian") + ") Simulator - (c) 1996-1999 gfa\n"); System.out.print("trace="+traceMode+ " (symbolic="+symbolicTraceMode+"), "); System.out.println("gdb="+gdb+", verbose="+verboseMode); if (psxMode) { System.out.println(" ***** running in PlayStation mode *****"); } // Initialize Tracer try { if(traceMode == true) { if (symbolicTraceMode == true) { System.out.println("Reading symbols from '" + symbolsFilename + "'"); tracer = new Tracer(traceFilename, symbolsFilename); } else { tracer = new Tracer(traceFilename); } } } catch (Exception exception) { System.out.print("Couldn't initialize tracer ("); System.out.print(exception.getClass().getName()+")\n\n"); return; } try { kernelFile = new RandomAccessFile(bootFilename, "r"); } catch (Exception exception) { System.out.print("Couldn't find kernel '"+bootFilename+"' ("); System.out.print(exception.getClass().getName()+")\n\n"); return; } // now we have a stream with the kernel file, // let's init cpu/memory/devices and load it try { proc = new Processor(); } catch (Exception exception) { System.out.print("Couldn't create processor ("); System.out.print(exception.getClass().getName() + ")\n\n"); return; } System.out.print("Loading from " + bootFilename + " "); try { new KernelLoader(kernelFile, proc.memory, proc); } catch (Exception exception) { System.out.print("Couldn't load kernel ("); System.out.print(exception.getClass().getName() + ")\n\n"); return; } // machine initialized, kernel loaded, let's go! System.out.print("ok.\n\n"); try { new Thread(proc).start(); } catch (Exception exception) { System.out.print("Exception while running ("); System.out.print(exception.getClass().getName() + ")\n"); proc.where(); return; } } }