Clean up ATA PIO driver.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-06-02 17:27:29 +02:00
parent 7c3740a85d
commit 2ea7607f4e
1 changed files with 20 additions and 21 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of Sortix.
@ -223,7 +223,8 @@ ATABus::~ATABus()
ATADrive* ATABus::Instatiate(unsigned driveid)
{
if ( 1 < driveid ) { errno = EINVAL; return NULL; }
if ( 1 < driveid )
return errno = EINVAL, (ATADrive*) NULL;
curdriveid = 0;
uint8_t drivemagic = 0xA0 | (driveid << 4);
@ -237,17 +238,16 @@ ATADrive* ATABus::Instatiate(unsigned driveid)
while ( true )
{
status = CPU::InPortB(iobase + STATUS);
if ( !status || status == 0xFF ) { errno = ENODEV; return NULL; }
if ( !(status & STATUS_BUSY) ) { break; }
if ( !status || status == 0xFF )
return errno = ENODEV, (ATADrive*) NULL;
if ( !(status & STATUS_BUSY) )
break;
}
// Check for ATAPI device not following spec.
if ( CPU::InPortB(iobase + LBA_MID) || CPU::InPortB(iobase + LBA_MID) )
{
errno = ENODEV; return NULL; // ATAPI device not following spec.
}
return errno = ENODEV, (ATADrive*) NULL;
while ( !(status & STATUS_DATAREADY) && !(status & STATUS_ERROR) )
{
status = CPU::InPortB(iobase + STATUS);
}
if ( status & STATUS_ERROR )
{
unsigned mid = CPU::InPortB(iobase + LBA_MID);
@ -268,8 +268,7 @@ ATADrive* ATABus::Instatiate(unsigned driveid)
{
//Log::PrintF("Error status during identify\n");
}
errno = EIO;
return NULL;
return errno = EIO, (ATADrive*) NULL;
}
ATADrive* drive = new ATADrive(this, driveid, iobase, altport);
return drive;