Esempio n. 1
0
        private void DoIdentifyDrive(byte index)
        {
            //HAL.DebugWriteLine("Device " + index.ToString() + " ID...");

            driveInfo[index].Present = false;

            //Send the identify command to the selected drive
            DeviceHeadPort.Write8((byte)((index == 0) ? 0xA0 : 0xB0));
            SectorCountPort.Write8(0);
            LBALowPort.Write8(0);
            LBAMidPort.Write8(0);
            LBAHighPort.Write8(0);
            CommandPort.Write8(IDECommand.IdentifyDrive);

            if (StatusPort.Read8() == 0)
            {
                //HAL.DebugWriteLine("Device " + index.ToString() + " doesnt exist...");

                //Drive doesn't exist
                return;
            }

            //Wait until a ready status is present
            if (!WaitForReadyStatus())
            {
                return;                                              //There's no ready status, this drive doesn't exist
            }
            if (LBAMidPort.Read8() != 0 && LBAHighPort.Read8() != 0) //Check if the drive is ATA
            {
                //In this case the drive is ATAPI

                HAL.DebugWriteLine("Device " + index.ToString() + " not ATA");

                return;
            }

            //Wait until the identify data is present (256x16 bits)
            if (!WaitForIdentifyData())
            {
                HAL.DebugWriteLine("Device " + index.ToString() + " ID error");
                return;
            }

            //An ATA drive is present
            driveInfo[index].Present = true;

            //Read the identification info
            var info = new DataBlock(512);

            for (uint ix = 0; ix < 256; ix++)
            {
                info.SetUShort(ix * 2, DataPort.Read16());
            }

            //Find the addressing mode
            var lba28SectorCount = info.GetUInt(IdentifyDrive.MaxLBA28);

            AddressingMode aMode = AddressingMode.NotSupported;

            if ((info.GetUShort(IdentifyDrive.CommandSetSupported83) & 0x200) == 0x200)             //Check the LBA48 support bit
            {
                aMode = AddressingMode.LBA48;
                driveInfo[index].MaxLBA = info.GetUInt(IdentifyDrive.MaxLBA48);
            }
            else if (lba28SectorCount > 0)             //LBA48 not supported, check LBA28
            {
                aMode = AddressingMode.LBA28;
                driveInfo[index].MaxLBA = lba28SectorCount;
            }

            driveInfo[index].AddressingMode = aMode;

            HAL.DebugWriteLine("Device " + index.ToString() + " present - MaxLBA=" + driveInfo[index].MaxLBA.ToString());
        }