sim
Class Mips

java.lang.Object
  |
  +--java.util.Observable
        |
        +--sim.Mips

public class Mips
extends java.util.Observable

Implements a simple MIPS simulator. There are two basic modes of operation:

(1) Bare mode: In this mode, the "bios" loader loads the OS loader (bootloader) into a location in high memory. This loader must be able to fit in a single 512 byte block and run in a location independent manner. Its job is to load the OS into low memory. The OS is standard-looking process (see the Linker class) and the loader can just slam it into memory starting at location zero. (Detail: the OS is linked as if it starts at location 24, because the top 6 words are always the executable descriptor -- the OS can reuse this space later, if it wishes. The OS should have its exception handling routines (trap handler) as the first thing in its text segment. The machine will automatically jump to location 24 on exceptions...) Once the kernel is loaded, the loader jumps to its entry point (as specified by the executable) and its off to the races. In this mode, memory mapped IO is used, and it's the kernels responsibility to provide system calls to read/write from these addresses to perform IO. If the kernel wishes to load/run other processes, it must manage the base & length registers accordingly to perform address translation for that process.

(2) System mode: In this mode, the simulator actually manages many of the system services, namely system calls. A set of system calls is provided to perform basic IO, which is all simply handled in software.

Memory mapped IO: By default, the machine has a single CharacterDevice, a single BlockDevice, and a single RAM. In bare mode, the user has to write code that uses these devices to do IO. In system mode, these devices are typically unused, in favor of doing IO through the system calls.

Limitations: Currently, there is no timer device, but this can/will be added.

Differences: The MULT and DIV instructions currently do not simulate the HI/LO registers as on a MIPS machine. MULT and DIV are encoded as normal R-type instructions, where the destination register takes the product (or quotient). Users wishing to implement modulus must do simulate the process in software.

R2000 Coprocessor 0: Simulates the coprocessor to some extent, with some differences from a real MIPS machine (base and length registers), the other 4 are the same. Currently reg 12 isn't used...

  1. 0: base register (used for addr translation in user mode)
  2. 1: length register (used for addr translation in user mode)
  3. 8: Bad address value
  4. 12: interrupt mask & enable bits
  5. 13: Cause (exception type and pending interrupts)
  6. 14: EPC

See Also:
Linker, Memory, MemoryMap, BlockDevice, CharacterDevice, RAM

Nested Class Summary
(package private)  class Mips.GlobalMemoryList
           
(package private)  class Mips.InsMemoryList
           
(package private)  class Mips.MemoryList
           
(package private)  class Mips.RegList
           
(package private)  class Mips.StackMemoryList
           
 
Field Summary
static int ADDRL
          Bad address for load.
static int ADDRS
          Bad address for store.
(package private)  int arith
           
(package private)  boolean bare
           
(package private)  int branches
           
(package private)  int branchesTaken
           
(package private)  java.util.Map breakPoints
           
static int BRKPT
          Breakpoint exception.
static int COP_BADADDR
          Cop0 BAD_ADDR register
static int COP_BASE
          Cop0 BASE register
static int COP_CAUSE
          Cop0 CAUSE register
static int COP_EPC
          Cop0 EPC register
static int COP_LENGTH
          Cop0 LENGTH register
static int COP_STATUS
          Cop0 STATUS register
(package private)  int[] cop0
           
static int DBUS
          Bus error on store.
(package private)  Cache dCache
           
static int defaultBlockDevLoc
           
static int defaultMemSize
           
static int defaultTermDevLoc
           
(package private)  int exeSize
           
(package private)  int hi
           
static int IBUS
          Bus error on load.
(package private)  Cache iCache
           
(package private) static java.io.BufferedReader in
           
(package private)  long instructions
           
static int INT
          External interrupt, such as IO completion.
(package private)  int jumps
           
(package private)  int loads
           
(package private)  int low
           
 MemoryMap mem
           
static int OVF
          Arithmetic overflow exception.
 int pc
           
(package private)  RAM ram
           
(package private)  int[] regs
           
static int RI
          Reserved/illegal instruction.
(package private)  boolean running
           
(package private)  int stores
           
static int SYSCALL
          Syscall exception.
(package private)  int syscalls
           
(package private)  boolean userMode
           
(package private)  boolean verbose
           
 
Constructor Summary
Mips(int newPC, int memSize)
           
 
Method Summary
 void addBreakPoint(int address)
           
 void biosLoad(java.lang.String fileName)
          Just raw loads whatever is in the given file, and sets $k0 to be the size of physical memory.
 void debugger()
           
 void deleteBreakPoint(int address)
           
 void doSysCall()
           
 void dumpMem(int addr, int words)
           
 void dumpState()
           
 void exeLoad(java.lang.String fileName, int atAddress)
          Loads a real executable, as per the format described in the class Linker.
 java.util.Vector getBreakPoints()
           
 javax.swing.ListModel getGlobalMemListModel()
           
 javax.swing.ListModel getInsMemListModel()
           
 javax.swing.ListModel getRegListModel()
           
 javax.swing.ListModel getStackMemListModel()
           
 void initialize(boolean breaks)
          Initialize the state of the machine.
static void main(java.lang.String[] args)
           
 void msg(java.lang.String s)
           
 void msgln(java.lang.String s)
           
 void quit()
           
 void raiseException(int type)
           
 byte readByte(int virtual)
           
(package private)  int readCop0(int reg)
           
 int readWord(int virtual)
           
 void run()
           
 void step(int numCycles)
           
 void writeByte(int virtual, byte value)
           
(package private)  void writeCop0(int reg, int val)
           
 void writeWord(int virtual, int value)
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

regs

int[] regs

cop0

int[] cop0

hi

int hi

low

int low

pc

public int pc

ram

RAM ram

mem

public MemoryMap mem

exeSize

int exeSize

verbose

boolean verbose

breakPoints

java.util.Map breakPoints

running

boolean running

userMode

boolean userMode

bare

boolean bare

instructions

long instructions

loads

int loads

stores

int stores

arith

int arith

branches

int branches

jumps

int jumps

syscalls

int syscalls

branchesTaken

int branchesTaken

iCache

Cache iCache

dCache

Cache dCache

defaultMemSize

public static int defaultMemSize

defaultTermDevLoc

public static int defaultTermDevLoc

defaultBlockDevLoc

public static int defaultBlockDevLoc

in

static java.io.BufferedReader in

INT

public static final int INT
External interrupt, such as IO completion.

See Also:
Constant Field Values

ADDRL

public static final int ADDRL
Bad address for load.

See Also:
Constant Field Values

ADDRS

public static final int ADDRS
Bad address for store.

See Also:
Constant Field Values

IBUS

public static final int IBUS
Bus error on load.

See Also:
Constant Field Values

DBUS

public static final int DBUS
Bus error on store.

See Also:
Constant Field Values

SYSCALL

public static final int SYSCALL
Syscall exception.

See Also:
Constant Field Values

BRKPT

public static final int BRKPT
Breakpoint exception.

See Also:
Constant Field Values

RI

public static final int RI
Reserved/illegal instruction.

See Also:
Constant Field Values

OVF

public static final int OVF
Arithmetic overflow exception.

See Also:
Constant Field Values

COP_BASE

public static final int COP_BASE
Cop0 BASE register

See Also:
Constant Field Values

COP_LENGTH

public static final int COP_LENGTH
Cop0 LENGTH register

See Also:
Constant Field Values

COP_BADADDR

public static final int COP_BADADDR
Cop0 BAD_ADDR register

See Also:
Constant Field Values

COP_STATUS

public static final int COP_STATUS
Cop0 STATUS register

See Also:
Constant Field Values

COP_CAUSE

public static final int COP_CAUSE
Cop0 CAUSE register

See Also:
Constant Field Values

COP_EPC

public static final int COP_EPC
Cop0 EPC register

See Also:
Constant Field Values
Constructor Detail

Mips

public Mips(int newPC,
            int memSize)
Method Detail

initialize

public void initialize(boolean breaks)
Initialize the state of the machine. If breaks is true, then the breakpoints will be initialized as well.


main

public static void main(java.lang.String[] args)

msg

public void msg(java.lang.String s)

msgln

public void msgln(java.lang.String s)

raiseException

public void raiseException(int type)

readCop0

int readCop0(int reg)

writeCop0

void writeCop0(int reg,
               int val)

readWord

public int readWord(int virtual)

readByte

public byte readByte(int virtual)

writeWord

public void writeWord(int virtual,
                      int value)

writeByte

public void writeByte(int virtual,
                      byte value)

biosLoad

public void biosLoad(java.lang.String fileName)
              throws java.io.IOException
Just raw loads whatever is in the given file, and sets $k0 to be the size of physical memory. Also sets the SP to bottom of physical memory...

java.io.IOException

exeLoad

public void exeLoad(java.lang.String fileName,
                    int atAddress)
             throws java.io.IOException
Loads a real executable, as per the format described in the class Linker. Ordinarily, the OS would have a loader that would do something like this.

java.io.IOException

dumpState

public void dumpState()

doSysCall

public void doSysCall()

quit

public void quit()

run

public void run()

step

public void step(int numCycles)

addBreakPoint

public void addBreakPoint(int address)

deleteBreakPoint

public void deleteBreakPoint(int address)

getBreakPoints

public java.util.Vector getBreakPoints()

dumpMem

public void dumpMem(int addr,
                    int words)

debugger

public void debugger()
              throws java.io.IOException
java.io.IOException

getInsMemListModel

public javax.swing.ListModel getInsMemListModel()

getGlobalMemListModel

public javax.swing.ListModel getGlobalMemListModel()

getStackMemListModel

public javax.swing.ListModel getStackMemListModel()

getRegListModel

public javax.swing.ListModel getRegListModel()