Fix ata detection bug. CD drives were recognized as ATAPI devices, but still handled as ATA ones. Currently we don't have an ATAPI driver, so the CD drives are ignored.

Fixes #129
This commit is contained in:
Matthijs ter Woord 2015-07-05 13:28:16 +02:00
parent 9b13be0d02
commit 5fca0ecbb7
5 changed files with 85 additions and 58 deletions

View file

@ -32,11 +32,11 @@ namespace Cosmos.Debug.VSDebugEngine.Host
"floppy_bootsig_check: disabled=0\n" + "floppy_bootsig_check: disabled=0\n" +
"# no floppya\n" + "# no floppya\n" +
"# no floppyb\n" + "# no floppyb\n" +
"ata0-master: type=cdrom, path=\"%CDROMBOOTPATH%\", status=inserted, model=\"Generic 1234\", biosdetect=auto\n" +
"ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14\n" + "ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14\n" +
"ata0-master: type=disk, path=\"%HARDDISKPATH%\", mode=vmware4, cylinders=0, heads=0, spt=0, model=\"Generic 1234\", biosdetect=auto, translation=auto\n" +
"ata0-slave: type=none\n" + "ata0-slave: type=none\n" +
"ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15\n" + "ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15\n" +
"ata1-master: type=cdrom, path=\"%CDROMBOOTPATH%\", status=inserted, model=\"Generic 1234\", biosdetect=auto\n" + "ata1-master: type=disk, path=\"%HARDDISKPATH%\", mode=vmware4, cylinders=0, heads=0, spt=0, model=\"Generic 1234\", biosdetect=auto, translation=auto\n" +
"ata2: enabled=0\n" + "ata2: enabled=0\n" +
"ata3: enabled=0\n" + "ata3: enabled=0\n" +
"pci: enabled=1, chipset=i440fx\n" + "pci: enabled=1, chipset=i440fx\n" +
@ -85,11 +85,8 @@ namespace Cosmos.Debug.VSDebugEngine.Host
defaultConfigs.Set("com1", defaultConfigs.Get("com1").Replace("%PIPESERVERNAME%", xParts[1].ToLower())); defaultConfigs.Set("com1", defaultConfigs.Get("com1").Replace("%PIPESERVERNAME%", xParts[1].ToLower()));
var xHarddiskFile = Path.Combine(CosmosPaths.Build, @"VMWare\Workstation\Filesystem.vmdk"); var xHarddiskFile = Path.Combine(CosmosPaths.Build, @"VMWare\Workstation\Filesystem.vmdk");
defaultConfigs.Set("ata0-master", defaultConfigs.Get("ata0-master").Replace("%HARDDISKPATH%", xHarddiskFile)); defaultConfigs.Set("ata0-master", defaultConfigs.Get("ata0-master").Replace("%CDROMBOOTPATH%", mParams["ISOFile"]));
defaultConfigs.Set("ata1-master", defaultConfigs.Get("ata1-master").Replace("%HARDDISKPATH%", xHarddiskFile));
defaultConfigs.Set("ata1-master", defaultConfigs.Get("ata1-master").Replace("%CDROMBOOTPATH%", mParams["ISOFile"]));
} }
private void GenerateConfiguration(string filePath) private void GenerateConfiguration(string filePath)

View file

@ -1,2 +1,8 @@
[*.cs] [*.cs]
indent_size=4 indent_size=4
[Global.cs]
indent_size = 2
[BlockDevice/Ata.cs]
indent_size = 2

View file

@ -2,9 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Cosmos.Debug.Kernel;
namespace Cosmos.HAL.BlockDevice { namespace Cosmos.HAL.BlockDevice {
public abstract class Ata : BlockDevice { public abstract class Ata : BlockDevice
{
internal static Debugger AtaDebugger = new Debugger("HAL", "Ata");
protected Ata() { protected Ata() {
mBlockSize = 512; mBlockSize = 512;

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Cosmos.Common; using Cosmos.Common;
using Cosmos.Debug.Kernel;
namespace Cosmos.HAL.BlockDevice namespace Cosmos.HAL.BlockDevice
{ {
@ -127,6 +128,13 @@ namespace Cosmos.HAL.BlockDevice
} }
#endregion #endregion
internal static Debugger mDebugger = new Debugger("HAL", "AtaPio");
private static void Debug(string message)
{
mDebugger.Send("AtaPio debug: " + message);
}
public AtaPio(Core.IOGroup.ATA aIO, Ata.ControllerIdEnum aControllerId, Ata.BusPositionEnum aBusPosition) public AtaPio(Core.IOGroup.ATA aIO, Ata.ControllerIdEnum aControllerId, Ata.BusPositionEnum aBusPosition)
{ {
IO = aIO; IO = aIO;
@ -206,7 +214,6 @@ namespace Cosmos.HAL.BlockDevice
return SendCmd(aCmd, true); return SendCmd(aCmd, true);
} }
public Status SendCmd(Cmd aCmd, bool aThrowOnError) public Status SendCmd(Cmd aCmd, bool aThrowOnError)
{ {
IO.Command.Byte = (byte)aCmd; IO.Command.Byte = (byte)aCmd;
@ -221,6 +228,7 @@ namespace Cosmos.HAL.BlockDevice
if (aThrowOnError && (xStatus & Status.Error) != 0) if (aThrowOnError && (xStatus & Status.Error) != 0)
{ {
// TODO: Read error port // TODO: Read error port
Debug("ATA Error in SendCmd. Cmd = " + (byte)aCmd + ", Status = " + (byte)xStatus);
throw new Exception("ATA Error"); throw new Exception("ATA Error");
} }
return xStatus; return xStatus;

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Cosmos.HAL.BlockDevice;
namespace Cosmos.HAL { namespace Cosmos.HAL {
static public class Global { static public class Global {
@ -14,46 +15,57 @@ namespace Cosmos.HAL {
public static PCI Pci; public static PCI Pci;
static void InitAta(BlockDevice.Ata.ControllerIdEnum aControllerID, BlockDevice.Ata.BusPositionEnum aBusPosition) { private static void InitAta(BlockDevice.Ata.ControllerIdEnum aControllerID, BlockDevice.Ata.BusPositionEnum aBusPosition)
{
var xIO = aControllerID == BlockDevice.Ata.ControllerIdEnum.Primary ? Cosmos.Core.Global.BaseIOGroups.ATA1 : Cosmos.Core.Global.BaseIOGroups.ATA2; var xIO = aControllerID == BlockDevice.Ata.ControllerIdEnum.Primary ? Cosmos.Core.Global.BaseIOGroups.ATA1 : Cosmos.Core.Global.BaseIOGroups.ATA2;
var xATA = new BlockDevice.AtaPio(xIO, aControllerID, aBusPosition); var xATA = new BlockDevice.AtaPio(xIO, aControllerID, aBusPosition);
if (xATA.DriveType != BlockDevice.AtaPio.SpecLevel.Null) { if (xATA.DriveType == BlockDevice.AtaPio.SpecLevel.Null)
{
return;
}
if (xATA.DriveType == BlockDevice.AtaPio.SpecLevel.ATA)
{
BlockDevice.BlockDevice.Devices.Add(xATA); BlockDevice.BlockDevice.Devices.Add(xATA);
var xMbrData = new byte[512]; }
xATA.ReadBlock(0UL, 1U, xMbrData); else
var xMBR = new BlockDevice.MBR(xMbrData); {
Ata.AtaDebugger.Send("ATA device with spec level " + (int)xATA.DriveType + " found, which is not supported!");
return;
}
var xMbrData = new byte[512];
xATA.ReadBlock(0UL, 1U, xMbrData);
var xMBR = new BlockDevice.MBR(xMbrData);
if (xMBR.EBRLocation != 0) if (xMBR.EBRLocation != 0)
{ {
//EBR Detected //EBR Detected
var xEbrData = new byte[512]; var xEbrData = new byte[512];
xATA.ReadBlock(xMBR.EBRLocation, 1U, xEbrData); xATA.ReadBlock(xMBR.EBRLocation, 1U, xEbrData);
var xEBR = new BlockDevice.EBR(xEbrData); var xEBR = new BlockDevice.EBR(xEbrData);
for (int i = 0; i < xEBR.Partitions.Count; i++) for (int i = 0; i < xEBR.Partitions.Count; i++)
{ {
//var xPart = xEBR.Partitions[i]; //var xPart = xEBR.Partitions[i];
//var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount); //var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
//BlockDevice.BlockDevice.Devices.Add(xPartDevice); //BlockDevice.BlockDevice.Devices.Add(xPartDevice);
} }
} }
// TODO Change this to foreach when foreach is supported // TODO Change this to foreach when foreach is supported
Console.WriteLine("Number of MBR partitions found: " + xMBR.Partitions.Count); Console.WriteLine("Number of MBR partitions found: " + xMBR.Partitions.Count);
for (int i = 0; i < xMBR.Partitions.Count; i++) for (int i = 0; i < xMBR.Partitions.Count; i++)
{ {
var xPart = xMBR.Partitions[i]; var xPart = xMBR.Partitions[i];
if (xPart == null) if (xPart == null)
{ {
Console.WriteLine("Null partition found at idx " + i); Console.WriteLine("Null partition found at idx " + i);
} }
else else
{ {
var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount); var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
BlockDevice.BlockDevice.Devices.Add(xPartDevice); BlockDevice.BlockDevice.Devices.Add(xPartDevice);
Console.WriteLine("Found partition at idx " + i); Console.WriteLine("Found partition at idx " + i);
} }
}
} }
} }