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;
282 if (PhysicalSector > 1)
293 if ((PhysicalHead >= DriveGeometry.
Heads) ||
294 (PhysicalTrack >= DriveGeometry.
Cylinders) ||
295 ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.
SectorsPerTrack + 1)) ||
298 DiskError(
"Disk read exceeds drive geometry limits.", 0);
320 RegsIn.
b.
al = DiskDrive->DaUa;
323 RegsIn.
b.
cl = PhysicalTrack & 0xFFFF;
325 RegsIn.
b.
dl = PhysicalSector;
326 RegsIn.
b.
dh = PhysicalHead;
347 RegsIn.
b.
al = DiskDrive->DaUa;
350 RegsIn.
w.
cx = PhysicalTrack & 0xFFFF;
351 RegsIn.
b.
dl = PhysicalSector;
352 RegsIn.
b.
dh = PhysicalHead;
358 for (RetryCount = 0; RetryCount < 3; RetryCount++)
360 Int386(0x1B, &RegsIn, &RegsOut);
368 else if (RegsOut.
b.
ah == 0x08)
383 DiskError(
"Disk Read Failed in CHS mode, after retrying 3 times", RegsOut.
b.
ah);
384 ERR(
"Disk Read Failed in CHS mode, after retrying 3 times: %x (%s) (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n",
392 SectorNumber += NumberOfSectorsToRead;
403 REGS RegsIn, RegsOut;
404 UCHAR UnitAddress = DaUa & 0x0F;
410 if (DiskEquipment & (1 << UnitAddress))
428 Int386(0x1B, &RegsIn, &RegsOut);
431 DiskDrive->Initialized =
FALSE;
435 DiskDrive->Geometry.Cylinders = RegsOut.
w.
cx;
436 DiskDrive->Geometry.Heads = RegsOut.
b.
dh;
437 DiskDrive->Geometry.SectorsPerTrack = RegsOut.
b.
dl;
438 DiskDrive->Geometry.BytesPerSector = RegsOut.
w.
bx;
439 DiskDrive->LBASupported =
FALSE;
440 DiskDrive->IsRemovable =
FALSE;
443 else if (ScsiParameters)
450 DiskDrive->Geometry.Cylinders = 0xFFFF;
451 DiskDrive->Geometry.Heads = 0xFFFF;
452 DiskDrive->Geometry.SectorsPerTrack = 0xFFFF;
453 DiskDrive->Geometry.BytesPerSector = 2048;
455 DiskDrive->LBASupported =
TRUE;
456 DiskDrive->IsRemovable =
TRUE;
461 DiskDrive->Geometry.Cylinders = 0xFFFF;
462 DiskDrive->Geometry.Heads = 8;
463 DiskDrive->Geometry.SectorsPerTrack = 32;
464 DiskDrive->Geometry.BytesPerSector = 512;
466 DiskDrive->LBASupported =
TRUE;
467 DiskDrive->IsRemovable =
TRUE;
471 DiskDrive->Initialized =
FALSE;
477 DiskDrive->Initialized =
FALSE;
481 DiskDrive->Geometry.Sectors = (
ULONGLONG)DiskDrive->Geometry.Cylinders *
482 DiskDrive->Geometry.Heads *
483 DiskDrive->Geometry.SectorsPerTrack;
485 DiskDrive->DaUa = DaUa;
487 DiskDrive->Initialized =
TRUE;
489 TRACE(
"InitScsiDrive(0x%x) returned:\n"
492 "Sects/Track: 0x%x\n"
493 "Bytes/Sect : 0x%x\n",
495 DiskDrive->Geometry.Cylinders,
496 DiskDrive->Geometry.Heads,
497 DiskDrive->Geometry.SectorsPerTrack,
498 DiskDrive->Geometry.BytesPerSector);
513 DiskDrive->Geometry.Cylinders = DeviceUnit->
Cylinders;
514 DiskDrive->Geometry.Heads = DeviceUnit->
Heads;
515 DiskDrive->Geometry.SectorsPerTrack = DeviceUnit->
Sectors;
516 DiskDrive->Geometry.BytesPerSector = DeviceUnit->
SectorSize;
519 DiskDrive->DaUa = 0xFF;
520 DiskDrive->IdeUnitNumber = UnitNumber;
522 DiskDrive->LBASupported =
TRUE;
523 DiskDrive->IsRemovable =
TRUE;
524 DiskDrive->Initialized =
TRUE;
526 TRACE(
"InitIdeDrive(0x%x) returned:\n"
529 "Sects/Track: 0x%x\n"
530 "Bytes/Sect : 0x%x\n",
532 DiskDrive->Geometry.Cylinders,
533 DiskDrive->Geometry.Heads,
534 DiskDrive->Geometry.SectorsPerTrack,
535 DiskDrive->Geometry.BytesPerSector);
540 DiskDrive->Initialized =
FALSE;
549 REGS RegsIn, RegsOut;
559 Int386(0x1B, &RegsIn, &RegsOut);
577 Int386(0x1B, &RegsIn, &RegsOut);
580 DiskDrive->Initialized =
FALSE;
584 DiskDrive->Geometry.Cylinders = RegsOut.
w.
cx;
585 DiskDrive->Geometry.Heads = RegsOut.
b.
dh;
586 DiskDrive->Geometry.SectorsPerTrack = RegsOut.
b.
dl;
587 DiskDrive->Geometry.BytesPerSector = RegsOut.
w.
bx;
589 DiskDrive->Geometry.Sectors = (
ULONGLONG)DiskDrive->Geometry.Cylinders *
590 DiskDrive->Geometry.Heads *
591 DiskDrive->Geometry.SectorsPerTrack;
593 DiskDrive->DaUa = DaUa;
595 DiskDrive->LBASupported =
FALSE;
596 DiskDrive->IsRemovable =
FALSE;
597 DiskDrive->Initialized =
TRUE;
599 TRACE(
"InitHardDrive(0x%x) returned:\n"
602 "Sects/Track: 0x%x\n"
603 "Bytes/Sect : 0x%x\n",
605 DiskDrive->Geometry.Cylinders,
606 DiskDrive->Geometry.Heads,
607 DiskDrive->Geometry.SectorsPerTrack,
608 DiskDrive->Geometry.BytesPerSector);
618 REGS RegsIn, RegsOut;
640 Int386(0x1B, &RegsIn, &RegsOut);
643 DiskDrive->Initialized =
FALSE;
647 BytesPerSector = 128 << RegsOut.
b.
ch;
648 switch (BytesPerSector)
654 DiskDrive->Geometry.Cylinders = 80;
655 DiskDrive->Geometry.Heads = 2;
656 DiskDrive->Geometry.SectorsPerTrack = 16;
661 DiskDrive->Geometry.Cylinders = 77;
662 DiskDrive->Geometry.Heads = 2;
663 DiskDrive->Geometry.SectorsPerTrack = 26;
671 DiskDrive->Geometry.Cylinders = 80;
672 DiskDrive->Geometry.Heads = 2;
673 DiskDrive->Geometry.SectorsPerTrack = 18;
678 DiskDrive->Geometry.Cylinders = 80;
679 DiskDrive->Geometry.Heads = 2;
680 DiskDrive->Geometry.SectorsPerTrack = 8;
685 DiskDrive->Geometry.Cylinders = 80;
686 DiskDrive->Geometry.Heads = 2;
687 DiskDrive->Geometry.SectorsPerTrack = 15;
693 DiskDrive->Geometry.Cylinders = 77;
694 DiskDrive->Geometry.Heads = 2;
695 DiskDrive->Geometry.SectorsPerTrack = 8;
699 DiskDrive->Initialized =
FALSE;
703 DiskDrive->Geometry.BytesPerSector = BytesPerSector;
704 DiskDrive->Geometry.Sectors = (
ULONGLONG)DiskDrive->Geometry.Cylinders *
705 DiskDrive->Geometry.Heads *
706 DiskDrive->Geometry.SectorsPerTrack;
708 DiskDrive->DaUa = DaUa;
710 DiskDrive->LBASupported =
FALSE;
711 DiskDrive->IsRemovable =
TRUE;
712 DiskDrive->Initialized =
TRUE;
714 TRACE(
"InitFloppyDrive(0x%x) returned:\n"
717 "Sects/Track: 0x%x\n"
718 "Bytes/Sect : 0x%x\n",
720 DiskDrive->Geometry.Cylinders,
721 DiskDrive->Geometry.Heads,
722 DiskDrive->Geometry.SectorsPerTrack,
723 DiskDrive->Geometry.BytesPerSector);
733 UCHAR FakeFloppyDriveNumber = 0x30;
734 UCHAR FakeHardDriveDriveNumber = 0x80;
735 UCHAR FakeCdRomDriveNumber = 0xE0;
737 UCHAR IdeDetectedCount;
740 TRACE(
"Pc98InitializeBootDevices()\n");
753 for (
i = 0;
i < 4;
i++)
760 ++FakeFloppyDriveNumber;
764 for (
i = 0;
i < 4;
i++)
770 ++FakeFloppyDriveNumber;
774 for (
i = 0;
i < 4;
i++)
780 ++FakeFloppyDriveNumber;
786 for (
i = 0;
i < 4;
i++)
790 ++FakeHardDriveDriveNumber;
794 for (
i = 0;
i <= IdeDetectedCount;
i++)
798 ++FakeCdRomDriveNumber;
803 for (
i = 0;
i < 7;
i++)
813 ++FakeCdRomDriveNumber;
817 ++FakeHardDriveDriveNumber;
855 TRACE(
"Pc98DiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n",
868 TRACE(
"--> Using LBA\n");
874 TRACE(
"--> Using CHS\n");
884 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)
ULONG BytesPerSector
Number of bytes per sector.
ULONG Cylinders
Number of cylinders on the disk.
ULONG SectorsPerTrack
Number of sectors per track.
ULONG Heads
Number of heads on the disk.
#define RtlZeroMemory(Destination, Length)
#define SECONDBYTE(VALUE)