// PART OF THE MACHINE SIMULATION. DO NOT CHANGE.
package nachos.machine;
import nachos.security.*;
/**
* The <tt>Processor</tt> 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.
*
* <p>
* The <tt>Processor</tt> API is re-entrant, so a single simulated processor
* can be shared by multiple user threads.
*
* <p>
* An instance of a <tt>Processor</tt> also includes pages of physical memory
* accessible to user programs, the size of which is fixed by the constructor.
*/
public final class Processor {
/**
* Allocate a new MIPS processor, with the specified amount of memory.
*
* @param privilege encapsulates privileged access to the Nachos
* machine.
* @param numPhysPages the number of pages of physical memory to
* attach.
*/
public Processor(Privilege privilege, int numPhysPages) {
System.out.print(" processor");
this.privilege = privilege;
privilege.processor = new ProcessorPrivilege();
Class<?> clsKernel = Lib.loadClass(Config.getString("Kernel.kernel"));
Class<?> clsVMKernel = Lib.tryLoadClass("nachos.vm.VMKernel");
usingTLB =
(clsVMKernel != null && clsVMKernel.isAssignableFrom(clsKernel));
this.numPhysPages = numPhysPages;
for (int i=0; i<numUserRegisters; i++)
registers[i] = 0;
mainMemory = new byte[pageSize * numPhysPages];
if (usingTLB) {
translations = new TranslationEntry[tlbSize];
for (int i=0; i<tlbSize; i++)
translations[i] = new TranslationEntry();
}
else {
translations = null;
}
}
/**
* Set the exception handler, called whenever a user exception occurs.
*
* <p>
* When the exception handler is called, interrupts will be enabled, and
* the CPU cause register will specify the cause of the exception (see the
* <tt>exception<i>*</i></tt> constants).
*
* @param exceptionHandler the kernel exception handler.
*/
public void setExceptionHandler(Runnable exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}
/**
* Get the exception handler, set by the last call to
* <tt>setExceptionHandler()</tt>.
*
* @return the exception handler.
*/
public Runnable getExceptionHandler() {
return exceptionHandler;
}
/**
* Start executing instructions at the current PC. Never returns.
*/
public void run() {
Lib.debug(dbgProcessor, "starting program in current thread");
registers[regNextPC] = registers[regPC] + 4;
Machine.autoGrader().runProcessor(privilege);
Instruction inst = new Instruction();
while (true) {
try {
inst.run();
}
catch (MipsException e) {
e.handle();
}
privilege.interrupt.tick(false);
}
}
/**
* Read and return the contents of the specified CPU register.
*
* @param number the register to read.
* @return the value of the register.
*/
public int readRegister(int number) {
Lib.assertTrue(number >= 0 && number < numUserRegisters);
return registers[number];
}
/**
* Write the specified value into the specified CPU register.
*
* @param number the register to write.
* @param value the value to write.
*/
public void writeRegister(int number, int value) {
Lib.assertTrue(number >= 0 && number < numUserRegisters);
if (number != 0)
registers[number] = value;
}
/**
* Test whether this processor uses a software-managed TLB, or single-level
* paging.
*
* <p>
* If <tt>false</tt>, this processor directly supports single-level paging;
* use <tt>setPageTable()</tt>.
*
* <p>
* If <tt>true</tt>, this processor has a software-managed TLB;
* use <tt>getTLBSize()</tt>, <tt>readTLBEntry()</tt>, and
* <tt>writeTLBEntry()</tt>.
*
* <p>
* Using a method associated with the wrong address translation mechanism
* will result in an assertion failure.
*
* @return <tt>true</tt> if this processor has a software-managed TLB.
*/
public boolean hasTLB() {
return usingTLB;
}
/**
* Get the current page table, set by the last call to setPageTable().
*
* @return the current page table.
*/
public TranslationEntry[] getPageTable() {
Lib.assertTrue(!usingTLB);
return translations;
}
/**
* Set the page table pointer. All further address translations will use
* the specified page table. The size of the current address space will be
* determined from the length of the page table array.
*
* @param pageTable the page table to use.
*/
public void setPageTable(TranslationEntry[] pageTable) {
Lib.assertTrue(!usingTLB);
this.translations = pageTable;
}
/**
* Return the number of entries in this processor's TLB.
*
* @return the number of entries in this processor's TLB.
*/
public int getTLBSize() {
Lib.assertTrue(usingTLB);
return tlbSize;
}
/**
* Returns the specified TLB entry.
*
* @param number the index into the TLB.
* @return the contents of the specified TLB entry.
*/
public TranslationEntry readTLBEntry(int number) {
Lib.assertTrue(usingTLB);
Lib.assertTrue(number >= 0 && number < tlbSize);
return new TranslationEntry(translations[number]);
}
/**
* Fill the specified TLB entry.
*
* <p>
* The TLB is fully associative, so the location of an entry within the TLB
* does not affect anything.
*
* @param number the index into the TLB.
* @param entry the new contents of the TLB entry.
*/
public void writeTLBEntry(int number, TranslationEntry entry) {
Lib.assertTrue(usingTLB);
Lib.assertTrue(number >= 0 && number < tlbSize);
translations[number] = new TranslationEntry(entry);
}
/**
* Return the number of pages of physical memory attached to this simulated
* processor.
*
* @return the number of pages of physical memory.
*/
public int getNumPhysPages() {
return numPhysPages;
}
/**
* Return a reference to the physical memory array. The size of this array
* is <tt>pageSize * getNumPhysPages()</tt>.
*
* @return the main memory array.
*/
public byte[] getMemory() {
return mainMemory;
}
/**
* Concatenate a page number and an offset into an address.
*
* @param page the page number. Must be between <tt>0</tt> and
* <tt>(2<sup>32</sup> / pageSize) - 1</tt>.
* @param offset the offset within the page. Must be between <tt>0</tt>
* and
* <tt>pageSize - 1</tt>.
* @return a 32-bit address consisting of the specified page and offset.
*/
public static int makeAddress(int page, int offset) {
Lib.assertTrue(page >= 0 && page < maxPages);
Lib.assertTrue(offset >= 0 && offset < pageSize);
return (page * pageSize) | offset;
}
/**
* Extract the page number component from a 32-bit address.
*
* @param address the 32-bit address.
* @return the page number component of the address.
*/
public static int pageFromAddress(int address) {
return (int) (((long) address & 0xFFFFFFFFL) / pageSize);
}
/**
* Extract the offset component from an address.
*
* @param address the 32-bit address.
* @return the offset component of the address.
*/
public static int offsetFromAdd
没有合适的资源?快使用搜索试试~ 我知道了~
nachos java
3星 · 超过75%的资源 需积分: 9 24 下载量 79 浏览量
2015-10-15
08:25:12
上传
评论
收藏 580KB GZ 举报
温馨提示
共143个文件
java:62个
c:22个
o:22个
nachos java,nachos for java. Nachos的全称是“Not Another Completely Heuristic Operating System”,它是一个可修改和跟踪的操作系统教学软件。
资源推荐
资源详情
资源评论
收起资源包目录
nachos java (143个子文件)
libnachos.a 15KB
sh.c 4KB
printf.c 3KB
sort.c 1016B
matmult.c 838B
readline.c 707B
mv.c 646B
cp.c 628B
halt.c 561B
cat.c 467B
strncmp.c 304B
rm.c 296B
stdio.c 281B
strcat.c 270B
strcmp.c 250B
strcpy.c 240B
atoi.c 231B
strlen.c 230B
echo.c 215B
memcpy.c 169B
assert.c 161B
memset.c 155B
stdlib.c 21B
sh.coff 10KB
mv.coff 7KB
cp.coff 7KB
cat.coff 7KB
rm.coff 7KB
echo.coff 7KB
sort.coff 3KB
matmult.coff 3KB
halt.coff 2KB
nachos.conf 571B
nachos.conf 530B
nachos.conf 469B
nachos.conf 382B
syscall.h 10KB
va-mips.h 10KB
stdarg.h 6KB
stdio.h 1KB
stdlib.h 1006B
package.html 135B
package.html 132B
package.html 111B
package.html 96B
package.html 92B
package.html 80B
package.html 72B
Processor.java 36KB
Lib.java 20KB
Machine.java 16KB
ElevatorBank.java 15KB
UserProcess.java 15KB
TCB.java 14KB
KThread.java 12KB
ElevatorGui.java 9KB
NetworkLink.java 9KB
NachosSecurityManager.java 8KB
AutoGrader.java 8KB
PriorityScheduler.java 7KB
Config.java 7KB
Interrupt.java 7KB
CoffSection.java 6KB
Privilege.java 6KB
Scheduler.java 5KB
RiderControls.java 5KB
StubFileSystem.java 4KB
Coff.java 4KB
OpenFile.java 4KB
ThreadQueue.java 4KB
Condition.java 4KB
StandardConsole.java 4KB
PostOffice.java 4KB
ElevatorTest.java 4KB
SynchConsole.java 4KB
Packet.java 4KB
MailMessage.java 3KB
Stats.java 3KB
ElevatorControls.java 3KB
UserKernel.java 3KB
NetKernel.java 3KB
BoatGrader.java 3KB
Semaphore.java 3KB
ThreadedKernel.java 2KB
Timer.java 2KB
RoundRobinScheduler.java 2KB
RiderInterface.java 2KB
Boat.java 2KB
Lock.java 2KB
TranslationEntry.java 2KB
Rider.java 2KB
SynchList.java 2KB
VMProcess.java 2KB
UThread.java 2KB
ElevatorControllerInterface.java 2KB
Alarm.java 2KB
Condition2.java 2KB
SerialConsole.java 1KB
FileSystem.java 1KB
LotteryScheduler.java 1KB
共 143 条
- 1
- 2
资源评论
- javaerzhang2015-11-14感觉没什么用
dkbnull
- 粉丝: 830
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功