private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice) { var ioPortRegions = new LinkedList <IOPortRegion>(); var memoryRegions = new LinkedList <MemoryRegion>(); foreach (var pciBaseAddress in pciDevice.BaseAddresses) { switch (pciBaseAddress.Region) { case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break; case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break; default: break; } } foreach (var memoryAttribute in deviceDriver.MemoryAttributes) { if (memoryAttribute.MemorySize > 0) { var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment); memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size)); } } foreach (var ioportregion in ioPortRegions) { Boot.Console.WriteLine(" I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]"); } foreach (var memoryregion in memoryRegions) { Boot.Console.WriteLine(" Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]"); } //Boot.Console.WriteLine(" Command: 0x" + hardwareDevice...ToString("X")); var hardwareResources = new HardwareResources( ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IPCIDeviceResource ); hardwareDevice.Setup(hardwareResources); deviceManager.Add(hardwareDevice); hardwareResources.EnableIRQ(); if (hardwareDevice.Start() == DeviceDriverStartStatus.Started) { pciDevice.SetDeviceOnline(); } }
/// <summary> /// Creates the partition devices. /// </summary> public void CreatePCIDevices() { // Find PCI controller devices var devices = deviceManager.GetDevices <IPCIController>(DeviceStatus.Online); if (devices.Count == 0) { return; } var pciController = devices[0] as IPCIController; // For each controller for (int bus = 0; bus < 255; bus++) { for (int slot = 0; slot < 16; slot++) { for (int fun = 0; fun < 7; fun++) { if (ProbeDevice(pciController, (byte)bus, (byte)slot, (byte)fun)) { var pciDevice = new PCI.PCIDevice(pciController, (byte)bus, (byte)slot, (byte)fun); deviceManager.Add(pciDevice); } } } } }
/// <summary> /// Creates the partition devices. /// </summary> public void CreatePartitionDevices() { // FIXME: Do not create multiple partition devices if this method executed more than once var disks = deviceManager.GetDevices <IDiskDevice>(DeviceStatus.Online); // Find all online disk devices foreach (var device in disks) { var diskDevice = device as IDiskDevice; var mbr = new MasterBootBlock(diskDevice); if (!mbr.Valid) { return; } for (uint i = 0; i < MasterBootBlock.MaxMBRPartitions; i++) { if (mbr.Partitions[i].PartitionType != PartitionType.Empty) { deviceManager.Add(new PartitionDevice(diskDevice, mbr.Partitions[i], false)); } } } }
public PartitionDevice(GenericPartition partition, IDiskDevice diskDevice, bool readOnly) { this.diskDevice = diskDevice; this.start = partition.StartLBA; this.blockCount = partition.TotalBlocks; this.readOnly = readOnly; base.parent = diskDevice as Device; base.name = base.parent.Name + "/Partition" + (partition.Index + 1).ToString(); // need to give it a unique name base.deviceStatus = DeviceStatus.Online; DeviceManager.Add(this); }
protected void Setup() { uint deviceCount = 0; // iterate over bus/device/function to list all devices for (uint bus = 0; bus < 256; bus++) { for (uint slot = 0; slot < 16; slot++) { for (uint fun = 0; fun < 7; fun++) { if (ProbeDevice(bus, slot, fun)) { DeviceManager.Add(new PCIDevice(this, bus, slot, fun)); deviceCount++; } } } } }
public void Initialize() { try { spinLock.Enter(); for (int drive = 0; drive < DrivesPerController; drive++) { trackCache[drive].valid = false; lastSeek[drive].calibrated = false; // default floppyMedia[drive].SectorsPerTrack = 18; floppyMedia[drive].TotalTracks = 80; //TODO: for 5.25, Gap1 = 0x2A and Gap2 = 0x50 floppyMedia[drive].Gap1Length = 0x1B; // 27 floppyMedia[drive].Gap2Length = 0x54; } verbose = true; ResetController(); SendByte(FIFOCommand.Version); if (GetByte() == 0x80) { enchancedController = false; } else { enchancedController = true; } TextMode.Write(base.name); TextMode.Write(": "); if (enchancedController) { TextMode.WriteLine("Enhanced floppy disk controller found at 0x" + ((uint)ioBase).ToString("X")); } else { TextMode.WriteLine("Non-enhanced floppy disk controller found at 0x" + ((uint)ioBase).ToString("X")); } DetectDrives(); for (uint drive = 0; drive < DrivesPerController; drive++) { if (floppyDrives[drive].Type != FloppyDriveType.None) { Open(drive); TextMode.Write(base.name); TextMode.Write(": Disk #"); TextMode.Write((int)drive); TextMode.Write(" - ", (int)floppyDrives[drive].KiloByteSize); TextMode.WriteLine("KB, media sector/track=", (int)floppyMedia[drive].SectorsPerTrack); DeviceManager.Add(new DiskDevice(this, drive, false)); //Timer.Delay (1000 * 5); //DeviceResource resource = new DeviceResource (driveNames[drive], DeviceResourceType.FloppyDisk, new GenericBlockDeviceAdapter (this, drive), DeviceResourceStatus.Online, 0, drive); //DeviceResourceManager.Add (resource); } } base.deviceStatus = DeviceStatus.Online; } finally { spinLock.Exit(); } }
public void Initialize() { spinLock.Enter(); //IdeIRQ = base.CreateIRQHandler (14); for (int drive = 0; drive < DrivesPerConroller; drive++) { driveInfo[drive].Present = false; driveInfo[drive].MaxLBA = 0; } TextMode.Write(base.name); TextMode.Write(": "); LBALowPort.Write8(0x88); if (LBALowPort.Read8() != 0x88) { base.deviceStatus = DeviceStatus.NotFound; TextMode.WriteLine("IDE controller not found at 0x" + ((uint)ioBase).ToString("X")); return; } TextMode.WriteLine("IDE controller found at 0x" + ((uint)ioBase).ToString("X")); DeviceHeadPort.Write8(0xA0); Timer.Delay(1000 / 250); // wait 1/250th of a second if ((StatusPort.Read8() & 0x40) == 0x40) { driveInfo[0].Present = true; } DeviceHeadPort.Write8(0xB0); Timer.Delay(1000 / 250); // wait 1/250th of a second if ((StatusPort.Read8() & 0x40) == 0x40) { driveInfo[1].Present = true; } for (uint drive = 0; drive < DrivesPerConroller; drive++) { if (driveInfo[drive].Present) { if (Open(drive)) { TextMode.Write(base.name); TextMode.Write(": Disk #"); TextMode.Write((int)drive); TextMode.Write(" - ", (int)(driveInfo[drive].MaxLBA / 1024 / 2)); TextMode.Write("MB, LBA=", (int)driveInfo[drive].MaxLBA); TextMode.WriteLine(""); DeviceManager.Add(new DiskDevice(this, drive, false)); } } } base.deviceStatus = DeviceStatus.Online; }
public static void Register() { DeviceManager.Add(new FATDevice()); }