/**
     * 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();
    }
Example #3
0
  /**
   * Handle a user exception. Called by <tt>UserKernel.exceptionHandler()</tt> . The <i>cause</i>
   * argument identifies which exception occurred; see the <tt>Processor.exceptionZZZ</tt>
   * constants.
   *
   * @param cause the user exception that occurred.
   */
  public void handleException(int cause) {
    Processor processor = Machine.processor();

    switch (cause) {
      case Processor.exceptionTLBMiss:
        handleTLBMiss();
        break;
      default:
        super.handleException(cause);
        break;
    }
  }
Example #4
0
  /*
   * if the input arguments are negative, return -1
   * @return the child process Id
   */
  private int handleExec(int file, int argc, int argv) {
    if (file < 0 || argc < 0 || argv < 0) {
      return -1;
    }
    String fileName = readVirtualMemoryString(file, 256);

    if (fileName == null) {
      return -1;
    }

    String args[] = new String[argc];

    int byteReceived, argAddress;
    byte temp[] = new byte[4];
    for (int i = 0; i < argc; i++) {
      byteReceived = readVirtualMemory(argv + i * 4, temp);
      if (byteReceived != 4) {
        return -1;
      }

      argAddress = Lib.bytesToInt(temp, 0);
      args[i] = readVirtualMemoryString(argAddress, 256);

      if (args[i] == null) {
        return -1;
      }
    }
    UserProcess child = UserProcess.newUserProcess();
    childProcess newProcessData = new childProcess(child);
    child.myChildProcess = newProcessData;

    if (child.execute(fileName, args)) {
      map.put(child.process_id, newProcessData);
      return child.process_id;
    }

    return -1;
  }