ReactOS  0.4.14-dev-608-gd495a4f
xboxdisk.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for xboxdisk.c:

Go to the source code of this file.

Classes

struct  _IDE_DRIVE_IDENTIFY
 

Macros

#define XBOX_IDE_COMMAND_PORT   0x1f0
 
#define XBOX_IDE_CONTROL_PORT   0x170
 
#define IDE_SECTOR_BUF_SZ   512
 
#define IDE_MAX_POLL_RETRIES   100000
 
#define IDE_MAX_BUSY_RETRIES   50000
 
#define IDE_REG_ALT_STATUS   0x0000
 
#define IDE_REG_DEV_CNTRL   0x0000 /* device control register */
 
#define IDE_DC_SRST   0x04 /* drive reset (both drives) */
 
#define IDE_DC_nIEN   0x02 /* IRQ enable (active low) */
 
#define IDE_REG_DRV_ADDR   0x0001
 
#define IDE_REG_DATA_PORT   0x0000
 
#define IDE_REG_ERROR   0x0001 /* error register */
 
#define IDE_ER_AMNF   0x01 /* addr mark not found */
 
#define IDE_ER_TK0NF   0x02 /* track 0 not found */
 
#define IDE_ER_ABRT   0x04 /* command aborted */
 
#define IDE_ER_MCR   0x08 /* media change requested */
 
#define IDE_ER_IDNF   0x10 /* ID not found */
 
#define IDE_ER_MC   0x20 /* Media changed */
 
#define IDE_ER_UNC   0x40 /* Uncorrectable data error */
 
#define IDE_REG_PRECOMP   0x0001
 
#define IDE_REG_SECTOR_CNT   0x0002
 
#define IDE_REG_SECTOR_NUM   0x0003
 
#define IDE_REG_CYL_LOW   0x0004
 
#define IDE_REG_CYL_HIGH   0x0005
 
#define IDE_REG_DRV_HEAD   0x0006
 
#define IDE_DH_FIXED   0xA0
 
#define IDE_DH_LBA   0x40
 
#define IDE_DH_HDMASK   0x0F
 
#define IDE_DH_DRV0   0x00
 
#define IDE_DH_DRV1   0x10
 
#define IDE_REG_STATUS   0x0007
 
#define IDE_SR_BUSY   0x80
 
#define IDE_SR_DRDY   0x40
 
#define IDE_SR_WERR   0x20
 
#define IDE_SR_DRQ   0x08
 
#define IDE_SR_ERR   0x01
 
#define IDE_REG_COMMAND   0x0007
 
#define IDE_CMD_RESET   0x08
 
#define IDE_CMD_READ   0x20
 
#define IDE_CMD_READ_RETRY   0x21
 
#define IDE_CMD_WRITE   0x30
 
#define IDE_CMD_WRITE_RETRY   0x31
 
#define IDE_CMD_PACKET   0xA0
 
#define IDE_CMD_READ_MULTIPLE   0xC4
 
#define IDE_CMD_WRITE_MULTIPLE   0xC5
 
#define IDE_CMD_READ_DMA   0xC8
 
#define IDE_CMD_WRITE_DMA   0xCA
 
#define IDE_CMD_FLUSH_CACHE   0xE7
 
#define IDE_CMD_FLUSH_CACHE_EXT   0xEA
 
#define IDE_CMD_IDENT_ATA_DRV   0xEC
 
#define IDE_CMD_IDENT_ATAPI_DRV   0xA1
 
#define IDE_CMD_GET_MEDIA_STATUS   0xDA
 
#define IDEReadError(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ERROR)))
 
#define IDEWritePrecomp(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_PRECOMP), (Data)))
 
#define IDEReadSectorCount(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT)))
 
#define IDEWriteSectorCount(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT), (Data)))
 
#define IDEReadSectorNum(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM)))
 
#define IDEWriteSectorNum(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM), (Data)))
 
#define IDEReadCylinderLow(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW)))
 
#define IDEWriteCylinderLow(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW), (Data)))
 
#define IDEReadCylinderHigh(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH)))
 
#define IDEWriteCylinderHigh(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH), (Data)))
 
#define IDEReadDriveHead(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD)))
 
#define IDEWriteDriveHead(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD), (Data)))
 
#define IDEReadStatus(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_STATUS)))
 
#define IDEWriteCommand(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_COMMAND), (Data)))
 
#define IDEReadDMACommand(Address)   (READ_PORT_UCHAR((PUCHAR)((Address))))
 
#define IDEWriteDMACommand(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address)), (Data)))
 
#define IDEReadDMAStatus(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + 2)))
 
#define IDEWriteDMAStatus(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + 2), (Data)))
 
#define IDEWritePRDTable(Address, Data)   (WRITE_PORT_ULONG((PULONG)((Address) + 4), (Data)))
 
#define IDEReadBlock(Address, Buffer, Count)   (READ_PORT_BUFFER_USHORT((PUSHORT)((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))
 
#define IDEReadBlock32(Address, Buffer, Count)   (READ_PORT_BUFFER_ULONG((PULONG)((Address) + IDE_REG_DATA_PORT), (PULONG)(Buffer), (Count) / 4))
 
#define IDEWriteBlock32(Address, Buffer, Count)   (WRITE_PORT_BUFFER_ULONG((PULONG)((Address) + IDE_REG_DATA_PORT), (PULONG)(Buffer), (Count) / 4))
 
#define IDEReadWord(Address)   (READ_PORT_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT)))
 
#define IDEReadAltStatus(Address)   (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ALT_STATUS)))
 
#define IDEWriteDriveControl(Address, Data)   (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DEV_CNTRL), (Data)))
 
#define IDE_DRID_STBY_SUPPORTED   0x2000
 
#define IDE_DRID_IORDY_SUPPORTED   0x0800
 
#define IDE_DRID_IORDY_DISABLE   0x0400
 
#define IDE_DRID_LBA_SUPPORTED   0x0200
 
#define IDE_DRID_DMA_SUPPORTED   0x0100
 

Typedefs

typedef struct _IDE_DRIVE_IDENTIFY IDE_DRIVE_IDENTIFY
 
typedef struct _IDE_DRIVE_IDENTIFYPIDE_DRIVE_IDENTIFY
 

Functions

 DBG_DEFAULT_CHANNEL (DISK)
 
static BOOLEAN XboxDiskPolledRead (ULONG CommandPort, ULONG ControlPort, UCHAR PreComp, UCHAR SectorCnt, UCHAR SectorNum, UCHAR CylinderLow, UCHAR CylinderHigh, UCHAR DrvHead, UCHAR Command, PVOID Buffer)
 
BOOLEAN XboxDiskReadLogicalSectors (UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
 
BOOLEAN XboxDiskGetDriveGeometry (UCHAR DriveNumber, PGEOMETRY Geometry)
 
ULONG XboxDiskGetCacheableBlockCount (UCHAR DriveNumber)
 

Macro Definition Documentation

◆ IDE_CMD_FLUSH_CACHE

#define IDE_CMD_FLUSH_CACHE   0xE7

Definition at line 84 of file xboxdisk.c.

◆ IDE_CMD_FLUSH_CACHE_EXT

#define IDE_CMD_FLUSH_CACHE_EXT   0xEA

Definition at line 85 of file xboxdisk.c.

◆ IDE_CMD_GET_MEDIA_STATUS

#define IDE_CMD_GET_MEDIA_STATUS   0xDA

Definition at line 88 of file xboxdisk.c.

◆ IDE_CMD_IDENT_ATA_DRV

#define IDE_CMD_IDENT_ATA_DRV   0xEC

Definition at line 86 of file xboxdisk.c.

◆ IDE_CMD_IDENT_ATAPI_DRV

#define IDE_CMD_IDENT_ATAPI_DRV   0xA1

Definition at line 87 of file xboxdisk.c.

◆ IDE_CMD_PACKET

#define IDE_CMD_PACKET   0xA0

Definition at line 79 of file xboxdisk.c.

◆ IDE_CMD_READ

#define IDE_CMD_READ   0x20

Definition at line 75 of file xboxdisk.c.

◆ IDE_CMD_READ_DMA

#define IDE_CMD_READ_DMA   0xC8

Definition at line 82 of file xboxdisk.c.

◆ IDE_CMD_READ_MULTIPLE

#define IDE_CMD_READ_MULTIPLE   0xC4

Definition at line 80 of file xboxdisk.c.

◆ IDE_CMD_READ_RETRY

#define IDE_CMD_READ_RETRY   0x21

Definition at line 76 of file xboxdisk.c.

◆ IDE_CMD_RESET

#define IDE_CMD_RESET   0x08

Definition at line 74 of file xboxdisk.c.

◆ IDE_CMD_WRITE

#define IDE_CMD_WRITE   0x30

Definition at line 77 of file xboxdisk.c.

◆ IDE_CMD_WRITE_DMA

#define IDE_CMD_WRITE_DMA   0xCA

Definition at line 83 of file xboxdisk.c.

◆ IDE_CMD_WRITE_MULTIPLE

#define IDE_CMD_WRITE_MULTIPLE   0xC5

Definition at line 81 of file xboxdisk.c.

◆ IDE_CMD_WRITE_RETRY

#define IDE_CMD_WRITE_RETRY   0x31

Definition at line 78 of file xboxdisk.c.

◆ IDE_DC_nIEN

#define IDE_DC_nIEN   0x02 /* IRQ enable (active low) */

Definition at line 41 of file xboxdisk.c.

◆ IDE_DC_SRST

#define IDE_DC_SRST   0x04 /* drive reset (both drives) */

Definition at line 40 of file xboxdisk.c.

◆ IDE_DH_DRV0

#define IDE_DH_DRV0   0x00

Definition at line 63 of file xboxdisk.c.

◆ IDE_DH_DRV1

#define IDE_DH_DRV1   0x10

Definition at line 64 of file xboxdisk.c.

◆ IDE_DH_FIXED

#define IDE_DH_FIXED   0xA0

Definition at line 60 of file xboxdisk.c.

◆ IDE_DH_HDMASK

#define IDE_DH_HDMASK   0x0F

Definition at line 62 of file xboxdisk.c.

◆ IDE_DH_LBA

#define IDE_DH_LBA   0x40

Definition at line 61 of file xboxdisk.c.

◆ IDE_DRID_DMA_SUPPORTED

#define IDE_DRID_DMA_SUPPORTED   0x0100

Definition at line 186 of file xboxdisk.c.

◆ IDE_DRID_IORDY_DISABLE

#define IDE_DRID_IORDY_DISABLE   0x0400

Definition at line 184 of file xboxdisk.c.

◆ IDE_DRID_IORDY_SUPPORTED

#define IDE_DRID_IORDY_SUPPORTED   0x0800

Definition at line 183 of file xboxdisk.c.

◆ IDE_DRID_LBA_SUPPORTED

#define IDE_DRID_LBA_SUPPORTED   0x0200

Definition at line 185 of file xboxdisk.c.

◆ IDE_DRID_STBY_SUPPORTED

#define IDE_DRID_STBY_SUPPORTED   0x2000

Definition at line 182 of file xboxdisk.c.

◆ IDE_ER_ABRT

#define IDE_ER_ABRT   0x04 /* command aborted */

Definition at line 49 of file xboxdisk.c.

◆ IDE_ER_AMNF

#define IDE_ER_AMNF   0x01 /* addr mark not found */

Definition at line 47 of file xboxdisk.c.

◆ IDE_ER_IDNF

#define IDE_ER_IDNF   0x10 /* ID not found */

Definition at line 51 of file xboxdisk.c.

◆ IDE_ER_MC

#define IDE_ER_MC   0x20 /* Media changed */

Definition at line 52 of file xboxdisk.c.

◆ IDE_ER_MCR

#define IDE_ER_MCR   0x08 /* media change requested */

Definition at line 50 of file xboxdisk.c.

◆ IDE_ER_TK0NF

#define IDE_ER_TK0NF   0x02 /* track 0 not found */

Definition at line 48 of file xboxdisk.c.

◆ IDE_ER_UNC

#define IDE_ER_UNC   0x40 /* Uncorrectable data error */

Definition at line 53 of file xboxdisk.c.

◆ IDE_MAX_BUSY_RETRIES

#define IDE_MAX_BUSY_RETRIES   50000

Definition at line 35 of file xboxdisk.c.

◆ IDE_MAX_POLL_RETRIES

#define IDE_MAX_POLL_RETRIES   100000

Definition at line 34 of file xboxdisk.c.

◆ IDE_REG_ALT_STATUS

#define IDE_REG_ALT_STATUS   0x0000

Definition at line 38 of file xboxdisk.c.

◆ IDE_REG_COMMAND

#define IDE_REG_COMMAND   0x0007

Definition at line 71 of file xboxdisk.c.

◆ IDE_REG_CYL_HIGH

#define IDE_REG_CYL_HIGH   0x0005

Definition at line 58 of file xboxdisk.c.

◆ IDE_REG_CYL_LOW

#define IDE_REG_CYL_LOW   0x0004

Definition at line 57 of file xboxdisk.c.

◆ IDE_REG_DATA_PORT

#define IDE_REG_DATA_PORT   0x0000

Definition at line 45 of file xboxdisk.c.

◆ IDE_REG_DEV_CNTRL

#define IDE_REG_DEV_CNTRL   0x0000 /* device control register */

Definition at line 39 of file xboxdisk.c.

◆ IDE_REG_DRV_ADDR

#define IDE_REG_DRV_ADDR   0x0001

Definition at line 42 of file xboxdisk.c.

◆ IDE_REG_DRV_HEAD

#define IDE_REG_DRV_HEAD   0x0006

Definition at line 59 of file xboxdisk.c.

◆ IDE_REG_ERROR

#define IDE_REG_ERROR   0x0001 /* error register */

Definition at line 46 of file xboxdisk.c.

◆ IDE_REG_PRECOMP

#define IDE_REG_PRECOMP   0x0001

Definition at line 54 of file xboxdisk.c.

◆ IDE_REG_SECTOR_CNT

#define IDE_REG_SECTOR_CNT   0x0002

Definition at line 55 of file xboxdisk.c.

◆ IDE_REG_SECTOR_NUM

#define IDE_REG_SECTOR_NUM   0x0003

Definition at line 56 of file xboxdisk.c.

◆ IDE_REG_STATUS

#define IDE_REG_STATUS   0x0007

Definition at line 65 of file xboxdisk.c.

◆ IDE_SECTOR_BUF_SZ

#define IDE_SECTOR_BUF_SZ   512

Definition at line 33 of file xboxdisk.c.

◆ IDE_SR_BUSY

#define IDE_SR_BUSY   0x80

Definition at line 66 of file xboxdisk.c.

◆ IDE_SR_DRDY

#define IDE_SR_DRDY   0x40

Definition at line 67 of file xboxdisk.c.

◆ IDE_SR_DRQ

#define IDE_SR_DRQ   0x08

Definition at line 69 of file xboxdisk.c.

◆ IDE_SR_ERR

#define IDE_SR_ERR   0x01

Definition at line 70 of file xboxdisk.c.

◆ IDE_SR_WERR

#define IDE_SR_WERR   0x20

Definition at line 68 of file xboxdisk.c.

◆ IDEReadAltStatus

#define IDEReadAltStatus (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ALT_STATUS)))

Definition at line 153 of file xboxdisk.c.

◆ IDEReadBlock

#define IDEReadBlock (   Address,
  Buffer,
  Count 
)    (READ_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))

Definition at line 136 of file xboxdisk.c.

◆ IDEReadBlock32

#define IDEReadBlock32 (   Address,
  Buffer,
  Count 
)    (READ_PORT_BUFFER_ULONG((PULONG)((Address) + IDE_REG_DATA_PORT), (PULONG)(Buffer), (Count) / 4))

Definition at line 141 of file xboxdisk.c.

◆ IDEReadCylinderHigh

#define IDEReadCylinderHigh (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH)))

Definition at line 110 of file xboxdisk.c.

◆ IDEReadCylinderLow

#define IDEReadCylinderLow (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW)))

Definition at line 106 of file xboxdisk.c.

◆ IDEReadDMACommand

#define IDEReadDMACommand (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address))))

Definition at line 122 of file xboxdisk.c.

◆ IDEReadDMAStatus

#define IDEReadDMAStatus (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + 2)))

Definition at line 126 of file xboxdisk.c.

◆ IDEReadDriveHead

#define IDEReadDriveHead (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD)))

Definition at line 114 of file xboxdisk.c.

◆ IDEReadError

#define IDEReadError (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_ERROR)))

Definition at line 94 of file xboxdisk.c.

◆ IDEReadSectorCount

#define IDEReadSectorCount (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT)))

Definition at line 98 of file xboxdisk.c.

◆ IDEReadSectorNum

#define IDEReadSectorNum (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM)))

Definition at line 102 of file xboxdisk.c.

◆ IDEReadStatus

#define IDEReadStatus (   Address)    (READ_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_STATUS)))

Definition at line 118 of file xboxdisk.c.

◆ IDEReadWord

#define IDEReadWord (   Address)    (READ_PORT_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT)))

Definition at line 146 of file xboxdisk.c.

◆ IDEWriteBlock

#define IDEWriteBlock (   Address,
  Buffer,
  Count 
)    (WRITE_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))

Definition at line 138 of file xboxdisk.c.

◆ IDEWriteBlock32

#define IDEWriteBlock32 (   Address,
  Buffer,
  Count 
)    (WRITE_PORT_BUFFER_ULONG((PULONG)((Address) + IDE_REG_DATA_PORT), (PULONG)(Buffer), (Count) / 4))

Definition at line 143 of file xboxdisk.c.

◆ IDEWriteCommand

#define IDEWriteCommand (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_COMMAND), (Data)))

Definition at line 120 of file xboxdisk.c.

◆ IDEWriteCylinderHigh

#define IDEWriteCylinderHigh (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_HIGH), (Data)))

Definition at line 112 of file xboxdisk.c.

◆ IDEWriteCylinderLow

#define IDEWriteCylinderLow (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_CYL_LOW), (Data)))

Definition at line 108 of file xboxdisk.c.

◆ IDEWriteDMACommand

#define IDEWriteDMACommand (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address)), (Data)))

Definition at line 124 of file xboxdisk.c.

◆ IDEWriteDMAStatus

#define IDEWriteDMAStatus (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + 2), (Data)))

Definition at line 128 of file xboxdisk.c.

◆ IDEWriteDriveControl

#define IDEWriteDriveControl (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DEV_CNTRL), (Data)))

Definition at line 155 of file xboxdisk.c.

◆ IDEWriteDriveHead

#define IDEWriteDriveHead (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_DRV_HEAD), (Data)))

Definition at line 116 of file xboxdisk.c.

◆ IDEWritePRDTable

#define IDEWritePRDTable (   Address,
  Data 
)    (WRITE_PORT_ULONG((PULONG)((Address) + 4), (Data)))

Definition at line 130 of file xboxdisk.c.

◆ IDEWritePrecomp

#define IDEWritePrecomp (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_PRECOMP), (Data)))

Definition at line 96 of file xboxdisk.c.

◆ IDEWriteSectorCount

#define IDEWriteSectorCount (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_CNT), (Data)))

Definition at line 100 of file xboxdisk.c.

◆ IDEWriteSectorNum

#define IDEWriteSectorNum (   Address,
  Data 
)    (WRITE_PORT_UCHAR((PUCHAR)((Address) + IDE_REG_SECTOR_NUM), (Data)))

Definition at line 104 of file xboxdisk.c.

◆ XBOX_IDE_COMMAND_PORT

#define XBOX_IDE_COMMAND_PORT   0x1f0

Definition at line 30 of file xboxdisk.c.

◆ XBOX_IDE_CONTROL_PORT

#define XBOX_IDE_CONTROL_PORT   0x170

Definition at line 31 of file xboxdisk.c.

Typedef Documentation

◆ IDE_DRIVE_IDENTIFY

◆ PIDE_DRIVE_IDENTIFY

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( DISK  )

◆ XboxDiskGetCacheableBlockCount()

ULONG XboxDiskGetCacheableBlockCount ( UCHAR  DriveNumber)

Definition at line 516 of file xboxdisk.c.

517 {
518  /* 64 seems a nice number, it is used by the machpc code for LBA devices */
519  return 64;
520 }

Referenced by XboxMachInit().

◆ XboxDiskGetDriveGeometry()

BOOLEAN XboxDiskGetDriveGeometry ( UCHAR  DriveNumber,
PGEOMETRY  Geometry 
)

Definition at line 456 of file xboxdisk.c.

457 {
458  IDE_DRIVE_IDENTIFY DrvParms;
459  ULONG i;
460  BOOLEAN Atapi;
461 
462  Atapi = FALSE; /* FIXME */
463  /* Get the Drive Identify block from drive or die */
466  0,
467  1,
468  0,
469  0,
470  0,
471  ((DriveNumber & 0x0f) == 0 ? IDE_DH_DRV0 : IDE_DH_DRV1),
473  (PUCHAR) &DrvParms))
474  {
475  ERR("XboxDiskPolledRead() failed\n");
476  return FALSE;
477  }
478 
479  Geometry->Cylinders = DrvParms.LogicalCyls;
480  Geometry->Heads = DrvParms.LogicalHeads;
481  Geometry->Sectors = DrvParms.SectorsPerTrack;
482 
483  if (!Atapi && (DrvParms.Capabilities & IDE_DRID_LBA_SUPPORTED) != 0)
484  {
485  /* LBA ATA drives always have a sector size of 512 */
486  Geometry->BytesPerSector = 512;
487  }
488  else
489  {
490  TRACE("BytesPerSector %d\n", DrvParms.BytesPerSector);
491  if (DrvParms.BytesPerSector == 0)
492  {
493  Geometry->BytesPerSector = 512;
494  }
495  else
496  {
497  for (i = 1 << 15; i; i /= 2)
498  {
499  if ((DrvParms.BytesPerSector & i) != 0)
500  {
501  Geometry->BytesPerSector = i;
502  break;
503  }
504  }
505  }
506  }
507  TRACE("Cylinders %d\n", Geometry->Cylinders);
508  TRACE("Heads %d\n", Geometry->Heads);
509  TRACE("Sectors %d\n", Geometry->Sectors);
510  TRACE("BytesPerSector %d\n", Geometry->BytesPerSector);
511 
512  return TRUE;
513 }
static BOOLEAN XboxDiskPolledRead(ULONG CommandPort, ULONG ControlPort, UCHAR PreComp, UCHAR SectorCnt, UCHAR SectorNum, UCHAR CylinderLow, UCHAR CylinderHigh, UCHAR DrvHead, UCHAR Command, PVOID Buffer)
Definition: xboxdisk.c:245
#define TRUE
Definition: types.h:120
ULONG Cylinders
Definition: disk.h:26
unsigned char * PUCHAR
Definition: retypes.h:3
#define XBOX_IDE_CONTROL_PORT
Definition: xboxdisk.c:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IDE_CMD_IDENT_ATAPI_DRV
Definition: xboxdisk.c:87
unsigned char BOOLEAN
ULONG Sectors
Definition: disk.h:28
#define TRACE(s)
Definition: solgame.cpp:4
#define IDE_DH_DRV1
Definition: xboxdisk.c:64
#define IDE_CMD_IDENT_ATA_DRV
Definition: xboxdisk.c:86
#define ERR(fmt,...)
Definition: debug.h:109
ULONG BytesPerSector
Definition: disk.h:29
#define IDE_DH_DRV0
Definition: xboxdisk.c:63
unsigned int ULONG
Definition: retypes.h:1
#define IDE_DRID_LBA_SUPPORTED
Definition: xboxdisk.c:185
#define XBOX_IDE_COMMAND_PORT
Definition: xboxdisk.c:30
ULONG Heads
Definition: disk.h:27

Referenced by XboxGetHarddiskConfigurationData(), and XboxMachInit().

◆ XboxDiskPolledRead()

static BOOLEAN XboxDiskPolledRead ( ULONG  CommandPort,
ULONG  ControlPort,
UCHAR  PreComp,
UCHAR  SectorCnt,
UCHAR  SectorNum,
UCHAR  CylinderLow,
UCHAR  CylinderHigh,
UCHAR  DrvHead,
UCHAR  Command,
PVOID  Buffer 
)
static

Definition at line 245 of file xboxdisk.c.

255 {
256  ULONG SectorCount = 0;
257  ULONG RetryCount;
258  BOOLEAN Junk = FALSE;
259  UCHAR Status;
260 
261  /* Wait for BUSY to clear */
262  for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
263  {
264  Status = IDEReadStatus(CommandPort);
265  if (!(Status & IDE_SR_BUSY))
266  break;
267 
269  }
270  TRACE("status=0x%x\n", Status);
271  TRACE("waited %d usecs for busy to clear\n", RetryCount * 10);
272  if (RetryCount >= IDE_MAX_BUSY_RETRIES)
273  {
274  WARN("Drive is BUSY for too long\n");
275  return FALSE;
276  }
277 
278  /* Write Drive/Head to select drive */
279  IDEWriteDriveHead(CommandPort, IDE_DH_FIXED | DrvHead);
281 
282  /* Disable interrupts */
283  IDEWriteDriveControl(ControlPort, IDE_DC_nIEN);
285 
286  /* Issue command to drive */
287  if (DrvHead & IDE_DH_LBA)
288  {
289  TRACE("READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
290  DrvHead & IDE_DH_DRV1 ? 1 : 0,
291  ((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum,
292  SectorCnt,
293  Command);
294  }
295  else
296  {
297  TRACE("READ:DRV=%d:LBA=0:CH=0x%x:CL=0x%x:HD=0x%x:SN=0x%x:SC=0x%x:CM=0x%x\n",
298  DrvHead & IDE_DH_DRV1 ? 1 : 0,
299  CylinderHigh,
300  CylinderLow,
301  DrvHead & 0x0f,
302  SectorNum,
303  SectorCnt,
304  Command);
305  }
306 
307  /* Setup command parameters */
308  IDEWritePrecomp(CommandPort, PreComp);
309  IDEWriteSectorCount(CommandPort, SectorCnt);
310  IDEWriteSectorNum(CommandPort, SectorNum);
311  IDEWriteCylinderHigh(CommandPort, CylinderHigh);
312  IDEWriteCylinderLow(CommandPort, CylinderLow);
313  IDEWriteDriveHead(CommandPort, IDE_DH_FIXED | DrvHead);
314 
315  /* Issue the command */
316  IDEWriteCommand(CommandPort, Command);
318 
319  /* Wait for DRQ or error */
320  for (RetryCount = 0; RetryCount < IDE_MAX_POLL_RETRIES; RetryCount++)
321  {
322  Status = IDEReadStatus(CommandPort);
323  if (!(Status & IDE_SR_BUSY))
324  {
325  if (Status & IDE_SR_ERR)
326  {
327  IDEWriteDriveControl(ControlPort, 0);
329  IDEReadStatus(CommandPort);
330  return FALSE;
331  }
332 
333  if (Status & IDE_SR_DRQ)
334  {
335  break;
336  }
337  else
338  {
339  IDEWriteDriveControl(ControlPort, 0);
341  IDEReadStatus(CommandPort);
342  return FALSE;
343  }
344  }
346  }
347 
348  /* Timed out */
349  if (RetryCount >= IDE_MAX_POLL_RETRIES)
350  {
351  IDEWriteDriveControl(ControlPort, 0);
353  IDEReadStatus(CommandPort);
354  return FALSE;
355  }
356 
357  while (1)
358  {
359  /* Read data into buffer */
360  if (Junk == FALSE)
361  {
362  IDEReadBlock(CommandPort, Buffer, IDE_SECTOR_BUF_SZ);
364  }
365  else
366  {
367  UCHAR JunkBuffer[IDE_SECTOR_BUF_SZ];
368  IDEReadBlock(CommandPort, JunkBuffer, IDE_SECTOR_BUF_SZ);
369  }
370  SectorCount++;
371 
372  /* Check for error or more sectors to read */
373  for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
374  {
375  Status = IDEReadStatus(CommandPort);
376  if (!(Status & IDE_SR_BUSY))
377  {
378  if (Status & IDE_SR_ERR)
379  {
380  IDEWriteDriveControl(ControlPort, 0);
382  IDEReadStatus(CommandPort);
383  return FALSE;
384  }
385  if (Status & IDE_SR_DRQ)
386  {
387  if (SectorCount >= SectorCnt)
388  {
389  TRACE("Buffer size exceeded!\n");
390  Junk = TRUE;
391  }
392  break;
393  }
394  else
395  {
396  if (SectorCount > SectorCnt)
397  {
398  TRACE("Read %lu sectors of junk!\n",
399  SectorCount - SectorCnt);
400  }
401 
402  IDEWriteDriveControl(ControlPort, 0);
404  IDEReadStatus(CommandPort);
405  return TRUE;
406  }
407  }
408  }
409  }
410 }
#define TRUE
Definition: types.h:120
#define IDEWriteDriveHead(Address, Data)
Definition: xboxdisk.c:116
#define WARN(fmt,...)
Definition: debug.h:111
#define IDE_SR_ERR
Definition: xboxdisk.c:70
Definition: shell.h:41
#define IDE_MAX_BUSY_RETRIES
Definition: xboxdisk.c:35
#define IDEWriteSectorCount(Address, Data)
Definition: xboxdisk.c:100
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IDE_DH_FIXED
Definition: xboxdisk.c:60
#define IDE_SECTOR_BUF_SZ
Definition: xboxdisk.c:33
#define IDEWritePrecomp(Address, Data)
Definition: xboxdisk.c:96
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: hardware.c:55
unsigned char BOOLEAN
#define IDE_SR_BUSY
Definition: xboxdisk.c:66
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define TRACE(s)
Definition: solgame.cpp:4
#define IDEReadBlock(Address, Buffer, Count)
Definition: xboxdisk.c:136
#define IDEWriteDriveControl(Address, Data)
Definition: xboxdisk.c:155
#define IDEWriteCommand(Address, Data)
Definition: xboxdisk.c:120
#define IDE_DH_LBA
Definition: xboxdisk.c:61
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG SectorCount
Definition: part_xbox.c:32
#define IDEWriteCylinderHigh(Address, Data)
Definition: xboxdisk.c:112
#define IDE_DH_DRV1
Definition: xboxdisk.c:64
Status
Definition: gdiplustypes.h:24
#define IDE_DC_nIEN
Definition: xboxdisk.c:41
#define IDEReadStatus(Address)
Definition: xboxdisk.c:118
#define IDE_MAX_POLL_RETRIES
Definition: xboxdisk.c:34
unsigned int ULONG
Definition: retypes.h:1
#define IDEWriteSectorNum(Address, Data)
Definition: xboxdisk.c:104
#define IDEWriteCylinderLow(Address, Data)
Definition: xboxdisk.c:108
#define IDE_SR_DRQ
Definition: xboxdisk.c:69

Referenced by XboxDiskGetDriveGeometry(), and XboxDiskReadLogicalSectors().

◆ XboxDiskReadLogicalSectors()

BOOLEAN XboxDiskReadLogicalSectors ( UCHAR  DriveNumber,
ULONGLONG  SectorNumber,
ULONG  SectorCount,
PVOID  Buffer 
)

Definition at line 413 of file xboxdisk.c.

414 {
415  ULONG StartSector;
416  UCHAR Count;
417 
418  if (DriveNumber < 0x80 || (DriveNumber & 0x0f) >= 2)
419  {
420  /* Xbox has only 1 IDE controller and no floppy */
421  WARN("Invalid drive number\n");
422  return FALSE;
423  }
424 
425  if (((SectorNumber + SectorCount) & UINT64_C(0xfffffffff0000000)) != UINT64_C(0))
426  {
427  FIXME("48bit LBA required but not implemented\n");
428  return FALSE;
429  }
430 
431  StartSector = (ULONG) SectorNumber;
432  while (SectorCount > 0)
433  {
434  Count = (SectorCount <= 255 ? (UCHAR)SectorCount : 255);
437  0, Count,
438  StartSector & 0xff,
439  (StartSector >> 8) & 0xff,
440  (StartSector >> 16) & 0xff,
441  ((StartSector >> 24) & 0x0f) | IDE_DH_LBA |
442  ((DriveNumber & 0x0f) == 0 ? IDE_DH_DRV0 : IDE_DH_DRV1),
443  IDE_CMD_READ,
444  Buffer))
445  {
446  return FALSE;
447  }
448  SectorCount -= Count;
450  }
451 
452  return TRUE;
453 }
signed char * PCHAR
Definition: retypes.h:7
static BOOLEAN XboxDiskPolledRead(ULONG CommandPort, ULONG ControlPort, UCHAR PreComp, UCHAR SectorCnt, UCHAR SectorNum, UCHAR CylinderLow, UCHAR CylinderHigh, UCHAR DrvHead, UCHAR Command, PVOID Buffer)
Definition: xboxdisk.c:245
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:111
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define XBOX_IDE_CONTROL_PORT
Definition: xboxdisk.c:31
#define UINT64_C(val)
Definition: freeldr.h:23
#define FIXME(fmt,...)
Definition: debug.h:110
#define IDE_SECTOR_BUF_SZ
Definition: xboxdisk.c:33
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define IDE_DH_LBA
Definition: xboxdisk.c:61
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG SectorCount
Definition: part_xbox.c:32
#define IDE_DH_DRV1
Definition: xboxdisk.c:64
#define IDE_DH_DRV0
Definition: xboxdisk.c:63
#define IDE_CMD_READ
Definition: xboxdisk.c:75
unsigned int ULONG
Definition: retypes.h:1
#define XBOX_IDE_COMMAND_PORT
Definition: xboxdisk.c:30

Referenced by XboxMachInit().