public void MEC2(Process process) throws IOException {
    process.setState("Running");
    int clock = 0;

    // while loop to execute instructions
    while (true) {
      clock++;
      if (isTermenated()) {
        // if the process terminates, then break the method
        process.setState("Terminated");
        if (!IOBoundJob.isExist(process)) CPUBoundJob.enqueue(process, 0);
        Statistic.NUMBER_OF_EXECUTED_PROCESSES++;
        file.writeProcess(process);
        RAM.loadProcessFromHardDisk();
        return;
      }
      if (isInterrupted(process)) {
        // if the process interrupted, then return the process to the Ready Queue (RAM)
        process.setState("Ready");
        process.setRemainingTime(process.getRemainingTime() - clock);
        RAM.returnProcess(process);
        return;
      }
    }
  }
示例#2
0
  private static void XGA_DrawPoint(/*Bitu*/ int x, /*Bitu*/ int y, /*Bitu*/ int c) {
    if ((xga.curcommand & 0x1) == 0) return;
    if ((xga.curcommand & 0x10) == 0) return;

    if (x < xga.scissors.x1) return;
    if (x > xga.scissors.x2) return;
    if (y < xga.scissors.y1) return;
    if (y > xga.scissors.y2) return;

    /*Bit32u*/ int memaddr = (y * XGA_SCREEN_WIDTH()) + x;
    /* Need to zero out all unused bits in modes that have any (15-bit or "32"-bit -- the last
    one is actually 24-bit. Without this step there may be some graphics corruption (mainly,
    during windows dragging. */
    switch (XGA_COLOR_MODE()) {
      case VGA.M_LIN8:
        if ((memaddr >= VGA.vga.vmemsize)) break;
        RAM.writeb(VGA.vga.mem.linear + memaddr, (short) c);
        break;
      case VGA.M_LIN15:
        if ((memaddr * 2 >= VGA.vga.vmemsize)) break;
        RAM.writew(VGA.vga.mem.linear + memaddr * 2, c & 0x7fff);
        break;
      case VGA.M_LIN16:
        if ((memaddr * 2 >= VGA.vga.vmemsize)) break;
        RAM.writew(VGA.vga.mem.linear + memaddr * 2, c & 0xffff);
        break;
      case VGA.M_LIN32:
        if ((memaddr * 4 >= VGA.vga.vmemsize)) break;
        RAM.writed(VGA.vga.mem.linear + memaddr * 4, c);
        break;
      default:
        break;
    }
  }
  @Test
  public void testVetoScaling() {
    control.replay();

    int maxScore = VetoType.INSUFFICIENT_RESOURCES.getScore();
    assertEquals((int) (maxScore * 1.0 / CPU.getRange()), CPU.veto(1).getScore());
    assertEquals(maxScore, CPU.veto(CPU.getRange() * 10).getScore());
    assertEquals((int) (maxScore * 2.0 / RAM.getRange()), RAM.veto(2).getScore());
    assertEquals((int) (maxScore * 200.0 / DISK.getRange()), DISK.veto(200).getScore());
  }
  @Test
  public void testInsufficientResources() {
    control.replay();

    IHostAttributes hostA = hostAttributes(HOST_A, host(HOST_A), rack(RACK_A));
    assertVetoes(
        makeTask(DEFAULT_CPUS + 1, DEFAULT_RAM + 1, DEFAULT_DISK + 1),
        hostA,
        CPU.veto(1),
        DISK.veto(1),
        RAM.veto(1));
    assertVetoes(makeTask(DEFAULT_CPUS + 1, DEFAULT_RAM, DEFAULT_DISK), hostA, CPU.veto(1));
    assertVetoes(makeTask(DEFAULT_CPUS, DEFAULT_RAM + 1, DEFAULT_DISK), hostA, RAM.veto(1));
    assertVetoes(makeTask(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK + 1), hostA, DISK.veto(1));
  }
示例#5
0
文件: CPU.java 项目: jgonis/TEOC
  /** Restarts the program from the beginning. */
  public void initProgram() {
    A.reset();
    A.setUpdatePointer(true);
    A.setUpdatePointer(false);

    D.reset();
    PC.reset();
    alu.reset();
    M.clearScreen();
    M.hideSelect();
    M.hideHighlight();
    rom.hideSelect();
    rom.hideHighlight();
    time = 0;
  }
示例#6
0
文件: CPU.java 项目: jgonis/TEOC
  // Sets the registers with the alu's output according to
  // the given instruction
  // Throws ProgramException if destination contains M and A contains
  // an illegal address.
  protected void setDestination(short instruction) throws ProgramException {
    boolean destA = (instruction & 0x0020) > 0;
    boolean destD = (instruction & 0x0010) > 0;
    boolean destM = (instruction & 0x0008) > 0;

    if (destM) {
      int address = A.get();
      if ((address < 0) || (address >= M.getSize())) {
        throw new ProgramException(
            "At line "
                + PC.get()
                + ": Destination is M but A="
                + address
                + " is an illegal memory address.");
      }
      A.setUpdatePointer(true);
      bus.send(alu, 2, M, address);
      A.setUpdatePointer(false);
    }
    if (destA) {
      bus.send(alu, 2, A, 0);
    }
    if (destD) {
      bus.send(alu, 2, D, 0);
    }
  }
示例#7
0
 /** Executa o programa carregado */
 public void run(int numCiclos) {
   ram.reset();
   try {
     for (int i = 0; i < numCiclos; i++) step();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#8
0
  private static /*Bitu*/ int XGA_GetPoint(/*Bitu*/ int x, /*Bitu*/ int y) {
    /*Bit32u*/ int memaddr = (y * XGA_SCREEN_WIDTH()) + x;

    switch (XGA_COLOR_MODE()) {
      case VGA.M_LIN8:
        if ((memaddr >= VGA.vga.vmemsize)) break;
        return RAM.readb(VGA.vga.mem.linear + memaddr);
      case VGA.M_LIN15:
      case VGA.M_LIN16:
        if ((memaddr * 2 >= VGA.vga.vmemsize)) break;
        return RAM.readw(VGA.vga.mem.linear + memaddr * 2);
      case VGA.M_LIN32:
        if ((memaddr * 4 >= VGA.vga.vmemsize)) break;
        return RAM.readd(VGA.vga.mem.linear + memaddr * 4);
      default:
        break;
    }
    return 0;
  }
示例#9
0
文件: CPU.java 项目: jgonis/TEOC
  // computes the exp part of the given instruction.
  // The result will be at the alu's output.
  // Throws ProgramException if the calculation involves M and A contains
  // an illegal address.
  protected void computeExp(short instruction) throws ProgramException {
    boolean indirect = (instruction & 0x1000) > 0;
    boolean zd = (instruction & 0x0800) > 0;
    boolean nd = (instruction & 0x0400) > 0;
    boolean zm = (instruction & 0x0200) > 0;
    boolean nm = (instruction & 0x0100) > 0;
    boolean f = (instruction & 0x0080) > 0;
    boolean no = (instruction & 0x0040) > 0;

    try {
      alu.setCommand(
          assemblerTranslator.getExpByCode((short) (instruction & 0xffc0)), zd, nd, zm, nm, f, no);
    } catch (AssemblerException ae) {
    }

    bus.send(D, 0, alu, 0); // sends D to input0 of the alu

    // sends A or M[A] to input1 of the alu
    if (indirect) {
      int address = A.get();
      if ((address < 0) || (address >= M.getSize())) {
        throw new ProgramException(
            "At line "
                + PC.get()
                + ": Expression involves M but A="
                + address
                + " is an illegal memory address.");
      }
      A.setUpdatePointer(true);
      bus.send(M, address, alu, 1);
      A.setUpdatePointer(false);
    } else {
      bus.send(A, 0, alu, 1);
    }

    alu.compute();
  }
示例#10
0
 public void step() {
   System.out.println("Passo");
   Instrucao instr = flash.programa.elementAt(ram.getPCL());
   instr.run(ram, cpu);
 }
示例#11
0
  public static void bootFromURI(
      ARMv5 cpu, RAM ramMain, String kimage, String initrd, String cmdline) {
    byte[] cmdlb = cmdline.getBytes();
    // +1: need null char at the end of line
    byte[] cmdalign = new byte[(cmdlb.length + 1 + 3) & ~0x3];
    System.arraycopy(cmdlb, 0, cmdalign, 0, cmdlb.length);

    final int addrRAM = 0x00000000;
    final int addrAtagsStart = addrRAM + 0x800000;
    int addrAtags = addrAtagsStart;
    final int addrImage = addrRAM + 0x00008000;
    int sizeImage = 0;
    final int addrInitrd = addrRAM + 0x00810000;
    int sizeInitrd = 0;
    boolean initrdExist = !initrd.equals("");

    // tentative boot loader for ARM Linux
    try {
      // load Image file
      sizeImage = loadURIResource(new URI(kimage), cpu, addrImage);
      // load Initrd/InitramFS file
      if (initrdExist) {
        sizeInitrd = loadURIResource(new URI(initrd), cpu, addrInitrd);
      }
    } catch (URISyntaxException e) {
      e.printStackTrace(System.err);
      return;
    }

    // report address mapping
    System.out.printf(
        "Address mapping:\n"
            + "  RAM   : 0x%08x\n"
            + "  Kernel: 0x%08x - 0x%08x\n"
            + "  Initrd: 0x%08x - 0x%08x\n"
            + "  ATAGS : 0x%08x - 0x%08x\n",
        addrRAM,
        addrImage,
        addrImage + sizeImage - 1,
        addrInitrd,
        addrInitrd + sizeInitrd - 1,
        addrAtags,
        addrAtags + 4096 - 1);

    // r0: 0
    cpu.setReg(0, 0);

    // r1: machine type
    // ARM-Versatile PB
    cpu.setReg(1, 0x00000183);
    // ARM-Versatile AB
    // cpu.setReg(1, 0x0000025e);

    // r2: ATAGS pointer.
    cpu.setReg(2, addrAtags);
    {
      // ATAG_CORE, size, tag, [flags, pagesize, rootdev]
      cpu.write32_a32(addrAtags + 0x00, 0x00000005);
      cpu.write32_a32(addrAtags + 0x04, ATAG_CORE);
      // bit 0: read only
      cpu.write32(addrAtags + 0x08, 0x00000001);
      cpu.write32(addrAtags + 0x0c, 0x00001000);
      cpu.write32(addrAtags + 0x10, 0x00000000);
      addrAtags += 0x14;

      // ATAG_MEM, size, tag, size, start
      cpu.write32_a32(addrAtags + 0x00, 0x00000004);
      cpu.write32_a32(addrAtags + 0x04, ATAG_MEM);
      cpu.write32_a32(addrAtags + 0x08, ramMain.getSize());
      cpu.write32_a32(addrAtags + 0x0c, addrRAM);
      addrAtags += 0x10;

      // ATAG_INITRD2, size, tag, size, start
      if (initrdExist) {
        cpu.write32_a32(addrAtags + 0x00, 0x00000004);
        cpu.write32_a32(addrAtags + 0x04, ATAG_INITRD2);
        cpu.write32_a32(addrAtags + 0x08, addrInitrd);
        cpu.write32_a32(addrAtags + 0x0c, sizeInitrd);
        addrAtags += 0x10;
      }

      // ATAG_CMDLINE
      cpu.write32_a32(addrAtags + 0x00, 0x00000002 + cmdalign.length / 4);
      cpu.write32_a32(addrAtags + 0x04, ATAG_CMDLINE);
      for (int i = 0; i < cmdalign.length; i++) {
        cpu.write8_a32(addrAtags + 0x08 + i, cmdalign[i]);
      }
      addrAtags += 0x08 + cmdalign.length;

      // ATAG_SERIAL, size, tag, low, high
      cpu.write32_a32(addrAtags + 0x00, 0x00000004);
      cpu.write32_a32(addrAtags + 0x04, ATAG_SERIAL);
      cpu.write32_a32(addrAtags + 0x08, 0x00000020);
      cpu.write32_a32(addrAtags + 0x0c, 0x00000030);
      addrAtags += 0x10;

      // ATAG_REVISION, size, tag, rev
      cpu.write32_a32(addrAtags + 0x00, 0x00000003);
      cpu.write32_a32(addrAtags + 0x04, ATAG_REVISION);
      cpu.write32_a32(addrAtags + 0x08, 0x00000010);
      addrAtags += 0x0c;

      // ATAG_NONE, size, tag
      // It is unique in that its size field in the header
      // should be set to 0 (not 2).
      cpu.write32_a32(addrAtags + 0x00, 0x00000000);
      cpu.write32_a32(addrAtags + 0x04, ATAG_NONE);
      addrAtags += 0x08;
    }

    // pc: entry of stext
    cpu.setPC(addrImage);
    cpu.setJumped(false);
  }