From 2b81d7cdf277fed41a41b9cc028ed669c69d0e2b Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Tue, 15 Feb 2011 00:19:08 +0000 Subject: [PATCH] --- .../System/Hardware/Cosmos.Hardware/ATA.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/ATA.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/ATA.cs index dd05d32b5..cf1736453 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/ATA.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/ATA.cs @@ -12,7 +12,7 @@ namespace Cosmos.Hardware { IO = aIO; } - [Flags] enum Status : byte {None = 0x00, Busy = 0x80, ATA_SR_DRD = 0x40, ATA_SR_DF = 0x20, ATA_SR_DSC = 0x10, DRQ = 0x08, ATA_SR_COR = 0x04, ATA_SR_IDX = 0x02, Error = 0x01 }; + [Flags] public enum Status : byte {None = 0x00, Busy = 0x80, ATA_SR_DRD = 0x40, ATA_SR_DF = 0x20, ATA_SR_DSC = 0x10, DRQ = 0x08, ATA_SR_COR = 0x04, ATA_SR_IDX = 0x02, Error = 0x01 }; [Flags] enum Error : byte { ATA_ER_BBK = 0x80, ATA_ER_UNC = 0x40, ATA_ER_MC = 0x20, ATA_ER_IDNF = 0x10, ATA_ER_MCR = 0x08, ATA_ER_ABRT = 0x04, ATA_ER_TK0NF = 0x02, ATA_ER_AMNF = 0x01 }; [Flags] enum DvcSelVal : byte { @@ -54,28 +54,31 @@ namespace Cosmos.Hardware { Wait(); } + public Status GetStatus() { + return (Status)IO.Status.Byte; + } + public void Test() { // Disable IRQs: IO.Control.Byte = 0x02; int xCount = 0; for (int xDrive = 0; xDrive <= 1; xDrive++) { - byte xErr = 0; + bool xError = false; SelectDrive((DriveSelect)xDrive); SendCmd(Cmd.Identify); // Polling // No drive found - if (IO.Status.Byte == 0) { + if (GetStatus() == Status.None) { continue; } while (true) { - Status xStatus; - xStatus = (Status)IO.Status.Byte; + var xStatus = GetStatus(); if ((xStatus & Status.Error) == Status.None) { // Device is not ATA - xErr = 1; + xError = true; break; } else if ((xStatus & Status.Busy) == Status.None && (xStatus & Status.DRQ) != Status.None) { // Found drive and its ok @@ -83,16 +86,15 @@ namespace Cosmos.Hardware { } } - // Look for ATAPI devices var xType = SpecLevel.ATA; - if (xErr == 0) { + if (!xError) { int xTypeId = IO.LBA2.Byte << 8 | IO.LBA1.Byte; if (xTypeId == 0xEB14 || xTypeId == 0x9669) { + xType = SpecLevel.ATAPI; } else { // Unknown type. Might not be a device. continue; } - xType = SpecLevel.ATAPI; } SendCmd(Cmd.IdentifyPacket);