ReactOS  0.4.13-dev-257-gfabbd7c
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 XBOX_SIGNATURE_SECTOR   3
 
#define XBOX_SIGNATURE   ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
 
#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 XboxDiskGetPartitionEntry (UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
 
BOOLEAN XboxDiskGetDriveGeometry (UCHAR DriveNumber, PGEOMETRY Geometry)
 
ULONG XboxDiskGetCacheableBlockCount (UCHAR DriveNumber)
 

Variables

struct {
   ULONG   SectorCountBeforePartition
 
   ULONG   PartitionSectorCount
 
   UCHAR   SystemIndicator
 
XboxPartitions []
 

Macro Definition Documentation

◆ IDE_CMD_FLUSH_CACHE

#define IDE_CMD_FLUSH_CACHE   0xE7

Definition at line 102 of file xboxdisk.c.

◆ IDE_CMD_FLUSH_CACHE_EXT

#define IDE_CMD_FLUSH_CACHE_EXT   0xEA

Definition at line 103 of file xboxdisk.c.

◆ IDE_CMD_GET_MEDIA_STATUS

#define IDE_CMD_GET_MEDIA_STATUS   0xDA

Definition at line 106 of file xboxdisk.c.

◆ IDE_CMD_IDENT_ATA_DRV

#define IDE_CMD_IDENT_ATA_DRV   0xEC

Definition at line 104 of file xboxdisk.c.

◆ IDE_CMD_IDENT_ATAPI_DRV

#define IDE_CMD_IDENT_ATAPI_DRV   0xA1

Definition at line 105 of file xboxdisk.c.

◆ IDE_CMD_PACKET

#define IDE_CMD_PACKET   0xA0

Definition at line 97 of file xboxdisk.c.

◆ IDE_CMD_READ

#define IDE_CMD_READ   0x20

Definition at line 93 of file xboxdisk.c.

◆ IDE_CMD_READ_DMA

#define IDE_CMD_READ_DMA   0xC8

Definition at line 100 of file xboxdisk.c.

◆ IDE_CMD_READ_MULTIPLE

#define IDE_CMD_READ_MULTIPLE   0xC4

Definition at line 98 of file xboxdisk.c.

◆ IDE_CMD_READ_RETRY

#define IDE_CMD_READ_RETRY   0x21

Definition at line 94 of file xboxdisk.c.

◆ IDE_CMD_RESET

#define IDE_CMD_RESET   0x08

Definition at line 92 of file xboxdisk.c.

◆ IDE_CMD_WRITE

#define IDE_CMD_WRITE   0x30

Definition at line 95 of file xboxdisk.c.

◆ IDE_CMD_WRITE_DMA

#define IDE_CMD_WRITE_DMA   0xCA

Definition at line 101 of file xboxdisk.c.

◆ IDE_CMD_WRITE_MULTIPLE

#define IDE_CMD_WRITE_MULTIPLE   0xC5

Definition at line 99 of file xboxdisk.c.

◆ IDE_CMD_WRITE_RETRY

#define IDE_CMD_WRITE_RETRY   0x31

Definition at line 96 of file xboxdisk.c.

◆ IDE_DC_nIEN

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

Definition at line 59 of file xboxdisk.c.

◆ IDE_DC_SRST

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

Definition at line 58 of file xboxdisk.c.

◆ IDE_DH_DRV0

#define IDE_DH_DRV0   0x00

Definition at line 81 of file xboxdisk.c.

◆ IDE_DH_DRV1

#define IDE_DH_DRV1   0x10

Definition at line 82 of file xboxdisk.c.

◆ IDE_DH_FIXED

#define IDE_DH_FIXED   0xA0

Definition at line 78 of file xboxdisk.c.

◆ IDE_DH_HDMASK

#define IDE_DH_HDMASK   0x0F

Definition at line 80 of file xboxdisk.c.

◆ IDE_DH_LBA

#define IDE_DH_LBA   0x40

Definition at line 79 of file xboxdisk.c.

◆ IDE_DRID_DMA_SUPPORTED

#define IDE_DRID_DMA_SUPPORTED   0x0100

Definition at line 204 of file xboxdisk.c.

◆ IDE_DRID_IORDY_DISABLE

#define IDE_DRID_IORDY_DISABLE   0x0400

Definition at line 202 of file xboxdisk.c.

◆ IDE_DRID_IORDY_SUPPORTED

#define IDE_DRID_IORDY_SUPPORTED   0x0800

Definition at line 201 of file xboxdisk.c.

◆ IDE_DRID_LBA_SUPPORTED

#define IDE_DRID_LBA_SUPPORTED   0x0200

Definition at line 203 of file xboxdisk.c.

◆ IDE_DRID_STBY_SUPPORTED

#define IDE_DRID_STBY_SUPPORTED   0x2000

Definition at line 200 of file xboxdisk.c.

◆ IDE_ER_ABRT

#define IDE_ER_ABRT   0x04 /* command aborted */

Definition at line 67 of file xboxdisk.c.

◆ IDE_ER_AMNF

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

Definition at line 65 of file xboxdisk.c.

◆ IDE_ER_IDNF

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

Definition at line 69 of file xboxdisk.c.

◆ IDE_ER_MC

#define IDE_ER_MC   0x20 /* Media changed */

Definition at line 70 of file xboxdisk.c.

◆ IDE_ER_MCR

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

Definition at line 68 of file xboxdisk.c.

◆ IDE_ER_TK0NF

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

Definition at line 66 of file xboxdisk.c.

◆ IDE_ER_UNC

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

Definition at line 71 of file xboxdisk.c.

◆ IDE_MAX_BUSY_RETRIES

#define IDE_MAX_BUSY_RETRIES   50000

Definition at line 53 of file xboxdisk.c.

◆ IDE_MAX_POLL_RETRIES

#define IDE_MAX_POLL_RETRIES   100000

Definition at line 52 of file xboxdisk.c.

◆ IDE_REG_ALT_STATUS

#define IDE_REG_ALT_STATUS   0x0000

Definition at line 56 of file xboxdisk.c.

◆ IDE_REG_COMMAND

#define IDE_REG_COMMAND   0x0007

Definition at line 89 of file xboxdisk.c.

◆ IDE_REG_CYL_HIGH

#define IDE_REG_CYL_HIGH   0x0005

Definition at line 76 of file xboxdisk.c.

◆ IDE_REG_CYL_LOW

#define IDE_REG_CYL_LOW   0x0004

Definition at line 75 of file xboxdisk.c.

◆ IDE_REG_DATA_PORT

#define IDE_REG_DATA_PORT   0x0000

Definition at line 63 of file xboxdisk.c.

◆ IDE_REG_DEV_CNTRL

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

Definition at line 57 of file xboxdisk.c.

◆ IDE_REG_DRV_ADDR

#define IDE_REG_DRV_ADDR   0x0001

Definition at line 60 of file xboxdisk.c.

◆ IDE_REG_DRV_HEAD

#define IDE_REG_DRV_HEAD   0x0006

Definition at line 77 of file xboxdisk.c.

◆ IDE_REG_ERROR

#define IDE_REG_ERROR   0x0001 /* error register */

Definition at line 64 of file xboxdisk.c.

◆ IDE_REG_PRECOMP

#define IDE_REG_PRECOMP   0x0001

Definition at line 72 of file xboxdisk.c.

◆ IDE_REG_SECTOR_CNT

#define IDE_REG_SECTOR_CNT   0x0002

Definition at line 73 of file xboxdisk.c.

◆ IDE_REG_SECTOR_NUM

#define IDE_REG_SECTOR_NUM   0x0003

Definition at line 74 of file xboxdisk.c.

◆ IDE_REG_STATUS

#define IDE_REG_STATUS   0x0007

Definition at line 83 of file xboxdisk.c.

◆ IDE_SECTOR_BUF_SZ

#define IDE_SECTOR_BUF_SZ   512

Definition at line 51 of file xboxdisk.c.

◆ IDE_SR_BUSY

#define IDE_SR_BUSY   0x80

Definition at line 84 of file xboxdisk.c.

◆ IDE_SR_DRDY

#define IDE_SR_DRDY   0x40

Definition at line 85 of file xboxdisk.c.

◆ IDE_SR_DRQ

#define IDE_SR_DRQ   0x08

Definition at line 87 of file xboxdisk.c.

◆ IDE_SR_ERR

#define IDE_SR_ERR   0x01

Definition at line 88 of file xboxdisk.c.

◆ IDE_SR_WERR

#define IDE_SR_WERR   0x20

Definition at line 86 of file xboxdisk.c.

◆ IDEReadAltStatus

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

Definition at line 171 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 154 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 159 of file xboxdisk.c.

◆ IDEReadCylinderHigh

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

Definition at line 128 of file xboxdisk.c.

◆ IDEReadCylinderLow

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

Definition at line 124 of file xboxdisk.c.

◆ IDEReadDMACommand

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

Definition at line 140 of file xboxdisk.c.

◆ IDEReadDMAStatus

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

Definition at line 144 of file xboxdisk.c.

◆ IDEReadDriveHead

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

Definition at line 132 of file xboxdisk.c.

◆ IDEReadError

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

Definition at line 112 of file xboxdisk.c.

◆ IDEReadSectorCount

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

Definition at line 116 of file xboxdisk.c.

◆ IDEReadSectorNum

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

Definition at line 120 of file xboxdisk.c.

◆ IDEReadStatus

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

Definition at line 136 of file xboxdisk.c.

◆ IDEReadWord

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

Definition at line 164 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 156 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 161 of file xboxdisk.c.

◆ IDEWriteCommand

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

Definition at line 138 of file xboxdisk.c.

◆ IDEWriteCylinderHigh

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

Definition at line 130 of file xboxdisk.c.

◆ IDEWriteCylinderLow

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

Definition at line 126 of file xboxdisk.c.

◆ IDEWriteDMACommand

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

Definition at line 142 of file xboxdisk.c.

◆ IDEWriteDMAStatus

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

Definition at line 146 of file xboxdisk.c.

◆ IDEWriteDriveControl

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

Definition at line 173 of file xboxdisk.c.

◆ IDEWriteDriveHead

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

Definition at line 134 of file xboxdisk.c.

◆ IDEWritePRDTable

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

Definition at line 148 of file xboxdisk.c.

◆ IDEWritePrecomp

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

Definition at line 114 of file xboxdisk.c.

◆ IDEWriteSectorCount

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

Definition at line 118 of file xboxdisk.c.

◆ IDEWriteSectorNum

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

Definition at line 122 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.

◆ XBOX_SIGNATURE

#define XBOX_SIGNATURE   ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))

Definition at line 34 of file xboxdisk.c.

◆ XBOX_SIGNATURE_SECTOR

#define XBOX_SIGNATURE_SECTOR   3

Definition at line 33 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 560 of file xboxdisk.c.

561 {
562  /* 64 seems a nice number, it is used by the machpc code for LBA devices */
563  return 64;
564 }

Referenced by XboxMachInit().

◆ XboxDiskGetDriveGeometry()

BOOLEAN XboxDiskGetDriveGeometry ( UCHAR  DriveNumber,
PGEOMETRY  Geometry 
)

Definition at line 500 of file xboxdisk.c.

501 {
502  IDE_DRIVE_IDENTIFY DrvParms;
503  ULONG i;
504  BOOLEAN Atapi;
505 
506  Atapi = FALSE; /* FIXME */
507  /* Get the Drive Identify block from drive or die */
510  0,
511  1,
512  0,
513  0,
514  0,
515  (0 == (DriveNumber & 0x0f) ? IDE_DH_DRV0 : IDE_DH_DRV1),
517  (PUCHAR) &DrvParms))
518  {
519  ERR("XboxDiskPolledRead() failed\n");
520  return FALSE;
521  }
522 
523  Geometry->Cylinders = DrvParms.LogicalCyls;
524  Geometry->Heads = DrvParms.LogicalHeads;
525  Geometry->Sectors = DrvParms.SectorsPerTrack;
526 
527  if (! Atapi && 0 != (DrvParms.Capabilities & IDE_DRID_LBA_SUPPORTED))
528  {
529  /* LBA ATA drives always have a sector size of 512 */
530  Geometry->BytesPerSector = 512;
531  }
532  else
533  {
534  TRACE("BytesPerSector %d\n", DrvParms.BytesPerSector);
535  if (DrvParms.BytesPerSector == 0)
536  {
537  Geometry->BytesPerSector = 512;
538  }
539  else
540  {
541  for (i = 1 << 15; i; i /= 2)
542  {
543  if ((DrvParms.BytesPerSector & i) != 0)
544  {
545  Geometry->BytesPerSector = i;
546  break;
547  }
548  }
549  }
550  }
551  TRACE("Cylinders %d\n", Geometry->Cylinders);
552  TRACE("Heads %d\n", Geometry->Heads);
553  TRACE("Sectors %d\n", Geometry->Sectors);
554  TRACE("BytesPerSector %d\n", Geometry->BytesPerSector);
555 
556  return TRUE;
557 }
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:263
#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:105
unsigned char BOOLEAN
ULONG Sectors
Definition: disk.h:28
#define TRACE(s)
Definition: solgame.cpp:4
#define IDE_DH_DRV1
Definition: xboxdisk.c:82
#define IDE_CMD_IDENT_ATA_DRV
Definition: xboxdisk.c:104
#define ERR(fmt,...)
Definition: debug.h:109
ULONG BytesPerSector
Definition: disk.h:29
#define IDE_DH_DRV0
Definition: xboxdisk.c:81
unsigned int ULONG
Definition: retypes.h:1
#define IDE_DRID_LBA_SUPPORTED
Definition: xboxdisk.c:203
#define XBOX_IDE_COMMAND_PORT
Definition: xboxdisk.c:30
ULONG Heads
Definition: disk.h:27

Referenced by XboxMachInit().

◆ XboxDiskGetPartitionEntry()

BOOLEAN XboxDiskGetPartitionEntry ( UCHAR  DriveNumber,
ULONG  PartitionNumber,
PPARTITION_TABLE_ENTRY  PartitionTableEntry 
)

Definition at line 474 of file xboxdisk.c.

475 {
476  UCHAR SectorData[IDE_SECTOR_BUF_SZ];
477 
478  /*
479  * This is the Xbox, chances are that there is a Xbox-standard
480  * partitionless disk in it so let's check that first.
481  */
482  if (1 <= PartitionNumber && PartitionNumber <= sizeof(XboxPartitions) / sizeof(XboxPartitions[0]) &&
483  MachDiskReadLogicalSectors(DriveNumber, XBOX_SIGNATURE_SECTOR, 1, SectorData))
484  {
485  if (*((PULONG) SectorData) == XBOX_SIGNATURE)
486  {
487  memset(PartitionTableEntry, 0, sizeof(PARTITION_TABLE_ENTRY));
488  PartitionTableEntry->SystemIndicator = XboxPartitions[PartitionNumber - 1].SystemIndicator;
489  PartitionTableEntry->SectorCountBeforePartition = XboxPartitions[PartitionNumber - 1].SectorCountBeforePartition;
490  PartitionTableEntry->PartitionSectorCount = XboxPartitions[PartitionNumber - 1].PartitionSectorCount;
491  return TRUE;
492  }
493  }
494 
495  /* No magic Xbox partitions, maybe there's a MBR */
496  return DiskGetMbrPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
497 }
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:120
#define TRUE
Definition: types.h:120
ULONG PartitionSectorCount
Definition: disk.h:65
UCHAR SystemIndicator
Definition: disk.h:60
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
#define XBOX_SIGNATURE
Definition: xboxdisk.c:34
#define IDE_SECTOR_BUF_SZ
Definition: xboxdisk.c:51
BOOLEAN DiskGetMbrPartitionEntry(UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:93
ULONG SectorCountBeforePartition
Definition: disk.h:64
Definition: parttest.c:75
unsigned char UCHAR
Definition: xmlstorage.h:181
#define XBOX_SIGNATURE_SECTOR
Definition: xboxdisk.c:33
unsigned int * PULONG
Definition: retypes.h:1
static struct @149 XboxPartitions[]
#define memset(x, y, z)
Definition: compat.h:39

Referenced by 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 263 of file xboxdisk.c.

273 {
274  ULONG SectorCount = 0;
275  ULONG RetryCount;
276  BOOLEAN Junk = FALSE;
277  UCHAR Status;
278 
279  /* Wait for BUSY to clear */
280  for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
281  {
282  Status = IDEReadStatus(CommandPort);
283  if (!(Status & IDE_SR_BUSY))
284  break;
285 
287  }
288  TRACE("status=0x%x\n", Status);
289  TRACE("waited %d usecs for busy to clear\n", RetryCount * 10);
290  if (RetryCount >= IDE_MAX_BUSY_RETRIES)
291  {
292  WARN("Drive is BUSY for too long\n");
293  return FALSE;
294  }
295 
296  /* Write Drive/Head to select drive */
297  IDEWriteDriveHead(CommandPort, IDE_DH_FIXED | DrvHead);
299 
300  /* Disable interrupts */
301  IDEWriteDriveControl(ControlPort, IDE_DC_nIEN);
303 
304  /* Issue command to drive */
305  if (DrvHead & IDE_DH_LBA)
306  {
307  TRACE("READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
308  DrvHead & IDE_DH_DRV1 ? 1 : 0,
309  ((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum,
310  SectorCnt,
311  Command);
312  }
313  else
314  {
315  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",
316  DrvHead & IDE_DH_DRV1 ? 1 : 0,
317  CylinderHigh,
318  CylinderLow,
319  DrvHead & 0x0f,
320  SectorNum,
321  SectorCnt,
322  Command);
323  }
324 
325  /* Setup command parameters */
326  IDEWritePrecomp(CommandPort, PreComp);
327  IDEWriteSectorCount(CommandPort, SectorCnt);
328  IDEWriteSectorNum(CommandPort, SectorNum);
329  IDEWriteCylinderHigh(CommandPort, CylinderHigh);
330  IDEWriteCylinderLow(CommandPort, CylinderLow);
331  IDEWriteDriveHead(CommandPort, IDE_DH_FIXED | DrvHead);
332 
333  /* Issue the command */
334  IDEWriteCommand(CommandPort, Command);
336 
337  /* Wait for DRQ or error */
338  for (RetryCount = 0; RetryCount < IDE_MAX_POLL_RETRIES; RetryCount++)
339  {
340  Status = IDEReadStatus(CommandPort);
341  if (!(Status & IDE_SR_BUSY))
342  {
343  if (Status & IDE_SR_ERR)
344  {
345  IDEWriteDriveControl(ControlPort, 0);
347  IDEReadStatus(CommandPort);
348  return FALSE;
349  }
350 
351  if (Status & IDE_SR_DRQ)
352  {
353  break;
354  }
355  else
356  {
357  IDEWriteDriveControl(ControlPort, 0);
359  IDEReadStatus(CommandPort);
360  return FALSE;
361  }
362  }
364  }
365 
366  /* Timed out */
367  if (RetryCount >= IDE_MAX_POLL_RETRIES)
368  {
369  IDEWriteDriveControl(ControlPort, 0);
371  IDEReadStatus(CommandPort);
372  return FALSE;
373  }
374 
375  while (1)
376  {
377  /* Read data into buffer */
378  if (Junk == FALSE)
379  {
380  IDEReadBlock(CommandPort, Buffer, IDE_SECTOR_BUF_SZ);
382  }
383  else
384  {
385  UCHAR JunkBuffer[IDE_SECTOR_BUF_SZ];
386  IDEReadBlock(CommandPort, JunkBuffer, IDE_SECTOR_BUF_SZ);
387  }
388  SectorCount++;
389 
390  /* Check for error or more sectors to read */
391  for (RetryCount = 0; RetryCount < IDE_MAX_BUSY_RETRIES; RetryCount++)
392  {
393  Status = IDEReadStatus(CommandPort);
394  if (!(Status & IDE_SR_BUSY))
395  {
396  if (Status & IDE_SR_ERR)
397  {
398  IDEWriteDriveControl(ControlPort, 0);
400  IDEReadStatus(CommandPort);
401  return FALSE;
402  }
403  if (Status & IDE_SR_DRQ)
404  {
405  if (SectorCount >= SectorCnt)
406  {
407  TRACE("Buffer size exceeded!\n");
408  Junk = TRUE;
409  }
410  break;
411  }
412  else
413  {
414  if (SectorCount > SectorCnt)
415  {
416  TRACE("Read %lu sectors of junk!\n",
417  SectorCount - SectorCnt);
418  }
419 
420  IDEWriteDriveControl(ControlPort, 0);
422  IDEReadStatus(CommandPort);
423  return TRUE;
424  }
425  }
426  }
427  }
428 }
#define TRUE
Definition: types.h:120
#define IDEWriteDriveHead(Address, Data)
Definition: xboxdisk.c:134
#define WARN(fmt,...)
Definition: debug.h:111
#define IDE_SR_ERR
Definition: xboxdisk.c:88
Definition: shell.h:41
#define IDE_MAX_BUSY_RETRIES
Definition: xboxdisk.c:53
#define IDEWriteSectorCount(Address, Data)
Definition: xboxdisk.c:118
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IDE_DH_FIXED
Definition: xboxdisk.c:78
#define IDE_SECTOR_BUF_SZ
Definition: xboxdisk.c:51
#define IDEWritePrecomp(Address, Data)
Definition: xboxdisk.c:114
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: hardware.c:57
unsigned char BOOLEAN
#define IDE_SR_BUSY
Definition: xboxdisk.c:84
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:154
#define IDEWriteDriveControl(Address, Data)
Definition: xboxdisk.c:173
#define IDEWriteCommand(Address, Data)
Definition: xboxdisk.c:138
#define IDE_DH_LBA
Definition: xboxdisk.c:79
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG SectorCount
Definition: part_xbox.c:32
#define IDEWriteCylinderHigh(Address, Data)
Definition: xboxdisk.c:130
#define IDE_DH_DRV1
Definition: xboxdisk.c:82
Status
Definition: gdiplustypes.h:24
#define IDE_DC_nIEN
Definition: xboxdisk.c:59
#define IDEReadStatus(Address)
Definition: xboxdisk.c:136
#define IDE_MAX_POLL_RETRIES
Definition: xboxdisk.c:52
unsigned int ULONG
Definition: retypes.h:1
#define IDEWriteSectorNum(Address, Data)
Definition: xboxdisk.c:122
#define IDEWriteCylinderLow(Address, Data)
Definition: xboxdisk.c:126
#define IDE_SR_DRQ
Definition: xboxdisk.c:87

Referenced by XboxDiskGetDriveGeometry(), and XboxDiskReadLogicalSectors().

◆ XboxDiskReadLogicalSectors()

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

Definition at line 431 of file xboxdisk.c.

432 {
433  ULONG StartSector;
434  UCHAR Count;
435 
436  if (DriveNumber < 0x80 || 2 <= (DriveNumber & 0x0f))
437  {
438  /* Xbox has only 1 IDE controller and no floppy */
439  WARN("Invalid drive number\n");
440  return FALSE;
441  }
442 
443  if (UINT64_C(0) != ((SectorNumber + SectorCount) & UINT64_C(0xfffffffff0000000)))
444  {
445  FIXME("48bit LBA required but not implemented\n");
446  return FALSE;
447  }
448 
449  StartSector = (ULONG) SectorNumber;
450  while (0 < SectorCount)
451  {
452  Count = (SectorCount <= 255 ? (UCHAR)SectorCount : 255);
455  0, Count,
456  StartSector & 0xff,
457  (StartSector >> 8) & 0xff,
458  (StartSector >> 16) & 0xff,
459  ((StartSector >> 24) & 0x0f) | IDE_DH_LBA |
460  (0 == (DriveNumber & 0x0f) ? IDE_DH_DRV0 : IDE_DH_DRV1),
461  IDE_CMD_READ,
462  Buffer))
463  {
464  return FALSE;
465  }
466  SectorCount -= Count;
468  }
469 
470  return TRUE;
471 }
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:263
#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:51
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define IDE_DH_LBA
Definition: xboxdisk.c:79
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG SectorCount
Definition: part_xbox.c:32
#define IDE_DH_DRV1
Definition: xboxdisk.c:82
#define IDE_DH_DRV0
Definition: xboxdisk.c:81
#define IDE_CMD_READ
Definition: xboxdisk.c:93
unsigned int ULONG
Definition: retypes.h:1
#define XBOX_IDE_COMMAND_PORT
Definition: xboxdisk.c:30

Referenced by XboxMachInit().

Variable Documentation

◆ PartitionSectorCount

ULONG PartitionSectorCount

Definition at line 39 of file xboxdisk.c.

Referenced by FatDetermineFatType(), and FatOpenVolume().

◆ SectorCountBeforePartition

ULONG SectorCountBeforePartition

Definition at line 38 of file xboxdisk.c.

◆ SystemIndicator

UCHAR SystemIndicator

Definition at line 40 of file xboxdisk.c.

◆ XboxPartitions

struct { ... } XboxPartitions[]
Initial value:
=
{
{ 0x0055F400, 0x0098f800, PARTITION_FAT32 },
{ 0x00465400, 0x000FA000, PARTITION_FAT_16 },
{ 0x00000400, 0x00177000, PARTITION_FAT_16 },
{ 0x00177400, 0x00177000, PARTITION_FAT_16 },
{ 0x002EE400, 0x00177000, PARTITION_FAT_16 }
}
#define PARTITION_FAT32
Definition: disk.h:95
#define PARTITION_FAT_16
Definition: disk.h:90

Referenced by XboxDiskGetPartitionEntry().