nachos.machine
Class Machine

java.lang.Object
  extended by nachos.machine.Machine

public class Machine
extends java.lang.Object

This class defines the simulated host workstation hardware, as seen by user programs -- the CPU registers, main memory, etc. User programs shouldn't be able to tell that they are running on our simulator or on the real hardware, except we don't support floating point instructions the system call interface to Nachos is not the same as UNIX (10 system calls in Nachos vs. 200 in UNIX!) If we were to implement more of the UNIX system calls, we ought to be able to run Nachos on top of Nachos!


Field Summary
static int AddressErrorException
          The exception generated when an unaligned reference is made, or a reference is made to an address that is beyond the end of the address space.
static int BadVAddrReg
          The failing virtual address on a page fault exception.
static int BusErrorException
          The exception generated when translation results in an invalid physical address.
static java.lang.String[] exceptionNames
          Names of the different types of exceptions -- for debugging.
static int HiReg
          Double register to hold the result of multiplication.
static int IllegalInstrException
          The exception generated by an attempt to execute an unimplemented or reserved (privileged) instruction.
static int LoadReg
          The register target of a delayed load.
static int LoadValueReg
          The value to be loaded by a delayed load.
static int LoReg
           
static byte[] mainMemory
          Physical memory to store user program, code and data, while executing.
static int MemorySize
          The total number of bytes of RAM on the system.
static int NextPCReg
          Next program counter (for branch delay).
static int NoException
          Not an exception -- everything OK!
static int NumExceptionTypes
          The number of different types of exceptions.
static int NumGPRegs
          Total number (32) of general purpose registers on MIPS.
static int NumPhysPages
          The number of pages of RAM on the system.
static int NumSegments
          Size of the segment table.
static int NumTotalRegs
          The total number of registers.
static int OverflowException
          The exception generated when an integer overflow occurs in add or sub.
static int PageFaultException
          The exception generated when a program accesses an unmapped page.
static int PageSize
          The size of a page is set equal to the disk sector size, for simplicity.
static int PCReg
          Current program counter.
static int PrevPCReg
          Previous program counter (for deuggin).
static int R31
          Register 31.
static int ReadOnlyException
          The exception generated when a program attempts a write to a page marked "read-only".
static int RetAddrReg
          Register that holds return address for procedure calls.
static int SegmentSize
          Maximum size of a segment.
static int SIGN_BIT
          Bitmask defining the position of the sign bit.
static int StackReg
          User's stack pointer.
static nachos.Statistics stats
          Collect statistics.
static int SyscallException
          The exception generated when a program executes a SYSCALL instruction.
static int TLBSize
          Number of entries in the TLB.
 
Constructor Summary
Machine()
           
 
Method Summary
static void debugger()
          Primitive debugger for user programs.
static void dumpState()
          Print the user program's CPU state.
static void enableDebugging()
          Turn on user-program debugging, which is off by default.
static SegmentDescriptor[] getSegmentTable()
          Obtain access to the segment table, if any.
static TranslationEntry[] getTLB()
          Obtain access to the TLB, if any.
static void init(java.lang.String[] args)
          Initialize the simulation of user program execution.
static int readRegister(int num)
           
static void run()
          Simulate the execution of a user-level program on Nachos.
static void setHandler(ExceptionHandler handler)
          Method called by the OS to register an exception handler to be used when a machine exception occurs in user mode.
static void setPageTable(TranslationEntry[] table)
          Install a new page table for address translation.
static void writeRegister(int num, int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NumSegments

public static final int NumSegments
Size of the segment table.

See Also:
Constant Field Values

SegmentSize

public static final int SegmentSize
Maximum size of a segment.

See Also:
Constant Field Values

TLBSize

public static final int TLBSize
Number of entries in the TLB. If there is a TLB, make it small.

See Also:
Constant Field Values

PageSize

public static final int PageSize
The size of a page is set equal to the disk sector size, for simplicity.

See Also:
Constant Field Values

NumPhysPages

public static final int NumPhysPages
The number of pages of RAM on the system.

See Also:
Constant Field Values

MemorySize

public static final int MemorySize
The total number of bytes of RAM on the system.

See Also:
Constant Field Values

NoException

public static final int NoException
Not an exception -- everything OK!

See Also:
Constant Field Values

SyscallException

public static final int SyscallException
The exception generated when a program executes a SYSCALL instruction.

See Also:
Constant Field Values

PageFaultException

public static final int PageFaultException
The exception generated when a program accesses an unmapped page.

See Also:
Constant Field Values

ReadOnlyException

public static final int ReadOnlyException
The exception generated when a program attempts a write to a page marked "read-only".

See Also:
Constant Field Values

BusErrorException

public static final int BusErrorException
The exception generated when translation results in an invalid physical address.

See Also:
Constant Field Values

AddressErrorException

public static final int AddressErrorException
The exception generated when an unaligned reference is made, or a reference is made to an address that is beyond the end of the address space.

See Also:
Constant Field Values

OverflowException

public static final int OverflowException
The exception generated when an integer overflow occurs in add or sub.

See Also:
Constant Field Values

IllegalInstrException

public static final int IllegalInstrException
The exception generated by an attempt to execute an unimplemented or reserved (privileged) instruction.

See Also:
Constant Field Values

NumExceptionTypes

public static final int NumExceptionTypes
The number of different types of exceptions.

See Also:
Constant Field Values

exceptionNames

public static final java.lang.String[] exceptionNames
Names of the different types of exceptions -- for debugging.


StackReg

public static final int StackReg
User's stack pointer.

See Also:
Constant Field Values

RetAddrReg

public static final int RetAddrReg
Register that holds return address for procedure calls.

See Also:
Constant Field Values

NumGPRegs

public static final int NumGPRegs
Total number (32) of general purpose registers on MIPS.

See Also:
Constant Field Values

HiReg

public static final int HiReg
Double register to hold the result of multiplication.

See Also:
Constant Field Values

LoReg

public static final int LoReg
See Also:
Constant Field Values

PCReg

public static final int PCReg
Current program counter.

See Also:
Constant Field Values

NextPCReg

public static final int NextPCReg
Next program counter (for branch delay).

See Also:
Constant Field Values

PrevPCReg

public static final int PrevPCReg
Previous program counter (for deuggin).

See Also:
Constant Field Values

LoadReg

public static final int LoadReg
The register target of a delayed load.

See Also:
Constant Field Values

LoadValueReg

public static final int LoadValueReg
The value to be loaded by a delayed load.

See Also:
Constant Field Values

BadVAddrReg

public static final int BadVAddrReg
The failing virtual address on a page fault exception.

See Also:
Constant Field Values

NumTotalRegs

public static final int NumTotalRegs
The total number of registers.

See Also:
Constant Field Values

SIGN_BIT

public static final int SIGN_BIT
Bitmask defining the position of the sign bit.

See Also:
Constant Field Values

R31

public static final int R31
Register 31. I don't know why there is a separate name for this.

See Also:
Constant Field Values

mainMemory

public static final byte[] mainMemory
Physical memory to store user program, code and data, while executing.


stats

public static final nachos.Statistics stats
Collect statistics.

Constructor Detail

Machine

public Machine()
Method Detail

init

public static void init(java.lang.String[] args)
Initialize the simulation of user program execution.

Parameters:
args - Command line args given to main program.

enableDebugging

public static void enableDebugging()
Turn on user-program debugging, which is off by default.


getSegmentTable

public static SegmentDescriptor[] getSegmentTable()
Obtain access to the segment table, if any.

Returns:
the segment table, or null if we are not using segments.

getTLB

public static TranslationEntry[] getTLB()
Obtain access to the TLB, if any.

Returns:
the TLB, or null if we are not using a TLB.

setPageTable

public static void setPageTable(TranslationEntry[] table)
Install a new page table for address translation.

Parameters:
table - The new page table to be installed.

run

public static void run()
Simulate the execution of a user-level program on Nachos. Called by the kernel when the program starts up; never returns. This routine is re-entrant, in that it can be called multiple times concurrently -- one for each thread executing user code.


setHandler

public static void setHandler(ExceptionHandler handler)
Method called by the OS to register an exception handler to be used when a machine exception occurs in user mode.

Parameters:
handler - Exception handler to be registered.

debugger

public static void debugger()
Primitive debugger for user programs. Note that we can't use gdb to debug user programs, since gdb doesn't run on top of Nachos. It could, but you'd have to implement *a lot* more system calls to get it to work! So just allow single-stepping, and printing the contents of memory.


dumpState

public static void dumpState()
Print the user program's CPU state. We might print the contents of memory, but that seemed like overkill.


readRegister

public static int readRegister(int num)

writeRegister

public static void writeRegister(int num,
                                 int value)