예제 #1
0
  public static void initEnv() throws NamingException {
    if (initialized) {
      return;
    }
    InitialNaming.setNameSpace(new BasicNameSpace());
    InitialNaming.bind(DeviceManager.NAME, DeviceManager.INSTANCE);
    AliasManager alias_mgr =
        new DefaultAliasManager(new DummyExtensionPoint()).createAliasManager();
    InitialNaming.bind(AliasManager.NAME, alias_mgr);
    InitialNaming.bind(ShellManager.NAME, new DefaultShellManager());
    InitialNaming.bind(HelpFactory.NAME, new DefaultHelpFactory());

    BasicConfigurator.configure();
    initialized = true;
  }
예제 #2
0
파일: FatTest.java 프로젝트: NanoGame/jnode
  public static void createFloppy(File f) throws Exception {

    GrubFatFormatter ff = new GrubFatFormatter(0, null, null);
    FileDevice newFd = new FileDevice(f, "rw");
    newFd.setLength(1440 * 1024);
    ff.format(newFd);

    // newFd.start();
    final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
    FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
    FatFileSystem fs = new FatFileSystem(newFd, false, type);

    FSDirectory dir = fs.getRootEntry().getDirectory();
    FSDirectory bDir = dir.addDirectory("boot").getDirectory();
    FSDirectory bgDir = bDir.addDirectory("grub").getDirectory();

    URLConnection urlConn = FatTest.class.getClassLoader().getResource("menu.lst").openConnection();
    // byte[] buf = new byte[urlConn.getContentLength()];
    ByteBuffer buf = ByteBuffer.allocate(urlConn.getContentLength());
    FileUtils.copy(urlConn.getInputStream(), buf.array());

    final FSFile fh1 = dir.addFile("test.lst").getFile();
    fh1.setLength(urlConn.getContentLength());
    fh1.write(0, buf);

    final FSFile fh2 = bgDir.addFile("menu.lst").getFile();
    fh2.setLength(urlConn.getContentLength());
    fh2.write(0, buf);

    fs.flush();

    // newFd.stop();
    newFd.close();
  }
예제 #3
0
  /**
   * Start the device
   *
   * @throws DriverException
   */
  protected void startDevice() throws DriverException {
    final Device dev = getDevice();

    // Find the ACPI info
    try {
      final ResourceManager rm;
      rm = InitialNaming.lookup(ResourceManager.NAME);
      info = findAcpiRSDTPTR(rm);
    } catch (NameNotFoundException ex) {
      throw new DriverException("Cannot find the resource manager");
    } catch (ResourceNotFreeException ex) {
      log.error("Cannot claim BIOS region", ex);
    }

    // Register out API
    dev.registerAPI(FirmwareAPI.class, this);

    // Start an ACPI device if we found the info for it.
    if (info != null) {
      log.info("Start ACPI device");
      acpiDevice = new AcpiDevice(dev.getBus(), "acpi", info);
      try {
        dev.getManager().register(acpiDevice);
      } catch (DeviceAlreadyRegisteredException ex) {
        log.error("Cannot register ACPI device", ex);
      }
    }
  }
 /** @see org.jnode.driver.Driver#startDevice() */
 protected void startDevice() throws DriverException {
   final Device device = getDevice();
   try {
     final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
     dm.rename(device, getDevicePrefix() + "-" + device.getId(), false);
   } catch (DeviceAlreadyRegisteredException ex) {
     log.error("Cannot rename device", ex);
   } catch (NameNotFoundException ex) {
     throw new DriverException("Cannot find DeviceManager", ex);
   }
   device.registerAPI(FrameBufferAPI.class, this);
 }
예제 #5
0
  public static void main(String[] args) throws Exception {

    final String devId = (args.length > 0) ? args[0] : "" /*"fb0"*/;

    Surface g = null;
    try {
      Device dev = null;
      if ("".equals(devId)) {
        final Collection<Device> devs = DeviceUtils.getDevicesByAPI(FrameBufferAPI.class);
        int dev_count = devs.size();
        if (dev_count > 0) {
          Device[] dev_a = devs.toArray(new Device[dev_count]);
          dev = dev_a[0];
        }
      }

      if (dev == null) {
        final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
        dev = dm.getDevice(devId);
      }

      final FrameBufferAPI api = dev.getAPI(FrameBufferAPI.class);
      final FrameBufferConfiguration conf = api.getConfigurations()[0];

      g = api.open(conf);

      TextScreenConsoleManager mgr = new TextScreenConsoleManager();

      ScrollableTextScreen ts =
          new FBConsole.FBPcTextScreen(g).createCompatibleScrollableBufferScreen(500);

      ScrollableTextScreenConsole first =
          new ScrollableTextScreenConsole(
              mgr,
              "console",
              ts,
              ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);

      mgr.registerConsole(first);
      mgr.focus(first);

      new CommandShell(first).run();
      Thread.sleep(60 * 1000);

    } catch (Throwable ex) {
      log.error("Error in FBConsole", ex);
    } finally {
      if (g != null) {
        log.info("Close graphics");
        g.close();
      }
    }
  }
예제 #6
0
  private static TextScreenConsoleManager getParentManager() throws NameNotFoundException {
    TextScreenConsoleManager manager = null;

    ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
    if (sm != null) {
      // current shell is null when JNode boot directly in GUI mode, without going
      // through command line
      if (sm.getCurrentShell() != null) {
        manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager();
      }
    }

    return manager;
  }
예제 #7
0
파일: FatTest.java 프로젝트: NanoGame/jnode
  public static void printInfo(File file, PrintWriter out) throws IOException, FileSystemException {
    FileDevice fd = new FileDevice(file, "r");
    try {
      final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
      FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
      FatFileSystem fs = new FatFileSystem(fd, false, type);
      try {
        BootSector bs = fs.getBootSector();
        bs.read(fd);

        out.println("OEM name          " + bs.getOemName());
        out.println("bytes/sector      " + bs.getBytesPerSector());
        out.println("sectors/cluster   " + bs.getSectorsPerCluster());
        out.println("#reserved sectors " + bs.getNrReservedSectors());
        out.println("#fats             " + bs.getNrFats());
        out.println("#rootdir entries  " + bs.getNrRootDirEntries());
        out.println("#logical sectors  " + bs.getNrLogicalSectors());
        out.println("Medium descriptor 0x" + Integer.toHexString(bs.getMediumDescriptor()));
        out.println("sectors/fat       " + bs.getSectorsPerFat());
        out.println("sectors/track     " + bs.getSectorsPerTrack());
        out.println("#heads            " + bs.getNrHeads());
        out.println("#hidden sectors   " + bs.getNrHiddenSectors());

        fs.getFat().printTo(out);
        fs.getRootDir().printTo(out);

        try {
          FatDirectory dir =
              (FatDirectory) fs.getRootEntry().getDirectory().getEntry("AAP").getDirectory();
          dir.printTo(out);
        } catch (FileNotFoundException ex) {
          out.println("No AAP directory");
        }

        try {
          FatDirectory dir =
              (FatDirectory) fs.getRootEntry().getDirectory().getEntry("boot").getDirectory();
          dir.printTo(out);
        } catch (FileNotFoundException ex) {
          out.println("No boot directory");
        }

      } finally {
        // fd.stop();
        fd.close();
      }
    } catch (NameNotFoundException e) {
      throw new FileSystemException(e);
    }
  }
예제 #8
0
 /**
  * This will be the entry point for the isolate.
  *
  * @param args
  */
 public static void main(String[] args) {
   try {
     final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
     final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();
     final PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
     TextConsole console = createConsoleWithShell(conMgr, out);
     System.setIn(new ReaderInputStream(console.getIn()));
     System.setOut(new PrintStream(new WriterOutputStream(console.getOut(), false), true));
     System.setErr(new PrintStream(new WriterOutputStream(console.getErr(), false), true));
   } catch (Exception ex) {
     // FIXME
     System.out.println("Problem creating the isolated console");
     ex.printStackTrace(System.err);
   }
 }
예제 #9
0
 protected void startDevice() throws DriverException {
   final Device device = getDevice();
   final DeviceManager dm;
   try {
     dm = InitialNaming.lookup(DeviceManager.NAME);
     dm.rename(device, getDevicePrefix(), true);
   } catch (DeviceAlreadyRegisteredException ex) {
     log.error("Cannot rename device", ex);
     throw new DriverException("Cannot rename device", ex);
   } catch (NameNotFoundException ex) {
     throw new DriverException("Cannot find DeviceManager", ex);
   }
   int busId = 0; // fix to handle multiple firewire controllers
   bus = new FireWireBus(this, busId);
 }
예제 #10
0
  @Override
  public void execute() throws NameNotFoundException, IsolateStartupException, ShellException {
    final PrintWriter out = getOutput().getPrintWriter();
    final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
    final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();

    boolean listConsoles = FLAG_LIST.isSet();
    boolean newConsole = FLAG_NEW.isSet();
    boolean isolateNewConsole = FLAG_ISOLATED.isSet();
    boolean test = FLAG_TEST.isSet();

    if (listConsoles) {
      conMgr.printConsoles(out);
    } else if (newConsole) {
      if (isolateNewConsole) {
        try {
          Isolate newIsolate =
              new Isolate(ConsoleCommand.IsolatedConsole.class.getName(), new String[0]);
          newIsolate.start();
          out.println("Started new isolated console");
        } catch (IsolateStartupException ex) {
          out.println("Failed to start new isolated console");
          throw ex;
        }
      } else {
        createConsoleWithShell(conMgr, out);
      }
    } else if (test) {
      out.println("test RawTextConsole");
      final TextConsole console =
          (TextConsole)
              conMgr.createConsole(
                  null,
                  ConsoleManager.CreateOptions.TEXT
                      | ConsoleManager.CreateOptions.NO_LINE_EDITTING);
      conMgr.registerConsole(console);
      conMgr.focus(console);
      console.clear();
    }
  }
예제 #11
0
 protected void ensurePluginLoaded(PluginSpecification plugin) throws TestRunnerException {
   String id = plugin.getPluginId();
   if (usingEmu) {
     TestEmu.loadPseudoPlugin(id, plugin.getClassName());
   } else {
     String ver =
         (plugin.getPluginVersion().length() == 0)
             ? System.getProperty("os.version")
             : plugin.getPluginVersion();
     try {
       PluginManager mgr = InitialNaming.lookup(PluginManager.NAME);
       PluginRegistry reg = mgr.getRegistry();
       if (reg.getPluginDescriptor(id) == null) {
         reg.loadPlugin(mgr.getLoaderManager(), new PluginReference(id, new Version(ver)), true);
       }
     } catch (Exception ex) {
       System.out.println(ex.getMessage());
       throw new TestRunnerException(
           "Cannot load plugin '" + plugin.getPluginId() + "/" + ver + "'", ex);
     }
   }
 }
예제 #12
0
  /** Set up the pager's console and command pipe. */
  private void setup() throws NameNotFoundException, IOException {
    ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
    manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager();
    console =
        manager.createConsole(
            "page",
            (ConsoleManager.CreateOptions.TEXT
                | ConsoleManager.CreateOptions.STACKED
                | ConsoleManager.CreateOptions.NO_LINE_EDITTING
                | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR));
    manager.focus(console);

    pageHeight = console.getDeviceHeight() - 1;
    pageWidth = console.getDeviceWidth();
    pageSize = pageHeight * pageWidth;
    tabSize = console.getTabSize();

    pw = new PipedWriter();
    pr = new PipedReader();
    pr.connect(pw);

    console.addKeyboardListener(this);
  }
예제 #13
0
  /** Create a new instance */
  protected DefaultIDEIO(Device device, boolean primary)
      throws IllegalArgumentException, DriverException, ResourceNotFreeException {

    int cmdBlockStart = (primary ? IDE0_START_PORT : IDE1_START_PORT);
    int ctrlBlockStart = cmdBlockStart + HIGH_OFFSET;
    int cmdBlockSize = IDE_NR_PORTS;
    int ctrlBlockSize = IDE_NR_HIGH_PORTS;
    int altStatusPort = ctrlBlockStart + R8_ALTSTATUS_OFFSET;
    int irq = (primary ? IDE0_IRQ : IDE1_IRQ);
    boolean nativeMode = false;

    // Detect PCI IDE Controller, look for enhanced mode
    if (device instanceof PCIDevice) {
      final PCIDevice pciDev = (PCIDevice) device;
      final PCIDeviceConfig pciCfg = pciDev.getConfig();
      final int pIntf = pciCfg.getMinorClass();
      final int progMask = 0x02 | 0x08;
      final int enhModeMask = 0x01 | 0x04;
      if ((pIntf & progMask) == progMask) {
        // Mode is programmable, set enhanced mode
        // pciCfg.setMinorClass(pIntf | enhModeMask);
      }
      if ((pciCfg.getMinorClass() & enhModeMask) == enhModeMask) {
        // Use enhanced mode
        final PCIBaseAddress[] baseAddrs = pciCfg.asHeaderType0().getBaseAddresses();
        final int idx = (primary ? 0 : 2);
        cmdBlockStart = baseAddrs[idx].getIOBase();
        cmdBlockSize = 8;
        ctrlBlockStart = baseAddrs[idx + 1].getIOBase();
        ctrlBlockSize = 4;
        altStatusPort = ctrlBlockStart + 0x02;
        irq = pciCfg.asHeaderType0().getInterruptLine();
        nativeMode = true;
      }
    }

    log.info(
        "Using PCI IDE " + (nativeMode ? "Native" : "Compatibility") + " mode [irq=" + irq + "]");

    // Now claim the resources
    IOResource cmdBlock = null;
    IOResource ctrlBlock = null;
    final ResourceManager rm;
    try {
      rm = InitialNaming.lookup(ResourceManager.NAME);
      cmdBlock = claimPorts(rm, device, cmdBlockStart, cmdBlockSize);
      ctrlBlock = claimPorts(rm, device, ctrlBlockStart, ctrlBlockSize);
    } catch (NameNotFoundException ex) {
      throw new ResourceNotFreeException("Cannot find ResourceManager", ex);
    } catch (ResourceNotFreeException ex) {
      if (cmdBlock != null) {
        cmdBlock.release();
      }
      if (ctrlBlock != null) {
        ctrlBlock.release();
      }
      throw ex;
    }
    this.irq = irq;
    this.cmdBlockStart = cmdBlockStart;
    this.ctrlBlockStart = ctrlBlockStart;
    this.cmdBlock = cmdBlock;
    this.ctrlBlock = ctrlBlock;
    this.altStatusPort = altStatusPort;
  }
예제 #14
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);
  }
예제 #15
0
 /**
  * Gets the device manager
  *
  * @return The device manager
  * @throws NameNotFoundException
  */
 public static DeviceManager getDeviceManager() throws NameNotFoundException {
   if (deviceManager == null) {
     deviceManager = InitialNaming.lookup(DeviceManager.NAME);
   }
   return deviceManager;
 }