nachos.kernel.userprog
Class AddrSpace

java.lang.Object
  extended by nachos.kernel.userprog.AddrSpace

public class AddrSpace
extends java.lang.Object

This class manages "address spaces", which are the contexts in which user programs execute. For now, an address space contains a "segment descriptor", which describes the the virtual-to-physical address mapping that is to be used when the user program is executing. As you implement more of Nachos, it will probably be necessary to add other fields to this class to keep track of things like open files, network connections, etc., in use by a user program. NOTE: Most of what is in currently this class assumes that just one user program at a time will be executing. You will have to rewrite this code so that it is suitable for multiprogramming.


Field Summary
private  nachos.machine.TranslationEntry[] pageTable
          Page table that describes a virtual-to-physical address mapping.
private static int UserStackSize
          Default size of the user stack area -- increase this as necessary!
 
Constructor Summary
AddrSpace()
          Create a new address space.
 
Method Summary
 int exec(OpenFile executable)
          Load the program from a file "executable", and set everything up so that we can start executing user instructions.
 void initRegisters()
          Initialize the user-level register set to values appropriate for starting execution of a user program loaded in this address space.
 void restoreState()
          On a context switch, restore any machine state specific to this address space.
private  long roundToPage(long size)
          Utility method for rounding up to a multiple of Machine.PageSize;
 void saveState()
          On a context switch, save any machine state, specific to this address space, that needs saving.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageTable

private nachos.machine.TranslationEntry[] pageTable
Page table that describes a virtual-to-physical address mapping.


UserStackSize

private static final int UserStackSize
Default size of the user stack area -- increase this as necessary!

See Also:
Constant Field Values
Constructor Detail

AddrSpace

public AddrSpace()
Create a new address space.

Method Detail

exec

public int exec(OpenFile executable)
Load the program from a file "executable", and set everything up so that we can start executing user instructions. Assumes that the object code file is in NOFF format. First, set up the translation from program memory to physical memory. For now, this is really simple (1:1), since we are only uniprogramming.

Parameters:
executable - The file containing the object code to load into memory
Returns:
-1 if an error occurs while reading the object file, otherwise 0.

initRegisters

public void initRegisters()
Initialize the user-level register set to values appropriate for starting execution of a user program loaded in this address space. We write these directly into the "machine" registers, so that we can immediately jump to user code.


saveState

public void saveState()
On a context switch, save any machine state, specific to this address space, that needs saving. For now, nothing!


restoreState

public void restoreState()
On a context switch, restore any machine state specific to this address space. For now, just tell the machine where to find the page table.


roundToPage

private long roundToPage(long size)
Utility method for rounding up to a multiple of Machine.PageSize;