public PATABase(ATAIOPorts anIO, ATA.ControllerID aControllerId, ATA.BusPosition aBusPosition) { IO = anIO; controllerId = aControllerId; busPosition = aBusPosition; // Disable IRQs, we use polling currently SelectDrive(0, false); IO.Control.Write_Byte((byte)0x02); mDriveType = DiscoverDrive(); if (mDriveType == SpecLevel.PATAPI) { blockSize = 2048; } if (mDriveType == SpecLevel.PATA || mDriveType == SpecLevel.PATAPI) { InitDrive(); initialised = true; } }
public AtaPio(Core.IOGroup.ATA aIO, Ata.ControllerIdEnum aControllerId, Ata.BusPositionEnum aBusPosition) { IO = aIO; mControllerID = aControllerId; mBusPosition = aBusPosition; // Disable IRQs, we use polling currently IO.Control.Byte = 0x02; mDriveType = DiscoverDrive(); if (mDriveType != SpecLevel.Null) { InitDrive(); } }
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++; } }