* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Note: mostly ripped from atapi.c
* Some of this code was based on knowledge and/or code developed
*
*/
-#include "freeldr.h"
-#include "debug.h"
-#include "hardware.h"
-#include "machine.h"
-#include "machxbox.h"
-#include "portio.h"
-#include "rtl.h"
+#include <freeldr.h>
+
+#define NDEBUG
+#include <debug.h>
#define XBOX_IDE_COMMAND_PORT 0x1f0
#define XBOX_IDE_CONTROL_PORT 0x170
#define IDEWriteDMAStatus(Address, Data) \
(WRITE_PORT_UCHAR((PUCHAR)((Address) + 2), (Data)))
#define IDEWritePRDTable(Address, Data) \
- (WRITE_PORT_ULONG((PULONG)((Address) + 4), (Data)))
+ (WRITE_PORT_ULONG((PULONG)((Address) + 4), (Data)))
/*
* Data block read and write commands
*/
#define IDEReadBlock(Address, Buffer, Count) \
- (READ_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
+ (__inwordstring(((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
#define IDEWriteBlock(Address, Buffer, Count) \
(WRITE_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
* PVOID Buffer Buffer for output data
*
* RETURNS:
- * BOOL: TRUE success, FALSE error
+ * BOOLEAN: TRUE success, FALSE error
*/
-static BOOL
+static BOOLEAN
XboxDiskPolledRead(ULONG CommandPort,
ULONG ControlPort,
UCHAR PreComp,
{
ULONG SectorCount = 0;
ULONG RetryCount;
- BOOL Junk = FALSE;
+ BOOLEAN Junk = FALSE;
UCHAR Status;
/* Wait for BUSY to clear */
}
StallExecutionProcessor(10);
}
- DbgPrint((DPRINT_DISK, "status=0x%x\n", Status));
- DbgPrint((DPRINT_DISK, "waited %d usecs for busy to clear\n", RetryCount * 10));
+ DPRINTM(DPRINT_DISK, "status=0x%x\n", Status);
+ DPRINTM(DPRINT_DISK, "waited %d usecs for busy to clear\n", RetryCount * 10);
if (RetryCount >= IDE_MAX_BUSY_RETRIES)
{
- DbgPrint((DPRINT_DISK, "Drive is BUSY for too long\n"));
+ DPRINTM(DPRINT_DISK, "Drive is BUSY for too long\n");
return FALSE;
}
/* Issue command to drive */
if (DrvHead & IDE_DH_LBA)
{
- DbgPrint((DPRINT_DISK, "READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
+ DPRINTM(DPRINT_DISK, "READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum,
SectorCnt,
- Command));
+ Command);
}
else
{
- DbgPrint((DPRINT_DISK, "READ:DRV=%d:LBA=0:CH=0x%x:CL=0x%x:HD=0x%x:SN=0x%x:SC=0x%x:CM=0x%x\n",
+ DPRINTM(DPRINT_DISK, "READ:DRV=%d:LBA=0:CH=0x%x:CL=0x%x:HD=0x%x:SN=0x%x:SC=0x%x:CM=0x%x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
CylinderHigh,
CylinderLow,
DrvHead & 0x0f,
SectorNum,
SectorCnt,
- Command));
+ Command);
}
/* Setup command parameters */
if (Junk == FALSE)
{
IDEReadBlock(CommandPort, Buffer, IDE_SECTOR_BUF_SZ);
- Buffer += IDE_SECTOR_BUF_SZ;
+ Buffer = (PVOID)((ULONG_PTR)Buffer + IDE_SECTOR_BUF_SZ);
}
else
{
{
if (SectorCount >= SectorCnt)
{
- DbgPrint((DPRINT_DISK, "Buffer size exceeded!\n"));
+ DPRINTM(DPRINT_DISK, "Buffer size exceeded!\n");
Junk = TRUE;
}
break;
{
if (SectorCount > SectorCnt)
{
- DbgPrint((DPRINT_DISK, "Read %lu sectors of junk!\n",
- SectorCount - SectorCnt));
+ DPRINTM(DPRINT_DISK, "Read %lu sectors of junk!\n",
+ SectorCount - SectorCnt);
}
IDEWriteDriveControl(ControlPort, 0);
StallExecutionProcessor(50);
}
}
-BOOL
+BOOLEAN
XboxDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{
ULONG StartSector;
if (DriveNumber < 0x80 || 2 <= (DriveNumber & 0x0f))
{
/* Xbox has only 1 IDE controller and no floppy */
- DbgPrint((DPRINT_DISK, "Invalid drive number\n"));
+ DPRINTM(DPRINT_DISK, "Invalid drive number\n");
return FALSE;
}
if (UINT64_C(0) != ((SectorNumber + SectorCount) & UINT64_C(0xfffffffff0000000)))
{
- DbgPrint((DPRINT_DISK, "48bit LBA required but not implemented\n"));
+ DPRINTM(DPRINT_DISK, "48bit LBA required but not implemented\n");
return FALSE;
}
return TRUE;
}
-BOOL
+BOOLEAN
XboxDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
{
UCHAR SectorData[IDE_SECTOR_BUF_SZ];
return DiskGetPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
}
-BOOL
+BOOLEAN
XboxDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
{
IDE_DRIVE_IDENTIFY DrvParms;
ULONG i;
- BOOL Atapi;
+ BOOLEAN Atapi;
Atapi = FALSE; /* FIXME */
/* Get the Drive Identify block from drive or die */
(Atapi ? IDE_CMD_IDENT_ATAPI_DRV : IDE_CMD_IDENT_ATA_DRV),
(PUCHAR) &DrvParms))
{
- DbgPrint((DPRINT_DISK, "XboxDiskPolledRead() failed\n"));
+ DPRINTM(DPRINT_DISK, "XboxDiskPolledRead() failed\n");
return FALSE;
}
}
else
{
- DbgPrint((DPRINT_DISK, "BytesPerSector %d\n", DrvParms.BytesPerSector));
+ DPRINTM(DPRINT_DISK, "BytesPerSector %d\n", DrvParms.BytesPerSector);
if (DrvParms.BytesPerSector == 0)
{
Geometry->BytesPerSector = 512;
}
else
{
- for (i = 15; i >= 0; i--)
+ for (i = 1 << 15; i; i /= 2)
{
- if (0 != (DrvParms.BytesPerSector & (1 << i)))
+ if (0 != (DrvParms.BytesPerSector & i))
{
- Geometry->BytesPerSector = 1 << i;
+ Geometry->BytesPerSector = i;
break;
}
}
}
}
- DbgPrint((DPRINT_DISK, "Cylinders %d\n", Geometry->Cylinders));
- DbgPrint((DPRINT_DISK, "Heads %d\n", Geometry->Heads));
- DbgPrint((DPRINT_DISK, "Sectors %d\n", Geometry->Sectors));
- DbgPrint((DPRINT_DISK, "BytesPerSector %d\n", Geometry->BytesPerSector));
+ DPRINTM(DPRINT_DISK, "Cylinders %d\n", Geometry->Cylinders);
+ DPRINTM(DPRINT_DISK, "Heads %d\n", Geometry->Heads);
+ DPRINTM(DPRINT_DISK, "Sectors %d\n", Geometry->Sectors);
+ DPRINTM(DPRINT_DISK, "BytesPerSector %d\n", Geometry->BytesPerSector);
return TRUE;
}