tac0S
Template Affectional Command Operating System
|
The following 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! More...
#include <machine.h>
Public Member Functions | |
Machine (bool debug) | |
Machine::Machine Initialize the simulation of user program execution. More... | |
~Machine () | |
Machine::~Machine De-allocate the data structures used to simulate user program execution. | |
void | Run (void *fExit) |
Machine::Run Simulate the execution of a user-level program on Nachos. Called by the kernel when the program starts up; never returns. More... | |
int | ReadRegister (int num) |
Machine::ReadRegister/WriteRegister Fetch or write the contents of a user program register. | |
void | WriteRegister (int num, int value) |
void | OneInstruction (Instruction *instr) |
void | DelayedLoad (int nextReg, int nextVal) |
Machine::DelayedLoad Simulate effects of a delayed load. More... | |
bool | ReadMem (int addr, int size, int *value) |
Machine::ReadMem Read "size" (1, 2, or 4) bytes of virtual memory at "addr" into the location pointed to by "value". More... | |
bool | WriteMem (int addr, int size, int value) |
Machine::WriteMem Write "size" (1, 2, or 4) bytes of the contents of "value" into virtual memory at location "addr". More... | |
ExceptionType | Translate (int virtAddr, int *physAddr, int size, bool writing) |
Machine::Translate Translate a virtual address into a physical address, using either a page table or a TLB. Check for alignment and all sorts of other errors, and if everything is ok, set the use/dirty bits in the translation table entry, and store the translated physical address in "physAddr". If there was an error, returns the type of the exception. More... | |
void | RaiseException (ExceptionType which, int badVAddr) |
Machine::RaiseException Transfer control to the Nachos kernel from user mode, because the user program either invoked a system call, or some exception occured (such as the address translation failed). More... | |
void | Debugger () |
Machine::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! More... | |
void | DumpState () |
Machine::DumpState Print the user program's CPU state. We might print the contents of memory, but that seemed like overkill. | |
Public Attributes | |
char * | mainMemory |
int | registers [NumTotalRegs] |
TranslationEntry * | tlb |
TranslationEntry * | pageTable |
unsigned int | pageTableSize |
The following 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!
The procedures in this class are defined in machine.cc, mipssim.cc, and translate.cc.
Machine::Machine | ( | bool | debug | ) |
Machine::Machine Initialize the simulation of user program execution.
debug | – if TRUE, drop into the debugger after each user instruction is executed. |
void Machine::Debugger | ( | ) |
Machine::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.
void Machine::DelayedLoad | ( | int | nextReg, |
int | nextValue | ||
) |
Machine::DelayedLoad Simulate effects of a delayed load.
NOTE – RaiseException/CheckInterrupts must also call DelayedLoad, since any delayed load must get applied before we trap to the kernel.
void Machine::RaiseException | ( | ExceptionType | which, |
int | badVAddr | ||
) |
Machine::RaiseException Transfer control to the Nachos kernel from user mode, because the user program either invoked a system call, or some exception occured (such as the address translation failed).
which | – the cause of the kernel trap |
badVaddr | – the virtual address causing the trap, if appropriate |
bool Machine::ReadMem | ( | int | addr, |
int | size, | ||
int * | value | ||
) |
Machine::ReadMem Read "size" (1, 2, or 4) bytes of virtual memory at "addr" into the location pointed to by "value".
addr | – the virtual address to read from |
size | – the number of bytes to read (1, 2, or 4) |
value | – the place to write the result |
void Machine::Run | ( | void * | fExit | ) |
Machine::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
ExceptionType Machine::Translate | ( | int | virtAddr, |
int * | physAddr, | ||
int | size, | ||
bool | writing | ||
) |
Machine::Translate Translate a virtual address into a physical address, using either a page table or a TLB. Check for alignment and all sorts of other errors, and if everything is ok, set the use/dirty bits in the translation table entry, and store the translated physical address in "physAddr". If there was an error, returns the type of the exception.
virtAddr | – the virtual address to translate |
physAddr | – the place to store the physical address |
size | – the amount of memory being read or written |
writing | – if TRUE, check the "read-only" bit in the TLB |
bool Machine::WriteMem | ( | int | addr, |
int | size, | ||
int | value | ||
) |
Machine::WriteMem Write "size" (1, 2, or 4) bytes of the contents of "value" into virtual memory at location "addr".
addr | – the virtual address to write to |
size | – the number of bytes to be written (1, 2, or 4) |
value | – the data to be written |