Beispiel #1
0
  public void func20() {
    // this function change pc to selected program (program pid must saved in v0)
    modeBit = false;
    enableintrrupt = true;
    interruptBit = false;
    System.out.println("func20");
    HashMap<Integer, SegmentDefragmenter> programsHashmap = aa.getPrograms();
    int selected = getRegfile().getRegfile(2);
    defaultRegisters = getRegfile();
    if (programs != null) {
      for (PCB program : programs) {
        if (program.getPid() == selected) {
          program.setSchedulingState(PCB.EXECUTE_STATE);
          stage_id.regfile = program.getRegs();
          currentProgram = program;
        }
      }
    }

    SegmentDefragmenter sd = programsHashmap.get(selected);
    String startadd = sd.getCode_seg_start_address();
    System.out.println("++++++++++++++++++++++++++++++++++++");
    System.out.println("start address said : " + startadd);
    System.out.println("ra said: " + Integer.toHexString(stage_id.regfile.getRegfile(31) * 4));
    System.out.println("++++++++++++++++++++++++++++++++++++");

    stage_if.setPC(Integer.parseInt(startadd, 16) / 4);

    lineOfInstructions = Integer.parseInt(startadd, 16) + sd.getCode_seg().size();
    modeBit = false;
    HashMap<Integer, Instruction> cache = new HashMap<Integer, Instruction>();

    int physicalAddress = Hex2Decimal(startadd);
    baseAddress = physicalAddress;
    sd.setCode_seg_start_address(parse8DigitHex(physicalAddress));
    for (int i = 0; i < sd.getCode_seg().size(); i++) {
      cache.put(
          stage_if.getPC() + i,
          new Instruction(sd.getCode_seg().get(i), parse8DigitHex(physicalAddress)));
      physicalAddress++;
    }
    stage_if.setIns_cache(cache);
    if (Integer.parseInt(Integer.toString(currentProgram.getPC(), 8)) >= 400000) {
      stage_if.setPC(currentProgram.getPC() * 4 / 4);
    } else {
      stage_if.setPC(Integer.parseInt(startadd, 16) / 4);
    }
  }
Beispiel #2
0
 void Fix_regfile_table(JTable regTable) {
   Register_file regfile = stage_id.getRegfile();
   for (int n = 0; n < 32; n++) {
     int c = 0;
     int r = n % 8;
     if (n <= 7) {
       c = 0;
     } else if (n <= 15) {
       c = 1;
     } else if (n <= 23) {
       c = 2;
     } else {
       c = 3;
     }
     if (n == 31)
       regTable.setValueAt(Integer.toHexString(regfile.getRegfile(n) * 4), r, 2 * c + 1);
     else regTable.setValueAt(regfile.getRegfile(n), r, 2 * c + 1);
   }
 }
Beispiel #3
0
 public String get_reg_monitor() {
   return stage_id.getRegfile().print();
 }
Beispiel #4
0
 public Register_file getRegisterFile() {
   return stage_id.getRegfile();
 }
Beispiel #5
0
  public boolean runSingleSycle() {
    if (currentLineOfInstructions < lineOfInstructions) {
      stage_if.action(modeBit);
      stage_id.action(modeBit);
      stage_exe.action(modeBit);
      if (programs != null) {
        for (PCB program : programs) {
          program.waitAction();
        }
      }
      if (stage_exe.isJump()) { // PC & 0xf0000000
        String pc4bit = "0000";
        String func_sign = "0111111111111111111";
        String func_first = pc4bit.concat(func_sign);

        try {
          String func_str =
              stage_exe
                  .getJ_pc()
                  .substring(stage_exe.getJ_pc().length() - 9, stage_exe.getJ_pc().length() - 2);
          func_str = String.valueOf(Integer.parseInt(func_str, 2));
          Method m = Computer.class.getMethod("func" + func_str);
          m.invoke(this);
        } catch (NoSuchMethodException e) {
          int old_pc = getPC();
          int pcbits = old_pc / (2 ^ 28);
          // not added pc to sign but it's ready for use then
          int offset = Integer.parseInt(stage_exe.getJ_pc(), 2) / 4;
          stage_if.setPC(offset);
          if (stage_exe.isRegwrite()) { // it's means have jal (our agreement)
            stage_exe.getExemem().setALU_result(old_pc); // this old_pc \
            // should not increment because it incremented in IF stage
            stage_exe.getExemem().setWrite_Register(31);
            // use mips structure to save new_pc in ra (not assign directly)
          }
        } catch (Exception e) {

        }
      }
      if (stage_exe.isJumpReg()) {
        int pc = stage_exe.getIdexe().getRS_DATA();
        stage_exe.getExemem().setControlBits("0000000000100");
        stage_if.setPC(pc);
      }
      if (stage_exe.isBranch()) {
        if (exemem.getALU_result() == 0 && !stage_exe.isNot()) {
          int offset;

          offset = Integer.parseInt(stage_exe.getIdexe().getSignExt(), 2);
          stage_if.setPC(stage_if.getPC() + offset);
        }
        if (exemem.getALU_result() != 0 && stage_exe.isNot()) {
          int offset = 0;
          String address = stage_exe.getIdexe().getSignExt();
          if (address.charAt(0) == '1') { // must use 2'scompliment method for negative numbers
            boolean flag = true;
            String newAddress = "";
            for (int i = address.length() - 1; i >= 0; i--) {
              if (flag) {
                char ch = address.charAt(i);
                newAddress = ch + newAddress;
                if (ch == '1') {
                  flag = false;
                }
              } else {
                char ch = address.charAt(i);

                if (ch == '1') {
                  newAddress = '0' + newAddress;
                }
                if (ch == '0') {
                  newAddress = '1' + newAddress;
                }
              }
              offset = Integer.parseInt(newAddress, 2);
              offset = -1 * offset;
            }
          } else {
            offset = Integer.parseInt(stage_exe.getIdexe().getSignExt(), 2);
          }

          stage_if.setPC(stage_if.getPC() + offset);
        }
      }
      if (stage_exe.isSyscall()) {
        System.out.println("here is Syscall");
        enableintrrupt = false;
        modeBit = true;
        interruptBit = true;
        interruptReason = 1; // reason 1 for syscall in program
      }
      stage_mem.action(modeBit, aa);
      stage_wb.action(modeBit);
      currentLineOfInstructions = stage_if.getPC();
      timer.action();
      if (timer.check_timer() && enableintrrupt) {
        interruptReason = 2;
        interruptBit = true;
        modeBit = true; // means in kernel Mode now
      }
      if (interruptBit) {
        int syscallReason = getRegisterFile().getRegfile(2);
        getRegisterFile().setReg(27, interruptReason);
        if (currentProgram != null) {
          currentProgram.setPC(stage_if.getPC());
        }
        switch (interruptReason) {
          case 1:
            switch (syscallReason) {
              case 10:
                System.out.println("exit");
                defaultRegisters.setReg(27, interruptReason);
                defaultRegisters.setReg(2, 10);
                break;
              case 20:
                defaultRegisters.setReg(27, interruptReason);
                defaultRegisters.setReg(2, 20);
                break;
              case 30:
                int loc = getRegisterFile().getRegfile(4);
                int ch = getRegisterFile().getRegfile(5);
                int col = getRegisterFile().getRegfile(6);
                me.changeMonitor(loc, ch, col);
            }
            ;
          case 2:
            // for timer intrupt
            break;

          case 3:
            // for exception
            break;
        }
        stage_if.setPC(0);
        currentLineOfInstructions = 0;
        lineOfInstructions = stage_if.getIns_mem().size();
        interruptBit = false;
        stage_id.regfile = defaultRegisters;
      }
      return true;
    } else {
      System.out.println("end of file ...");
      setRunable(true);
      return false;
    }
  }