19#define MAX_DRIVES 0x100
44 case 0x00:
return "No error";
45 case 0x10:
return "Drive write protection error";
46 case 0x20:
return "DMA access across 64 kB boundary";
47 case 0x30:
return "End of cylinder";
48 case 0x40:
return "The drive name is invalid or the device have low health";
49 case 0x50:
return "Time out, data not written";
50 case 0x60:
return "Time out, drive not ready";
53 return "Illegal disk address";
55 return "Drive write protection error";
56 case 0x80:
return "Undefined error";
57 case 0x90:
return "Time out error";
58 case 0xA0:
return "CRC error in the ID section";
59 case 0xB0:
return "CRC error in the DATA section";
62 return "Seek failure";
64 return "No data (Sector not found)";
65 case 0xD0:
return "Bad cylinder";
66 case 0xE0:
return "No ID address mark was found";
67 case 0xF0:
return "No DATA address mark was found";
69 default:
return "Unknown error code";
76 CHAR ErrorCodeString[200];
81 RtlStringCbPrintfA(ErrorCodeString,
sizeof(ErrorCodeString),
"%s\n\nError Code: 0x%lx\nError: %s",
84 ERR(
"%s\n", ErrorCodeString);
128 WARN(
"DiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DiskDrive->DaUa);
130 Regs.
b.
al = DiskDrive->DaUa;
131 Int386(0x1B, &Regs, &Regs);
161 switch (BytesPerSector)
185 REGS RegsIn, RegsOut;
209 RegsIn.
b.
al = DiskDrive->DaUa;
212 RegsIn.
w.
cx = SectorNumber & 0xFFFF;
213 RegsIn.
w.
dx = (SectorNumber >> 16) & 0xFFFF;
218 for (RetryCount = 0; RetryCount < 3; RetryCount++)
220 Int386(0x1B, &RegsIn, &RegsOut);
228 else if (RegsOut.
b.
ah == 0x08)
242 DiskError(
"Disk Read Failed in LBA mode", RegsOut.
b.
ah);
243 ERR(
"Disk Read Failed in LBA mode: %x (%s) (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n",
257 UCHAR PhysicalSector;
261 ULONG NumberOfSectorsToRead;
262 REGS RegsIn, RegsOut;
265 DriveGeometry = DiskDrive->Geometry;
273 PhysicalSector = (
UCHAR)(SectorNumber % DriveGeometry.
Sectors);
274 PhysicalHead = (
UCHAR)((SectorNumber / DriveGeometry.
Sectors) % DriveGeometry.
Heads);
275 PhysicalTrack = (
ULONG)((SectorNumber / DriveGeometry.
Sectors) / DriveGeometry.
Heads);
282 if (PhysicalSector > 1)
285 NumberOfSectorsToRead = (DriveGeometry.
Sectors - (PhysicalSector - 1));
292 NumberOfSectorsToRead = DriveGeometry.
Sectors;
298 if ((PhysicalHead >= DriveGeometry.
Heads) ||
299 (PhysicalTrack >= DriveGeometry.
Cylinders) ||
300 ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.
Sectors + 1)) ||
301 (PhysicalSector > DriveGeometry.
Sectors))
303 DiskError(
"Disk read exceeds drive geometry limits.", 0);
325 RegsIn.
b.
al = DiskDrive->DaUa;
328 RegsIn.
b.
cl = PhysicalTrack & 0xFFFF;
330 RegsIn.
b.
dl = PhysicalSector;
331 RegsIn.
b.
dh = PhysicalHead;
352 RegsIn.
b.
al = DiskDrive->DaUa;
355 RegsIn.
w.
cx = PhysicalTrack & 0xFFFF;
356 RegsIn.
b.
dl = PhysicalSector;
357 RegsIn.
b.
dh = PhysicalHead;
363 for (RetryCount = 0; RetryCount < 3; RetryCount++)
365 Int386(0x1B, &RegsIn, &RegsOut);
373 else if (RegsOut.
b.
ah == 0x08)
388 DiskError(
"Disk Read Failed in CHS mode, after retrying 3 times", RegsOut.
b.
ah);
389 ERR(
"Disk Read Failed in CHS mode, after retrying 3 times: %x (%s) (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n",
397 SectorNumber += NumberOfSectorsToRead;
408 REGS RegsIn, RegsOut;
409 UCHAR UnitAddress = DaUa & 0x0F;
415 if (DiskEquipment & (1 << UnitAddress))
433 Int386(0x1B, &RegsIn, &RegsOut);
436 DiskDrive->Initialized =
FALSE;
440 DiskDrive->Geometry.Cylinders = RegsOut.
w.
cx;
441 DiskDrive->Geometry.Heads = RegsOut.
b.
dh;
442 DiskDrive->Geometry.Sectors = RegsOut.
b.
dl;
443 DiskDrive->Geometry.BytesPerSector = RegsOut.
w.
bx;
444 DiskDrive->LBASupported =
FALSE;
445 DiskDrive->IsRemovable =
FALSE;
448 else if (ScsiParameters)
455 DiskDrive->Geometry.Cylinders = 0xFFFF;
456 DiskDrive->Geometry.Heads = 0xFFFF;
457 DiskDrive->Geometry.Sectors = 0xFFFF;
458 DiskDrive->Geometry.BytesPerSector = 2048;
460 DiskDrive->LBASupported =
TRUE;
461 DiskDrive->IsRemovable =
TRUE;
466 DiskDrive->Geometry.Cylinders = 0xFFFF;
467 DiskDrive->Geometry.Heads = 8;
468 DiskDrive->Geometry.Sectors = 32;
469 DiskDrive->Geometry.BytesPerSector = 512;
471 DiskDrive->LBASupported =
TRUE;
472 DiskDrive->IsRemovable =
TRUE;
476 DiskDrive->Initialized =
FALSE;
482 DiskDrive->Initialized =
FALSE;
486 DiskDrive->DaUa = DaUa;
488 DiskDrive->Initialized =
TRUE;
490 TRACE(
"InitScsiDrive(0x%x) returned:\n"
493 "Sects/Track: 0x%x\n"
494 "Bytes/Sect : 0x%x\n",
496 DiskDrive->Geometry.Cylinders,
497 DiskDrive->Geometry.Heads,
498 DiskDrive->Geometry.Sectors,
499 DiskDrive->Geometry.BytesPerSector);
514 DiskDrive->Geometry.Cylinders = DeviceUnit->
Cylinders;
515 DiskDrive->Geometry.Heads = DeviceUnit->
Heads;
516 DiskDrive->Geometry.Sectors = DeviceUnit->
Sectors;
517 DiskDrive->Geometry.BytesPerSector = DeviceUnit->
SectorSize;
518 DiskDrive->DaUa = 0xFF;
519 DiskDrive->IdeUnitNumber = UnitNumber;
521 DiskDrive->LBASupported =
TRUE;
522 DiskDrive->IsRemovable =
TRUE;
523 DiskDrive->Initialized =
TRUE;
525 TRACE(
"InitIdeDrive(0x%x) returned:\n"
528 "Sects/Track: 0x%x\n"
529 "Bytes/Sect : 0x%x\n",
531 DiskDrive->Geometry.Cylinders,
532 DiskDrive->Geometry.Heads,
533 DiskDrive->Geometry.Sectors,
534 DiskDrive->Geometry.BytesPerSector);
539 DiskDrive->Initialized =
FALSE;
548 REGS RegsIn, RegsOut;
558 Int386(0x1B, &RegsIn, &RegsOut);
576 Int386(0x1B, &RegsIn, &RegsOut);
579 DiskDrive->Initialized =
FALSE;
583 DiskDrive->Geometry.Cylinders = RegsOut.
w.
cx;
584 DiskDrive->Geometry.Heads = RegsOut.
b.
dh;
585 DiskDrive->Geometry.Sectors = RegsOut.
b.
dl;
586 DiskDrive->Geometry.BytesPerSector = RegsOut.
w.
bx;
587 DiskDrive->DaUa = DaUa;
589 DiskDrive->LBASupported =
FALSE;
590 DiskDrive->IsRemovable =
FALSE;
591 DiskDrive->Initialized =
TRUE;
593 TRACE(
"InitHardDrive(0x%x) returned:\n"
596 "Sects/Track: 0x%x\n"
597 "Bytes/Sect : 0x%x\n",
599 DiskDrive->Geometry.Cylinders,
600 DiskDrive->Geometry.Heads,
601 DiskDrive->Geometry.Sectors,
602 DiskDrive->Geometry.BytesPerSector);
612 REGS RegsIn, RegsOut;
634 Int386(0x1B, &RegsIn, &RegsOut);
637 DiskDrive->Initialized =
FALSE;
641 BytesPerSector = 128 << RegsOut.
b.
ch;
642 switch (BytesPerSector)
648 DiskDrive->Geometry.Cylinders = 80;
649 DiskDrive->Geometry.Heads = 2;
650 DiskDrive->Geometry.Sectors = 16;
655 DiskDrive->Geometry.Cylinders = 77;
656 DiskDrive->Geometry.Heads = 2;
657 DiskDrive->Geometry.Sectors = 26;
665 DiskDrive->Geometry.Cylinders = 80;
666 DiskDrive->Geometry.Heads = 2;
667 DiskDrive->Geometry.Sectors = 18;
672 DiskDrive->Geometry.Cylinders = 80;
673 DiskDrive->Geometry.Heads = 2;
674 DiskDrive->Geometry.Sectors = 8;
679 DiskDrive->Geometry.Cylinders = 80;
680 DiskDrive->Geometry.Heads = 2;
681 DiskDrive->Geometry.Sectors = 15;
687 DiskDrive->Geometry.Cylinders = 77;
688 DiskDrive->Geometry.Heads = 2;
689 DiskDrive->Geometry.Sectors = 8;
693 DiskDrive->Initialized =
FALSE;
697 DiskDrive->Geometry.BytesPerSector = BytesPerSector;
698 DiskDrive->DaUa = DaUa;
700 DiskDrive->LBASupported =
FALSE;
701 DiskDrive->IsRemovable =
TRUE;
702 DiskDrive->Initialized =
TRUE;
704 TRACE(
"InitFloppyDrive(0x%x) returned:\n"
707 "Sects/Track: 0x%x\n"
708 "Bytes/Sect : 0x%x\n",
710 DiskDrive->Geometry.Cylinders,
711 DiskDrive->Geometry.Heads,
712 DiskDrive->Geometry.Sectors,
713 DiskDrive->Geometry.BytesPerSector);
723 UCHAR FakeFloppyDriveNumber = 0x30;
724 UCHAR FakeHardDriveDriveNumber = 0x80;
725 UCHAR FakeCdRomDriveNumber = 0xE0;
727 UCHAR IdeDetectedCount;
730 TRACE(
"Pc98InitializeBootDevices()\n");
743 for (
i = 0;
i < 4;
i++)
750 ++FakeFloppyDriveNumber;
754 for (
i = 0;
i < 4;
i++)
760 ++FakeFloppyDriveNumber;
764 for (
i = 0;
i < 4;
i++)
770 ++FakeFloppyDriveNumber;
776 for (
i = 0;
i < 4;
i++)
780 ++FakeHardDriveDriveNumber;
784 for (
i = 0;
i <= IdeDetectedCount;
i++)
788 ++FakeCdRomDriveNumber;
793 for (
i = 0;
i < 7;
i++)
803 ++FakeCdRomDriveNumber;
807 ++FakeHardDriveDriveNumber;
845 TRACE(
"Pc98DiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n",
858 TRACE(
"--> Using LBA\n");
864 TRACE(
"--> Using CHS\n");
874 TRACE(
"Pc98DiskGetDriveGeometry(0x%x)\n", DriveNumber);
#define DBG_DEFAULT_CHANNEL(ch)
VOID UiMessageBox(_In_ PCSTR Format,...)
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
_In_ PUSB_DEVICE_HANDLE _Out_ PUSHORT DeviceAddress
BOOLEAN PcInitializeBootDevices(VOID)
PDEVICE_UNIT AtaGetDevice(IN UCHAR UnitNumber)
BOOLEAN AtaAtapiReadLogicalSectorsLBA(IN OUT PDEVICE_UNIT DeviceUnit, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
BOOLEAN AtaInit(OUT PUCHAR DetectedCount)
_In_ NDIS_ERROR_CODE ErrorCode
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
ULONG Pc98DiskGetCacheableBlockCount(UCHAR DriveNumber)
static BOOLEAN InitHardDrive(IN UCHAR DaUa, IN OUT PPC98_DISK_DRIVE DiskDrive)
static PCSTR DiskGetErrorCodeString(ULONG ErrorCode)
PPC98_DISK_DRIVE Pc98DiskDriveNumberToDrive(IN UCHAR DriveNumber)
PC98_DISK_DRIVE Pc98DiskDrive[MAX_DRIVES]
static BOOLEAN Pc98DiskReadLogicalSectorsLBA(IN PPC98_DISK_DRIVE DiskDrive, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
BOOLEAN DiskResetController(IN PPC98_DISK_DRIVE DiskDrive)
LONG DiskReportError(BOOLEAN bShowError)
VOID Pc98DiskPrepareForReactOS(VOID)
BOOLEAN Pc98InitializeBootDevices(VOID)
static BOOLEAN InitFloppyDrive(IN UCHAR DaUa, IN OUT PPC98_DISK_DRIVE DiskDrive)
BOOLEAN Pc98DiskReadLogicalSectors(IN UCHAR DriveNumber, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
static BOOLEAN Pc98DiskReadLogicalSectorsCHS(IN PPC98_DISK_DRIVE DiskDrive, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
static BOOLEAN InitIdeDrive(IN UCHAR UnitNumber, IN OUT PPC98_DISK_DRIVE DiskDrive)
static BOOLEAN InitScsiDrive(IN UCHAR DaUa, IN OUT PPC98_DISK_DRIVE DiskDrive)
static UCHAR BytesPerSectorToSectorLengthCode(IN ULONG BytesPerSector)
BOOLEAN Pc98DiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry)
static VOID DiskError(PCSTR ErrorString, ULONG ErrorCode)
#define INT386_SUCCESS(regs)
int __cdecl Int386(int ivec, REGS *in, REGS *out)
#define RtlZeroMemory(Destination, Length)
#define SECONDBYTE(VALUE)