예제 #1
0
  /**
   * Initialize the processor's registers in preparation for running the program loaded into this
   * process. Set the PC register to point at the start function, set the stack pointer register to
   * point at the top of the stack, set the A0 and A1 registers to argc and argv, respectively, and
   * initialize all other registers to 0.
   */
  public void initRegisters() {
    Processor processor = Machine.processor();

    // by default, everything's 0
    for (int i = 0; i < processor.numUserRegisters; i++) processor.writeRegister(i, 0);

    // initialize PC and SP according
    processor.writeRegister(Processor.regPC, initialPC);
    processor.writeRegister(Processor.regSP, initialSP);

    // initialize the first two argument registers to argc and argv
    processor.writeRegister(Processor.regA0, argc);
    processor.writeRegister(Processor.regA1, argv);
  }
예제 #2
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.exceptionSyscall:
        int result =
            handleSyscall(
                processor.readRegister(Processor.regV0),
                processor.readRegister(Processor.regA0),
                processor.readRegister(Processor.regA1),
                processor.readRegister(Processor.regA2),
                processor.readRegister(Processor.regA3));
        processor.writeRegister(Processor.regV0, result);
        processor.advancePC();
        break;

      default:
        Lib.debug(dbgProcess, "Unexpected exception: " + Processor.exceptionNames[cause]);
        handleExit(-1);
        Lib.assertNotReached("Unexpected exception");
    }
  }
예제 #3
0
 public void handleTLBMiss() {
   int vaddr = Machine.processor().readRegister(Processor.regBadVAddr);
   int vpn = Processor.pageFromAddress(vaddr);
   allocatePage(vpn);
 }