public static void DetectDrive(ControllerIdEnum aControllerID, BusPositionEnum aBusPosition) { var dev = new ATABlockDevice(aControllerID == ControllerIdEnum.Primary, aControllerID, aBusPosition); if (dev.Exists) { ATABlockDevices.Add(dev); } }
/// <summary> /// Constructor for ATAPI speclevel device. /// </summary> /// <param name="parentDevice"></param> public ATAPI(ATA_PIO parentDevice) { device = parentDevice; this.BusPosition = parentDevice.BusPosition; this.Primary = parentDevice.ControllerID == ControllerIdEnum.Primary; mBlockSize = SectorSize; IO = new Core.IOGroup.ATA(!Primary); var p = BusPosition == BusPositionEnum.Master; Ata.AtaDebugger.Send("ATAPI: Primary controller: " + this.Primary + " Bus postion: IsMaster: " + p); Init(); }
private static void InitAta(ControllerIdEnum aControllerID, BusPositionEnum aBusPosition) { var xIO = aControllerID == ControllerIdEnum.Primary ? baseIOGroup.ATA1 : baseIOGroup.ATA2; var xATA = new BlockDevice(); xATA.Setup(xIO, aControllerID, aBusPosition); if (xATA.DriveType == SpecLevel.Null) { return; } if (xATA.DriveType != SpecLevel.ATA) { return; } DeviceManager.AllDevices.Add(xATA); }
public ATABlockDevice(bool primary, ControllerIdEnum aControllerId, BusPositionEnum aBusPosition) { var xBAR0 = (ushort)(!primary ? 0x0170 : 0x01F0); var xBAR1 = (ushort)(!primary ? 0x0374 : 0x03F4); IOControl = (ushort)(xBAR1 + 2); IOCommand = (ushort)(xBAR0 + 7); IOData = (ushort)xBAR0; IOStatus = (ushort)(xBAR0 + 7); IODeviceSelect = (ushort)(xBAR0 + 6); IOLBA0 = (ushort)(xBAR0 + 3); IOLBA1 = (ushort)(xBAR0 + 4); IOLBA2 = (ushort)(xBAR0 + 5); IOSectorCount = (ushort)(xBAR0 + 2); mControllerID = aControllerId; mBusPosition = aBusPosition; IOPort.outb(IOControl, 0x02); DriveType = DiscoverDrive(); if (DriveType == SpecLevel.Null) { Exists = false; return; } if (DriveType != SpecLevel.ATA) { Exists = false; return; } if (DriveType == SpecLevel.ATA) { SendCmd(Cmd.Identify); } else { SendCmd(Cmd.IdentifyPacket); } var xBuff = (ushort *)Heap.alloc(512); for (int i = 0; i < 256; i++) { ushort read = IOPort.inw(IOData); byte upper = (byte)(read >> 8); byte lower = (byte)read; xBuff[i] = (ushort)((lower << 8) | upper); } SerialNo = GetString(xBuff, 10, 20); FirmwareRev = GetString(xBuff, 23, 8); ModelNo = GetString(xBuff, 27, 40); DeviceLa = GetString(xBuff, 54, 40); uint l = 0; byte *ptr = DeviceLa; while (*ptr != 0) { ptr++; l++; } char[] tmp = new char[l]; for (int i = 0; i < l; i++) { tmp[i] = (char)DeviceLa[i]; } Label = new string(tmp); BlockCount = ((uint)xBuff[61] << 16 | xBuff[60]) - 1; LBA48Bit = (xBuff[83] & 0x40) != 0; if (LBA48Bit) { BlockCount = ((ulong)xBuff[102] << 32 | (ulong)xBuff[101] << 16 | (ulong)xBuff[100]) - 1; } byte *xMbrData = (byte *)Heap.alloc(512); ReadBlock(0, 1, xMbrData); MBR xMBR = new MBR(); xMBR.Setup(this, xMbrData); PartitionCount = 0; for (int i = 0; i < xMBR.partitions.Count; i++) { ATA.ATAPartitions.Add(xMBR.partitions[i]); PartitionCount++; } }