Exemple #1
0
  /** Sets the monitor power state. */
  final void setDpms(DpmsState state) {
    int crtc_ext_cntl = vgaIO.getReg32(CRTC_EXT_CNTL);
    int lvds_gen_cntl = vgaIO.getReg32(LVDS_GEN_CNTL);
    // log.debug("Get LVDS_GEN_CTRL 0x" + NumberUtils.hex(lvds_gen_cntl));

    crtc_ext_cntl &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | CRTC_VSYNC_DIS);
    lvds_gen_cntl &= ~(LVDS_DISPLAY_DIS | LVDS_ON);

    if (state.isDisplay()) {
      lvds_gen_cntl |= (LVDS_BLON | LVDS_ON);
    } else {
      crtc_ext_cntl |= CRTC_DISPLAY_DIS;
      lvds_gen_cntl |= LVDS_DISPLAY_DIS;
    }
    if (!state.isHsync()) {
      crtc_ext_cntl |= CRTC_HSYNC_DIS;
    }
    if (!state.isVsync()) {
      crtc_ext_cntl |= CRTC_VSYNC_DIS;
    }

    if (fbinfo.getDviDispType() == MonitorType.LCD) {
      vgaIO.setReg32(LVDS_GEN_CNTL, lvds_gen_cntl);
      log.debug("Set LVDS_GEN_CTRL to 0x" + NumberUtils.hex(lvds_gen_cntl));
    } else {
      vgaIO.setReg32(CRTC_EXT_CNTL, crtc_ext_cntl);
      log.debug("Set CRTC_EXT_CNTL to 0x" + NumberUtils.hex(crtc_ext_cntl));
    }
  }
Exemple #2
0
  /**
   * Look for the ROM in the ISA region.
   *
   * @param rm
   * @return The claimed ROM region, or null if not found.
   */
  private final MemoryResource findRom(final ResourceOwner owner, final ResourceManager rm)
      throws ResourceNotFreeException {
    final MemoryScanner scanner =
        AccessController.doPrivileged(
            new PrivilegedAction<MemoryScanner>() {

              public MemoryScanner run() {
                return rm.getMemoryScanner();
              }
            });

    final Address start = Address.fromIntZeroExtend(0xC0000);
    final Address end = Address.fromIntZeroExtend(0xF0000);
    final int size = end.toWord().sub(start.toWord()).toInt();
    final int stepSize = 0x1000;
    int offset = 0;
    while (offset < size) {
      final Address romAddr;
      // Search for BIOS expansion
      romAddr =
          scanner.findInt8Array(
              start.add(offset),
              size - offset,
              BIOS_ROM_SIGNATURE,
              0,
              BIOS_ROM_SIGNATURE.length,
              stepSize);
      if (romAddr == null) {
        return null;
      } else {
        offset = romAddr.toWord().sub(start.toWord()).toInt() + stepSize;
      }
      // Search for ATI signature
      final Address atiSigAddr;
      atiSigAddr =
          scanner.findInt8Array(romAddr, 128, ATI_ROM_SIGNATURE, 0, ATI_ROM_SIGNATURE.length, 1);
      if (atiSigAddr == null) {
        continue;
      }

      // We found it
      // Claim a small region, so we can read the size.
      MemoryResource mem;
      mem = rm.claimMemoryResource(owner, romAddr, 4, ResourceManager.MEMMODE_NORMAL);
      final int blocks = mem.getByte(2) & 0xFF;
      final int romSize = blocks * 512;
      mem.release();

      log.info(
          "Found ATI ROM at 0x"
              + NumberUtils.hex(romAddr.toInt())
              + " size="
              + NumberUtils.toBinaryByte(romSize));
      return rm.claimMemoryResource(owner, romAddr, romSize, ResourceManager.MEMMODE_NORMAL);
    }

    return null;
  }
Exemple #3
0
 public void print() {
   System.out.println("  ----- Reloc -----");
   System.out.println("  r_address     : " + Long.toHexString(r_address));
   System.out.println("  r_symbol      : " + getSymbol());
   System.out.println("  r_type        : " + getTypeName());
   System.out.println("  r_info        : " + NumberUtils.hex(r_info));
   if (hasAddEnd()) {
     System.out.println("  r_addend      : " + NumberUtils.hex(getAddEnd()));
   }
 }
Exemple #4
0
  public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append("id=0x");
    sb.append(NumberUtils.hex(getId(), 2));

    return sb.toString();
  }
Exemple #5
0
 public String toString() {
   StringBuilder str = new StringBuilder();
   str.append("Status  : ");
   str.append(NumberUtils.hex(this.getStatus()));
   str.append('\n');
   str.append("Command : ");
   str.append(NumberUtils.hex(this.getCommand()));
   str.append('\n');
   str.append("Link    : ");
   str.append(NumberUtils.hex(this.getLink()));
   str.append('\n');
   str.append("Count   : ");
   str.append(NumberUtils.hex(this.getCount()));
   str.append('\n');
   return str.toString();
 }
 /** @see java.lang.Object#toString() */
 public String toString() {
   StringBuilder b = new StringBuilder(32);
   b.append('[').append(getBootIndicator() ? 'A' : ' ').append(' ');
   b.append(NumberUtils.hex(getSystemIndicator().getCode(), 2)).append(' ');
   b.append("s:").append(getStartLba()).append(' ');
   b.append("e:").append(getStartLba() + getNrSectors() - 1).append(']');
   return b.toString();
 }
 public String dump() {
   StringBuilder b = new StringBuilder(64);
   for (int i = 0; i < 16; i++) {
     b.append(NumberUtils.hex(LittleEndian.getUInt8(bs, ofs + i), 2));
     b.append(' ');
   }
   return b.toString();
 }
Exemple #8
0
 /**
  * Block the current thread until the status of the controller masked by the given mask equals
  * value.
  */
 public void waitUntilStatus(int mask, int value, long timeout, String message)
     throws TimeoutException {
   while ((getAltStatusReg() & mask) != value) {
     final int state = getAltStatusReg();
     if ((state & ST_ERROR) != 0) {
       throw new TimeoutException("IDE error " + NumberUtils.hex(getErrorReg(), 2));
     }
     if (timeout <= 0) {
       throw new TimeoutException((message != null) ? message : "Timeout in waitUntilStatus");
     }
     TimeUtils.sleep(10);
     timeout -= 10;
   }
 }
 /**
  * Deliver a packet to the corresponding protocol
  *
  * @param hdr
  * @param skbuf
  */
 private void deliver(IPv4Header hdr, SocketBuffer skbuf) throws SocketException {
   final IPv4Protocol protocol;
   try {
     protocol = getProtocol(hdr.getProtocol());
     protocol.receive(skbuf);
   } catch (NoSuchProtocolException ex) {
     log.debug(
         "Found unknown IP src="
             + hdr.getSource()
             + ", dst="
             + hdr.getDestination()
             + ", prot=0x"
             + NumberUtils.hex(hdr.getProtocol(), 2));
   }
 }
    /**
     * (non-Javadoc)
     *
     * @see org.jnode.driver.bus.scsi.SCSIDevice#executeCommand(org.jnode.driver.bus.scsi.CDB,
     *     byte[], int, long)
     */
    public final int executeCommand(CDB cdb, byte[] data, int dataOffset, long timeout)
        throws SCSIException, TimeoutException, InterruptedException {
      final IDEDevice dev = (IDEDevice) getDevice();
      final IDEBus bus = (IDEBus) dev.getBus();

      final IDEPacketCommand cmd =
          new IDEPacketCommand(
              dev.isPrimary(), dev.isMaster(), cdb.toByteArray(), data, dataOffset);
      bus.executeAndWait(cmd, timeout);

      if (!cmd.isFinished()) {
        throw new TimeoutException("Timeout in SCSI command");
      } else if (cmd.hasError()) {
        throw new SCSIException("Command error 0x" + NumberUtils.hex(cmd.getError(), 2));
      } else {
        return cmd.getDataTransfered();
      }
    }
Exemple #11
0
  /**
   * Gets all overflow extents that match the given key.
   *
   * @param key the key to match.
   * @param nodeNumber the current node to read from.
   * @return the overflow extents.
   * @throws IOException if an error occurs.
   */
  public final ExtentDescriptor[] getOverflowExtents(final ExtentKey key, long nodeNumber)
      throws IOException {
    try {
      long currentNodeNumber = nodeNumber;
      int nodeSize = bthr.getNodeSize();
      ByteBuffer nodeData = ByteBuffer.allocate(nodeSize);
      extentFile.read(fs, (currentNodeNumber * nodeSize), nodeData);
      byte[] data = nodeData.array();
      NodeDescriptor nd = new NodeDescriptor(data, 0);

      if (nd.isIndexNode()) {
        ExtentNode extentNode = new ExtentNode(data, nodeSize);

        IndexRecord[] records = extentNode.findAll(key);
        List<ExtentDescriptor> overflowExtents = new LinkedList<ExtentDescriptor>();
        for (IndexRecord record : records) {
          Collections.addAll(overflowExtents, getOverflowExtents(key, record.getIndex()));
        }

        return overflowExtents.toArray(new ExtentDescriptor[overflowExtents.size()]);

      } else if (nd.isLeafNode()) {
        ExtentLeafNode node = new ExtentLeafNode(nodeData.array(), nodeSize);
        return node.getOverflowExtents(key);

      } else {
        log.info(
            String.format(
                "Node %d wasn't a leaf or index: %s\n%s", nodeNumber, nd, NumberUtils.hex(data)));
        return new ExtentDescriptor[0];
      }

    } catch (Exception e) {
      e.printStackTrace();
      throw new IOException(e);
    }
  }
Exemple #12
0
  /**
   * @param driver
   * @param architecture
   * @param model
   * @param device
   */
  public RadeonCore(RadeonDriver driver, int architecture, String model, PCIDevice device)
      throws ResourceNotFreeException, DriverException {
    this.driver = driver;
    this.fbinfo = new FBInfo(architecture);

    final PCIHeaderType0 pciCfg = device.getConfig().asHeaderType0();
    final PCIBaseAddress ioAddr = pciCfg.getBaseAddresses()[2];
    final PCIBaseAddress fbAddr = pciCfg.getBaseAddresses()[0];
    final PCIRomAddress romAddr = pciCfg.getRomAddress();
    log.info("Found ATI " + model + ", chipset 0x" + NumberUtils.hex(pciCfg.getRevision()));
    try {
      final ResourceManager rm = InitialNaming.lookup(ResourceManager.NAME);
      final int ioBase = (int) ioAddr.getMemoryBase();
      final int ioSize = ioAddr.getSize();
      final int fbBase = (int) fbAddr.getMemoryBase() /* & 0xFF800000 */;

      // Map Memory Mapped IO
      this.mmio =
          rm.claimMemoryResource(
              device, Address.fromIntZeroExtend(ioBase), ioSize, ResourceManager.MEMMODE_NORMAL);
      this.vgaIO = new RadeonVgaIO(mmio);
      final int memSize = readMemorySize();
      log.info("Memory size " + NumberUtils.toBinaryByte(memSize));
      this.accel = new RadeonAcceleration(vgaIO);

      // Map Device RAM
      this.deviceRam =
          rm.claimMemoryResource(
              device, Address.fromIntZeroExtend(fbBase), memSize, ResourceManager.MEMMODE_NORMAL);
      vgaIO.setVideoRam(deviceRam);

      // Find ROM
      MemoryResource rom = null;
      if (romAddr != null) {
        romAddr.setEnabled(true);
        if (romAddr.isEnabled()) {
          rom =
              rm.claimMemoryResource(
                  device,
                  Address.fromIntZeroExtend(romAddr.getRomBase()),
                  romAddr.getSize(),
                  ResourceManager.MEMMODE_NORMAL);
          if (!verifyBiosSignature(rom)) {
            log.info("Signature mismatch");
            rom.release();
            rom = null;
          }
        } else {
          log.debug("Failed to enabled expansion ROM");
        }
      }
      if (rom == null) {
        // Use the ISA regions rom instead
        rom = findRom(device, rm);
      }
      this.rom = rom;

      log.debug(
          "Found ATI "
              + model
              + ", FB at 0x"
              + NumberUtils.hex(fbBase)
              + "s0x"
              + NumberUtils.hex(memSize)
              + ", MMIO at 0x"
              + NumberUtils.hex(ioBase)
              + ", ROM "
              + pciCfg.getRomAddress());

      fbinfo.readMonitorInfo(vgaIO);
      if (this.rom != null) {
        log.info("ROM[0-3] 0x" + NumberUtils.hex(rom.getInt(0)));
        // Read monitor information
        fbinfo.readFPIInfo(rom);
      }

    } catch (NameNotFoundException ex) {
      throw new ResourceNotFreeException(ex);
    }

    // Read the current state of the device
    this.oldVgaState = new RadeonVgaState(architecture, fbinfo.hasCRTC2, vgaIO);
    this.currentState = new RadeonVgaState(architecture, fbinfo.hasCRTC2, vgaIO);

    // Claim the first 128K for VGA only
    deviceRam.claimChildResource(0, 128 * 1024, false);

    // Allocate the hardware cursor
    this.hwCursor = new RadeonHardwareCursor(this, vgaIO);
  }
Exemple #13
0
  /**
   * Open the given configuration
   *
   * @param config
   */
  final RadeonSurface open(RadeonConfiguration config) throws ResourceNotFreeException {

    // Get the best matching config
    config = fbinfo.getBestConfiguration(config);
    log.debug("BestConfig:" + config);

    // Calculate new configuration
    final DisplayMode mode = config.getDisplayMode();
    final int width = mode.getWidth();
    final int height = mode.getHeight();
    final int pixels = width * height;
    final int bitsPerPixel = config.getBitsPerPixel();
    final int bytesPerLine = config.getBytesPerLine();
    final int bytesPerScreen = bytesPerLine * height;
    log.debug("PLLInfo:" + fbinfo.getPllInfo());
    currentState.calcForConfiguration(config, vgaIO, fbinfo);

    // Disable video interrupts
    vgaIO.disableIRQ();

    // Allocate the screen memory
    final MemoryResource screen = claimDeviceMemory(bytesPerScreen, 4 * 1024);
    // final MemoryResource screen = deviceRam;
    log.debug(
        "Screen at 0x"
            + NumberUtils.hex(screen.getOffset().toInt())
            + ", size 0x"
            + NumberUtils.hex(screen.getSize().toInt()));

    // if (true) { throw new ResourceNotFreeException("TEST"); }

    // Save the current state
    oldVgaState.saveFromVGA(vgaIO);
    log.debug("oldState:" + oldVgaState);

    // Turn off the screen
    final DpmsState dpmsState = getDpms();
    setDpms(DpmsState.OFF);

    try {
      // Set the new configuration
      currentState.restoreToVGA(vgaIO);
      log.debug("NewState: " + currentState);
      vgaIO.setReg32(CRTC_OFFSET, (int) screen.getOffset().toInt());
      if (fbinfo.hasCRTC2) {
        vgaIO.setReg32(CRTC2_OFFSET, (int) screen.getOffset().toInt());
      }

      // Set the 8-bit palette
      setPalette(1.0f);

      // Create the graphics helper & clear the screen
      final BitmapGraphics bitmapGraphics;
      switch (bitsPerPixel) {
        case 8:
          bitmapGraphics =
              BitmapGraphics.create8bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setByte(0, (byte) 0, pixels);
          break;
        case 16:
          bitmapGraphics =
              BitmapGraphics.create16bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setShort(0, (byte) 0, pixels);
          break;
        case 24:
          bitmapGraphics =
              BitmapGraphics.create24bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setInt24(0, 0, pixels);
          break;
        case 32:
          bitmapGraphics =
              BitmapGraphics.create32bppInstance(screen, width, height, bytesPerLine, 0);
          screen.setInt(0, 0, pixels);
          break;
        default:
          throw new IllegalArgumentException("Invalid bits per pixel " + bitsPerPixel);
      }
      return new RadeonSurface(this, config, bitmapGraphics, screen, accel);
    } finally {
      // Turn the screen back on
      setDpms(dpmsState);
    }
  }