Merge freeldr from amd64 branch:
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / xboxdisk.c
index 45358cf..f9d991d 100644 (file)
@@ -288,11 +288,11 @@ XboxDiskPolledRead(ULONG CommandPort,
         }
       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;
     }
 
@@ -307,22 +307,22 @@ XboxDiskPolledRead(ULONG CommandPort,
   /*  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  */
@@ -411,7 +411,7 @@ XboxDiskPolledRead(ULONG CommandPort,
                {
                  if (SectorCount >= SectorCnt)
                    {
-                     DbgPrint((DPRINT_DISK, "Buffer size exceeded!\n"));
+                     DPRINTM(DPRINT_DISK, "Buffer size exceeded!\n");
                      Junk = TRUE;
                    }
                  break;
@@ -420,8 +420,8 @@ XboxDiskPolledRead(ULONG CommandPort,
                {
                  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);
@@ -443,13 +443,13 @@ XboxDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG Sect
   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;
     }
 
@@ -522,7 +522,7 @@ XboxDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
                            (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;
     }
 
@@ -537,27 +537,27 @@ XboxDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
     }
   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;
 }