/** * The exception handler. This handler is called by the processor whenever * a user instruction causes a processor exception. * * <p> * When the exception handler is invoked, interrupts are enabled, and the * processor's cause register contains an integer identifying the cause of * the exception (see the <tt>exceptionZZZ</tt> constants in the * <tt>Processor</tt> class). If the exception involves a bad virtual * address (e.g. page fault, TLB miss, read-only, bus error, or address * error), the processor's BadVAddr register identifies the virtual address * that caused the exception. */ public void exceptionHandler() { Lib.assert(KThread.currentThread() instanceof UThread); UserProcess process = ((UThread) KThread.currentThread()).process; int cause = Machine.processor().readRegister(Processor.regCause); process.handleException(cause); }
/** * Start running user programs, by creating a process and running a shell * program in it. The name of the shell program it must run is returned by * <tt>Machine.getShellProgramName()</tt>. * * @see nachos.machine.Machine#getShellProgramName */ public void run() { super.run(); UserProcess process = UserProcess.newUserProcess(); String shellProgram = Machine.getShellProgramName(); Lib.assert(process.execute(shellProgram, new String[] { })); KThread.currentThread().finish(); }
/** * Returns the current process. * * @return the current process, or <tt>null</tt> if no process is current. */ public static UserProcess currentProcess() { if (!(KThread.currentThread() instanceof UThread)) return null; return ((UThread) KThread.currentThread()).process; }