|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.machine.Processor
public final class Processor
The Processor class simulates a MIPS processor that supports a subset of the R3000 instruction set. Specifically, the processor lacks all coprocessor support, and can only execute in user mode. Address translation information is accessed via the API. The API also allows a kernel to set an exception handler to be called on any user mode exception.
The Processor API is re-entrant, so a single simulated processor can be shared by multiple user threads.
An instance of a Processor also includes pages of physical memory accessible to user programs, the size of which is fixed by the constructor.
Field Summary | |
---|---|
static int |
exceptionAddressError
Caused by an access to a misaligned virtual address. |
static int |
exceptionBusError
Caused by an access to an invalid physical page. |
static int |
exceptionIllegalInstruction
Caused by an attempt to execute an illegal instruction. |
static String[] |
exceptionNames
The names of the CPU exceptions. |
static int |
exceptionOverflow
Caused by an overflow by a signed operation. |
static int |
exceptionPageFault
Caused by an access to an invalid virtual page. |
static int |
exceptionReadOnly
Caused by a write access to a read-only virtual page. |
static int |
exceptionSyscall
Caused by a syscall instruction. |
static int |
exceptionTLBMiss
Caused by an access to a virtual page not mapped by any TLB entry. |
static int |
maxPages
Number of pages in a 32-bit address space. |
static int |
numUserRegisters
The total number of software-accessible CPU registers. |
static int |
pageSize
Size of a page, in bytes. |
static int |
regA0
Index of argument register 0. |
static int |
regA1
Index of argument register 1. |
static int |
regA2
Index of argument register 2. |
static int |
regA3
Index of argument register 3. |
static int |
regBadVAddr
Index of the exception bad virtual address register. |
static int |
regCause
Index of the exception cause register. |
static int |
regHi
Index of the high register, used for multiplication and division. |
static int |
regLo
Index of the low register, used for multiplication and division. |
static int |
regNextPC
Index of the next program counter register. |
static int |
regPC
Index of the program counter register. |
static int |
regRA
Index of the return address register. |
static int |
regSP
Index of the stack pointer register. |
static int |
regV0
Index of return value register 0. |
static int |
regV1
Index of return value register 1. |
Constructor Summary | |
---|---|
Processor(Privilege privilege,
int numPhysPages)
Allocate a new MIPS processor, with the specified amount of memory. |
Method Summary | |
---|---|
void |
advancePC()
Advance the PC to the next instruction. |
Runnable |
getExceptionHandler()
Get the exception handler, set by the last call to setExceptionHandler(). |
byte[] |
getMemory()
Return a reference to the physical memory array. |
int |
getNumPhysPages()
Return the number of pages of physical memory attached to this simulated processor. |
TranslationEntry[] |
getPageTable()
Get the current page table, set by the last call to setPageTable(). |
int |
getTLBSize()
Return the number of entries in this processor's TLB. |
boolean |
hasTLB()
Test whether this processor uses a software-managed TLB, or single-level paging. |
static int |
makeAddress(int page,
int offset)
Concatenate a page number and an offset into an address. |
static int |
offsetFromAddress(int address)
Extract the offset component from an address. |
static int |
pageFromAddress(int address)
Extract the page number component from a 32-bit address. |
int |
readRegister(int number)
Read and return the contents of the specified CPU register. |
TranslationEntry |
readTLBEntry(int number)
Returns the specified TLB entry. |
void |
run()
Start executing instructions at the current PC. |
void |
setExceptionHandler(Runnable exceptionHandler)
Set the exception handler, called whenever a user exception occurs. |
void |
setPageTable(TranslationEntry[] pageTable)
Set the page table pointer. |
void |
writeRegister(int number,
int value)
Write the specified value into the specified CPU register. |
void |
writeTLBEntry(int number,
TranslationEntry entry)
Fill the specified TLB entry. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int exceptionSyscall
public static final int exceptionPageFault
public static final int exceptionTLBMiss
public static final int exceptionReadOnly
public static final int exceptionBusError
public static final int exceptionAddressError
public static final int exceptionOverflow
public static final int exceptionIllegalInstruction
public static final String[] exceptionNames
public static final int regV0
public static final int regV1
public static final int regA0
public static final int regA1
public static final int regA2
public static final int regA3
public static final int regSP
public static final int regRA
public static final int regLo
public static final int regHi
public static final int regPC
public static final int regNextPC
public static final int regCause
public static final int regBadVAddr
public static final int numUserRegisters
public static final int pageSize
public static final int maxPages
Constructor Detail |
---|
public Processor(Privilege privilege, int numPhysPages)
privilege
- encapsulates privileged access to the Nachos
machine.numPhysPages
- the number of pages of physical memory to
attach.Method Detail |
---|
public void setExceptionHandler(Runnable exceptionHandler)
When the exception handler is called, interrupts will be enabled, and the CPU cause register will specify the cause of the exception (see the exception* constants).
exceptionHandler
- the kernel exception handler.public Runnable getExceptionHandler()
public void run()
public int readRegister(int number)
number
- the register to read.
public void writeRegister(int number, int value)
number
- the register to write.value
- the value to write.public boolean hasTLB()
If false, this processor directly supports single-level paging; use setPageTable().
If true, this processor has a software-managed TLB; use getTLBSize(), readTLBEntry(), and writeTLBEntry().
Using a method associated with the wrong address translation mechanism will result in an assertion failure.
public TranslationEntry[] getPageTable()
public void setPageTable(TranslationEntry[] pageTable)
pageTable
- the page table to use.public int getTLBSize()
public TranslationEntry readTLBEntry(int number)
number
- the index into the TLB.
public void writeTLBEntry(int number, TranslationEntry entry)
The TLB is fully associative, so the location of an entry within the TLB does not affect anything.
number
- the index into the TLB.entry
- the new contents of the TLB entry.public int getNumPhysPages()
public byte[] getMemory()
public static int makeAddress(int page, int offset)
page
- the page number. Must be between 0 and
(232 / pageSize) - 1.offset
- the offset within the page. Must be between 0
and
pageSize - 1.
public static int pageFromAddress(int address)
address
- the 32-bit address.
public static int offsetFromAddress(int address)
address
- the 32-bit address.
public void advancePC()
Transfer the contents of the nextPC register into the PC register, and then add 4 to the value in the nextPC register. Same as advancePC(readRegister(regNextPC)+4).
Use after handling a syscall exception so that the processor will move on to the next instruction.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |